jni - How to use a C library such as PJSIP on java? -


is there way use , invoke method calls library compiled in c such pjsip library?

i want use , invoke calls pjsip lib have compiled obvious issue pjsip c library not java library ie jar file.

possible? maybe jni?

thanks

edit: tried using swig task @ hand create empty class file.

here command use execute swig:

swig  -verbose -java -package com.josh.sip.util -o jni_wrapper.c pjsua.i 

output swig command

    language subdirectory: java search paths:    .\    .\swig_lib\java\    c:\users\jonney\downloads\swigwin-2.0.9\lib\java\    .\swig_lib\    c:\users\jonney\downloads\swigwin-2.0.9\lib\ preprocessing... starting language-specific parse... processing types... c++ analysis... generating wrappers... 

pjsua java class creates me:

    /* ----------------------------------------------------------------------------  * file automatically generated swig (http://www.swig.org).  * version 2.0.9  *  * not make changes file unless know doing--modify  * swig interface file instead.  * ----------------------------------------------------------------------------- */  package com.josh.sip.util;  public class pjsua { } 

the pjsua jni file creates me

/* ----------------------------------------------------------------------------  * file automatically generated swig (http://www.swig.org).  * version 2.0.9  *  * not make changes file unless know doing--modify  * swig interface file instead.  * ----------------------------------------------------------------------------- */  package com.josh.sip.util;  public class pjsuajni { } 

the jni_wrapper.c generates me below:

    /* ----------------------------------------------------------------------------  * file automatically generated swig (http://www.swig.org).  * version 2.0.9  *   * file not intended readable , contains number of   * coding conventions designed improve portability , efficiency. not make  * changes file unless know doing--modify swig   * interface file instead.   * ----------------------------------------------------------------------------- */  #define swigjava  /* -----------------------------------------------------------------------------  *  section contains generic swig labels method/variable  *  declarations/attributes, , other compiler dependent labels.  * ----------------------------------------------------------------------------- */  /* template workaround compilers cannot correctly implement c++ standard */ #ifndef swigtemplatedisambiguator # if defined(__sunpro_cc) && (__sunpro_cc <= 0x560) #  define swigtemplatedisambiguator template # elif defined(__hp_acc) /* needed `acc -aa' when `acc -v' reports hp ansi c++ b3910b a.03.55 */ /* if find maximum version requires this, test __hp_acc <= 35500 a.03.55 */ #  define swigtemplatedisambiguator template # else #  define swigtemplatedisambiguator # endif #endif  /* inline attribute */ #ifndef swiginline # if defined(__cplusplus) || (defined(__gnuc__) && !defined(__strict_ansi__)) #   define swiginline inline # else #   define swiginline # endif #endif  /* attribute recognised compilers avoid 'unused' warnings */ #ifndef swigunused # if defined(__gnuc__) #   if !(defined(__cplusplus)) || (__gnuc__ > 3 || (__gnuc__ == 3 && __gnuc_minor__ >= 4)) #     define swigunused __attribute__ ((__unused__))  #   else #     define swigunused #   endif # elif defined(__icc) #   define swigunused __attribute__ ((__unused__))  # else #   define swigunused  # endif #endif  #ifndef swig_msc_unsuppress_4505 # if defined(_msc_ver) #   pragma warning(disable : 4505) /* unreferenced local function has been removed */ # endif  #endif  #ifndef swigunusedparm # ifdef __cplusplus #   define swigunusedparm(p) # else #   define swigunusedparm(p) p swigunused  # endif #endif  /* internal swig method */ #ifndef swigintern # define swigintern static swigunused #endif  /* internal inline swig method */ #ifndef swiginterninline # define swiginterninline swigintern swiginline #endif  /* exporting methods */ #if (__gnuc__ >= 4) || (__gnuc__ == 3 && __gnuc_minor__ >= 4) #  ifndef gcc_hasclassvisibility #    define gcc_hasclassvisibility #  endif #endif  #ifndef swigexport # if defined(_win32) || defined(__win32__) || defined(__cygwin__) #   if defined(static_linked) #     define swigexport #   else #     define swigexport __declspec(dllexport) #   endif # else #   if defined(__gnuc__) && defined(gcc_hasclassvisibility) #     define swigexport __attribute__ ((visibility("default"))) #   else #     define swigexport #   endif # endif #endif  /* calling conventions windows */ #ifndef swigstdcall # if defined(_win32) || defined(__win32__) || defined(__cygwin__) #   define swigstdcall __stdcall # else #   define swigstdcall # endif  #endif  /* deal microsoft's attempt @ deprecating c standard runtime functions */ #if !defined(swig_no_crt_secure_no_deprecate) && defined(_msc_ver) && !defined(_crt_secure_no_deprecate) # define _crt_secure_no_deprecate #endif  /* deal microsoft's attempt @ deprecating methods in standard c++ library */ #if !defined(swig_no_scl_secure_no_deprecate) && defined(_msc_ver) && !defined(_scl_secure_no_deprecate) # define _scl_secure_no_deprecate #endif    /* fix jlong on versions of gcc on windows */ #if defined(__gnuc__) && !defined(__intel_compiler)   typedef long long __int64; #endif  /* fix jlong on 64-bit x86 solaris */ #if defined(__x86_64) # ifdef _lp64 #   undef _lp64 # endif #endif  #include <jni.h> #include <stdlib.h> #include <string.h>   /* support throwing java exceptions */ typedef enum {   swig_javaoutofmemoryerror = 1,    swig_javaioexception,    swig_javaruntimeexception,    swig_javaindexoutofboundsexception,   swig_javaarithmeticexception,   swig_javaillegalargumentexception,   swig_javanullpointerexception,   swig_javadirectorpurevirtual,   swig_javaunknownerror } swig_javaexceptioncodes;  typedef struct {   swig_javaexceptioncodes code;   const char *java_exception; } swig_javaexceptions_t;   static void swigunused swig_javathrowexception(jnienv *jenv, swig_javaexceptioncodes code, const char *msg) {   jclass excep;   static const swig_javaexceptions_t java_exceptions[] = {     { swig_javaoutofmemoryerror, "java/lang/outofmemoryerror" },     { swig_javaioexception, "java/io/ioexception" },     { swig_javaruntimeexception, "java/lang/runtimeexception" },     { swig_javaindexoutofboundsexception, "java/lang/indexoutofboundsexception" },     { swig_javaarithmeticexception, "java/lang/arithmeticexception" },     { swig_javaillegalargumentexception, "java/lang/illegalargumentexception" },     { swig_javanullpointerexception, "java/lang/nullpointerexception" },     { swig_javadirectorpurevirtual, "java/lang/runtimeexception" },     { swig_javaunknownerror,  "java/lang/unknownerror" },     { (swig_javaexceptioncodes)0,  "java/lang/unknownerror" }   };   const swig_javaexceptions_t *except_ptr = java_exceptions;    while (except_ptr->code != code && except_ptr->code)     except_ptr++;    (*jenv)->exceptionclear(jenv);   excep = (*jenv)->findclass(jenv, except_ptr->java_exception);   if (excep)     (*jenv)->thrownew(jenv, excep, msg); }   /* contract support */  #define swig_contract_assert(nullreturn, expr, msg) if (!(expr)) {swig_javathrowexception(jenv, swig_javaillegalargumentexception, msg); return nullreturn; } else   #include "pjsua.h"   #ifdef __cplusplus extern "c" { #endif  #ifdef __cplusplus } #endif 

i have pjsua.h file inside same location .i file easier find both whilst executing swig command , advice?

i want swig or other tool create pjsua or pjsip java class implementations or interface methods can use use library.

such pain there no java version of sip stack

try jna jnaerator: https://code.google.com/p/jnaerator. i've used in own projects.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -