]> rtime.felk.cvut.cz Git - orte.git/blobdiff - orte/libjorte/JORTESubscriptionCreate.c
Revert "JORTE: update license headers and clean-up includes"
[orte.git] / orte / libjorte / JORTESubscriptionCreate.c
index 6475a2c2819ecee0b1a61034b9e76a25bc29e06a..b02edea7227c2c06254959bdf8dc73a2d13ce25f 100644 (file)
 
 
 #include <stdlib.h>
+#include <inttypes.h>
 
 // library header file's path
-#include "orte.h"
+#include "orte_all.h"
 // pregenerated header
 #include "jorte/org_ocera_orte_Subscription.h"
 // enable TEST_STAGE run level
@@ -50,9 +51,10 @@ recvCallBack(const ORTERecvInfo *info,void *vinstance, void *recvCallBackParam)
   JNIEnv          *env = 0;
   jclass           cls = 0; // local reference!
   jclass           cls_msg = 0;
-  jobject          obj = 0;
   jobject          rinfo = 0;
   jobject          obj_msg;
+  jobject          obj_bo = 0;
+  jfieldID         fid = 0;
   jmethodID        mid = 0;
   jmethodID        mid_callback = 0;
   //
@@ -74,7 +76,13 @@ recvCallBack(const ORTERecvInfo *info,void *vinstance, void *recvCallBackParam)
     }
     jvm = callback_cont->jvm;
     // get env
-    (*jvm)->AttachCurrentThread(jvm, (void **)&env, NULL);
+    (*jvm)->AttachCurrentThread(jvm,
+                                #ifdef __ANDROID__
+                                  &env,
+                                #else
+                                  (void **)&env,
+                                #endif
+                                NULL);
     if(env == 0)
     {
       #ifdef TEST_STAGE
@@ -83,6 +91,71 @@ recvCallBack(const ORTERecvInfo *info,void *vinstance, void *recvCallBackParam)
       break;
     }
     //
+    // set byte order only if it differs from that currently set
+    if(info->data_endian != callback_cont->cur_endian) {
+      //prepare ByteOrder
+      cls = (*env)->FindClass(env, "java/nio/ByteOrder");
+      if (cls == 0) {
+        #ifdef TEST_STAGE
+          printf(":!c: cls = NULL \n");
+        #endif
+      }
+      if(info->data_endian == BigEndian) {
+        fid = (*env)->GetStaticFieldID(env,
+                                       cls,
+                                       "BIG_ENDIAN",
+                                       "Ljava/nio/ByteOrder;");
+        callback_cont->cur_endian = BigEndian;
+      }
+      else {
+        fid = (*env)->GetStaticFieldID(env,
+                                       cls,
+                                       "LITTLE_ENDIAN",
+                                       "Ljava/nio/ByteOrder;");
+        callback_cont->cur_endian = LittleEndian;
+      }
+      if(fid == 0) {
+        #ifdef TEST_STAGE
+          printf(":!c: fid = NULL \n");
+        #endif
+      }
+      obj_bo = (*env)->GetStaticObjectField(env, cls, fid);
+      if(obj_bo == 0) {
+        #ifdef TEST_STAGE
+          printf(":!c: cls = NULL \n");
+        #endif
+      }
+
+      // set byte order to ByteBuffer
+      // get BB class
+      cls = (*env)->GetObjectClass(env, callback_cont->obj_buf);
+      if(cls == 0)
+      {
+        #ifdef TEST_STAGE
+          printf(":!c: cls = NULL \n");
+        #endif
+      }
+      // get methodID - order(ByteOrder)
+      mid = (*env)->GetMethodID(env,
+                                cls,
+                                "order",
+                                "(Ljava/nio/ByteOrder;)Ljava/nio/ByteBuffer;");
+      if(mid == 0)
+      {
+        #ifdef TEST_STAGE
+          printf(":!c: mid = NULL \n");
+        #endif
+      }
+
+      // set ByteOrder
+      if((*env)->CallObjectMethod(env,callback_cont->obj_buf,mid,obj_bo) == 0)
+      {
+        #ifdef TEST_STAGE
+          printf(":!c: set byte order failed.. \n");
+        #endif
+      }
+    }
+    //
     if(callback_cont->obj == 0)
     {
       #ifdef TEST_STAGE
@@ -91,14 +164,13 @@ recvCallBack(const ORTERecvInfo *info,void *vinstance, void *recvCallBackParam)
       break;
     }
     // set local vars
-    obj = callback_cont->obj;
     rinfo = callback_cont->rinfo;
     obj_msg = callback_cont->msg;
 
 
       #ifdef TEST_STAGE
          printf(":c: #0 \n");
-         printf(":c: env = %p, obj_msg = %p \n", env, obj_msg);
+         printf(":c: env = %#"PRIxPTR", obj_msg = %#"PRIxPTR" \n", (intptr_t)env, (intptr_t)obj_msg);
       #endif
 
 
@@ -156,16 +228,16 @@ recvCallBack(const ORTERecvInfo *info,void *vinstance, void *recvCallBackParam)
     #ifdef TEST_STAGE
       printf(":c: rinfo created :] \n");
       printf(":c:----- ORTERecvInfo members  ------ \n");
-      printf(":c:    recvStatus: %d \n", info->status);
-      printf(":c:    senderGuid: hid = %d, aid = %d, oid = %d \n",
+      printf(":c:    recvStatus: %#x \n", info->status);
+      printf(":c:    senderGuid: hid = %#"PRIx32", aid = %#"PRIx32", oid = %#"PRIx32" \n",
              info->senderGUID.hid,info->senderGUID.aid,info->senderGUID.oid);
       printf(":c:         topic: %s \n",info->topic);
       printf(":c:          type: %s \n",info->type);
-      printf(":c: localTimeRecv: sec = %d, fract = %d \n",
+      printf(":c: localTimeRecv: sec = %"PRId32", fract = %"PRIu32" \n",
              info->localTimeReceived.seconds,info->localTimeReceived.fraction);
-      printf(":c: remoteTimePub: sec = %d, fract = %d \n",
+      printf(":c: remoteTimePub: sec = %"PRId32", fract = %"PRIu32" \n",
              info->remoteTimePublished.seconds,info->remoteTimePublished.fraction);
-      printf(":c:         seqNr: high = %d, low = %d \n",info->sn.high,info->sn.low);
+      printf(":c:         seqNr: high = %"PRId32", low = %"PRIu32" \n",info->sn.high,info->sn.low);
       printf(":c:---------------------------------- \n");
     #endif
     ////////////////////////////////////////////////////
@@ -262,6 +334,7 @@ Java_org_ocera_orte_Subscription_jORTESubscriptionCreate
  jstring   jtopic,    // subs topic
  jstring   jtname,    // subs typeName
  jobject   jinstance, // direct ByteBuffer
+ jint      jbyteOrder,// byte order of ByteBuffer
  jobject   obj_msg,   // messageData instance
  jobject   jdeadline,
  jobject   jminSeparation,
@@ -319,6 +392,7 @@ Java_org_ocera_orte_Subscription_jORTESubscriptionCreate
       #endif
     }
     callback_cont->jvm = jvm;
+    callback_cont->cur_endian = (CDR_Endianness) jbyteOrder;
     // create global references
     callback_cont->obj = (*env)->NewGlobalRef(env, obj_callback);
     //
@@ -330,6 +404,16 @@ Java_org_ocera_orte_Subscription_jORTESubscriptionCreate
       break;
     }
     // create global references
+    callback_cont->obj_buf = (*env)->NewGlobalRef(env, jinstance);
+    //
+    if (callback_cont->obj_buf == 0)
+    {
+      #ifdef TEST_STAGE
+        printf(":c: global reference not created! \n");
+      #endif
+      break;
+    }
+    // create global references
     callback_cont->msg = (*env)->NewGlobalRef(env, obj_msg);
     //
     if (callback_cont->msg == 0)