gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r2911 - in freeway/src/org/gnu/freeway: . cwrappers service


From: mdonoughe
Subject: [GNUnet-SVN] r2911 - in freeway/src/org/gnu/freeway: . cwrappers services
Date: Fri, 26 May 2006 17:24:29 -0700 (PDT)

Author: mdonoughe
Date: 2006-05-26 17:24:25 -0700 (Fri, 26 May 2006)
New Revision: 2911

Added:
   freeway/src/org/gnu/freeway/cwrappers/CLong.java
   freeway/src/org/gnu/freeway/cwrappers/CString.java
   freeway/src/org/gnu/freeway/cwrappers/ConstCLong.java
   freeway/src/org/gnu/freeway/cwrappers/ConstCString.java
   freeway/src/org/gnu/freeway/services/
   freeway/src/org/gnu/freeway/services/StatsService.java
Log:
The StatsService interface and the CWrappers still needed to support it
Wrappers are untested, but look okay



Added: freeway/src/org/gnu/freeway/cwrappers/CLong.java
===================================================================
--- freeway/src/org/gnu/freeway/cwrappers/CLong.java    2006-05-26 21:20:19 UTC 
(rev 2910)
+++ freeway/src/org/gnu/freeway/cwrappers/CLong.java    2006-05-27 00:24:25 UTC 
(rev 2911)
@@ -0,0 +1,43 @@
+ /*
+      This file is part of Freeway
+
+      Freeway is free software; you can redistribute it and/or modify
+      it under the terms of the GNU General Public License as published
+      by the Free Software Foundation; either version 2, or (at your
+      option) any later version.
+
+      Freeway is distributed in the hope that it will be useful, but
+      WITHOUT ANY WARRANTY; without even the implied warranty of
+      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+      General Public License for more details.
+
+      You should have received a copy of the GNU General Public License
+      along with Freeway; see the file COPYING.  If not, write to the
+      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+      Boston, MA 02111-1307, USA.
+ */
+
+package org.gnu.freeway.cwrappers;
+
+import org.gnu.freeway.cwrappers.util.CWrapper;
+
+/**
+ * @file freeway/src/org/gnu/freeway/cwrappers/CLong.java
+ * @brief A wrapper for using long long values with JNI
+ * @author mdonoughe
+ */
+public class CLong extends ConstCLong implements CWrapper {
+
+       public CLong(long value) {
+               super(value);
+       }
+
+       public void deserializeFromByteArray(byte[] serializedData) {
+               // those bitmasks seem to keep the sign bit from moving around
+               value = ((serializedData[0] & 0xffl) << 56) | 
((serializedData[1] & 0xffl) << 48) | ((serializedData[2] & 0xffl) << 40) | 
((serializedData[3] & 0xffl) << 32) | ((serializedData[4] & 0xffl) << 24) | 
((serializedData[5] & 0xffl) << 16) | ((serializedData[6] & 0xffl) << 8) | 
((serializedData[7] & 0xffl));
+       }
+       
+       public void setValue(long value) {
+               this.value = value;
+       }
+}

Added: freeway/src/org/gnu/freeway/cwrappers/CString.java
===================================================================
--- freeway/src/org/gnu/freeway/cwrappers/CString.java  2006-05-26 21:20:19 UTC 
(rev 2910)
+++ freeway/src/org/gnu/freeway/cwrappers/CString.java  2006-05-27 00:24:25 UTC 
(rev 2911)
@@ -0,0 +1,51 @@
+ /*
+      This file is part of Freeway
+
+      Freeway is free software; you can redistribute it and/or modify
+      it under the terms of the GNU General Public License as published
+      by the Free Software Foundation; either version 2, or (at your
+      option) any later version.
+
+      Freeway is distributed in the hope that it will be useful, but
+      WITHOUT ANY WARRANTY; without even the implied warranty of
+      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+      General Public License for more details.
+
+      You should have received a copy of the GNU General Public License
+      along with Freeway; see the file COPYING.  If not, write to the
+      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+      Boston, MA 02111-1307, USA.
+ */
+
+package org.gnu.freeway.cwrappers;
+
+import org.gnu.freeway.cwrappers.util.CWrapper;
+import java.io.UnsupportedEncodingException;
+
+/**
+ * @file CString.java
+ * @brief A class used to move Strings in and out of native code
+ * @author mdonoughe
+ */
+public class CString extends ConstCString implements CWrapper {
+
+       public CString(String value) {
+               super(value);
+       }
+       
+       /* (non-Javadoc)
+        * @see 
org.gnu.freeway.cwrappers.util.CWrapper#deserializeFromByteArray(byte[])
+        */
+       public void deserializeFromByteArray(byte[] serializedData) {
+               try {
+                       value = new String(serializedData, 0, 
getSerializedSize(), "UTF-8");
+               } catch(UnsupportedEncodingException e) {
+                       //TODO: define this behavior
+               }
+       }
+       
+       public void setValue(String value) {
+               this.value = value;
+       }
+
+}

Added: freeway/src/org/gnu/freeway/cwrappers/ConstCLong.java
===================================================================
--- freeway/src/org/gnu/freeway/cwrappers/ConstCLong.java       2006-05-26 
21:20:19 UTC (rev 2910)
+++ freeway/src/org/gnu/freeway/cwrappers/ConstCLong.java       2006-05-27 
00:24:25 UTC (rev 2911)
@@ -0,0 +1,51 @@
+ /*
+      This file is part of Freeway
+
+      Freeway is free software; you can redistribute it and/or modify
+      it under the terms of the GNU General Public License as published
+      by the Free Software Foundation; either version 2, or (at your
+      option) any later version.
+
+      Freeway is distributed in the hope that it will be useful, but
+      WITHOUT ANY WARRANTY; without even the implied warranty of
+      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+      General Public License for more details.
+
+      You should have received a copy of the GNU General Public License
+      along with Freeway; see the file COPYING.  If not, write to the
+      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+      Boston, MA 02111-1307, USA.
+ */
+
+package org.gnu.freeway.cwrappers;
+
+import org.gnu.freeway.cwrappers.util.ConstCWrapper;
+
+/**
+ * @file freeway/src/org/gnu/freeway/cwrappers/ConstCLong.java
+ * @brief A wrapper for using constant long long values with JNI
+ * @author mdonoughe
+ */
+public class ConstCLong implements ConstCWrapper {
+
+       protected long value;
+       
+       public ConstCLong(long value) {
+               this.value = value;
+       }
+       
+       /**
+        * Returns a byte array containing the long in big endian format
+        */
+       public byte[] serializeToByteArray() {
+               return new byte[] {(byte) (value >> 56), (byte) (value >> 48), 
(byte) (value >> 40), (byte) (value >> 32), (byte) (value >> 24), (byte) (value 
>> 16), (byte) (value >> 8), (byte) value};
+       }
+
+       public long getValue() {
+               return value;
+       }
+
+       public int getSerializedSize() {
+               return 8;
+       }
+}

Added: freeway/src/org/gnu/freeway/cwrappers/ConstCString.java
===================================================================
--- freeway/src/org/gnu/freeway/cwrappers/ConstCString.java     2006-05-26 
21:20:19 UTC (rev 2910)
+++ freeway/src/org/gnu/freeway/cwrappers/ConstCString.java     2006-05-27 
00:24:25 UTC (rev 2911)
@@ -0,0 +1,71 @@
+ /*
+      This file is part of Freeway
+
+      Freeway is free software; you can redistribute it and/or modify
+      it under the terms of the GNU General Public License as published
+      by the Free Software Foundation; either version 2, or (at your
+      option) any later version.
+
+      Freeway is distributed in the hope that it will be useful, but
+      WITHOUT ANY WARRANTY; without even the implied warranty of
+      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+      General Public License for more details.
+
+      You should have received a copy of the GNU General Public License
+      along with Freeway; see the file COPYING.  If not, write to the
+      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+      Boston, MA 02111-1307, USA.
+ */
+
+package org.gnu.freeway.cwrappers;
+
+import org.gnu.freeway.cwrappers.util.ConstCWrapper;
+import java.io.UnsupportedEncodingException;
+import java.lang.reflect.Array;
+
+/**
+ * @file ConstCString.java
+ * @brief A class used to get Strings in and out of JNI
+ * @author mdonoughe
+ */
+public class ConstCString implements ConstCWrapper {
+
+       protected String value;
+       
+       public ConstCString(String value) {
+               this.value = value;
+       }
+       
+       /* (non-Javadoc)
+        * @see 
org.gnu.freeway.cwrappers.util.ConstCWrapper#serializeToByteArray()
+        */
+       public byte[] serializeToByteArray() {
+               byte[] string = {};
+               try {
+                       string = value.getBytes("UTF-8");
+               } catch(UnsupportedEncodingException e) {
+                       //TODO: what happens here?
+               }
+               string = (byte[]) 
Array.newInstance(string.getClass().getComponentType(), string.length + 1);
+               string[string.length - 1] = 0;
+               return string;
+       }
+
+       /* (non-Javadoc)
+        * @see org.gnu.freeway.cwrappers.util.ConstCWrapper#getSerializedSize()
+        */
+       public int getSerializedSize() {
+               byte[] string = {};
+               try {
+                       string = value.getBytes("UTF-8");
+               } catch(UnsupportedEncodingException e) {
+                       //TODO: what happens here?
+               }
+               return string.length + 1;
+       }
+       
+       public String getValue() {
+               return value;
+       }
+
+}

Added: freeway/src/org/gnu/freeway/services/StatsService.java
===================================================================
--- freeway/src/org/gnu/freeway/services/StatsService.java      2006-05-26 
21:20:19 UTC (rev 2910)
+++ freeway/src/org/gnu/freeway/services/StatsService.java      2006-05-27 
00:24:25 UTC (rev 2911)
@@ -0,0 +1,35 @@
+ /*
+      This file is part of Freeway
+
+      Freeway is free software; you can redistribute it and/or modify
+      it under the terms of the GNU General Public License as published
+      by the Free Software Foundation; either version 2, or (at your
+      option) any later version.
+
+      Freeway is distributed in the hope that it will be useful, but
+      WITHOUT ANY WARRANTY; without even the implied warranty of
+      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+      General Public License for more details.
+
+      You should have received a copy of the GNU General Public License
+      along with Freeway; see the file COPYING.  If not, write to the
+      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+      Boston, MA 02111-1307, USA.
+ */
+
+package org.gnu.freeway.services;
+import org.gnu.freeway.cwrappers.ConstCString;
+import org.gnu.freeway.cwrappers.ConstCInt;
+import org.gnu.freeway.cwrappers.ConstCLong;
+import org.gnu.freeway.cwrappers.CLong;
+
+/**
+ * @file StatsService.java
+ * @brief 
+ * @author mdonoughe
+ */
+public interface StatsService {
+       public int create(ConstCString name);
+       public void set(ConstCInt handle, ConstCLong value);
+       public CLong get(ConstCInt handle); //cannot return a constant type 
because those can't be deserialized
+}





reply via email to

[Prev in Thread] Current Thread [Next in Thread]