]> rtime.felk.cvut.cz Git - orte.git/blob - orte/libjorte/JORTEPublicationCreate.c
Reformat the sources with orte/uncrustify script
[orte.git] / orte / libjorte / JORTEPublicationCreate.c
1 /* JORTEPublicationCreate.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 #include <stdlib.h>
29 // origin orte headers
30 #include "orte.h"
31 #include "orte_all.h"
32 // pregenerated header
33 #include "jorte/org_ocera_orte_Publication.h"
34 #include "jorte/jorte_protos_api.h"
35 #include "jorte/4all.h"
36
37 // ### DOCASNE ##################################################################
38
39 // ### DOCASNE ##################################################################
40 int counter = 0;
41
42 void
43 sendCallBack(const ORTESendInfo *info, void *vinstance, void *sendCallBackParam)
44 {
45
46   printf(":c: zacatek sendCallBack()..\n");
47
48   switch (info->status) {
49     case NEED_DATA:
50       printf(":c:PUB: Sampling publication, count %d\n", counter++);
51       printf(":c:PUB: !! DOCASNE - ZRUSIT!! - callback() u Publishera \n");
52       break;
53     case CQL:  //criticalQueueLevel
54       break;
55   }
56 }
57 // ### DOCASNE ##################################################################
58
59 // ### DOCASNE ##################################################################
60
61
62 // native method
63 JNIEXPORT jlong JNICALL
64 Java_org_ocera_orte_Publication_jORTEPublicationCreate
65   (JNIEnv   *env,
66   jobject   obj,
67   jlong     dom_handle,
68   jstring   j_topic,
69   jstring   j_type_name,
70   jobject   j_instance,
71   jobject   j_persistence,
72   jint      j_strength)
73 {
74   ORTEPublication  *p = 0;
75   ORTEDomain       *d;
76   const char       *topic;
77   const char       *typeName;
78   void             *buffer;
79   NtpTime           persistence;
80   int               strength;
81   int               flag_ok = 0;
82
83   // check domain handle
84   d = (ORTEDomain *)dom_handle;
85   if (d == 0) {
86     printf(":!c: publication create failed! [bad domain handle] \n");
87     return 0;
88   }
89   // get topic
90   topic = (*env)->GetStringUTFChars(env, j_topic, 0);
91   if (topic == 0) {
92     // OutOfMemoryError already thrown
93     #ifdef TEST_STAGE
94     printf(":!c: topic = NULL \n");
95     #endif
96     return 0;
97   }
98   // get typeName
99   typeName = (*env)->GetStringUTFChars(env, j_type_name, 0);
100   if (typeName == 0) {
101     // OutOfMemoryError already thrown
102     #ifdef TEST_STAGE
103     printf(":!c: typeName = NULL \n");
104     #endif
105     // free memory
106     (*env)->ReleaseStringUTFChars(env, j_topic, topic);
107     return 0;
108   }
109
110   do {
111     // get persistence
112     persistence = getNtpTime(env, j_persistence);
113     // get strenght
114     strength = (int)j_strength;
115     // get direct ByteBuffer pointer from Java
116     buffer = (*env)->GetDirectBufferAddress(env, j_instance);
117     if (buffer == 0) {
118       printf(":!c: buffer create failed! \n");
119       break;
120     }
121     // call ORTE function
122     p = ORTEPublicationCreate(d,
123                               topic,
124                               typeName,
125                               buffer,
126                               &persistence,
127                               strength,
128                               sendCallBack, // BUDE NULL!!
129                               NULL,
130                               NULL);
131     if (p == 0) {
132       printf(":!c: publication create failed! \n");
133       break;
134     }
135     // set flag
136     flag_ok = 1;
137   }  while (0);
138
139   // free memory in every case
140   (*env)->ReleaseStringUTFChars(env, j_topic, topic);
141   (*env)->ReleaseStringUTFChars(env, j_type_name, typeName);
142   //
143   if (flag_ok == 0) {
144     return 0;
145   }
146   return ((jlong)p);
147
148 }