Commit 54daa12c authored by jehan's avatar jehan

implement native api

git-svn-id: svn+ssh://svn.savannah.nongnu.org/linphone/trunk@80 3f6dc0c8-ddfe-455d-9043-3cd528dc4637
parent 0132b106
......@@ -29,7 +29,7 @@ all: p2pproxy-launcher
p2pproxy-launcher: $(OBJS) $(USER_OBJS)
@echo 'Building target: $@'
@echo 'Invoking: GCC C Linker'
gcc -L/usr/lib/jvm/java-6-openjdk/jre/lib/amd64 -L/usr/lib/jvm/java-6-openjdk/jre/lib/amd64/server -o"p2pproxy-launcher" $(OBJS) $(USER_OBJS) $(LIBS)
gcc -L/usr/lib/jvm/java-6-openjdk/jre/lib/amd64 -L/usr/lib/jvm/java-6-openjdk/jre/lib/i386 -L/usr/lib/jvm/java-6-openjdk/jre/lib/amd64/server -L/usr/lib/jvm/java-6-openjdk/jre/lib/i386/server -o"p2pproxy-launcher" $(OBJS) $(USER_OBJS) $(LIBS)
@echo 'Finished building target: $@'
@echo ' '
......
......@@ -11,11 +11,37 @@ static void * thread_starter(void *args){
int main(int argc, char **argv) {
pthread_t th;
printf("starting p2pproxy tester");
printf("starting p2pproxy tester \n");
pthread_create(&th,NULL,thread_starter,NULL);
sleep(3);
sleep(1000);
/*p2pproxy_application_stop();*/
if (p2pproxy_application_get_state() == P2PPROXY_CONNECTED) {
printf("CONNECTED \n");
} else {
printf("NOT CONNECTED \n");
};
if (p2pproxy_accountmgt_createAccount("sip:titi@p2p.linphone.org") != P2PPROXY_NO_ERROR) {
printf("cannot create account \n");
}
if (p2pproxy_accountmgt_isValidAccount("sip:titi@p2p.linphone.org") != P2PPROXY_ACCOUNTMGT_USER_EXIST) {
printf("user not created \n");
}
char string_buffer[256];
if (p2pproxy_resourcelocation_get_sip_proxyregistrar_uri(string_buffer,256) != P2PPROXY_NO_ERROR) {
printf("cannot get proxy\n");
} else {
printf("registrar is [%s]\n",string_buffer);
}
if (p2pproxy_accountmgt_deleteAccount("sip:titi@p2p.linphone.org") != P2PPROXY_NO_ERROR) {
printf("cannot delete account \n");
}
p2pproxy_application_stop();
pthread_join(th,NULL);
return 0;
}
\ No newline at end of file
......@@ -12,12 +12,28 @@
#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;
int p2pproxy_application_start(int argc, char **argv) {
#define GET_JNI_ENV \
jint lResut = 0 ;\
JNIEnv* lJniEnv = 0;\
jclass lMainClass = 0;\
lResut = (*p2pproxy_application_jvm)->AttachCurrentThread(p2pproxy_application_jvm,&lJniEnv,NULL);\
if (lResut != 0) { \
fprintf(stderr,"cannot attach VM\n");\
return P2PPROXY_ERROR;\
}\
lMainClass = (*lJniEnv)->FindClass(lJniEnv, "org/linphone/p2pproxy/core/P2pProxyMain");\
if (lMainClass == 0) { \
fprintf(stderr,"cannot load class org/linphone/p2pproxy/core/P2pProxyMain\n");\
return P2PPROXY_ERROR; \
} \
int p2pproxy_application_start(int argc, char **argv) {
JNIEnv* lJniEnv = 0;
jclass lMainClass = 0;
JavaVMInitArgs args;
JavaVMOption options[NUMBER_OF_OPTION];
jint res=-1;
......@@ -27,7 +43,7 @@ int p2pproxy_application_start(int argc, char **argv) {
int i=0;
int optioncount=0;
if (p2pproxy_application_jnienv != 0) {
if (p2pproxy_application_jvm != 0) {
fprintf(stderr,"p2pproxy already started");
return P2PPROXY_ERROR_APPLICATION_ALREADY_STARTED;
}
......@@ -52,34 +68,36 @@ int p2pproxy_application_start(int argc, char **argv) {
args.nOptions = NUMBER_OF_OPTION;
args.options = options;
args.ignoreUnrecognized = JNI_FALSE;
args.ignoreUnrecognized = JNI_FALSE; int lResult;
res = JNI_CreateJavaVM(&p2pproxy_application_jvm, (void **)&p2pproxy_application_jnienv, &args);
res = JNI_CreateJavaVM(&p2pproxy_application_jvm, (void **)&lJniEnv, &args);
if (res < 0) {
fprintf(stderr,"cannot start p2pproxy vm [%i]",res);
return P2PPROXY_ERROR;
}
p2pproxy_proxy_main_class = (*p2pproxy_application_jnienv)->FindClass(p2pproxy_application_jnienv, "org/linphone/p2pproxy/core/P2pProxyMain");
lMainClass = (*lJniEnv)->FindClass(lJniEnv, "org/linphone/p2pproxy/core/P2pProxyMain");
if (p2pproxy_proxy_main_class == 0) {
if (lMainClass == 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");
mainMethod = (*lJniEnv)->GetStaticMethodID(lJniEnv, lMainClass, "main", "([Ljava/lang/String;)V");
applicationArgsList = (*p2pproxy_application_jnienv)->NewObjectArray(p2pproxy_application_jnienv, argc, (*p2pproxy_application_jnienv)->FindClass(p2pproxy_application_jnienv, "java/lang/String"), NULL);
applicationArgsList = (*lJniEnv)->NewObjectArray(lJniEnv, argc, (*lJniEnv)->FindClass(lJniEnv, "java/lang/String"), NULL);
for (i=0;i<argc;i++) {
applicationArg = (*p2pproxy_application_jnienv)->NewStringUTF(p2pproxy_application_jnienv, argv[i]);
(*p2pproxy_application_jnienv)->SetObjectArrayElement(p2pproxy_application_jnienv, applicationArgsList, 0, applicationArg);
applicationArg = (*lJniEnv)->NewStringUTF(lJniEnv, argv[i]);
(*lJniEnv)->SetObjectArrayElement(lJniEnv, applicationArgsList, i, applicationArg);
}
(*p2pproxy_application_jnienv)->CallStaticVoidMethod(p2pproxy_application_jnienv, p2pproxy_proxy_main_class, mainMethod, applicationArgsList);
(*lJniEnv)->CallStaticVoidMethod(lJniEnv, lMainClass, mainMethod, applicationArgsList);
return P2PPROXY_NO_ERROR;
}
int lResult;
const char* p2pproxy_status_string(int status_code) {
......@@ -89,29 +107,35 @@ const char* p2pproxy_status_string(int status_code) {
int p2pproxy_accountmgt_createAccount(const char* user_name) {
jmethodID createAccountMethod;
jstring applicationArg;
createAccountMethod = (*p2pproxy_application_jnienv)->GetStaticMethodID(p2pproxy_application_jnienv, p2pproxy_proxy_main_class, "createAccount", "([java/lang/String;)I");
applicationArg = (*p2pproxy_application_jnienv)->NewStringUTF(p2pproxy_application_jnienv, user_name);
return (*p2pproxy_application_jnienv)->CallStaticIntMethod(p2pproxy_application_jnienv, p2pproxy_proxy_main_class, createAccountMethod, applicationArg);
jstring applicationArg;
GET_JNI_ENV
createAccountMethod = (*lJniEnv)->GetStaticMethodID(lJniEnv, lMainClass, "createAccount", "(Ljava/lang/String;)I");
applicationArg = (*lJniEnv)->NewStringUTF(lJniEnv, user_name);
lResult = (*lJniEnv)->CallStaticIntMethod(lJniEnv, lMainClass, createAccountMethod, applicationArg);
(*p2pproxy_application_jvm)->DetachCurrentThread(p2pproxy_application_jvm);
return lResult;
}
int p2pproxy_accountmgt_isValidAccount(const char* user_name) {
jmethodID isValidAccountMethod;
jstring applicationArg;
isValidAccountMethod = (*p2pproxy_application_jnienv)->GetStaticMethodID(p2pproxy_application_jnienv, p2pproxy_proxy_main_class, "isValidAccount", "([java/lang/String;)I");
applicationArg = (*p2pproxy_application_jnienv)->NewStringUTF(p2pproxy_application_jnienv, user_name);
return (*p2pproxy_application_jnienv)->CallStaticIntMethod(p2pproxy_application_jnienv, p2pproxy_proxy_main_class, isValidAccountMethod, applicationArg);
GET_JNI_ENV
isValidAccountMethod = (*lJniEnv)->GetStaticMethodID(lJniEnv, lMainClass, "isValidAccount", "(Ljava/lang/String;)I");
applicationArg = (*lJniEnv)->NewStringUTF(lJniEnv, user_name);
lResult = (*lJniEnv)->CallStaticIntMethod(lJniEnv, lMainClass, isValidAccountMethod, applicationArg);
(*p2pproxy_application_jvm)->DetachCurrentThread(p2pproxy_application_jvm);
return lResult;
}
int p2pproxy_accountmgt_deleteAccount(const char* user_name) {
jmethodID deleteAccountMethod;
jstring applicationArg;
deleteAccountMethod = (*p2pproxy_application_jnienv)->GetStaticMethodID(p2pproxy_application_jnienv, p2pproxy_proxy_main_class, "deleteAccount", "([java/lang/String;)I");
applicationArg = (*p2pproxy_application_jnienv)->NewStringUTF(p2pproxy_application_jnienv, user_name);
return (*p2pproxy_application_jnienv)->CallStaticIntMethod(p2pproxy_application_jnienv, p2pproxy_proxy_main_class, deleteAccountMethod, applicationArg);
GET_JNI_ENV
deleteAccountMethod = (*lJniEnv)->GetStaticMethodID(lJniEnv, lMainClass, "deleteAccount", "(Ljava/lang/String;)I");
applicationArg = (*lJniEnv)->NewStringUTF(lJniEnv, user_name);
lResult = (*lJniEnv)->CallStaticIntMethod(lJniEnv, lMainClass, deleteAccountMethod, applicationArg);
(*p2pproxy_application_jvm)->DetachCurrentThread(p2pproxy_application_jvm);
return lResult;
}
int p2pproxy_resourcelocation_get_sip_proxyregistrar_uri(char* aStringArray, size_t aSize) {
......@@ -119,30 +143,39 @@ int p2pproxy_resourcelocation_get_sip_proxyregistrar_uri(char* aStringArray, siz
jstring lJStringResult;
const jbyte* lString;
jboolean lIsCopy;
GET_JNI_ENV
getSipProxyRegistrarUriMethod = (*p2pproxy_application_jnienv)->GetStaticMethodID(p2pproxy_application_jnienv, p2pproxy_proxy_main_class, "getSipProxyRegistrarUriMethod", "()[java/lang/String;");
lJStringResult = (*p2pproxy_application_jnienv)->CallStaticObjectMethod(p2pproxy_application_jnienv, p2pproxy_proxy_main_class, getSipProxyRegistrarUriMethod);
getSipProxyRegistrarUriMethod = (*lJniEnv)->GetStaticMethodID(lJniEnv, lMainClass, "getSipProxyRegistrarUri", "()Ljava/lang/String;");
lJStringResult = (*lJniEnv)->CallStaticObjectMethod(lJniEnv, lMainClass, getSipProxyRegistrarUriMethod);
if (lJStringResult == 0) {
return P2PPROXY_ERROR_RESOURCELOCATOR_SERVER_NOT_FOUND;
}
lString = (*p2pproxy_application_jnienv)->GetStringUTFChars(p2pproxy_application_jnienv, lJStringResult, &lIsCopy);
lString = (*lJniEnv)->GetStringUTFChars(lJniEnv, lJStringResult, &lIsCopy);
memcpy(aStringArray,lString,aSize);
(*p2pproxy_application_jnienv)->ReleaseStringUTFChars(p2pproxy_application_jnienv, lJStringResult, lString);
(*lJniEnv)->ReleaseStringUTFChars(lJniEnv, lJStringResult, lString);
(*p2pproxy_application_jvm)->DetachCurrentThread(p2pproxy_application_jvm);
return P2PPROXY_NO_ERROR;
}
int p2pproxy_application_get_state() {
jmethodID stateMethod;
GET_JNI_ENV
stateMethod = (*p2pproxy_application_jnienv)->GetStaticMethodID(p2pproxy_application_jnienv, p2pproxy_proxy_main_class, "getState", "()I");
return (*p2pproxy_application_jnienv)->CallStaticIntMethod(p2pproxy_application_jnienv, p2pproxy_proxy_main_class, stateMethod);
stateMethod = (*lJniEnv)->GetStaticMethodID(lJniEnv, lMainClass, "getState", "()I");
lResult = (*lJniEnv)->CallStaticIntMethod(lJniEnv, lMainClass, stateMethod);
(*p2pproxy_application_jvm)->DetachCurrentThread(p2pproxy_application_jvm);
return lResult;
}
void p2pproxy_application_stop() {
jmethodID stopMethod;
jmethodID stopMethod = 0;
GET_JNI_ENV
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);
stopMethod = (*lJniEnv)->GetStaticMethodID(lJniEnv, lMainClass, "stop", "()V");
(*lJniEnv)->CallStaticVoidMethod(lJniEnv, lMainClass, stopMethod);
(*p2pproxy_application_jvm)->DetachCurrentThread(p2pproxy_application_jvm);
(*p2pproxy_application_jvm)->DestroyJavaVM(p2pproxy_application_jvm);
p2pproxy_application_jvm = 0;
return;
}
......
......@@ -19,6 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.linphone.p2pproxy.core;
import java.io.IOException;
import java.net.Socket;
import java.net.URI;
import java.util.concurrent.ExecutorService;
......@@ -56,6 +57,7 @@ public class GenericService implements Runnable,ServiceProvider {
private Thread mSocketServerThread ;
private final ExecutorService mPool;
private final ServiceSocketHandlerFactory mServiceSocketHandlerFactory;
private boolean mExist = false;
public GenericService(Configurator lProperties,JxtaNetworkManager aJxtaNetworkManager,String aServiceName,ServiceSocketHandlerFactory aServiceSocketHandlerFactory) {
mJxtaNetworkManager = aJxtaNetworkManager;
......@@ -122,10 +124,15 @@ public class GenericService implements Runnable,ServiceProvider {
}
}
public void stop(){
throw new RuntimeException("Not implemented");
try {
mJxtaServerSocket.close();
} catch (IOException e) {
//nop
}
mExist = true;
}
public void run() {
while (true) {
while (mExist) {
try {
mLog.info("Waiting for connection on service ["+ADV_NAME+"]");
Socket lSocket = mJxtaServerSocket.accept();
......
......@@ -42,6 +42,7 @@ import org.linphone.p2pproxy.api.P2pProxyNotReadyException;
import org.linphone.p2pproxy.api.P2pProxyUserAlreadyExistException;
import org.linphone.p2pproxy.core.media.rtprelay.RtpRelayService;
import org.linphone.p2pproxy.core.sipproxy.SipProxyRegistrar;
import org.linphone.p2pproxy.core.sipproxy.SipProxyRegistrarAdvertisement;
import org.zoolu.sip.provider.SipStack;
import org.linphone.p2pproxy.launcher.P2pProxylauncherConstants;
......@@ -379,8 +380,13 @@ public static void staticLoadTraceConfigFile() throws P2pProxyException {
private static void isReady() throws P2pProxyNotReadyException {
try {
if (mJxtaNetworkManager!=null && mJxtaNetworkManager.isConnectedToRendezVous(0) == false) {
throw new P2pProxyNotReadyException("not connected to any rdv");
if ((mJxtaNetworkManager!=null && mJxtaNetworkManager.isConnectedToRendezVous(0) == true)
||
(mJxtaNetworkManager!=null && mJxtaNetworkManager.getPeerGroup().getRendezVousService().isRendezVous()))
{
//nop connected
} else {
throw new P2pProxyNotReadyException("not connected to any rdv");
}
} catch (InterruptedException e) {
throw new P2pProxyNotReadyException(e);
......@@ -424,10 +430,11 @@ public static int isValidAccount(String aUserName){
public static String getSipProxyRegistrarUri() {
try {
isReady();
return mP2pProxyManagement.getSipProxyRegistrarUri();
} catch (P2pProxyException e) {
SipProxyRegistrarAdvertisement lSipProxyRegistrarAdvertisement = (SipProxyRegistrarAdvertisement) (mJxtaNetworkManager.getAdvertisement(null, SipProxyRegistrarAdvertisement.NAME, true));
return lSipProxyRegistrarAdvertisement.getAddress();
} catch (Exception e) {
return null;
}
}
}
public static int getState() {
try {
......
......@@ -61,6 +61,7 @@ public class PeerInfoProviderService implements Runnable,PeerInfoProvider,Servic
private final static int SO_TIMOUT=3000;
public final static String PEERINFO_MODULE_CLASS_ID="org.linphone.p2pproxy.PeerInfoProviderService.module-class.id";
public final static String PEERINFO_MODULE_SPEC_ID="org.linphone.p2pproxy.PeerInfoProviderService.module-spec.id";
private boolean mExist = false;
public PeerInfoProviderService(Configurator lProperties,JxtaNetworkManager aJxtaNetworkManager) {
mJxtaNetworkManager = aJxtaNetworkManager;
......@@ -118,12 +119,18 @@ public class PeerInfoProviderService implements Runnable,PeerInfoProvider,Servic
PeerInfoProviderService.mLog.error("socket instance error", e);
}
}
public void stop(){
throw new RuntimeException("Not implemented");
public void stop() {
try {
mJxtaServerSocket.close();
} catch (IOException e) {
//nop
}
mExist = true;
mLog.info("PeerInfoProviderService stopped");
}
public void run() {
while (true) {
while (mExist) {
try {
mLog.info("Waiting for connection on ["+ADV_NAME+"]");
Socket lSocket = mJxtaServerSocket.accept();
......@@ -155,8 +162,7 @@ public class PeerInfoProviderService implements Runnable,PeerInfoProvider,Servic
ObjectInputStream lIn = new ObjectInputStream(mSocket.getInputStream());
Object lInputObj;
Object lOutputObj;
boolean lStop = false;
while (lStop == false) {
while (mExist == false) {
lInputObj = lIn.readObject();
mLog.info("request message ["+lInputObj+"] received");
......
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