[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r2919 - in freeway: native src/org/gnu/freeway/server
From: |
mdonoughe |
Subject: |
[GNUnet-SVN] r2919 - in freeway: native src/org/gnu/freeway/server |
Date: |
Sun, 28 May 2006 10:04:14 -0700 (PDT) |
Author: mdonoughe
Date: 2006-05-28 10:04:09 -0700 (Sun, 28 May 2006)
New Revision: 2919
Added:
freeway/src/org/gnu/freeway/server/CPluginLoaderTest.java
Modified:
freeway/native/org_gnu_freeway_server_CPluginLoader.c
freeway/native/org_gnu_freeway_server_CPluginLoader.h
freeway/src/org/gnu/freeway/server/CPluginLoader.java
freeway/src/org/gnu/freeway/server/CoreAPI.java
Log:
CoreAPI is now a singleton(but still does nothing)
CPluginLoader's functions are now static and have public counterparts
added a test for CPluginLoader
CPluginLoader.c has code, but it does not work. I'm not sure if this is
the correct direction to be headed, so I am commiting and waiting for
feedback.
Modified: freeway/native/org_gnu_freeway_server_CPluginLoader.c
===================================================================
--- freeway/native/org_gnu_freeway_server_CPluginLoader.c 2006-05-28
03:47:54 UTC (rev 2918)
+++ freeway/native/org_gnu_freeway_server_CPluginLoader.c 2006-05-28
17:04:09 UTC (rev 2919)
@@ -23,22 +23,37 @@
* @author mdonoughe
**/
+#include <stdio.h>
#include <jni.h>
#include <GNUnet/gnunet_util.h>
#include "org_gnu_freeway_server_CPluginLoader.h"
-JNIEXPORT jlong JNICALL Java_org_gnu_freeway_server_CPluginLoader_loadService
+#define DSO_PREFIX "libgnunet" // from GNUnet's core.c
+
+JNIEXPORT jlong JNICALL Java_org_gnu_freeway_server_CPluginLoader_cLoadService
(JNIEnv *env, jobject cls, jstring serviceName, jobject capi) {
- return 0;
+ const char *strServiceName;
+ void *modulePtr;
+ strServiceName = (*env)->GetStringUTFChars(env, serviceName, NULL);
+ if(!strServiceName)
+ return 0;
+ //fprintf(stderr, "%s", strServiceName);
+ modulePtr = loadDynamicLibrary(DSO_PREFIX, strServiceName);
+ if(!modulePtr) {
+ jclass UnsatisfiedLinkError = (*env)->FindClass(env,
"java/lang/UnsatisfiedLinkError");
+ if(UnsatisfiedLinkError)
+ (*env)->ThrowNew(env, UnsatisfiedLinkError,
strServiceName);
+ }
+ return modulePtr;
}
-JNIEXPORT jobject JNICALL Java_org_gnu_freeway_server_CPluginLoader_callC
+JNIEXPORT jobject JNICALL Java_org_gnu_freeway_server_CPluginLoader_cCallC
(JNIEnv *env, jobject cls, jlong modulePtr, jint functionOffset,
jobjectArray arguments, jint callType) {
return 0;
}
-JNIEXPORT void JNICALL Java_org_gnu_freeway_server_CPluginLoader_unloadService
+JNIEXPORT void JNICALL Java_org_gnu_freeway_server_CPluginLoader_cUnloadService
(JNIEnv *env, jobject cls, jlong modulePtr) {
-
+ unloadDynamicLibrary(modulePtr);
}
Modified: freeway/native/org_gnu_freeway_server_CPluginLoader.h
===================================================================
--- freeway/native/org_gnu_freeway_server_CPluginLoader.h 2006-05-28
03:47:54 UTC (rev 2918)
+++ freeway/native/org_gnu_freeway_server_CPluginLoader.h 2006-05-28
17:04:09 UTC (rev 2919)
@@ -9,26 +9,26 @@
#endif
/*
* Class: org_gnu_freeway_server_CPluginLoader
- * Method: loadService
+ * Method: cLoadService
* Signature: (Ljava/lang/String;Lorg/gnu/freeway/server/CoreAPI;)J
*/
-JNIEXPORT jlong JNICALL Java_org_gnu_freeway_server_CPluginLoader_loadService
+JNIEXPORT jlong JNICALL Java_org_gnu_freeway_server_CPluginLoader_cLoadService
(JNIEnv *, jobject, jstring, jobject);
/*
* Class: org_gnu_freeway_server_CPluginLoader
- * Method: callC
+ * Method: cCallC
* Signature: (JI[Ljava/lang/Object;I)Ljava/lang/Object;
*/
-JNIEXPORT jobject JNICALL Java_org_gnu_freeway_server_CPluginLoader_callC
+JNIEXPORT jobject JNICALL Java_org_gnu_freeway_server_CPluginLoader_cCallC
(JNIEnv *, jobject, jlong, jint, jobjectArray, jint);
/*
* Class: org_gnu_freeway_server_CPluginLoader
- * Method: unloadService
+ * Method: cUnloadService
* Signature: (J)V
*/
-JNIEXPORT void JNICALL Java_org_gnu_freeway_server_CPluginLoader_unloadService
+JNIEXPORT void JNICALL Java_org_gnu_freeway_server_CPluginLoader_cUnloadService
(JNIEnv *, jobject, jlong);
#ifdef __cplusplus
Modified: freeway/src/org/gnu/freeway/server/CPluginLoader.java
===================================================================
--- freeway/src/org/gnu/freeway/server/CPluginLoader.java 2006-05-28
03:47:54 UTC (rev 2918)
+++ freeway/src/org/gnu/freeway/server/CPluginLoader.java 2006-05-28
17:04:09 UTC (rev 2919)
@@ -25,7 +25,25 @@
* @author mdonoughe
*/
public class CPluginLoader {
- private native long loadService(String serviceName, CoreAPI capi);
- private native Object callC(long modulePtr, int functionOffset,
Object[] arguments, int callType);
- private native void unloadService(long modulePtr);
+
+ static {
+ try {
+
System.loadLibrary("org_gnu_freeway_server_CPluginLoader");
+ } catch(UnsatisfiedLinkError e) {
+
System.err.println("liborg_gnu_freeway_server_CPluginLoader was not found.");
+ }
+ }
+
+ 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 Object callC(long modulePtr, int functionOffset, Object[]
arguments, int callType) {
+ return cCallC(modulePtr, functionOffset, arguments, callType);
+ }
+ public static void unloadService(long modulePtr) {
+ cUnloadService(modulePtr);
+ }
}
Added: freeway/src/org/gnu/freeway/server/CPluginLoaderTest.java
===================================================================
--- freeway/src/org/gnu/freeway/server/CPluginLoaderTest.java 2006-05-28
03:47:54 UTC (rev 2918)
+++ freeway/src/org/gnu/freeway/server/CPluginLoaderTest.java 2006-05-28
17:04:09 UTC (rev 2919)
@@ -0,0 +1,20 @@
+package org.gnu.freeway.server;
+
+import junit.framework.TestCase;
+import junit.textui.TestRunner;
+
+public class CPluginLoaderTest extends TestCase {
+
+ public void testService() {
+ long modulePtr = CPluginLoader.loadService("module_chat",
CoreAPI.getInstance());
+ assertFalse(modulePtr == 0);
+ CPluginLoader.unloadService(modulePtr);
+ }
+
+
+
+ public static void main(String[] args) {
+ TestRunner.run(CPluginLoaderTest.class);
+ }
+
+}
Modified: freeway/src/org/gnu/freeway/server/CoreAPI.java
===================================================================
--- freeway/src/org/gnu/freeway/server/CoreAPI.java 2006-05-28 03:47:54 UTC
(rev 2918)
+++ freeway/src/org/gnu/freeway/server/CoreAPI.java 2006-05-28 17:04:09 UTC
(rev 2919)
@@ -25,5 +25,16 @@
* @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() {
+
+ }
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r2919 - in freeway: native src/org/gnu/freeway/server,
mdonoughe <=