[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r2925 - in freeway/src/org/gnu/freeway: cwrappers server
From: |
mdonoughe |
Subject: |
[GNUnet-SVN] r2925 - in freeway/src/org/gnu/freeway: cwrappers server |
Date: |
Sun, 28 May 2006 11:59:31 -0700 (PDT) |
Author: mdonoughe
Date: 2006-05-28 11:59:27 -0700 (Sun, 28 May 2006)
New Revision: 2925
Added:
freeway/src/org/gnu/freeway/cwrappers/CLibraryHandle.java
Modified:
freeway/src/org/gnu/freeway/server/CPluginLoader.java
freeway/src/org/gnu/freeway/server/CPluginLoaderTest.java
freeway/src/org/gnu/freeway/server/CoreAPI.java
Log:
CoreAPI is more compact
C pointers from CPluginLoader are now kept in CLibraryHandle objects
CPluginLoader throws NullPointerExceptions instead of causing null
pointer exceptions in the C code
Added: freeway/src/org/gnu/freeway/cwrappers/CLibraryHandle.java
===================================================================
--- freeway/src/org/gnu/freeway/cwrappers/CLibraryHandle.java 2006-05-28
18:34:19 UTC (rev 2924)
+++ freeway/src/org/gnu/freeway/cwrappers/CLibraryHandle.java 2006-05-28
18:59:27 UTC (rev 2925)
@@ -0,0 +1,32 @@
+ /*
+ 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;
+
+/**
+ * @file CLibraryHandle.java
+ * @brief
+ * @author mdonoughe
+ */
+public class CLibraryHandle {
+ public final long _;
+ public CLibraryHandle(long value) {
+ _ = value;
+ }
+}
Modified: freeway/src/org/gnu/freeway/server/CPluginLoader.java
===================================================================
--- freeway/src/org/gnu/freeway/server/CPluginLoader.java 2006-05-28
18:34:19 UTC (rev 2924)
+++ freeway/src/org/gnu/freeway/server/CPluginLoader.java 2006-05-28
18:59:27 UTC (rev 2925)
@@ -17,8 +17,11 @@
Boston, MA 02111-1307, USA.
*/
+
package org.gnu.freeway.server;
+import org.gnu.freeway.cwrappers.CLibraryHandle;
+
/**
* @file CPluginLoader.java
* @brief
@@ -27,23 +30,25 @@
public class CPluginLoader {
static {
- try {
-
System.loadLibrary("org_gnu_freeway_server_CPluginLoader");
- } catch(UnsatisfiedLinkError e) {
-
System.err.println("liborg_gnu_freeway_server_CPluginLoader was not found.");
- }
+ System.loadLibrary("org_gnu_freeway_server_CPluginLoader");
}
private static native long cLoadService(String serviceName, CoreAPI
capi);
private static native Object cCallC(long modulePtr, int functionOffset,
Object[] arguments, int callType);
private static native void cUnloadService(long modulePtr);
- public static long loadService(String serviceName, CoreAPI capi) {
- return cLoadService(serviceName, capi);
+ public static CLibraryHandle loadService(String serviceName, CoreAPI
capi) {
+ if(serviceName == null || capi == null)
+ throw new NullPointerException();
+ return new CLibraryHandle(cLoadService(serviceName, capi));
}
- public static Object callC(long modulePtr, int functionOffset, Object[]
arguments, int callType) {
- return cCallC(modulePtr, functionOffset, arguments, callType);
+ public static Object callC(CLibraryHandle modulePtr, int
functionOffset, Object[] arguments, int callType) {
+ if(modulePtr._ == 0)
+ throw new NullPointerException();
+ return cCallC(modulePtr._, functionOffset, arguments, callType);
}
- public static void unloadService(long modulePtr) {
- cUnloadService(modulePtr);
+ public static void unloadService(CLibraryHandle modulePtr) {
+ if(modulePtr._ == 0)
+ throw new NullPointerException();
+ cUnloadService(modulePtr._);
}
}
Modified: freeway/src/org/gnu/freeway/server/CPluginLoaderTest.java
===================================================================
--- freeway/src/org/gnu/freeway/server/CPluginLoaderTest.java 2006-05-28
18:34:19 UTC (rev 2924)
+++ freeway/src/org/gnu/freeway/server/CPluginLoaderTest.java 2006-05-28
18:59:27 UTC (rev 2925)
@@ -2,12 +2,13 @@
import junit.framework.TestCase;
import junit.textui.TestRunner;
+import org.gnu.freeway.cwrappers.CLibraryHandle;
public class CPluginLoaderTest extends TestCase {
public void testService() {
- long modulePtr = CPluginLoader.loadService("module_chat",
CoreAPI.getInstance());
- assertFalse(modulePtr == 0);
+ CLibraryHandle modulePtr =
CPluginLoader.loadService("module_chat", CoreAPI._);
+ assertFalse(modulePtr._ == 0);
CPluginLoader.unloadService(modulePtr);
}
Modified: freeway/src/org/gnu/freeway/server/CoreAPI.java
===================================================================
--- freeway/src/org/gnu/freeway/server/CoreAPI.java 2006-05-28 18:34:19 UTC
(rev 2924)
+++ freeway/src/org/gnu/freeway/server/CoreAPI.java 2006-05-28 18:59:27 UTC
(rev 2925)
@@ -25,16 +25,8 @@
* @author mdonoughe
*/
public class CoreAPI {
- static CoreAPI instance;
- public static void initialize() {
- instance = new CoreAPI();
- }
- public static CoreAPI getInstance() {
- if(instance == null)
- initialize();
- return instance;
- }
- protected CoreAPI() {
+ public static final CoreAPI _ = new CoreAPI();
+ private CoreAPI() {
}
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r2925 - in freeway/src/org/gnu/freeway: cwrappers server,
mdonoughe <=