Merge branch 'master' of ssh://plrg.eecs.uci.edu/home/git/iot2
[iot2.git] / iotjava / iotrmi / C++ / IoTRMIUtil.hpp
index 5da411cfd4d85179bd5e1a6291766aef4454f8ac..2f18adc5952f4d44ab9dbc0bc3477cb576f22525 100644 (file)
@@ -16,6 +16,7 @@
 #include <cstdlib>
 #include <memory>
 #include <typeinfo>
+#include <map>
 
 #include <iostream>
 #include <string>
@@ -26,7 +27,7 @@
 
 using namespace std;
 
-class IoTRMIUtil {
+class IoTRMIUtil final {
 
        public:
                IoTRMIUtil();
@@ -97,11 +98,19 @@ class IoTRMIUtil {
                // Constants
                const static int        OBJECT_ID_LEN = 4;      // 4 bytes = 32 bits
                const static int        METHOD_ID_LEN = 4;      // 4 bytes = 32 bits
+               const static int        PACKET_TYPE_LEN = 4;// 4 bytes = 32 bits
                const static int        PARAM_LEN = 4;          // 4 bytes = 32 bits (4-byte field that stores the length of the param)
                const static int        RETURN_LEN = 4;         // 4 bytes = 32 bits (4-byte field that stores the length of the return object)
                const static int        CHAR_LEN = 2;           // 2 bytes (we follow Java convention)
                const static int        BYTE_LEN = 1;           // 1 byte
                const static int        BOOL_LEN = 1;           // 1 byte
+               const static int        METHOD_TYPE = 1;        // Packet type of method
+               const static int        RET_VAL_TYPE = -1;      // Packet type of return value
+
+               // Static containers
+               static map<int,void*>* mapStub;         // Map object to its stub ID
+               static map<void*,void*>* mapSkel;       // Map object to its skeleton
+               static map<void*,int>* mapSkelId;       // Map object to its skeleton ID
                
        private:
                map<string,string>      mapPrimitives;
@@ -109,6 +118,10 @@ class IoTRMIUtil {
                map<string,string>      mapNonPrimitives;
 };
 
+map<int,void*>* IoTRMIUtil::mapStub = new map<int,void*>();
+map<void*,void*>* IoTRMIUtil::mapSkel = new map<void*,void*>();
+map<void*,int>* IoTRMIUtil::mapSkelId = new map<void*,int>();
+
 
 // Constructor
 IoTRMIUtil::IoTRMIUtil() {
@@ -300,6 +313,10 @@ void* IoTRMIUtil::getParamObject(void* retObj, const char* type, char* paramByte
        } else if ( string(type).find("*") != string::npos) {
                // This is an array type, i.e. vector
                retObj = getArrayParamObject(retObj, type, paramBytes, len);
+       } else if ( (string(type).find("<") != string::npos) &&
+                               (string(type).find(">") != string::npos)) {
+               // This is a vector/list type
+               retObj = getArrayParamObject(retObj, type, paramBytes, len);
        } else {
                cerr << "IoTRMIUtil: Unrecognizable type: " << type << endl;
                exit(-1);
@@ -389,6 +406,10 @@ char* IoTRMIUtil::getObjectBytes(char* retObjBytes, void* obj, const char* type)
        } else if ( string(type).find("*") != string::npos) {
        // This is an array type, i.e. vector
                retObjBytes = getArrayObjectBytes(retObjBytes, obj, type);
+       } else if ( (string(type).find("<") != string::npos) &&
+                               (string(type).find(">") != string::npos)) {
+       // This is a vector/list type
+               retObjBytes = getArrayObjectBytes(retObjBytes, obj, type);
        } else {
                cerr << "IoTRMIUtil: Unrecognizable type: " << type << endl;
                exit(-1);