| 1 | #include <stdio.h> |
|---|
| 2 | #include <jni.h> |
|---|
| 3 | #include "p2pproxy.h" |
|---|
| 4 | |
|---|
| 5 | #ifndef P2PPROXY_JMX_PORT |
|---|
| 6 | #define P2PPROXY_JMX_PORT "5678" |
|---|
| 7 | #endif |
|---|
| 8 | #ifndef P2PPROXY_INSTALLDIR |
|---|
| 9 | #define P2PPROXY_INSTALLDIR "/usr/local/share/java" |
|---|
| 10 | #endif |
|---|
| 11 | #ifndef P2PPROXY_BUILDDIR |
|---|
| 12 | #define P2PPROXY_BUILDDIR "./antbuild/dist/p2pproxy_0.1" |
|---|
| 13 | #endif |
|---|
| 14 | JNIEnv* p2pproxy_application_jnienv = 0; |
|---|
| 15 | JavaVM* p2pproxy_application_jvm = 0; |
|---|
| 16 | |
|---|
| 17 | int p2pproxy_application_start(int argc, char **argv) { |
|---|
| 18 | |
|---|
| 19 | JavaVMInitArgs args; |
|---|
| 20 | JavaVMOption options[0]; |
|---|
| 21 | jint res=-1; |
|---|
| 22 | |
|---|
| 23 | if (p2pproxy_application_jnienv != 0) { |
|---|
| 24 | fprintf(stderr,"p2pproxy already started"); |
|---|
| 25 | return P2PPROXY_ERROR_APPLICATION_ALREADY_STARTED; |
|---|
| 26 | } |
|---|
| 27 | args.version = JNI_VERSION_1_4; |
|---|
| 28 | args.nOptions = sizeof (options); |
|---|
| 29 | /*options[0].optionString = "-verbose:jni";*/ |
|---|
| 30 | /*options[1].optionString = "-Djava.class.path="P2PPROXY_BUILDDIR"/p2pproxy.jar:"\ |
|---|
| 31 | P2PPROXY_INSTALLDIR"/p2pproxy.jar:"\ |
|---|
| 32 | P2PPROXY_BUILDDIR"/log4j.jar:"\ |
|---|
| 33 | P2PPROXY_INSTALLDIR"/log4j.jar"; |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | /* |
|---|
| 37 | options[1].optionString = "-Dcom.sun.management.jmxremote"; |
|---|
| 38 | options[2].optionString = "-Dcom.sun.management.jmxremote.port="P2PPROXY_JMX_PORT; |
|---|
| 39 | options[3].optionString = "-Dcom.sun.management.jmxremote.authenticate=false"; |
|---|
| 40 | options[4].optionString = "-Dcom.sun.management.jmxremote.ssl=false"; |
|---|
| 41 | */ |
|---|
| 42 | |
|---|
| 43 | args.options = options; |
|---|
| 44 | args.ignoreUnrecognized = JNI_FALSE; |
|---|
| 45 | |
|---|
| 46 | res = JNI_CreateJavaVM(&p2pproxy_application_jvm, (void **)&p2pproxy_application_jnienv, &args); |
|---|
| 47 | if (res < 0) { |
|---|
| 48 | fprintf(stderr,"cannot start p2pproxy vm [%i]",res); |
|---|
| 49 | return P2PPROXY_ERROR; |
|---|
| 50 | } |
|---|
| 51 | return P2PPROXY_NO_ERROR; |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | const char* p2pproxy_status_string(int status_code) { |
|---|
| 56 | return 0; |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | int p2pproxy_accountmgt_createAccount(const char* user_name) { |
|---|
| 61 | return P2PPROXY_ERROR; |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | int p2pproxy_accountmgt_isValidAccount(const char* user_name) { |
|---|
| 65 | return P2PPROXY_ERROR; |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | int p2pproxy_accountmgt_deleteAccount(const char* user_name) { |
|---|
| 69 | return P2PPROXY_ERROR; |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | JNIEnv* create_vm() { |
|---|
| 75 | |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | void invoke_class(JNIEnv* env) { |
|---|
| 79 | jclass helloWorldClass; |
|---|
| 80 | jmethodID mainMethod; |
|---|
| 81 | jobjectArray applicationArgs; |
|---|
| 82 | jstring applicationArg0; |
|---|
| 83 | |
|---|
| 84 | helloWorldClass = (*env)->FindClass(env, "example/jni/InvocationHelloWorld"); |
|---|
| 85 | |
|---|
| 86 | mainMethod = (*env)->GetStaticMethodID(env, helloWorldClass, "main", "([Ljava/lang/String;)V"); |
|---|
| 87 | |
|---|
| 88 | applicationArgs = (*env)->NewObjectArray(env, 1, (*env)->FindClass(env, "java/lang/String"), NULL); |
|---|
| 89 | applicationArg0 = (*env)->NewStringUTF(env, "From-C-program"); |
|---|
| 90 | (*env)->SetObjectArrayElement(env, applicationArgs, 0, applicationArg0); |
|---|
| 91 | |
|---|
| 92 | (*env)->CallStaticVoidMethod(env, helloWorldClass, mainMethod, applicationArgs); |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | |
|---|