]> 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 42b6f36660d3146c2a0d853fa1b4c281c20505ab..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"
-#include "orte_all.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 ##################################################################
 
@@ -42,7 +36,6 @@ int counter = 0;
 void
 sendCallBack(const ORTESendInfo *info,void *vinstance, void *sendCallBackParam)
 {
-  char *instance=(char*)vinstance;
 
   printf(":c: zacatek sendCallBack()..\n");
 
@@ -50,7 +43,6 @@ sendCallBack(const ORTESendInfo *info,void *vinstance, void *sendCallBackParam)
     case NEED_DATA:
       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;
@@ -69,7 +61,6 @@ Java_org_ocera_orte_Publication_jORTEPublicationCreate
  jlong     dom_handle,
  jstring   j_topic,
  jstring   j_type_name,
- jint      jbufflen,
  jobject   j_instance,
  jobject   j_persistence,
  jint      j_strength)
@@ -78,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;
@@ -119,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");
@@ -130,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)
     {
@@ -151,8 +142,6 @@ Java_org_ocera_orte_Publication_jORTEPublicationCreate
   //
   if (flag_ok == 0)
   {
-    // free memory
-    if(buffer != 0) free(buffer);
     return 0;
   }
   return ((jlong) p);