java.i 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* File : java.i
  2. * http://www.swig.org/Doc1.3/Java.html
  3. */
  4. // http://www.swig.org/Doc1.3/Java.html#enumerations
  5. %include "enums.swg"
  6. %javaconst(1);
  7. //================== Mapping void* (Java to C) as ByteBuffer
  8. %typemap(jni) void * "jbyteArray"
  9. %typemap(jtype) void * "java.nio.ByteBuffer"
  10. %typemap(jstype) void * "java.nio.ByteBuffer"
  11. %typemap(javain) void * "$javainput"
  12. %typemap(javaout) void * { return $jnicall; }
  13. // (From Java to C)
  14. %typemap(in) void * %{
  15. $1 = jenv->GetDirectBufferAddress($input);
  16. %}
  17. // (From C to Java)
  18. //%typemap(out) void * %{
  19. // $result = $1;
  20. //%}
  21. %typemap(javadirectorin) void * "$jniinput"
  22. //==================
  23. %typemap(javacode) SipMessage %{
  24. public byte[] getSipContent() {
  25. final int clen = (int)this.getSipContentLength();
  26. if(clen>0){
  27. final java.nio.ByteBuffer buffer = java.nio.ByteBuffer.allocateDirect(clen);
  28. final int read = (int)this.getSipContent(buffer, clen);
  29. final byte[] bytes = new byte[read];
  30. buffer.get(bytes, 0, read);
  31. return bytes;
  32. }
  33. return null;
  34. }
  35. %}
  36. %typemap(javacode) SipSession %{
  37. protected java.nio.ByteBuffer getByteBuffer(byte[] bytes) {
  38. if(bytes != null){
  39. final java.nio.ByteBuffer byteBuffer = java.nio.ByteBuffer.allocateDirect(bytes.length);
  40. byteBuffer.put(bytes);
  41. return byteBuffer;
  42. }
  43. return null;
  44. }
  45. %}
  46. %typemap(javacode) PublicationSession %{
  47. public boolean Publish(byte[] bytes) {
  48. if(bytes != null){
  49. final java.nio.ByteBuffer byteBuffer = this.getByteBuffer(bytes);
  50. return this.publish(byteBuffer, bytes.length);
  51. }
  52. return false;
  53. }
  54. %}
  55. %typemap(javacode) XcapMessage %{
  56. public byte[] getXcapContent() {
  57. final int clen = (int)this.getXcapContentLength();
  58. if(clen>0){
  59. final java.nio.ByteBuffer buffer = java.nio.ByteBuffer.allocateDirect(clen);
  60. final int read = (int)this.getXcapContent(buffer, clen);
  61. final byte[] bytes = new byte[read];
  62. buffer.get(bytes, 0, read);
  63. return bytes;
  64. }
  65. return null;
  66. }
  67. %}
  68. %typemap(javacode) T140CallbackData %{
  69. public byte[] getData() {
  70. final int size = (int)this.getSize();
  71. if(size > 0){
  72. final java.nio.ByteBuffer buffer = java.nio.ByteBuffer.allocateDirect(size);
  73. final int read = (int)this.getData(buffer, size);
  74. final byte[] bytes = new byte[read];
  75. buffer.get(bytes, 0, read);
  76. return bytes;
  77. }
  78. return null;
  79. }
  80. %}
  81. %include ../_common/tinyWRAP.i