]> rtime.felk.cvut.cz Git - orte.git/blobdiff - orte/libjorte/JORTEPublicationCreate.c
JORTE: update license headers and clean-up includes
[orte.git] / orte / libjorte / JORTEPublicationCreate.c
index c4595fc1235d9702617968e767b2895bda71cc80..b2b5876a1070271fe50cee1ac3a74968f2fe5bf9 100644 (file)
@@ -7,6 +7,7 @@
   * (by command 'javah -jni class_with_native_function')
   *
   * @author Lukas Pokorny (lukas_pokorny@centrum.cz)
+  * @author Martin Vajnar (martin.vajnar@gmail.com)
   * @author CTU FEE Prague - Department of Control Engineering (dce.felk.cvut.cz)
   * @author Project ORTE - OCERA Real Time Ethernet (www.ocera.org)
   * @author dedication to Kj
   *
   */
 
-#include <stdlib.h>
-// origin orte headers
-#include "orte.h"
-// pregenerated header
-#include "jorte/org_ocera_orte_Publication.h"
-#include "jorte/jorte_protos_api.h"
-#include "jorte/4all.h"
+#include "jorte/jorte.h"
 
 // ### DOCASNE ##################################################################
 
@@ -41,15 +36,13 @@ int counter = 0;
 void
 sendCallBack(const ORTESendInfo *info,void *vinstance, void *sendCallBackParam)
 {
-  char *instance=(char*)vinstance;
 
   printf(":c: zacatek sendCallBack()..\n");
 
   switch (info->status) {
     case NEED_DATA:
-      printf(":c:PUB: Sampling publication, count %d\n", counter);
+      printf(":c:PUB: Sampling publication, count %d\n", counter++);
       printf(":c:PUB: !! DOCASNE - ZRUSIT!! - callback() u Publishera \n");
-         sprintf(instance,"Hello Universe! (%d)",counter++);
       break;
     case CQL:  //criticalQueueLevel
       break;
@@ -61,14 +54,13 @@ sendCallBack(const ORTESendInfo *info,void *vinstance, void *sendCallBackParam)
 
 
 // native method
-JNIEXPORT jint JNICALL
+JNIEXPORT jlong JNICALL
 Java_org_ocera_orte_Publication_jORTEPublicationCreate
 (JNIEnv   *env ,
  jobject   obj,
- jint      dom_handle,
+ jlong     dom_handle,
  jstring   j_topic,
  jstring   j_type_name,
- jint      jbufflen,
  jobject   j_instance,
  jobject   j_persistence,
  jint      j_strength)
@@ -77,7 +69,7 @@ Java_org_ocera_orte_Publication_jORTEPublicationCreate
   ORTEDomain       *d;
   const char       *topic;
   const char       *typeName;
-  char             *buffer;
+  void             *buffer;
   NtpTime           persistence;
   int               strength;
   int               flag_ok = 0;
@@ -118,8 +110,8 @@ Java_org_ocera_orte_Publication_jORTEPublicationCreate
     persistence = getNtpTime(env, j_persistence);
     // get strenght
     strength = (int) j_strength;
-    // create buffer
-    buffer = (char*) malloc((int32_t) jbufflen);
+    // get direct ByteBuffer pointer from Java
+    buffer = (*env)->GetDirectBufferAddress(env, j_instance);
     if(buffer == 0)
     {
       printf(":!c: buffer create failed! \n");
@@ -129,11 +121,11 @@ Java_org_ocera_orte_Publication_jORTEPublicationCreate
     p = ORTEPublicationCreate(d,
                               topic,
                               typeName,
-                              (void *) buffer,
+                              buffer,
                               &persistence,
                               strength,
                               sendCallBack, // BUDE NULL!!
-                              j_instance,
+                              NULL,
                               NULL);
     if(p == 0)
     {
@@ -150,10 +142,8 @@ Java_org_ocera_orte_Publication_jORTEPublicationCreate
   //
   if (flag_ok == 0)
   {
-    // free memory
-    if(buffer != 0) free(buffer);
     return 0;
   }
-  return ((jint) p);
+  return ((jlong) p);
 
 }