PageRenderTime 27ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/protocols/ss7/hardware/dialogic/native/src/main/native/ipc.c

http://mobicents.googlecode.com/
C | 159 lines | 82 code | 38 blank | 39 comment | 9 complexity | 6b9b8c9d47edac3ec74c7450b93e9c53 MD5 | raw file
Possible License(s): LGPL-3.0, GPL-3.0, LGPL-2.1, GPL-2.0, CC-BY-SA-3.0, CC0-1.0, Apache-2.0, BSD-3-Clause
  1. #include "system.h"
  2. #include "msg.h"
  3. #include "sysgct.h"
  4. #include "ss7_inc.h" /* ss7 message & parameter definitions */
  5. #include "org_mobicents_ss7_hardware_dialogic_InterProcessCommunicator.h"
  6. /*
  7. * Class: org_mobicents_gct_InterProcessCommunicator
  8. * Method: receive
  9. * Signature: (I[B)I
  10. */
  11. JNIEXPORT jint JNICALL Java_org_mobicents_ss7_hardware_dialogic_InterProcessCommunicator_receive
  12. (JNIEnv *env, jobject obj, jint src_module_id, jbyteArray msg_buffer) {
  13. jclass cls;
  14. jfieldID fid;
  15. jsize len;
  16. jbyte *body;
  17. u16 mlen; /* message length */
  18. u8 *pptr; /* pointer into parameter area */
  19. HDR* h;
  20. MSG *m;
  21. int i;
  22. // h = GCT_grab(src_module_id);
  23. h = GCT_receive(src_module_id);
  24. if (h == 0) {
  25. return -1;
  26. }
  27. m = (MSG *)h;
  28. len = (*env)->GetArrayLength(env, msg_buffer);
  29. body = (*env)->GetByteArrayElements(env, msg_buffer, 0);
  30. if ((mlen = ((MSG*) h)->len) > 0) {
  31. pptr = get_param((MSG *) h);
  32. i = 0;
  33. switch (m->hdr.type)
  34. {
  35. case MTP_MSG_PAUSE :
  36. body[i++] = 0; /* SI = 0 */
  37. body[i++] = 3; /* PAUSE */
  38. break;
  39. case MTP_MSG_RESUME :
  40. body[i++] = 0; /* SI = 0 */
  41. body[i++] = 4; /* RESUME */
  42. break;
  43. case MTP_MSG_STATUS :
  44. body[i++] = 0; /* SI = 0 */
  45. body[i++] = 5; /* STATUS */
  46. body[i++] = m->hdr.status; /* actual status. 1 = Remote User Unavailable 2 = Signaling Network Congestion */
  47. break;
  48. /* Do we care for API_MSG_RX_IND and default or directly pass to upper layer?
  49. case API_MSG_RX_IND :
  50. UPE_mtp_transfer_ind(m);
  51. break;
  52. default :
  53. printf("Rx MSG: type=0x%04x src=0x%02x status=0x%02x len=0x%04x\n", m->hdr.type, m->hdr.src, m->hdr.status, m->len);
  54. break;
  55. */
  56. }
  57. while (mlen--) {
  58. body[i++] = *pptr++;
  59. }
  60. (*env)->ReleaseByteArrayElements(env, msg_buffer, body, 0);
  61. /*
  62. printf("MTP Message id: %d", h->id);
  63. */
  64. relm(h);
  65. return i;
  66. }
  67. (*env)->ReleaseByteArrayElements(env, msg_buffer, body, 0);
  68. relm(h);
  69. return -1;
  70. }
  71. /*
  72. * Class: org_mobicents_gct_InterProcessCommunicator
  73. * Method: send
  74. * Signature: (I[B)I
  75. */
  76. JNIEXPORT jint JNICALL Java_org_mobicents_ss7_hardware_dialogic_InterProcessCommunicator_send
  77. (JNIEnv *env, jobject obj, jint src_module_id, jint dest_module_id, jbyteArray msg_buffer) {
  78. jclass cls;
  79. jfieldID fid;
  80. jsize len;
  81. jbyte *body;
  82. int status;
  83. /* HDR* h; */
  84. u8 *pptr;
  85. int i;
  86. MSG *m;
  87. /*
  88. printf("*********Preparing for sending data*******");
  89. */
  90. len = (*env)->GetArrayLength(env, msg_buffer);
  91. body = (*env)->GetByteArrayElements(env, msg_buffer, 0);
  92. m = getm(0xcf00, 3, 0,len);
  93. if (m == 0) {
  94. return -1;
  95. }
  96. m->hdr.src = src_module_id;
  97. m->hdr.dst = dest_module_id;
  98. /*
  99. h->src = src_module_id;
  100. h->dst = dest_module_id;
  101. ((MSG*) h)->len = len;
  102. */
  103. m->len = len;
  104. pptr = get_param(m);
  105. for(i = 0; i < len; i++) {
  106. *pptr++ = body[i];
  107. }
  108. status = GCT_send(dest_module_id,(HDR *)m);
  109. /* If the function does not return success then the calling program must release
  110. the message back to the system using relm().
  111. */
  112. if(status!=0)
  113. relm(m);
  114. /*
  115. printf("Sent %d bytes, status %d", len, status);
  116. */
  117. (*env)->ReleaseByteArrayElements(env, msg_buffer, body, 0);
  118. return status;
  119. }