From 5d71fbcf561f8e4a7759f6e19f39580df2041464 Mon Sep 17 00:00:00 2001 From: jehan Date: Fri, 10 Oct 2008 15:15:49 +0000 Subject: [PATCH] add native test git-svn-id: svn+ssh://svn.savannah.nongnu.org/linphone/trunk@77 3f6dc0c8-ddfe-455d-9043-3cd528dc4637 --- p2pproxy/build.xml | 3 +- p2pproxy/launcher/src/launcher-tester.c | 19 ++++++++- p2pproxy/launcher/src/p2pproxy.c | 41 ++++++++++++------- p2pproxy/launcher/src/p2pproxy.h | 6 +++ .../linphone/p2pproxy/core/P2pProxyMain.java | 13 +++++- .../core/sipproxy/SipProxyRegistrar.java | 9 +++- 6 files changed, 71 insertions(+), 20 deletions(-) diff --git a/p2pproxy/build.xml b/p2pproxy/build.xml index 3baab9453..a5c6d1c01 100644 --- a/p2pproxy/build.xml +++ b/p2pproxy/build.xml @@ -54,7 +54,7 @@ - + @@ -62,6 +62,7 @@ + diff --git a/p2pproxy/launcher/src/launcher-tester.c b/p2pproxy/launcher/src/launcher-tester.c index f0507b21d..35b159e4b 100644 --- a/p2pproxy/launcher/src/launcher-tester.c +++ b/p2pproxy/launcher/src/launcher-tester.c @@ -1,5 +1,20 @@ #include "p2pproxy.h" -int main(int argc, char **argv) { - printf("starting p2pproxy tester"); +#include +#include + +static void * thread_starter(void *args){ p2pproxy_application_start( 0, 0); + return NULL; +} + + +int main(int argc, char **argv) { + pthread_t th; + printf("starting p2pproxy tester"); + pthread_create(&th,NULL,thread_starter,NULL); + p2pproxy_application_start( 0, 0); + sleep(10); + /*p2pproxy_application_stop();*/ + pthread_join(th,NULL); + return 0; } \ No newline at end of file diff --git a/p2pproxy/launcher/src/p2pproxy.c b/p2pproxy/launcher/src/p2pproxy.c index f65593bd6..1427af2f3 100644 --- a/p2pproxy/launcher/src/p2pproxy.c +++ b/p2pproxy/launcher/src/p2pproxy.c @@ -9,8 +9,9 @@ #define P2PPROXY_INSTALLDIR "/usr/local/share/java" #endif #ifndef P2PPROXY_BUILDDIR - #define P2PPROXY_BUILDDIR ".././antbuild/dist/p2pproxy_0.1" + #define P2PPROXY_BUILDDIR "../antbuild/dist/p2pproxy_0.1" #endif +#define NUMBER_OF_OPTION 7 JNIEnv* p2pproxy_application_jnienv = 0; JavaVM* p2pproxy_application_jvm = 0; jclass p2pproxy_proxy_main_class = 0; @@ -18,36 +19,38 @@ jclass p2pproxy_proxy_main_class = 0; int p2pproxy_application_start(int argc, char **argv) { JavaVMInitArgs args; - JavaVMOption options[7]; + JavaVMOption options[NUMBER_OF_OPTION]; jint res=-1; - jclass lP2pProxyMainClass=0; jmethodID mainMethod; jobjectArray applicationArgsList; jstring applicationArg; int i=0; + int optioncount=0; if (p2pproxy_application_jnienv != 0) { fprintf(stderr,"p2pproxy already started"); return P2PPROXY_ERROR_APPLICATION_ALREADY_STARTED; } args.version = JNI_VERSION_1_4; - args.nOptions = 7; - /*options[0].optionString = "-verbose:jni";*/ - options[0].optionString = "-Djava.class.path="P2PPROXY_BUILDDIR"/p2pproxy.jar:"\ + + /*options[optioncount++].optionString = "-verbose:jni";*/ + /*options[optioncount++].optionString = "-verbose:class";*/ + /*options[optioncount++].optionString = "-verbose:class";*/ + options[optioncount++].optionString = "-Djava.class.path="P2PPROXY_BUILDDIR"/p2pproxy.jar:"\ P2PPROXY_INSTALLDIR"/p2pproxy.jar:"\ P2PPROXY_BUILDDIR"/log4j.jar:"\ P2PPROXY_INSTALLDIR"/log4j.jar"; - options[1].optionString = "-Dcom.sun.management.jmxremote"; - options[2].optionString = "-Dcom.sun.management.jmxremote.port="P2PPROXY_JMX_PORT; - options[3].optionString = "-Dcom.sun.management.jmxremote.authenticate=false"; - options[4].optionString = "-Dcom.sun.management.jmxremote.ssl=false"; - options[5].optionString = "-Dorg.linphone.p2pproxy.install.dir="P2PPROXY_INSTALLDIR; - options[6].optionString = "-Dorg.linphone.p2pproxy.build.dir="P2PPROXY_BUILDDIR; - + options[optioncount++].optionString = "-Dcom.sun.management.jmxremote"; + options[optioncount++].optionString = "-Dcom.sun.management.jmxremote.port="P2PPROXY_JMX_PORT; + options[optioncount++].optionString = "-Dcom.sun.management.jmxremote.authenticate=false"; + options[optioncount++].optionString = "-Dcom.sun.management.jmxremote.ssl=false"; + options[optioncount++].optionString = "-Dorg.linphone.p2pproxy.install.dir="P2PPROXY_INSTALLDIR; + options[optioncount++].optionString = "-Dorg.linphone.p2pproxy.build.dir="P2PPROXY_BUILDDIR; + args.nOptions = NUMBER_OF_OPTION; args.options = options; args.ignoreUnrecognized = JNI_FALSE; @@ -59,8 +62,8 @@ int p2pproxy_application_start(int argc, char **argv) { p2pproxy_proxy_main_class = (*p2pproxy_application_jnienv)->FindClass(p2pproxy_application_jnienv, "org/linphone/p2pproxy/core/P2pProxyMain"); - if (lP2pProxyMainClass == 0) { - fprintf(stderr,"cannot find class org/linphone/p2pproxy/core/P2pProxyMain"); + if (p2pproxy_proxy_main_class == 0) { + fprintf(stderr,"cannot load class org/linphone/p2pproxy/core/P2pProxyMain\n"); return P2PPROXY_ERROR; } mainMethod = (*p2pproxy_application_jnienv)->GetStaticMethodID(p2pproxy_application_jnienv, p2pproxy_proxy_main_class, "main", "([Ljava/lang/String;)V"); @@ -135,5 +138,13 @@ int p2pproxy_application_get_state() { return (*p2pproxy_application_jnienv)->CallStaticIntMethod(p2pproxy_application_jnienv, p2pproxy_proxy_main_class, stateMethod); } +void p2pproxy_application_stop() { + jmethodID stopMethod; + + stopMethod = (*p2pproxy_application_jnienv)->GetStaticMethodID(p2pproxy_application_jnienv, p2pproxy_proxy_main_class, "stop", "()V"); + (*p2pproxy_application_jnienv)->CallStaticVoidMethod(p2pproxy_application_jnienv, p2pproxy_proxy_main_class, stopMethod); + return; + +} diff --git a/p2pproxy/launcher/src/p2pproxy.h b/p2pproxy/launcher/src/p2pproxy.h index 7317199ae..08f6a4999 100644 --- a/p2pproxy/launcher/src/p2pproxy.h +++ b/p2pproxy/launcher/src/p2pproxy.h @@ -61,6 +61,12 @@ int p2pproxy_application_start(int argc, char **argv); */ int p2pproxy_application_get_state(); +/** + * stop p2pproxy application + * + */ +void p2pproxy_application_stop(); + /** * return the status string corresponding to the status code */ diff --git a/p2pproxy/src/org/linphone/p2pproxy/core/P2pProxyMain.java b/p2pproxy/src/org/linphone/p2pproxy/core/P2pProxyMain.java index c5b754cf5..e56760bd1 100644 --- a/p2pproxy/src/org/linphone/p2pproxy/core/P2pProxyMain.java +++ b/p2pproxy/src/org/linphone/p2pproxy/core/P2pProxyMain.java @@ -58,6 +58,7 @@ public class P2pProxyMain implements P2pProxyMainMBean { private static P2pProxyMain mP2pProxyMain = new P2pProxyMain(); private static Configurator mConfigurator; private static String mConfigHomeDir; + static private boolean mExit = false; static { @@ -279,9 +280,15 @@ public class P2pProxyMain implements P2pProxyMainMBean { mLog.warn("p2pproxy initilized"); - while (true) { + while (mExit == false) { Thread.sleep(1000); } + if (mServiceProvider!= null) mServiceProvider.stop(); + if (mServiceProvider!= null) mServiceProvider.stop(); + if (mSipAndPipeListener!= null) mSipAndPipeListener.stop(); + if (mJxtaNetworkManager != null) mJxtaNetworkManager.stop(); + mLog.info("p2pproxy stopped"); + } catch (Exception e) { mLog.fatal("error",e); System.exit(1); @@ -430,4 +437,8 @@ public static int getState() { return P2pProxylauncherConstants.P2PPROXY_NOT_CONNECTED; } } +public static void stop() { + mExit = true; + +} } \ No newline at end of file diff --git a/p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/SipProxyRegistrar.java b/p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/SipProxyRegistrar.java index 86cf3d70a..2a78b3c86 100644 --- a/p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/SipProxyRegistrar.java +++ b/p2pproxy/src/org/linphone/p2pproxy/core/sipproxy/SipProxyRegistrar.java @@ -337,7 +337,14 @@ public class SipProxyRegistrar implements SipProviderListener,SipProxyRegistrarM } - +public void stop() { + try { + mJxtaNetworkManager.getPeerGroup().getDiscoveryService().flushAdvertisement(mProxyRegistrationAdvertisement); + } catch (IOException e) { + mLog.warn("cannot flush registrar adv",e ); + } + mProvider.halt(); +} // public long getNumberOfEstablishedCall() { // return mNumberOfEstablishedCall;