mkdir -p $(BIN_DIR)/iotrmi/C++
#$(G++) iotrmi/C++/IoTSocketServer.cpp -o $(BIN_DIR)/iotrmi/C++/IoTSocketServer.out
#$(G++) iotrmi/C++/IoTSocketClient.cpp -o $(BIN_DIR)/iotrmi/C++/IoTSocketClient.out
- $(G++) iotrmi/C++/IoTRMICall.cpp -o $(BIN_DIR)/iotrmi/C++/IoTRMICall.out --std=c++11
- $(G++) iotrmi/C++/IoTRMIObject.cpp -o $(BIN_DIR)/iotrmi/C++/IoTRMIObject.out --std=c++11
+ #$(G++) iotrmi/C++/IoTRMICall.cpp -o $(BIN_DIR)/iotrmi/C++/IoTRMICall.out --std=c++11
+ #$(G++) iotrmi/C++/IoTRMIObject.cpp -o $(BIN_DIR)/iotrmi/C++/IoTRMIObject.out --std=c++11
+ mkdir -p $(BIN_DIR)/iotrmi/C++/sample
+ $(G++) iotrmi/C++/sample/TestClass.cpp -o $(BIN_DIR)/iotrmi/C++/sample/TestClass.out --std=c++11
+ $(G++) iotrmi/C++/sample/TestClass_Stub.cpp -o $(BIN_DIR)/iotrmi/C++/sample/TestClass_Stub.out --std=c++11
+ $(G++) iotrmi/C++/sample/TestClass_Skeleton.cpp -o $(BIN_DIR)/iotrmi/C++/sample/TestClass_Skeleton.out --std=c++11
PHONY += run-rmiserver
run-rmiserver:
int retLen = 0;
char* retObjBytes = NULL;
retObjBytes = rmiClient->receiveBytes(retObjBytes, &retLen);
- retObj = IoTRMIUtil::getParamObject(retObj, retType.c_str(), retObjBytes);
+ retObj = IoTRMIUtil::getParamObject(retObj, retType.c_str(), retObjBytes, retLen);
}
return retObj;
if (paramCls[i].compare("string") == 0) {
// Get the length of the string through void* casting to string*
paramLen = (*(string*)paramObj[i]).length();
+ } else if (paramCls[i].compare("string[]") == 0) {
+ paramLen = IoTRMIUtil::getByteStringLength(*(vector<string>*) paramObj[i]);
+ } else {
+ string error = "IoTRMICall: Unrecognizable type: " + paramCls[i];
+ throw error;
}
// Some space for param length, i.e. 32 bits for integer
methodLen = methodLen + IoTRMIUtil::PARAM_LEN;
if (paramCls[i].compare("string") == 0) {
// Get the length of the string through void* casting to string*
paramLen = (*(string*)paramObj[i]).length();
+ } else if (paramCls[i].compare("string[]") == 0) {
+ paramLen = IoTRMIUtil::getByteStringLength(*(vector<string>*) paramObj[i]);
+ } else {
+ string error = "IoTRMICall: Unrecognizable type: " + paramCls[i];
+ throw error;
}
// Write the parameter length
char prmLenBytes[IoTRMIUtil::METHOD_ID_LEN];
if (type.compare("string") == 0) {
// Get the length of the string through void* casting to string*
retLen = (*(string*)retObj).length();
+ } else if (type.compare("string[]") == 0) {
+ retLen = IoTRMIUtil::getByteStringLength(*(vector<string>*) retObj);
+ } else {
+ string error = "IoTRMICall: Unrecognizable type: " + type;
+ throw error;
}
}
// Need object bytes variable
// Get method in bytes and update method length
methodBytes = rmiServer->receiveBytes(methodBytes, &methodLen);
fflush(NULL);
- IoTRMIUtil::printBytes(methodBytes, methodLen, false);
}
// Get method object
int methodId = 0;
IoTRMIUtil::byteArrayToInt(&methodId, methodIdBytes);
- cout << "Method Id: " << methodId << endl;
return mapHash2Sign.find(methodId)->second;
}
// Byte scanning position
int pos = IoTRMIUtil::METHOD_ID_LEN;
for (int i = 0; i < numParam; i++) {
-
int paramLen = rmiUtil->getTypeSize(paramCls[i]);
// Get the 32-bit field in the byte array to get the actual
// length (this is a param with indefinite length)
char paramBytes[paramLen];
memcpy(paramBytes, methodBytes + pos, paramLen);
pos = pos + paramLen;
- paramObj[i] = IoTRMIUtil::getParamObject(paramObj[i], paramCls[i].c_str(), paramBytes);
-
+ paramObj[i] = IoTRMIUtil::getParamObject(paramObj[i], paramCls[i].c_str(), paramBytes, paramLen);
}
// Delete methodBytes
delete[] methodBytes;
static string* byteArrayToString(string* result, char* bytes, int len);
// Get parameter object from byte array
- static void* getParamObject(void* retObj, const char* type, char* paramBytes);
+ static void* getParamObject(void* retObj, const char* type, char* paramBytes, int len);
static char* getObjectBytes(char* retObjBytes, void* obj, const char* type);
// Arrays to bytes
// Aggregator functions
static char* getArrayObjectBytes(char* retObjBytes, void* obj, const char* type);
- static void* getParamObject(void* retObj, const char* type, char* paramBytes, int len);
+ static void* getArrayParamObject(void* retObj, const char* type, char* paramBytes, int len);
// Constants
const static int METHOD_ID_LEN = 4; // 4 bytes = 32 bits
// ****************************
// Getting parameter object based on received byte array
-void* IoTRMIUtil::getParamObject(void* retObj, const char* type, char* paramBytes) {
+void* IoTRMIUtil::getParamObject(void* retObj, const char* type, char* paramBytes, int len) {
if (strcmp(type, "b") == 0 ||
strcmp(type, "byte") == 0) {
retObj = (void*) byteArrayToChar((char*) retObj, paramBytes);
} else if ( strcmp(type, "Ss") == 0 ||
strcmp(type, "string") == 0) {
- retObj = (void*) byteArrayToString((string*) retObj, paramBytes);
+ 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;
// Get array of objects from byte array - overload getParamObject function
-void* IoTRMIUtil::getParamObject(void* retObj, const char* type, char* paramBytes, int len) {
+void* IoTRMIUtil::getArrayParamObject(void* retObj, const char* type, char* paramBytes, int len) {
if (strcmp(type, "byte[]") == 0) {
retObj = (vector<char>*) paramBytes;
+++ /dev/null
-#include <iostream>
-
-using namespace std;
-
-class TestClass {
- public:
- TestClass();
- TestClass(int _int, float _float, string _string);
- ~TestClass();
-
- void setA(int _int);
- void setB(float _float);
- void setC(string _string);
- string sumArray(const string newA[]);
- int setAndGetA(int newA);
- int setACAndGetA(string newC, int newA);
- //void registerCallback(CallBackInterface _cb);
- //int callBack();
-
- private:
- int intA;
- float floatB;
- string stringC;
- //CallBackInterface cb;
-
-};
-
-
-TestClass::TestClass() {
-
- intA = 1;
- floatB = 2;
- stringC = "345";
- //cb = NULL;
-}
-
-
-TestClass::TestClass(int _int, float _float, string _string) {
-
- intA = _int;
- floatB = _float;
- stringC = _string;
- //cb = NULL;
-}
-
-
-void TestClass::setA(int _int) {
-
- intA = _int;
-}
-
-
-void TestClass::setB(float _float) {
-
- floatB = _float;
-}
-
-
-void TestClass::setC(string _string) {
-
- stringC = _string;
-}
-
-
-string TestClass::sumArray(const string newA[]) {
-
- string sum = "";
- int len = sizeof(newA) / sizeof(string);
- for(int c = 0; c < len; c++) {
- sum = sum + newA[c];
- }
- return sum;
-}
-
-
-int TestClass::setAndGetA(int newA) {
-
- intA = newA;
- return intA;
-}
-
-
-int TestClass::setACAndGetA(string newC, int newA) {
-
- stringC = newC;
- intA = newA;
- return intA;
-}
-
-
-/*void TestClass::registerCallback(CallBackInterface _cb) {
-
- cb = _cb;
-}
-
-
-int TestClass::callBack() {
-
- return cb.printInt();
-}*/
-
--- /dev/null
+#include <iostream>
+#include <string>
+#include "TestClass.hpp"
+
+using namespace std;
+
+int main(int argc, char *argv[])
+{
+
+ TestClassInterface *tc = new TestClass();
+ cout << "Return value: " << tc->setAndGetA(123) << endl;
+ cout << "Return value: " << tc->setACAndGetA("string", 123) << endl;
+ vector<string> input;
+ input.push_back("123");
+ input.push_back("456");
+ input.push_back("987");
+
+ cout << "Return value: " << tc->sumArray(input) << endl;
+
+ delete tc;
+
+ return 0;
+}
--- /dev/null
+#include <iostream>
+#include "TestClassInterface.hpp"
+
+using namespace std;
+
+class TestClass : public TestClassInterface {
+ public:
+ TestClass();
+ TestClass(int _int, float _float, string _string);
+ //~TestClass();
+
+ void setA(int _int);
+ void setB(float _float);
+ void setC(string _string);
+ string sumArray(vector<string> newA);
+ int setAndGetA(int newA);
+ int setACAndGetA(string newC, int newA);
+ //void registerCallback(CallBackInterface _cb);
+ //int callBack();
+
+ private:
+ int intA;
+ float floatB;
+ string stringC;
+ //CallBackInterface cb;
+
+};
+
+
+TestClass::TestClass() {
+
+ intA = 1;
+ floatB = 2;
+ stringC = "345";
+ //cb = NULL;
+}
+
+
+TestClass::TestClass(int _int, float _float, string _string) {
+
+ intA = _int;
+ floatB = _float;
+ stringC = _string;
+ //cb = NULL;
+}
+
+
+void TestClass::setA(int _int) {
+
+ intA = _int;
+}
+
+
+void TestClass::setB(float _float) {
+
+ floatB = _float;
+}
+
+
+void TestClass::setC(string _string) {
+
+ stringC = _string;
+}
+
+
+string TestClass::sumArray(vector<string> newA) {
+
+ string sum = "";
+ int len = newA.size();
+ for(int c = 0; c < len; c++) {
+ sum = sum + newA[c];
+ }
+ return sum;
+}
+
+
+int TestClass::setAndGetA(int newA) {
+
+ intA = newA;
+ return intA;
+}
+
+
+int TestClass::setACAndGetA(string newC, int newA) {
+
+ stringC = newC;
+ intA = newA;
+ return intA;
+}
+
+
+/*void TestClass::registerCallback(CallBackInterface _cb) {
+
+ cb = _cb;
+}
+
+
+int TestClass::callBack() {
+
+ return cb.printInt();
+}*/
+
--- /dev/null
+#include <iostream>
+#include <vector>
+
+using namespace std;
+
+class TestClassInterface {
+ public:
+ virtual void setA(int _int) = 0;
+ virtual void setB(float _float) = 0;
+ virtual void setC(string _string) = 0;
+ virtual string sumArray(vector<string> newA) = 0;
+ virtual int setAndGetA(int newA) = 0;
+ virtual int setACAndGetA(string newC, int newA) = 0;
+ //virtual void registerCallback(CallBackInterface _cb);
+ //virtual int callBack();
+};
+
--- /dev/null
+#include <iostream>
+#include <string>
+#include "TestClass_Skeleton.hpp"
+
+using namespace std;
+
+int main(int argc, char *argv[])
+{
+
+ int port = 5010;
+ TestClassInterface *tc = new TestClass(3, 5.0, "7911");
+ TestClass_Skeleton *tcSkel = new TestClass_Skeleton(tc, port);
+ tcSkel->waitRequestInvokeMethod();
+
+ delete tc;
+ delete tcSkel;
+ return 0;
+}
--- /dev/null
+#include <iostream>
+#include "../IoTRMIObject.hpp"
+#include "TestClass.hpp"
+
+using namespace std;
+
+class TestClass_Skeleton {
+ public:
+ TestClass_Skeleton(TestClassInterface* _tc, int _port);
+ ~TestClass_Skeleton();
+
+ void waitRequestInvokeMethod();
+
+ private:
+ TestClassInterface *tc;
+ IoTRMIObject *rmiObj;
+ //CallBackInterface cbstub;
+
+ const static int size = 8;
+ string methodSignatures[size] = {
+
+ "voidsetA(int)",
+ "voidsetB(float)",
+ "voidsetC(string)",
+ "sumArray(string[])",
+ "intsetAndGetA(int)",
+ "intsetACAndGetA(string,int)",
+ "intcallBack()",
+ "voidregisterCallBack(CallBackInterface)"
+ };
+};
+
+
+TestClass_Skeleton::TestClass_Skeleton(TestClassInterface* _tc, int _port) {
+
+ bool _bResult = false;
+ tc = _tc;
+ rmiObj = new IoTRMIObject(_port, &_bResult, methodSignatures, size);
+}
+
+
+TestClass_Skeleton::~TestClass_Skeleton() {
+
+ if (rmiObj != NULL) {
+ delete rmiObj;
+ rmiObj = NULL;
+ }
+}
+
+
+void TestClass_Skeleton::waitRequestInvokeMethod() {
+
+ // Loop continuously waiting for incoming bytes
+ while (true) {
+
+ rmiObj->getMethodBytes();
+ string methodSign = rmiObj->getSignature();
+ cout << "Method sign: " << methodSign << endl;
+
+ if (methodSign.compare("voidsetA(int)") == 0) {
+ string paramCls[] = { "int" };
+ int numParam = 1;
+ int param1 = 0;
+ void* paramObj[] = { ¶m1 };
+ rmiObj->getMethodParams(paramCls, numParam, paramObj);
+ tc->setA(param1);
+ } else if (methodSign.compare("voidsetB(float)") == 0) {
+ string paramCls[] = { "float" };
+ int numParam = 1;
+ float param1 = 0.0;
+ void* paramObj[] = { ¶m1 };
+ rmiObj->getMethodParams(paramCls, numParam, paramObj);
+ tc->setB(param1);
+ } else if (methodSign.compare("voidsetC(string)") == 0) {
+ string paramCls[] = { "string" };
+ int numParam = 1;
+ string param1 = "";
+ void* paramObj[] = { ¶m1 };
+ rmiObj->getMethodParams(paramCls, numParam, paramObj);
+ tc->setC(param1);
+ } else if (methodSign.compare("sumArray(string[])") == 0) {
+ string paramCls[] = { "string[]" };
+ int numParam = 1;
+ vector<string> param1;
+ void* paramObj[] = { ¶m1 };
+ rmiObj->getMethodParams(paramCls, numParam, paramObj);
+ string retVal = tc->sumArray(param1);
+ void* retObj = &retVal;
+ rmiObj->sendReturnObj(retObj, "string");
+ } else if (methodSign.compare("intsetAndGetA(int)") == 0) {
+ string paramCls[] = { "int" };
+ int numParam = 1;
+ int param1 = 0;
+ void* paramObj[] = { ¶m1 };
+ rmiObj->getMethodParams(paramCls, numParam, paramObj);
+ int retVal = tc->setAndGetA(param1);
+ void* retObj = &retVal;
+ rmiObj->sendReturnObj(retObj, "int");
+ } else if (methodSign.compare("intsetACAndGetA(string,int)") == 0) {
+ string paramCls[] = { "string", "int" };
+ int numParam = 2;
+ string param1 = "";
+ int param2 = 0;
+ void* paramObj[] = { ¶m1, ¶m2 };
+ rmiObj->getMethodParams(paramCls, numParam, paramObj);
+ int retVal = tc->setACAndGetA(param1, param2);
+ void* retObj = &retVal;
+ rmiObj->sendReturnObj(retObj, "int");
+ /*} else if (methodSign.compare("voidregisterCallBack(CallBackInterface)") == 0) {
+ //
+ } else if (methodSign.compare("intcallBack()") == 0) {
+ //*/
+ } else {
+ string error = "Signature unreqcognized: " + string(methodSign);
+ throw error;
+ }
+ }
+}
+
+
+/*void TestClass_Stub::registerCallback(CallBackInterface _cb) {
+
+ cb = _cb;
+}
+
+
+int TestClass_Stub::callBack() {
+
+ return cb.printInt();
+}*/
+
--- /dev/null
+#include <iostream>
+#include <string>
+#include "TestClass_Stub.hpp"
+
+using namespace std;
+
+int main(int argc, char *argv[])
+{
+
+ int port = 5010;
+ const char* address = "localhost";
+ int rev = 0;
+ bool bResult = false;
+
+ TestClassInterface *tcStub = new TestClass_Stub(port, address, rev, &bResult);
+ cout << "Return value: " << tcStub->setAndGetA(123) << endl;
+ cout << "Return value: " << tcStub->setACAndGetA("string", 123) << endl;
+ vector<string> input;
+ input.push_back("123");
+ input.push_back("456");
+ input.push_back("987");
+
+ cout << "Return value: " << tcStub->sumArray(input) << endl;
+
+ delete tcStub;
+
+ return 0;
+}
--- /dev/null
+#include <iostream>
+#include "../IoTRMICall.hpp"
+#include "TestClassInterface.hpp"
+
+using namespace std;
+
+class TestClass_Stub : public TestClassInterface {
+ public:
+ TestClass_Stub();
+ TestClass_Stub(int _port, const char* _address, int _rev, bool* _bResult);
+ ~TestClass_Stub();
+
+ void setA(int _int);
+ void setB(float _float);
+ void setC(string _string);
+ string sumArray(vector<string> newA);
+ int setAndGetA(int newA);
+ int setACAndGetA(string newC, int newA);
+ //void registerCallback(CallBackInterface _cb);
+ //int callBack();
+
+ private:
+ int intA;
+ float floatB;
+ string stringC;
+ //CallBackInterface cb;
+ IoTRMICall *rmiCall;
+ string address;
+ //vector<int> ports;
+};
+
+
+TestClass_Stub::TestClass_Stub() {
+
+ address = "";
+ rmiCall = NULL;
+}
+
+
+TestClass_Stub::TestClass_Stub(int _port, const char* _address, int _rev, bool* _bResult) {
+
+ address = _address;
+ rmiCall = new IoTRMICall(_port, _address, _rev, _bResult);
+}
+
+
+TestClass_Stub::~TestClass_Stub() {
+
+ if (rmiCall != NULL) {
+ delete rmiCall;
+ rmiCall = NULL;
+ }
+}
+
+
+void TestClass_Stub::setA(int _int) {
+
+ int numParam = 1;
+ string sign = "voidsetA(int)";
+ string retType = "void";
+ string paramCls[] = { "int" };
+ void* paramObj[] = { &_int };
+ void* retObj = NULL;
+ rmiCall->remoteCall(sign, retType, paramCls, paramObj, numParam, retObj);
+}
+
+
+void TestClass_Stub::setB(float _float) {
+
+ int numParam = 1;
+ string sign = "voidsetB(float)";
+ string retType = "void";
+ string paramCls[] = { "float" };
+ void* paramObj[] = { &_float };
+ void* retObj = NULL;
+ rmiCall->remoteCall(sign, retType, paramCls, paramObj, numParam, retObj);
+}
+
+
+void TestClass_Stub::setC(string _string) {
+
+ int numParam = 1;
+ string sign = "voidsetC(string)";
+ string retType = "void";
+ string paramCls[] = { "string" };
+ void* paramObj[] = { &_string };
+ void* retObj = NULL;
+ rmiCall->remoteCall(sign, retType, paramCls, paramObj, numParam, retObj);
+}
+
+
+string TestClass_Stub::sumArray(vector<string> newA) {
+
+ int numParam = 1;
+ string sign = "sumArray(string[])";
+ string retType = "string";
+ string paramCls[] = { "string[]" };
+ void* paramObj[] = { &newA };
+ string retVal = "";
+ void* retObj = &retVal;
+ rmiCall->remoteCall(sign, retType, paramCls, paramObj, numParam, retObj);
+ return retVal;
+}
+
+
+int TestClass_Stub::setAndGetA(int newA) {
+
+ int numParam = 1;
+ string sign = "intsetAndGetA(int)";
+ string retType = "int";
+ string paramCls[] = { "int" };
+ void* paramObj[] = { &newA };
+ int retVal = 0;
+ void* retObj = &retVal;
+ rmiCall->remoteCall(sign, retType, paramCls, paramObj, numParam, retObj);
+ return retVal;
+}
+
+
+int TestClass_Stub::setACAndGetA(string newC, int newA) {
+
+ int numParam = 2;
+ string sign = "intsetACAndGetA(string,int)";
+ string retType = "int";
+ string paramCls[] = { "string", "int" };
+ void* paramObj[] = { &newC, &newA };
+ int retVal = 0;
+ void* retObj = &retVal;
+ rmiCall->remoteCall(sign, retType, paramCls, paramObj, numParam, retObj);
+ return retVal;
+}
+
+
+/*void TestClass_Stub::registerCallback(CallBackInterface _cb) {
+
+ cb = _cb;
+}
+
+
+int TestClass_Stub::callBack() {
+
+ return cb.printInt();
+}*/
+
import java.util.Set;
-public class TestClass {
+public class TestClass implements TestClassInterface {
/**
* Class Properties
--- /dev/null
+package iotrmi.Java.sample;
+
+import java.util.Set;
+
+public interface TestClassInterface {
+
+ public void setA(int _int);
+ public void setB(float _float);
+ public void setC(String _string);
+ public String sumArray(String[] newA);
+ public int setAndGetA(int newA);
+ public int setACAndGetA(String newC, int newA);
+ public void registerCallback(CallBackInterface _cb);
+ public int callBack();
+}
import java.util.Arrays;
-public class TestClass_Stub {
+public class TestClass_Stub implements TestClassInterface {
/**
* Class Properties
}
- private void registerCallback(CallBackInterface _cb) {
+ public void registerCallback(CallBackInterface _cb) {
//int port = 5011; // Send this info to the other end to start the stub
//String address = "localhost";