Commit f43e79b9 authored by jehan's avatar jehan

implement account management c interface

git-svn-id: svn+ssh://svn.savannah.nongnu.org/linphone/trunk@57 3f6dc0c8-ddfe-455d-9043-3cd528dc4637
parent 5f20f44e
......@@ -11,6 +11,7 @@
<classpathentry kind="src" path="dependencies-src/jxse-src-2.5/impl/src"/>
<classpathentry kind="src" path="dependencies-src/jxse-src-2.5/api/src"/>
<classpathentry kind="src" path="test-src"/>
<classpathentry kind="src" path="jni_src"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="lib" path="dependencies/junit-4.3.1.jar"/>
<classpathentry kind="output" path="eclipsebuild"/>
......
......@@ -14,4 +14,11 @@
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<linkedResources>
<link>
<name>jni_src</name>
<type>2</type>
<locationURI>jni_src</locationURI>
</link>
</linkedResources>
</projectDescription>
......@@ -17,6 +17,7 @@
<property name="jxta-src" location="dependencies-src/jxse-src-2.5"/>
<property name="jstun-src" location="dependencies-src/jstun-src-0.7.1"/>
<property name="dist.dir" location="antbuild/dist/p2pproxy_${version}"/>
<property name="jni-src" location="antbuild/p2pproxy/jni_src/org/linphone/p2pproxy/launcher"/>
<path id="p2pproxy.classpath">
<pathelement location="antbuild/p2pproxy"/>
......@@ -44,7 +45,16 @@
<target name="build" depends="build-subprojects,build-project"/>
<target name="build-subprojects"/>
<target name="build-project" depends="init">
<target name="jni-src" depends="init" >
<property name="p2pproxy-h" location="launcher/src/p2pproxy.h"/>
<mkdir dir="${jni-src}"/>
<exec failonerror="yes" executable="swig">
<arg line=" -java -outdir ${jni-src} -package org.linphone.p2pproxy.launcher"/>
<arg line=" ${p2pproxy-h} "/>
</exec>
</target>
<target name="build-project" depends="init">
<echo message="${ant.project.name}: ${ant.file}"/>
<javac destdir="antbuild/p2pproxy" debug="true" debuglevel="${debuglevel}" source="${source}" target="${target}">
......
src/p2pproxy_wrap.d src/p2pproxy_wrap.o: ../src/p2pproxy_wrap.c \
/usr/lib/jvm/java-6-openjdk/include/jni.h \
/usr/lib/jvm/java-6-openjdk/include/jni_md.h
/usr/lib/jvm/java-6-openjdk/include/jni.h:
/usr/lib/jvm/java-6-openjdk/include/jni_md.h:
......@@ -5,15 +5,18 @@
# Add inputs and outputs from these tool invocations to the build variables
C_SRCS += \
../src/launcher-tester.c \
../src/p2pproxy.c
../src/p2pproxy.c \
../src/p2pproxy_wrap.c
OBJS += \
./src/launcher-tester.o \
./src/p2pproxy.o
./src/p2pproxy.o \
./src/p2pproxy_wrap.o
C_DEPS += \
./src/launcher-tester.d \
./src/p2pproxy.d
./src/p2pproxy.d \
./src/p2pproxy_wrap.d
# Each subdirectory must supply rules for building sources it contributes
......
......@@ -13,13 +13,14 @@
#endif
JNIEnv* p2pproxy_application_jnienv = 0;
JavaVM* p2pproxy_application_jvm = 0;
jclass p2pproxy_proxy_main_class = 0;
int p2pproxy_application_start(int argc, char **argv) {
JavaVMInitArgs args;
JavaVMOption options[7];
jint res=-1;
jclass lP2pProxyMainClass;
jclass lP2pProxyMainClass=0;
jmethodID mainMethod;
jobjectArray applicationArgsList;
jstring applicationArg;
......@@ -56,13 +57,13 @@ int p2pproxy_application_start(int argc, char **argv) {
return P2PPROXY_ERROR;
}
lP2pProxyMainClass = (*p2pproxy_application_jnienv)->FindClass(p2pproxy_application_jnienv, "org/linphone/p2pproxy/core/P2pProxyMain");
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");
return P2PPROXY_ERROR;
}
mainMethod = (*p2pproxy_application_jnienv)->GetStaticMethodID(p2pproxy_application_jnienv, lP2pProxyMainClass, "main", "([Ljava/lang/String;)V");
mainMethod = (*p2pproxy_application_jnienv)->GetStaticMethodID(p2pproxy_application_jnienv, p2pproxy_proxy_main_class, "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);
......@@ -72,7 +73,7 @@ int p2pproxy_application_start(int argc, char **argv) {
}
(*p2pproxy_application_jnienv)->CallStaticVoidMethod(p2pproxy_application_jnienv, lP2pProxyMainClass, mainMethod, applicationArgsList);
(*p2pproxy_application_jnienv)->CallStaticVoidMethod(p2pproxy_application_jnienv, p2pproxy_proxy_main_class, mainMethod, applicationArgsList);
return P2PPROXY_NO_ERROR;
}
......@@ -84,27 +85,34 @@ const char* p2pproxy_status_string(int status_code) {
int p2pproxy_accountmgt_createAccount(const char* user_name) {
return P2PPROXY_ERROR;
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);
}
int p2pproxy_accountmgt_isValidAccount(const char* user_name) {
return P2PPROXY_ERROR;
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);
}
int p2pproxy_accountmgt_deleteAccount(const char* user_name) {
return P2PPROXY_ERROR;
}
jobject p2pproxy_get_accountmgt() {
jclass lP2pProxyMainClass;
jmethodID getAccountMgtMethod;
lP2pProxyMainClass = (*p2pproxy_application_jnienv)->FindClass(p2pproxy_application_jnienv, "org/linphone/p2pproxy/core/P2pProxyMain");
getAccountMgtMethod = (*p2pproxy_application_jnienv)->GetStaticMethodID(p2pproxy_application_jnienv, lP2pProxyMainClass, "getAccountManager", "(V)Lorg/linphone/p2pproxy/core/P2pProxyAccountManagementMBean");
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);
}
......@@ -20,6 +20,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef P2PPROXY_LAUNCHER_H_
#define P2PPROXY_LAUNCHER_H_
#ifdef SWIG
%module P2pProxylauncher
%javaconst(1);
%include "p2pproxy.h"
#endif /*SWIG*/
#define P2PPROXY_ACCOUNTMGT_USER_EXIST 1
#define P2PPROXY_ACCOUNTMGT_USER_NOT_EXIST 0
......@@ -33,6 +39,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define P2PPROXY_ERROR_ACCOUNTMGT_USER_ALREADY_EXIST -4
#define P2PPROXY_ERROR_ACCOUNTMGT_BAD_SIP_URI -5
#ifndef SWIG
/**
* start p2pproxy application
* blocking call
......@@ -46,7 +53,7 @@ int p2pproxy_application_start(int argc, char **argv);
/**
* return the status string corresponding to the status code
*/
const char* p2pproxy_status_string(int status_code);
/*const char* p2pproxy_status_string(int status_code);*/
/************************/
/***account management***/
......@@ -72,5 +79,7 @@ int p2pproxy_accountmgt_isValidAccount(const char* user_name);
* @return P2PPROXY_NO_ERROR, P2PPROXY_ERROR_APPLICATIONNOTSTARTED
*/
int p2pproxy_accountmgt_deleteAccount(const char* user_name);
#endif /*SWIG*/
#endif /*P2PPROXY_LAUNCHER_H_*/
......@@ -38,9 +38,11 @@ import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.linphone.p2pproxy.api.P2pProxyException;
import org.linphone.p2pproxy.api.P2pProxyManagement;
import org.linphone.p2pproxy.api.P2pProxyUserAlreadyExistException;
import org.linphone.p2pproxy.core.media.rtprelay.RtpRelayService;
import org.linphone.p2pproxy.core.sipproxy.SipProxyRegistrar;
import org.zoolu.sip.provider.SipStack;
import org.linphone.p2pproxy.launcher.P2pProxylauncherConstants;
public class P2pProxyMain implements P2pProxyMainMBean {
private final static Logger mLog = Logger.getLogger(P2pProxyMain.class);
......@@ -366,7 +368,37 @@ public static void staticLoadTraceConfigFile() throws P2pProxyException {
throw new P2pProxyException("enable to load traces",e);
}
}
public static P2pProxyAccountManagementMBean getAccountManager() {
return mP2pProxyAccountManagement;
/* p2pproxy.h implementation*/
public static int createAccount(String aUserName) {
try {
mP2pProxyAccountManagement.createAccount(aUserName);
} catch (P2pProxyUserAlreadyExistException e) {
return P2pProxylauncherConstants.P2PPROXY_ACCOUNTMGT_USER_EXIST;
} catch (P2pProxyException e) {
return P2pProxylauncherConstants.P2PPROXY_ERROR;
}
return P2pProxylauncherConstants.P2PPROXY_NO_ERROR;
}
public static int deleteAccount(String aUserName) {
try {
mP2pProxyAccountManagement.deleteAccount(aUserName);
} catch (P2pProxyException e) {
return P2pProxylauncherConstants.P2PPROXY_ERROR;
}
return P2pProxylauncherConstants.P2PPROXY_NO_ERROR;
}
public static int isValidAccount(String aUserName){
try {
if (mP2pProxyAccountManagement.isValidAccount(aUserName)) {
return P2pProxylauncherConstants.P2PPROXY_ACCOUNTMGT_USER_EXIST;
} else {
return P2pProxylauncherConstants.P2PPROXY_ACCOUNTMGT_USER_NOT_EXIST;
}
} catch (P2pProxyException e) {
return P2pProxylauncherConstants.P2PPROXY_ERROR;
}
}
}
\ No newline at end of file
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