]> rtime.felk.cvut.cz Git - orte.git/blob - orte/libjorte/JORTEPublicationSend.c
JORTE: add 64-bit support
[orte.git] / orte / libjorte / JORTEPublicationSend.c
1 /* JORTEPublicationSend.c */
2
3 /**
4   * This code provides conversion between JAVA a C environments.
5   * The C functions are calling here and results are send to JAVA
6   * native functions. It uses the header pregenerated by JAVA
7   * (by command 'javah -jni class_with_native_function')
8   *
9   * @author Lukas Pokorny (lukas_pokorny@centrum.cz)
10   * @author CTU FEE Prague - Department of Control Engineering (dce.felk.cvut.cz)
11   * @author Project ORTE - OCERA Real Time Ethernet (www.ocera.org)
12   * @author dedication to Kj
13   * @version 0.1
14   *
15   *
16   * This program is free software; you can redistribute it and/or modify
17   * it under the terms of the GNU General Public License as published by
18   * the Free Software Foundation; either version 2 of the License, or
19   * (at your option) any later version.
20   *
21   * This program is distributed in the hope that it will be useful,
22   * but WITHOUT ANY WARRANTY; without even the implied warranty of
23   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24   * GNU General Public License for more details.
25   *
26   */
27
28
29 #include <stdlib.h>
30 // library header file's path
31 #include "orte.h"
32 // pregenerated header
33 #include "jorte/org_ocera_orte_Publication.h"
34 // enable TEST_STAGE run level
35 #include "jorte/4all.h"
36
37
38 JNIEXPORT jboolean JNICALL
39 Java_org_ocera_orte_Publication_jORTEPublicationSend
40 (JNIEnv *env, jobject obj, jlong pub_handle, jobject obj_msg)
41 {
42   jclass    cls;
43   jobject   obj_bb;
44   jfieldID  fid;
45   jmethodID  mid;
46   //
47   int       flag_ok = 0;
48   int8_t    b;
49   int       buff_length,i = 0;
50   char     *orte_instance;
51   //
52   ORTEPublicationSendParam psp;
53
54   #ifdef TEST_STAGE
55     printf(":c: jORTEPublicationSend() called.. \n");
56   #endif
57
58   do
59   {
60     // get class MessageData
61     cls = (*env)->GetObjectClass(env, obj_msg);
62     if(cls == 0)
63     {
64      #ifdef TEST_STAGE
65        printf(":!c: cls = NULL \n");
66      #endif
67      break;
68     }
69     // methodID
70     mid = (*env)->GetMethodID(env,
71                               cls,
72                               "getMaxDataLength",
73                               "()I");
74     if(mid == 0)
75     {
76      #ifdef TEST_STAGE
77        printf(":!c: mid = NULL \n");
78      #endif
79      break;
80     }
81     // call method
82     buff_length = (*env)->CallIntMethod(env,
83                                         obj_msg,
84                                         mid);
85     // get fieldID - buffer
86     fid = (*env)->GetFieldID(env,
87                              cls,
88                              "buffer",
89                              "Ljava/nio/ByteBuffer;");
90     if(fid == 0)
91     {
92      #ifdef TEST_STAGE
93        printf(":!c: fid = NULL \n");
94      #endif
95      break;
96     }
97     // get object
98     obj_bb = (*env)->GetObjectField(env,obj_msg,fid);
99     if(obj_bb == 0)
100     {
101      #ifdef TEST_STAGE
102        printf(":!c: obj_bb = NULL \n");
103      #endif
104      break;
105     }
106     // get obj class
107     cls = (*env)->GetObjectClass(env, obj_bb);
108     if(cls == 0)
109     {
110      #ifdef TEST_STAGE
111        printf(":!c: cls = NULL \n");
112      #endif
113      break;
114     }
115     // methodID
116     mid = (*env)->GetMethodID(env,
117                               cls,
118                               "get",
119                               "(I)B");
120     if(mid == 0)
121     {
122      #ifdef TEST_STAGE
123        printf(":!c: mid = NULL \n");
124      #endif
125      break;
126     }
127     /////////////////////////////////////////////////
128     // get handle to data buffer
129     orte_instance = ORTEPublicationGetInstance((ORTEPublication *) pub_handle);
130     // copy the bytes from JAVA to C buffer
131     /////////////////////////////////////////////////
132     for(i = 0; i < buff_length; i++)
133     {
134       // calling method
135       char b;
136
137       b = (*env)->CallByteMethod(env,
138                                  obj_bb,
139                                  mid,
140                                  i);
141       orte_instance[i] = b;
142
143       #ifdef TEST_STAGE
144         printf(":c: #7.%d: znak %c [%d] \n",
145                i,orte_instance[i],orte_instance[i]);
146       #endif
147     }
148     /////////////////////////////////////////////////
149     psp.instance = (void *) orte_instance;
150     psp.data_endian = 1; /* BIG -pak tahat z headeru !!*/
151     #ifdef TEST_STAGE
152       printf(":c: endian? \n");
153     #endif
154     /////////////////////////////////////////////////
155     // call ORTE function
156     b = ORTEPublicationSendEx((ORTEPublication *) pub_handle, &psp);
157     #ifdef TEST_STAGE
158       printf(":c: b = ORTEPublicationSendEx() = %d \n",b);
159     #endif
160     if (b == ORTE_BAD_HANDLE)
161     {
162      #ifdef TEST_STAGE
163        printf(":!c: data not sent! [bad pub handle] \n");
164      #endif
165      break;
166     }
167     if(b == ORTE_OK)
168     {
169      #ifdef TEST_STAGE
170        printf(":c: data sent succesfuly.. \n");
171      #endif
172     }
173     // set flag
174     flag_ok = 1;
175   } while(0);
176
177   if(flag_ok == 0)
178   {
179     return 0;
180   }
181
182   return 1;
183
184 }