[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r2944 - in freeway: native src/org/gnu/freeway/server
From: |
mdonoughe |
Subject: |
[GNUnet-SVN] r2944 - in freeway: native src/org/gnu/freeway/server |
Date: |
Wed, 31 May 2006 12:05:32 -0700 (PDT) |
Author: mdonoughe
Date: 2006-05-31 12:05:27 -0700 (Wed, 31 May 2006)
New Revision: 2944
Added:
freeway/native/org_gnu_freeway_server_CPluginLoader_Handle.h
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/CPluginLoaderTest.java
freeway/src/org/gnu/freeway/server/CoreAPI.java
Log:
Work in progress implementing requestService.
org_gnu_freeway_server_CPluginLoader.c:90 fails
cannot find org/gnu/freeway/server/CPluginLoader/Handle?
Modified: freeway/native/org_gnu_freeway_server_CPluginLoader.c
===================================================================
--- freeway/native/org_gnu_freeway_server_CPluginLoader.c 2006-05-30
19:27:32 UTC (rev 2943)
+++ freeway/native/org_gnu_freeway_server_CPluginLoader.c 2006-05-31
19:05:27 UTC (rev 2944)
@@ -58,14 +58,53 @@
+static int convCIntToInt(jobject input, JNIEnv * env);
+static jobject convJStringToCString(jstring input, JNIEnv * env);
+static void * jrequestService(const char * name) {
+fprintf(stderr, "in jrequestService\n");
+ ModuleList * pos;
+ jstring mname;
+ jmethodID method;
+ jclass capiClazz;
+ JNIEnv * env;
+ jobject retHandle;
+ jlong ret;
+
+ pos = modules;
+ while (pos != NULL) {
+ if (PTHREAD_SELF_TEST(&pos->thread))
+ break;
+ pos = pos->next;
+ }
+ if (pos == NULL)
+ errexit(_("Thread creation in C modules not supported by Freeway.\n"));
+ env = pos->env;
+ GNUNET_ASSERT(env != NULL);
+ mname = (*env)->NewStringUTF(env, name);
+ GNUNET_ASSERT(mname != 0);
+ capiClazz = (*env)->GetObjectClass(env, pos->jcapi);
+ GNUNET_ASSERT(capiClazz != 0);
+// next line does not work
+ method = (*env)->GetMethodID(env, capiClazz, "requestService",
"(Lorg/gnu/freeway/cwrappers/CString;)Lorg/gnu/freeway/server/CPluginLoader.Handle;");
+ GNUNET_ASSERT(method != 0);
+ retHandle = (*env)->CallObjectMethod(env, pos->jcapi, method,
convJStringToCString(mname, env));
+ jfieldID handle_ = (*env)->GetFieldID(env, (*env)->GetObjectClass(env,
retHandle), "_", "J");
+ if(handle_ == NULL)
+ return 0;
+ ret = (*env)->GetLongField(env, retHandle, handle_);
+fprintf(stderr, "leaving jrequestService\n");
+ return ret;
+}
+
static int jloadApplicationModule(const char * name) {
+fprintf(stderr, "in jloadApplicationModule\n");
ModuleList * pos;
jstring mname;
jmethodID method;
jclass capiClazz;
JNIEnv * env;
- jint ret;
+ jobject ret;
pos = modules;
while (pos != NULL) {
@@ -81,18 +120,53 @@
GNUNET_ASSERT(mname != 0);
capiClazz = (*env)->GetObjectClass(env, pos->jcapi);
GNUNET_ASSERT(capiClazz != 0);
- method = (*env)->GetMethodID(env, capiClazz, "loadApplicationModule",
"FIXME-SIGNATURE");
+ method = (*env)->GetMethodID(env, capiClazz, "loadApplicationModule",
"(Lorg/gnu/freeway/cwrappers/CString;)Lorg/gnu/freeway/cwrappers/CInt;");
GNUNET_ASSERT(method != 0);
- ret = (*env)->CallIntMethod(env, pos->jcapi, method, mname);
- return (int) ret;
+ ret = (*env)->CallObjectMethod(env, pos->jcapi, method,
convJStringToCString(mname, env));
+fprintf(stderr, "leaving jloadApplicationModule\n");
+ return convCIntToInt(ret, env);
}
+static int convCIntToInt(jobject input, JNIEnv * env) {
+fprintf(stderr, "in convCIntToInt\n");
+ jclass classCInt;
+ jmethodID method;
+
+ if(input == NULL)
+ return 0;
+ classCInt = (*env)->FindClass(env, "org/gnu/freeway/cwrappers/CInt");
+ if(classCInt == NULL)
+ return 0;
+ method = (*env)->GetMethodID(env, classCInt, "getValue", "()I");
+ if(method == NULL)
+ return 0;
+fprintf(stderr, "leaving convCIntToInt\n");
+ return (*env)->CallIntMethod(env, input, method);
+}
+static jobject convJStringToCString(jstring input, JNIEnv * env) {
+fprintf(stderr, "in convJStringToCString\n");
+ jclass classCString;
+ jmethodID method;
+
+ if(input == NULL)
+ return NULL;
+ classCString = (*env)->FindClass(env,
"org/gnu/freeway/cwrappers/CString");
+ if(classCString == NULL)
+ return NULL;
+ method = (*env)->GetMethodID(env, classCString, "<init>",
"(Ljava/lang/String;)V");
+ if(method == NULL)
+ return NULL;
+fprintf(stderr, "leaving convJStringToCString\n");
+ return (*env)->NewObject(env, classCString, method, input);
+}
+
static CoreAPIForApplication jcapi = {
0,
- NULL, /* FIXME */
+ NULL, /* FIXME... */
&jloadApplicationModule,
NULL, /* FIXME... */
+ &jrequestService,
NULL, /* FIXME... */
NULL, /* FIXME... */
NULL, /* FIXME... */
@@ -124,7 +198,6 @@
NULL, /* FIXME... */
NULL, /* FIXME... */
NULL, /* FIXME... */
- NULL, /* FIXME... */
};
@@ -137,13 +210,12 @@
void * fptr;
ServiceInitMethod mptr;
jclass UnsatisfiedLinkError;
-
strServiceName = (*env)->GetStringUTFChars(env, serviceName, NULL);
if (! strServiceName)
return 0;
modulePtr = loadDynamicLibrary(DSO_PREFIX, strServiceName);
if (! modulePtr)
- goto ULE;
+ goto ULE;
mptr = bindDynamicMethod(modulePtr,
"initialize_",
strServiceName);
@@ -158,22 +230,19 @@
m->jcapi = capi;
m->next = modules;
modules = m;
-
- fptr = mptr(&jcapi);
-
+ fptr = mptr(&jcapi); //crash here
/* by JNI API definition, these are no longer valid
after we return! */
PTHREAD_REL_SELF(&m->thread);
m->env = NULL;
m->jcapi = 0;
-
if (fptr == NULL) {
FREE(m->name);
/* FIXME: concurrent modification of modules... */
modules = m->next;
FREE(m);
goto ULE;
- }
+ }
(*env)->ReleaseStringUTFChars(env, serviceName, strServiceName);
return (jlong) (long) m;
ULE:
@@ -234,3 +303,44 @@
}
+
+JNIEXPORT jlong JNICALL
Java_org_gnu_freeway_server_CPluginLoader_cBindDynamicMethod
+ (JNIEnv *env, jobject cls, jlong libhandle, jstring methodprefix, jstring
dsoname) {
+ if(methodprefix == NULL)
+ return 0;
+ if(dsoname == NULL)
+ return 0;
+ const char * strmethodprefix = (*env)->GetStringUTFChars(env, methodprefix,
NULL);
+ if(strmethodprefix == NULL)
+ return 0;
+ const char * strdsoname = (*env)->GetStringUTFChars(env, dsoname, NULL);
+ if(strdsoname == NULL)
+ return 0;
+ long returnValue = (long) bindDynamicMethod((void *)(long)libhandle,
strmethodprefix, strdsoname);
+ (*env)->ReleaseStringUTFChars(env, methodprefix, strmethodprefix);
+ (*env)->ReleaseStringUTFChars(env, dsoname, strdsoname);
+ return (jlong) returnValue;
+}
+
+JNIEXPORT jlong JNICALL
Java_org_gnu_freeway_server_CPluginLoader_cLoadDynamicLibrary
+ (JNIEnv *env, jobject cls, jstring libprefix, jstring dsoname) {
+ if(libprefix == NULL)
+ return 0;
+ if(dsoname == NULL)
+ return 0;
+ const char * strlibprefix = (*env)->GetStringUTFChars(env, libprefix, NULL);
+ if(strlibprefix == NULL)
+ return 0;
+ const char * strdsoname = (*env)->GetStringUTFChars(env, dsoname, NULL);
+ if(strdsoname == NULL)
+ return 0;
+ long returnValue = (long) loadDynamicLibrary(strlibprefix, strdsoname);
+ (*env)->ReleaseStringUTFChars(env, libprefix, strlibprefix);
+ (*env)->ReleaseStringUTFChars(env, dsoname, strdsoname);
+ return (jlong) returnValue;
+}
+
+JNIEXPORT void JNICALL
Java_org_gnu_freeway_server_CPluginLoader_cUnloadDynamicLibrary
+ (JNIEnv *env, jobject cls, jlong libhandle) {
+ unloadDynamicLibrary((void *)(long)libhandle);
+}
Modified: freeway/native/org_gnu_freeway_server_CPluginLoader.h
===================================================================
--- freeway/native/org_gnu_freeway_server_CPluginLoader.h 2006-05-30
19:27:32 UTC (rev 2943)
+++ freeway/native/org_gnu_freeway_server_CPluginLoader.h 2006-05-31
19:05:27 UTC (rev 2944)
@@ -18,7 +18,7 @@
/*
* Class: org_gnu_freeway_server_CPluginLoader
* Method: cCallC
- * Signature:
(JLorg/gnu/freeway/server/CoreAPI;II[Ljava/lang/Object;I)Ljava/lang/Object;
+ * Signature:
(JLorg/gnu/freeway/server/CoreAPI;II[Ljava/lang/Object;)Ljava/lang/Object;
*/
JNIEXPORT jobject JNICALL Java_org_gnu_freeway_server_CPluginLoader_cCallC
(JNIEnv *, jclass, jlong, jobject, jint, jint, jobjectArray);
@@ -31,6 +31,30 @@
JNIEXPORT void JNICALL Java_org_gnu_freeway_server_CPluginLoader_cUnloadService
(JNIEnv *, jclass, jlong);
+/*
+ * Class: org_gnu_freeway_server_CPluginLoader
+ * Method: cBindDynamicMethod
+ * Signature: (JLjava/lang/String;Ljava/lang/String;)J
+ */
+JNIEXPORT jlong JNICALL
Java_org_gnu_freeway_server_CPluginLoader_cBindDynamicMethod
+ (JNIEnv *, jclass, jlong, jstring, jstring);
+
+/*
+ * Class: org_gnu_freeway_server_CPluginLoader
+ * Method: cLoadDynamicLibrary
+ * Signature: (Ljava/lang/String;Ljava/lang/String;)J
+ */
+JNIEXPORT jlong JNICALL
Java_org_gnu_freeway_server_CPluginLoader_cLoadDynamicLibrary
+ (JNIEnv *, jclass, jstring, jstring);
+
+/*
+ * Class: org_gnu_freeway_server_CPluginLoader
+ * Method: cUnloadDynamicLibrary
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL
Java_org_gnu_freeway_server_CPluginLoader_cUnloadDynamicLibrary
+ (JNIEnv *, jclass, jlong);
+
#ifdef __cplusplus
}
#endif
Added: freeway/native/org_gnu_freeway_server_CPluginLoader_Handle.h
===================================================================
--- freeway/native/org_gnu_freeway_server_CPluginLoader_Handle.h
2006-05-30 19:27:32 UTC (rev 2943)
+++ freeway/native/org_gnu_freeway_server_CPluginLoader_Handle.h
2006-05-31 19:05:27 UTC (rev 2944)
@@ -0,0 +1,13 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include <jni.h>
+/* Header for class org_gnu_freeway_server_CPluginLoader_Handle */
+
+#ifndef _Included_org_gnu_freeway_server_CPluginLoader_Handle
+#define _Included_org_gnu_freeway_server_CPluginLoader_Handle
+#ifdef __cplusplus
+extern "C" {
+#endif
+#ifdef __cplusplus
+}
+#endif
+#endif
Modified: freeway/src/org/gnu/freeway/server/CPluginLoader.java
===================================================================
--- freeway/src/org/gnu/freeway/server/CPluginLoader.java 2006-05-30
19:27:32 UTC (rev 2943)
+++ freeway/src/org/gnu/freeway/server/CPluginLoader.java 2006-05-31
19:05:27 UTC (rev 2944)
@@ -41,6 +41,12 @@
int functionOffset, int functionType, Object[]
arguments);
private static native void cUnloadService(long modulePtr);
+
+ private static native long cBindDynamicMethod(long libhandle, String
methodprefix, String dsoname);
+
+ private static native long cLoadDynamicLibrary(String dsoprefix, String
name);
+
+ private static native void cUnloadDynamicLibrary(long libhandle);
public CPluginLoader() {
}
@@ -126,6 +132,24 @@
assert modulePtr != null;
cUnloadService(modulePtr._);
}
+
+ public static Handle bindDynamicMethod(Handle libhandle, String
methodprefix, String dsoname) {
+ assert libhandle != null;
+ assert methodprefix != null;
+ assert dsoname != null;
+ return new Handle(cBindDynamicMethod(libhandle._, methodprefix,
dsoname));
+ }
+
+ public static Handle loadDynamicLibrary(String dsoprefix, String name) {
+ assert dsoprefix != null;
+ assert name != null;
+ return new Handle(cLoadDynamicLibrary(dsoprefix, name));
+ }
+
+ public static void unloadDynamicLibrary(Handle libhandle) {
+ assert libhandle != null;
+ cUnloadDynamicLibrary(libhandle._);
+ }
/**
* @file CLibraryHandle.java
@@ -140,5 +164,4 @@
assert value != 0;
}
}
-
}
Modified: freeway/src/org/gnu/freeway/server/CPluginLoaderTest.java
===================================================================
--- freeway/src/org/gnu/freeway/server/CPluginLoaderTest.java 2006-05-30
19:27:32 UTC (rev 2943)
+++ freeway/src/org/gnu/freeway/server/CPluginLoaderTest.java 2006-05-31
19:05:27 UTC (rev 2944)
@@ -11,12 +11,12 @@
public class CPluginLoaderTest extends TestCase {
- public void testServiceLoad() {
+ /*public void testServiceLoad() {
CPluginLoader cpl = new CPluginLoader();
CPluginLoader.Handle modulePtr = cpl.loadService("module_chat");
assertFalse(modulePtr._ == 0);
cpl.unloadService(modulePtr);
- }
+ }*/
public void testStatService() {
CPluginLoader cpl = new CPluginLoader();
Modified: freeway/src/org/gnu/freeway/server/CoreAPI.java
===================================================================
--- freeway/src/org/gnu/freeway/server/CoreAPI.java 2006-05-30 19:27:32 UTC
(rev 2943)
+++ freeway/src/org/gnu/freeway/server/CoreAPI.java 2006-05-31 19:05:27 UTC
(rev 2944)
@@ -20,6 +20,8 @@
package org.gnu.freeway.server;
import org.gnu.freeway.cwrappers.*;
+import java.util.ArrayList;
+import java.util.Iterator;
/**
* @file CoreAPI.java
@@ -32,9 +34,13 @@
public final static CInt YES = new CInt(1);
public final static CInt NO = new CInt(0);
+ private final static String DSO_PREFIX = "libgnunet";
+
public CUnsignedInt version;
public CPeerIdentity myIdentity;
+ private ArrayList shutdownList;
+
public CInt loadApplicationModule(CString name) {
return SYSERR;
}
@@ -43,11 +49,105 @@
return SYSERR;
}
- public CPointer requestService(CString name) {
- return new CPointer();
+ private String getConfigurationString(String section, String option) {
+ return null;
+ //TODO: write this and put it where it belongs
}
- public CInt releaseService(CPointer service) {
+ public class ServiceDesc {
+ String dsoName;
+ CPluginLoader.Handle library;
+ int applicationInitialized;
+ int serviceCount;
+ CPluginLoader.Handle servicePtr;
+
+ public ServiceDesc(String dsoName, CPluginLoader.Handle
library, int applicationInitialized, int serviceCount, CPluginLoader.Handle
servicePtr) {
+ this.dsoName = dsoName;
+ this.library = library;
+ this.applicationInitialized = applicationInitialized;
+ this.serviceCount = serviceCount;
+ this.servicePtr = servicePtr;
+ }
+
+ public String getDsoName() {
+ return dsoName;
+ }
+
+ public void setServiceCount(int count) {
+ serviceCount = count;
+ }
+
+ public int getServiceCount() {
+ return serviceCount;
+ }
+
+ public CPluginLoader.Handle getServicePtr() {
+ return servicePtr;
+ }
+
+ public int incrementServiceCount() {
+ return serviceCount++;
+ }
+
+ public void setServicePtr(CPluginLoader.Handle ptr) {
+ servicePtr = ptr;
+ }
+
+ public CPluginLoader.Handle getLibrary() {
+ return library;
+ }
+ }
+
+ public CPluginLoader.Handle requestService(CString iname) {
+ String rpos = iname.getValue();
+ String pos = getConfigurationString("MODULES", rpos);
+ if(pos == null)
+ pos = rpos;
+
+ String name = "module_" + pos;
+
+ ServiceDesc nxt = null;
+ for(Iterator i = shutdownList.iterator(); i.hasNext(); nxt =
(ServiceDesc) i.next()) {
+ if(name.equals(nxt.getDsoName())) {
+ if(nxt.getServiceCount() > 0) {
+ if(nxt.getServicePtr() != null)
+ nxt.incrementServiceCount();
+ return nxt.getServicePtr();
+ } else {
+ CPluginLoader.Handle mptr =
CPluginLoader.bindDynamicMethod(nxt.getLibrary(), "provide_", name);
+ if(mptr == null) {
+ return null;
+ }
+ nxt.setServicePtr(mptr);
//mptr(&applicationCore)
+ if(nxt.getServicePtr() != null)
+ nxt.incrementServiceCount();
+ return nxt.getServicePtr();
+ }
+ }
+ }
+
+ CPluginLoader.Handle library =
CPluginLoader.loadDynamicLibrary(DSO_PREFIX, name);
+
+ if(library == null)
+ return null;
+
+ CPluginLoader.Handle mptr =
CPluginLoader.bindDynamicMethod(library, "provide_", name);
+ if(mptr == null) {
+ CPluginLoader.unloadDynamicLibrary(library);
+ return null;
+ }
+ nxt = new ServiceDesc(name, library, NO.getValue(), 1, null);
+ shutdownList.add(nxt);
+ CPluginLoader.Handle api = mptr; //mptr(&applicationCore)
+ if(api != null) {
+ nxt.setServicePtr(api);
+ } else {
+ nxt.setServiceCount(0);
+ }
+ return api;
+ }
+
+ public CInt releaseService(CPluginLoader.Handle service) {
return SYSERR;
}
@@ -59,11 +159,11 @@
}
- public void unicastCallback(ConstCPeerIdentity receiver,
CBuildMessageCallback callback, CPointer closure) {
+ public void unicastCallback(ConstCPeerIdentity receiver,
CBuildMessageCallback callback, CPluginLoader.Handle closure) {
}
- public CInt forAllConnectedNodes(CPerNodeCallback method, CPointer arg)
{
+ public CInt forAllConnectedNodes(CPerNodeCallback method,
CPluginLoader.Handle arg) {
return SYSERR;
}
@@ -184,7 +284,7 @@
public static final CoreAPI _ = new CoreAPI();
private CoreAPI() {
-
+ shutdownList = new ArrayList();
}
private class CPeerIdentity {
@@ -211,13 +311,6 @@
//TODO: write CBuildMessageCallback
}
- private class CPointer {
- //TODO: write CPointer class for void *
- public CPointer() {
-
- }
- }
-
private class CPerNodeCallback {
//TODO: write CPerNodeCallback
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r2944 - in freeway: native src/org/gnu/freeway/server,
mdonoughe <=