From d28f0fc2d782ab10217f4395fbd6c92a24c797da Mon Sep 17 00:00:00 2001 From: jehan Date: Wed, 24 Sep 2008 14:26:31 +0000 Subject: [PATCH] add c interface git-svn-id: svn+ssh://svn.savannah.nongnu.org/linphone/trunk@38 3f6dc0c8-ddfe-455d-9043-3cd528dc4637 --- p2pproxy/launcher/.cproject | 844 ++++++++++++++++++++++++ p2pproxy/launcher/.project | 81 +++ p2pproxy/launcher/src/launcher-tester.c | 0 p2pproxy/launcher/src/p2pproxy.c | 84 +++ p2pproxy/launcher/src/p2pproxy.h | 76 +++ 5 files changed, 1085 insertions(+) create mode 100644 p2pproxy/launcher/.cproject create mode 100644 p2pproxy/launcher/.project create mode 100644 p2pproxy/launcher/src/launcher-tester.c create mode 100644 p2pproxy/launcher/src/p2pproxy.c create mode 100644 p2pproxy/launcher/src/p2pproxy.h diff --git a/p2pproxy/launcher/.cproject b/p2pproxy/launcher/.cproject new file mode 100644 index 000000000..f7d0a27f5 --- /dev/null +++ b/p2pproxy/launcher/.cproject @@ -0,0 +1,844 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/p2pproxy/launcher/.project b/p2pproxy/launcher/.project new file mode 100644 index 000000000..cf9890a0a --- /dev/null +++ b/p2pproxy/launcher/.project @@ -0,0 +1,81 @@ + + + p2pproxy-launcher + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + org.eclipse.cdt.make.core.fullBuildTarget + all + + + ?name? + + + + org.eclipse.cdt.make.core.enableAutoBuild + false + + + org.eclipse.cdt.make.core.buildLocation + ${workspace_loc:/p2pproxy-launcher/Debug} + + + org.eclipse.cdt.make.core.enableFullBuild + true + + + org.eclipse.cdt.make.core.enableCleanBuild + true + + + org.eclipse.cdt.make.core.cleanBuildTarget + clean + + + org.eclipse.cdt.make.core.append_environment + true + + + org.eclipse.cdt.make.core.contents + org.eclipse.cdt.make.core.activeConfigSettings + + + org.eclipse.cdt.make.core.useDefaultBuildCmd + true + + + org.eclipse.cdt.make.core.buildArguments + + + + org.eclipse.cdt.make.core.buildCommand + make + + + org.eclipse.cdt.make.core.autoBuildTarget + all + + + org.eclipse.cdt.make.core.stopOnError + true + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + + diff --git a/p2pproxy/launcher/src/launcher-tester.c b/p2pproxy/launcher/src/launcher-tester.c new file mode 100644 index 000000000..e69de29bb diff --git a/p2pproxy/launcher/src/p2pproxy.c b/p2pproxy/launcher/src/p2pproxy.c new file mode 100644 index 000000000..fc9861ddb --- /dev/null +++ b/p2pproxy/launcher/src/p2pproxy.c @@ -0,0 +1,84 @@ +#include +#include +#include "p2pproxy.c" + +#ifndef P2PPROXY_CLASSPATH + #define P2PPROXY_INSTALL_PREFIX "/usr/" +#endif +#ifndef P2PPROXY_JMX_PORT + #define P2PPROXY_JMX_PORT "5678" +#endif +JNIEnv* p2pproxy_application_jnienv = 0; + +int p2pproxy_application_start(int argc, char **argv) { + JavaVM* jvm; + JNIEnv* env; + JavaVMInitArgs args; + JavaVMOption options[5]; + + if (p2pproxy_application_jnienv != 0) { + fprintf(stderr,"p2pproxy already started"); + return P2PPROXY_ERROR_APPLICATION_ALREADY_STARTED; + } + args.version = JNI_VERSION_1_6; + args.nOptions = sizeof (options); + options[0].optionString = "-Dcom.sun.management.jmxremote"; + options[1].optionString = "-Dcom.sun.management.jmxremote.port="P2PPROXY_JMX_POR"; + options[2].optionString = "-Dcom.sun.management.jmxremote.authenticate=false"; + options[3].optionString = "-Dcom.sun.management.jmxremote.ssl=false"; + options[4].optionString = "-Djava.class.path="P2PPROXY_INSTALL_PREFIX"/share/java/p2pproxy.jar"; + + args.options = options; + args.ignoreUnrecognized = JNI_FALSE; + + JNI_CreateJavaVM(&jvm, (void **)&env, &args); + return env; + return P2PPROXY_ERROR; +} + + +const char* p2pproxy_status_string(int status_code) { + return P2PPROXY_ERROR; +} + + +int p2pproxy_accountmgt_createAccount(const char* user_name) { + return P2PPROXY_ERROR; +} + +int p2pproxy_accountmgt_isValidAccount(const char* user_name) { + return P2PPROXY_ERROR; +} + +int p2pproxy_accountmgt_deleteAccount(const char* user_name) { + return P2PPROXY_ERROR; +} + + + +JNIEnv* create_vm() { + +} + +void invoke_class(JNIEnv* env) { + jclass helloWorldClass; + jmethodID mainMethod; + jobjectArray applicationArgs; + jstring applicationArg0; + + helloWorldClass = (*env)->FindClass(env, "example/jni/InvocationHelloWorld"); + + mainMethod = (*env)->GetStaticMethodID(env, helloWorldClass, "main", "([Ljava/lang/String;)V"); + + applicationArgs = (*env)->NewObjectArray(env, 1, (*env)->FindClass(env, "java/lang/String"), NULL); + applicationArg0 = (*env)->NewStringUTF(env, "From-C-program"); + (*env)->SetObjectArrayElement(env, applicationArgs, 0, applicationArg0); + + (*env)->CallStaticVoidMethod(env, helloWorldClass, mainMethod, applicationArgs); +} + + +int main(int argc, char **argv) { + JNIEnv* env = create_vm(); + invoke_class( env ); +} \ No newline at end of file diff --git a/p2pproxy/launcher/src/p2pproxy.h b/p2pproxy/launcher/src/p2pproxy.h new file mode 100644 index 000000000..db45cd999 --- /dev/null +++ b/p2pproxy/launcher/src/p2pproxy.h @@ -0,0 +1,76 @@ +/* +p2pproxy Copyright (C) 2007 Jehan Monnier () + +p2pproxy.h - sip proxy. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ +#ifndef P2PPROXY_LAUNCHER_H_ +#define P2PPROXY_LAUNCHER_H_ + +#define P2PPROXY_ACCOUNTMGT_USER_EXIST 1 +#define P2PPROXY_ACCOUNTMGT_USER_NOT_EXIST 0 + + +/* status code*/ +#define P2PPROXY_NO_ERROR 0 +/*error codes*/ +#define P2PPROXY_ERROR -1 +#define P2PPROXY_ERROR_APPLICATION_NOT_STARTED = -2 +#define P2PPROXY_ERROR_APPLICATION_ALREADY_STARTED = -3 +#define P2PPROXY_ERROR_ACCOUNTMGT_USER_ALREADY_EXIST = -4 +#define P2PPROXY_ERROR_ACCOUNTMGT_BAD_SIP_URI = -5 + +/** + * start p2pproxy application + * blocking call + * @param argc number of argument + * @param argv arguments + * @return status code + * + */ +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); + +/************************/ +/***account management***/ +/************************/ + +/** +* create an account with the given name (must be unique) +* @param user_name user sip uri (sip:joe@p2p.linphone.org) +* +* @return P2PPROXY_NO_ERROR, P2PPROXY_ERROR_APPLICATIONNOTSTARTED, P2PPROXY_ERROR_ACCOUNTMGT_USERALREADYEXIST, P2PPROXY_ERROR_ACCOUNTMGT_BADSIPURI +*/ +int p2pproxy_accountmgt_createAccount(const char* user_name); +/** +* check if a user name has been already created +* @param user_name user sip uri (sip:joe@p2p.linphone.org) +* @return P2PPROXY_ACCOUNTMGT_USEREXIST, P2PPROXY_ACCOUNTMGT_USERNOTEXIST , P2PPROXY_ERROR_APPLICATIONNOTSTARTED +*/ +int p2pproxy_accountmgt_isValidAccount(const char* user_name); + +/** +* delete an account with the given name +* @param user_name user sip uri (sip:joe@p2p.linphone.org) +* @return P2PPROXY_NO_ERROR, P2PPROXY_ERROR_APPLICATIONNOTSTARTED +*/ +int p2pproxy_accountmgt_deleteAccount(const char* user_name); + +#endif /*P2PPROXY_LAUNCHER_H_*/