Replacing throw error with exit statements for now to handle fatal errors when commun...
[iot2.git] / iotjava / iotrmi / C++ / IoTRMIUtil.hpp
index b80b1156b6a9e353c8146ae6ba65058956847dfd..6b33b6199b58ce2a71d5d4dfaab5d6fc495ea284 100644 (file)
@@ -91,8 +91,10 @@ class IoTRMIUtil {
                static void*    getArrayParamObject(void* retObj, const char* type, char* paramBytes, int len);
 
                // 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        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        BOOL_LEN = 1;           // 1 byte
                
@@ -183,10 +185,10 @@ int IoTRMIUtil::getTypeSize(string type) {
 int IoTRMIUtil::getVarTypeSize(string type, void* paramObj) {
 
        int paramLen = 0;
-       if (type.compare("string") == 0) {
+       if (type.compare("String") == 0) {
                // Get the length of the string through void* casting to string*
                paramLen = (*(string*)paramObj).length();
-       } else if (type.compare("string[]") == 0) {
+       } else if (type.compare("String[]") == 0) {
                paramLen = IoTRMIUtil::getByteStringLength(*(vector<string>*) paramObj);
        } else if (type.compare("byte[]") == 0) {
                int dataSize = getTypeSize("byte");
@@ -207,14 +209,14 @@ int IoTRMIUtil::getVarTypeSize(string type, void* paramObj) {
                int dataSize = getTypeSize("double");
                paramLen = (*(vector<double>*) paramObj).size() * dataSize;
        } else if (type.compare("bool[]") == 0) {
-               int dataSize = getTypeSize("bool");
+               int dataSize = getTypeSize("boolean");
                paramLen = (*(vector<bool>*) paramObj).size() * dataSize;
        } else if (type.compare("char[]") == 0) {
                int dataSize = getTypeSize("char");
                paramLen = (*(vector<char>*) paramObj).size() * dataSize;
        } else {
-               string error = "IoTRMICall: Unrecognizable type: " + type;
-               throw error;
+               cerr << "IoTRMIUtil: Unrecognizable type: " << type;
+               exit(-1);
        }
 
        return paramLen;
@@ -264,20 +266,20 @@ void* IoTRMIUtil::getParamObject(void* retObj, const char* type, char* paramByte
                                strcmp(type, "double") == 0) {
                retObj = (void*) byteArrayToDouble((double*) retObj, paramBytes);
        } else if ( strcmp(type, "b") == 0 ||
-                               strcmp(type, "bool") == 0) {
+                               strcmp(type, "boolean") == 0) {
                retObj = (void*) byteArrayToBoolean((bool*) retObj, paramBytes);
        } else if ( strcmp(type, "c") == 0 ||
                                strcmp(type, "char") == 0) {
                retObj = (void*) byteArrayToChar((char*) retObj, paramBytes);
        } else if ( strcmp(type, "Ss") == 0 ||
-                               strcmp(type, "string") == 0) {
+                               strcmp(type, "String") == 0) {
                retObj = (void*) byteArrayToString((string*) retObj, paramBytes, len);
        } else if ( string(type).find("[]") != string::npos) {
                // This is an array type, i.e. vector
                retObj = getArrayParamObject(retObj, type, paramBytes, len);
        } else {
-               string error = "IoTRMIUtil: Unrecognizable type: " + string(type);
-               throw error;
+               cerr << "IoTRMIUtil: Unrecognizable type: " << type;
+               exit(-1);
        }
 
        return retObj;
@@ -303,11 +305,11 @@ void* IoTRMIUtil::getArrayParamObject(void* retObj, const char* type, char* para
                retObj = byteArrayToBooleanArray((vector<bool>*) retObj, paramBytes, len);
        } else if (strcmp(type, "char[]") == 0) {
                retObj = byteArrayToCharArray((vector<char>*) retObj, paramBytes, len);
-       } else if (strcmp(type, "string[]") == 0) {
+       } else if (strcmp(type, "String[]") == 0) {
                retObj = byteArrayToStringArray((vector<string>*) retObj, paramBytes, len);
        } else {
-               string error = "IoTRMIUtil: Unrecognizable type: " + string(type);
-               throw error;
+               cerr << "IoTRMIUtil: Unrecognizable type: " << type;
+               exit(-1);       
        }
 
        return retObj;
@@ -336,20 +338,21 @@ char* IoTRMIUtil::getObjectBytes(char* retObjBytes, void* obj, const char* type)
                                strcmp(type, "double") == 0) {
                retObjBytes = doubleToByteArray(*((double*) obj), retObjBytes);
        } else if ( strcmp(type, "b") == 0 ||
-                               strcmp(type, "bool") == 0) {
+                               strcmp(type, "boolean") == 0) {
                retObjBytes = booleanToByteArray(*((bool*) obj), retObjBytes);
        } else if ( strcmp(type, "c") == 0 ||
                                strcmp(type, "char") == 0) {
                retObjBytes = charToByteArray(*((char*) obj), retObjBytes);
        } else if ( strcmp(type, "Ss") == 0 ||
+                               strcmp(type, "String") == 0 ||
                                strcmp(type, "string") == 0) {
                retObjBytes = stringToByteArray(*((string*) obj), retObjBytes);
        } else if ( string(type).find("[]") != string::npos) {
        // This is an array type, i.e. vector
                retObjBytes = getArrayObjectBytes(retObjBytes, obj, type);
        } else {
-               string error = "IoTRMIUtil: Unrecognizable type: " + string(type);
-               throw error;
+               cerr << "IoTRMIUtil: Unrecognizable type: " << type;
+               exit(-1);
        }
 
        return retObjBytes;
@@ -375,11 +378,11 @@ char* IoTRMIUtil::getArrayObjectBytes(char* retObjBytes, void* obj, const char*
                retObjBytes = arrBooleanToByteArray(*((vector<bool>*) obj), retObjBytes);
        } else if (strcmp(type, "char[]") == 0) {
                retObjBytes = arrCharToByteArray(*((vector<char>*) obj), retObjBytes);
-       } else if (strcmp(type, "string[]") == 0) {
+       } else if (strcmp(type, "String[]") == 0) {
                retObjBytes = arrStringToByteArray(*((vector<string>*) obj), retObjBytes);
        } else {
-               string error = "IoTRMIUtil: Unrecognizable type: " + string(type);
-               throw error;
+               cerr << "IoTRMIUtil: Unrecognizable type: " << type;
+               exit(-1);
        }
 
        return retObjBytes;