PageRenderTime 36ms CodeModel.GetById 22ms app.highlight 10ms RepoModel.GetById 2ms 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
  1#include "system.h"
  2#include "msg.h"
  3#include "sysgct.h"
  4#include "ss7_inc.h"    /* ss7 message & parameter definitions */
  5
  6#include "org_mobicents_ss7_hardware_dialogic_InterProcessCommunicator.h"
  7
  8/*
  9 * Class:     org_mobicents_gct_InterProcessCommunicator
 10 * Method:    receive
 11 * Signature: (I[B)I
 12 */
 13JNIEXPORT jint JNICALL Java_org_mobicents_ss7_hardware_dialogic_InterProcessCommunicator_receive
 14(JNIEnv *env, jobject obj, jint src_module_id, jbyteArray msg_buffer) {
 15	jclass cls;
 16	jfieldID fid;
 17
 18	jsize len;
 19	jbyte *body;
 20
 21    	u16   mlen;           /* message length */
 22    	u8    *pptr;          /* pointer into parameter area */
 23
 24	HDR*  h;
 25	MSG *m;
 26	int i;
 27
 28	// h = GCT_grab(src_module_id);
 29	h = GCT_receive(src_module_id);
 30
 31	if (h == 0) {
 32		return -1;
 33	}
 34
 35	m = (MSG *)h;
 36
 37	len = (*env)->GetArrayLength(env, msg_buffer);
 38    	body = (*env)->GetByteArrayElements(env, msg_buffer, 0);
 39
 40    	if ((mlen = ((MSG*) h)->len) > 0) {
 41		
 42		pptr = get_param((MSG *) h);
 43		i = 0;	
 44
 45		switch (m->hdr.type)
 46		{
 47		case MTP_MSG_PAUSE :
 48		  body[i++] = 0; /* SI = 0 */
 49		  body[i++] = 3; /* PAUSE */
 50		  break;
 51
 52		case MTP_MSG_RESUME :
 53		  body[i++] = 0; /* SI = 0 */
 54		  body[i++] = 4; /* RESUME */
 55		  break;
 56
 57		case MTP_MSG_STATUS :
 58		  body[i++] = 0; /* SI = 0 */
 59		  body[i++] = 5; /* STATUS */
 60		  body[i++] = m->hdr.status; /* actual status. 1 = Remote User Unavailable 2 = Signaling Network Congestion */
 61		  break;
 62		
 63		/* Do we care for API_MSG_RX_IND and default or directly pass to upper layer?
 64		case API_MSG_RX_IND :
 65		  UPE_mtp_transfer_ind(m);
 66		  break;
 67
 68		default :
 69		  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);
 70		  break;
 71		*/
 72		}
 73
 74	
 75		while (mlen--) {
 76			body[i++] = *pptr++;
 77		}
 78
 79		(*env)->ReleaseByteArrayElements(env, msg_buffer, body, 0);
 80
 81		/*
 82		printf("MTP Message id: %d", h->id);
 83		*/
 84
 85		relm(h);
 86		return i;
 87	}
 88
 89
 90	(*env)->ReleaseByteArrayElements(env, msg_buffer, body, 0);
 91	relm(h);
 92	return -1;
 93
 94}
 95
 96/*
 97 * Class:     org_mobicents_gct_InterProcessCommunicator
 98 * Method:    send
 99 * Signature: (I[B)I
100 */
101JNIEXPORT jint JNICALL Java_org_mobicents_ss7_hardware_dialogic_InterProcessCommunicator_send
102(JNIEnv *env, jobject obj, jint src_module_id, jint dest_module_id, jbyteArray msg_buffer) {
103	jclass cls;
104	jfieldID fid;
105
106	jsize len;
107	jbyte *body;
108	int status;
109
110	/* HDR*  h; */
111    	u8  *pptr;
112	int i;
113	MSG   *m;
114	
115/*	
116	printf("*********Preparing for sending data*******");
117*/	
118
119	len = (*env)->GetArrayLength(env, msg_buffer);
120    body = (*env)->GetByteArrayElements(env, msg_buffer, 0);
121	
122	m = getm(0xcf00, 3, 0,len);
123
124	if (m == 0) {
125		return -1;
126	}
127
128	m->hdr.src = src_module_id;
129      	m->hdr.dst = dest_module_id;
130/*
131	h->src = src_module_id;
132	h->dst = dest_module_id;
133
134	((MSG*) h)->len = len;
135*/
136	m->len = len;
137	pptr = get_param(m);
138
139	for(i = 0; i < len; i++) {
140		*pptr++ = body[i];
141	}
142
143	status = GCT_send(dest_module_id,(HDR *)m);
144
145	/* If the function does not return success then the calling program must release
146	the message back to the system using relm().
147	*/
148	if(status!=0)
149		relm(m);
150
151	/*
152	printf("Sent %d bytes, status %d", len, status);
153	*/
154
155	(*env)->ReleaseByteArrayElements(env, msg_buffer, body, 0);	
156
157	return status;
158}
159