Commit 5d71fbcf authored by jehan's avatar jehan

add native test

git-svn-id: svn+ssh://svn.savannah.nongnu.org/linphone/trunk@77 3f6dc0c8-ddfe-455d-9043-3cd528dc4637
parent 60405029
......@@ -54,7 +54,7 @@
</exec>
</target>
<target name="build-project" depends="init">
<target name="build-project" depends="init,jni-src">
<echo message="${ant.project.name}: ${ant.file}"/>
<javac destdir="antbuild/p2pproxy" debug="true" debuglevel="${debuglevel}" source="${source}" target="${target}">
......@@ -62,6 +62,7 @@
<src path="${jxta-src}/api/src"/>
<src path="${jxta-src}/impl/src"/>
<src path="${jstun-src}" />
<src path="${jni-src}" />
<exclude name="**/*Tester.java"/>
<classpath refid="p2pproxy.classpath"/>
</javac>
......
#include "p2pproxy.h"
#include <pthread.h>
#include <unistd.h>
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
......@@ -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;
}
......@@ -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
*/
......
......@@ -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
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment