Ignore:
Timestamp:
Jun 29, 2013 1:14:27 AM (11 years ago)
Author:
nanang
Message:

Work on JNI project:

  • Only use single SWIG C++ wrapper.
  • Initial work on pjsua_callback: added parser and auto proxy generation.
  • Updated SWIG typemaps: SWIG director, input output, array of pointer, etc.
Location:
pjproject/branches/projects/jni/pjsip-apps/src/jni
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/projects/jni/pjsip-apps/src/jni

    • Property svn:ignore set to
      output
      yacctab.py
      lextab.py
      *.log
  • pjproject/branches/projects/jni/pjsip-apps/src/jni/header.i

    r4541 r4549  
    1 %module pjsua 
     1/* $Id$ */ 
    22 
    3 %include "typemaps.i" 
     3%module (directors="1") pjsua 
     4 
    45%include "enums.swg" 
    5 %include "arrays_java.i" 
     6%include "../my_typemaps.i" 
    67 
    78%header %{ 
    89    #include <pjsua-lib/pjsua.h> 
    9     extern pjsua_callback* PJSUA_CALLBACK_PROXY; 
    1010%} 
    1111 
    12 /* 'void *' shall be handled as byte arrays */ 
    13 %typemap(jni)            void * "void *" 
    14 %typemap(jtype)          void * "byte[]" 
    15 %typemap(jstype)         void * "byte[]" 
    16 %typemap(javain)         void * "$javainput" 
    17 %typemap(javadirectorin) void * "$jniinput" 
    18 %typemap(in)             void * { $1 = $input; } 
    19 %typemap(out)            void * { $result = $1; } 
    20 %typemap(javaout)        void * { return $jnicall; } 
     12/* Strip "pjsua_" prefix from pjsua functions, for better compatibility with  
     13 * pjsip-jni & csipsimple. 
     14 */ 
     15%rename("%(strip:[pjsua_])s", %$isfunction) ""; 
    2116 
    22 /* Apply output args */ 
    23 %apply unsigned *INOUT  { unsigned *count }; 
    24 %apply unsigned *OUTPUT { unsigned *tx_level }; 
    25 %apply unsigned *OUTPUT { unsigned *rx_level }; 
    26 %apply unsigned *OUTPUT { unsigned *p_tail_ms }; 
    27 %apply int      *OUTPUT { pjsua_acc_id *p_acc_id }; 
    28 %apply int      *OUTPUT { pjsua_call_id *p_call_id }; 
    29 %apply int      *OUTPUT { pjsua_transport_id *p_id }; 
    30 %apply int      *OUTPUT { pjsua_recorder_id *p_id }; 
    31 %apply int      *OUTPUT { pjsua_player_id *p_id }; 
    32 %apply int      *OUTPUT { pjsua_buddy_id *p_buddy_id }; 
    33 %apply int      *OUTPUT { pjsua_conf_port_id *p_id }; 
    34 %apply int      *OUTPUT { int *capture_dev }; 
    35 %apply int      *OUTPUT { int *playback_dev }; 
    36 %apply int      *OUTPUT { pj_stun_nat_type * }; 
    37 %apply int[ANY]         { pjmedia_format_id dec_fmt_id[8] }; 
     17/* Map 'void *' simply as long, app can use this "long" as index of its real user data */ 
     18%apply long { void * }; 
    3819 
    39 /* Array of pj_str_t */ 
     20/* Handle void *[ANY], e.g: pjsip_tx_data::mod_data, pjsip_transaction::mod_data */ 
     21//%ignore pjsip_tx_data::mod_data; 
     22//%ignore pjsip_transaction::mod_data; 
     23%apply long[ANY] { void *[ANY] }; 
     24 
     25/* Map "int*" & "unsigned*" as input & output */ 
     26%apply unsigned *INOUT  { unsigned * }; 
     27%apply int      *INOUT  { int * }; 
     28 
     29/* Map the following args as input & output */ 
     30%apply int      *INOUT  { pj_stun_nat_type * }; 
     31%apply int      *INOUT  { pjsip_status_code * }; 
     32%apply int[ANY]         { pjmedia_format_id dec_fmt_id[ANY] }; 
     33 
     34/* Handle array of pj_str_t */ 
    4035JAVA_ARRAYSOFCLASSES(pj_str_t) 
    41 #ifndef __cplusplus 
    42     /* On C target, pj_str_t::cArrayWrap/Unwrap Java code are missing, this somehow 'fixes' it. */ 
    43     JAVA_ARRAYSOFCLASSES(struct pj_str_t) 
    44 #endif 
    4536 
    46 /* Array of pj_ssl_cipher in pjsip_tls_setting. Warning: this breaks JAVA_ARRAYS_TYPEMAPS(int)! */ 
    47 %typemap(out) int[] %{$result = SWIG_JavaArrayOutInt(jenv, (int*)$1, arg1->ciphers_num); %} 
    48 %apply int[] { pj_ssl_cipher* }; 
    49 %ignore pjsip_tls_setting::ciphers; 
    50 %ignore pjsip_tls_setting::ciphers_num; 
    51 %extend pjsip_tls_setting { 
    52     void setCiphers(pj_ssl_cipher *ciphers, int num) { 
    53         int i; 
    54         $self->ciphers = (pj_ssl_cipher*)calloc(num, sizeof(pj_ssl_cipher)); 
    55         for (i=0; i<num; ++i) $self->ciphers[i] = ciphers[i]; 
    56         $self->ciphers_num = num; 
    57     } 
    58     pj_ssl_cipher* getCiphers() { 
    59         return $self->ciphers; 
    60     } 
    61 }; 
     37/* Handle pointer-to-pointer-to-object as input & output */ 
     38MY_JAVA_CLASS_INOUT(pjmedia_port, p_port) 
     39MY_JAVA_CLASS_INOUT(pjsip_tx_data, p_tdata) 
    6240 
     41/* Handle array of pj_ssl_cipher in pjsip_tls_setting. */ 
     42MY_JAVA_MEMBER_ARRAY_OF_ENUM(pjsip_tls_setting, pj_ssl_cipher, ciphers, ciphers_num) 
    6343 
    64 /* C++ SWIG target doesn't support nested class (C version does though). 
     44/* Handle array of pointer in struct/class member */ 
     45MY_JAVA_MEMBER_ARRAY_OF_POINTER(pjsip_regc_cbparam, pjsip_contact_hdr, contact, contact_cnt) 
     46MY_JAVA_MEMBER_ARRAY_OF_POINTER(pjmedia_sdp_session, pjmedia_sdp_media, media, media_count) 
     47MY_JAVA_MEMBER_ARRAY_OF_POINTER(pjmedia_sdp_media, pjmedia_sdp_bandw, bandw, bandw_count) 
     48MY_JAVA_MEMBER_ARRAY_OF_POINTER(pjmedia_sdp_media, pjmedia_sdp_attr, attr, attr_count) 
     49 
     50/* C++ SWIG target doesn't support nested class (C version does though!). 
    6551 * This is minimal workaround, ignore nested class as if it is not there. 
    6652 * TODO: proper workaround will be moving out inner classes to global scope. 
     
    7258#endif 
    7359 
    74 /* Typemaps for marshalling pjmedia_port ** */ 
    75 %typemap(jni) pjmedia_port **p_port "jobject" 
    76 %typemap(jtype) pjmedia_port **p_port "pjmedia_port" 
    77 %typemap(jstype) pjmedia_port **p_port "pjmedia_port" 
    78  
    79 /* Typemaps for pjmedia_port ** as a parameter output type */ 
    80 %typemap(in) pjmedia_port **p_port (pjmedia_port *ppMediaPort = 0) %{ $1 = &ppMediaPort; %} 
    81 %typemap(argout) pjmedia_port **p_port { 
    82   // Give Java proxy the C pointer (of newly created object) 
    83   jclass clazz = JCALL1(FindClass, jenv, "org/pjsip/pjsua/pjmedia_port"); 
    84   jfieldID fid = JCALL3(GetFieldID, jenv, clazz, "swigCPtr", "J"); 
    85   jlong cPtr = 0; 
    86   *(pjmedia_port **)&cPtr = *$1; 
    87   JCALL3(SetLongField, jenv, $input, fid, cPtr); 
    88 } 
    89 %typemap(javain) pjmedia_port **p_port "$javainput" 
    90  
    91  
    92 /* Strip "pjsua_" prefix from pjsua functions, for better compatibility with  
    93  * pjsip-jni & csipsimple. 
    94  */ 
    95 %rename("%(strip:[pjsua_])s", %$isfunction) ""; 
    96  
    97 /* Automatically init pjsua_config::cb to cb proxy via pjsua_config_default() */ 
    98 /* 1. Hide 'cb' from 'pjsua_config' */ 
    99 %ignore pjsua_config::cb; 
    100 /* 2. Ignore original pjsua_config_default() */ 
    101 %ignore pjsua_config_default; 
    102 /* 3. Optional, put back "pjsua_" prefix, if stripping is not preferred */ 
    103 //%rename(pjsua_config_default) config_default; 
    104 /* 4. Put custom implementation */ 
    105 %inline %{ 
    106     void config_default(pjsua_config *cfg) { 
    107         pjsua_config_default(cfg); 
    108         cfg->cb = *PJSUA_CALLBACK_PROXY; 
    109     } 
    110 %} 
     60%include "../callbacks.i" 
    11161 
    11262/* Global constants */ 
Note: See TracChangeset for help on using the changeset viewer.