summaryrefslogtreecommitdiffstats
path: root/branches/1.0/bindings/java/java.i
blob: 6872e59b1e4f60221e50a7a3baef825c087163e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* File : java.i 
* http://www.swig.org/Doc1.3/Java.html
*/

// http://www.swig.org/Doc1.3/Java.html#enumerations
%include "enums.swg"
%javaconst(1);


//================== Mapping void* (Java to C) as ByteBuffer
%typemap(jni) void * "jbyteArray"
%typemap(jtype) void * "java.nio.ByteBuffer"
%typemap(jstype) void * "java.nio.ByteBuffer"
%typemap(javain) void * "$javainput"
%typemap(javaout) void * { return $jnicall; }

// (From Java to C)
%typemap(in) void * %{ 
	$1 = jenv->GetDirectBufferAddress($input); 
%}

// (From C to Java)
//%typemap(out) void * %{
//	$result = $1; 
//%}
%typemap(javadirectorin) void * "$jniinput"
//==================


%typemap(javacode) SipMessage %{
  public byte[] getSipContent() {
    final int clen = (int)this.getSipContentLength();
    if(clen>0){
		final java.nio.ByteBuffer buffer = java.nio.ByteBuffer.allocateDirect(clen);
        final int read = (int)this.getSipContent(buffer, clen);
        final byte[] bytes = new byte[read];
        buffer.get(bytes, 0, read);
        return bytes;
    }
    return null;
  }
%}

%typemap(javacode) SipSession %{
  protected java.nio.ByteBuffer getByteBuffer(byte[] bytes) {
    if(bytes != null){
		final java.nio.ByteBuffer byteBuffer = java.nio.ByteBuffer.allocateDirect(bytes.length);
        byteBuffer.put(bytes);
        return byteBuffer;
    }
    return null;
  }
%}

%typemap(javacode) PublicationSession %{
  public boolean Publish(byte[] bytes) {
    if(bytes != null){
		final java.nio.ByteBuffer byteBuffer = this.getByteBuffer(bytes);
        return this.publish(byteBuffer, bytes.length);
    }
    return false;
  }
%}

%typemap(javacode) XcapMessage %{
  public byte[] getXcapContent() {
    final int clen = (int)this.getXcapContentLength();
    if(clen>0){
		final java.nio.ByteBuffer buffer = java.nio.ByteBuffer.allocateDirect(clen);
        final int read = (int)this.getXcapContent(buffer, clen);
        final byte[] bytes = new byte[read];
        buffer.get(bytes, 0, read);
        return bytes;
    }
    return null;
  }
%}

%include ../_common/tinyWRAP.i
OpenPOWER on IntegriCloud