PHONY += rmi
rmi:
mkdir -p $(BIN_DIR)
- $(JAVAC) -cp .:../$(BIN_DIR) -d $(BIN_DIR) iotrmi/Java/*.java
- $(JAVAC) -cp .:../$(BIN_DIR) -d $(BIN_DIR) iotrmi/Java/sample/*.java
+# $(JAVAC) -cp .:../$(BIN_DIR) -d $(BIN_DIR) iotrmi/Java/*.java
+# $(JAVAC) -cp .:../$(BIN_DIR) -d $(BIN_DIR) iotrmi/Java/sample/*.java
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
# 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
+ $(G++) iotrmi/C++/sample/CallBackInterface.hpp -o $(BIN_DIR)/iotrmi/C++/sample/CallBackInterface.out --std=c++11
+ $(G++) iotrmi/C++/sample/CallBack.hpp -o $(BIN_DIR)/iotrmi/C++/sample/CallBack.out --std=c++11
+ $(G++) iotrmi/C++/sample/CallBack_CBStub.hpp -o $(BIN_DIR)/iotrmi/C++/sample/CallBack_CBStub.out --std=c++11
+ $(G++) iotrmi/C++/sample/CallBack_CBSkeleton.hpp -o $(BIN_DIR)/iotrmi/C++/sample/CallBack_CBSkeleton.out --std=c++11
+ $(G++) iotrmi/C++/sample/CallBack_Stub.cpp -o $(BIN_DIR)/iotrmi/C++/sample/CallBack_Stub.out --std=c++11
+ $(G++) iotrmi/C++/sample/CallBack_Skeleton.cpp -o $(BIN_DIR)/iotrmi/C++/sample/CallBack_Skeleton.out --std=c++11
+ $(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
+ #$(G++) iotrmi/C++/sample/Test.cpp -o ../bin/iotrmi/C++/sample/Test.out --std=c++11 -lpthread
+ $(G++) iotrmi/C++/sample/Test2.cpp -o ../bin/iotrmi/C++/sample/Test2.out --std=c++11 -pthread -pg
+
PHONY += run-rmiserver
run-rmiserver:
class IoTRMICall {
public:
- IoTRMICall(int _port, const char* _address, int _rev, bool* _bResult, string _methodSign[], int _size);
+ IoTRMICall(int _port, const char* _address, int _rev, bool* _bResult,
+ const string _methodSign[], const int _size);
~IoTRMICall();
// Public methods
int methodLength(string paramCls[], void* paramObj[], int numParam);
- char* methodToBytes(string methodSign, string paramCls[], void* paramObj[],
+ char* methodToBytes(int objectId, string methodSign, string paramCls[], void* paramObj[],
char* method, int numParam);
- void* remoteCall(string methodSign, string retType, string paramCls[],
+ void* remoteCall(int objectId, string methodSign, string retType, string paramCls[],
void* paramObj[], int numParam, void* retObj);
private:
IoTSocketClient *rmiClient;
// Private methods
- void getMethodIds(string methodSign[], int size);
+ void getMethodIds(const string methodSign[], const int size);
};
// Constructor
-IoTRMICall::IoTRMICall(int _port, const char* _address, int _rev, bool* _bResult, string _methodSign[], int _size) {
+IoTRMICall::IoTRMICall(int _port, const char* _address, int _rev, bool* _bResult, const string _methodSign[], const int _size) {
getMethodIds(_methodSign, _size);
rmiUtil = new IoTRMIUtil();
// Calls a method remotely by passing in parameters and getting a return object
-void* IoTRMICall::remoteCall(string methodSign, string retType, string paramCls[],
+void* IoTRMICall::remoteCall(int objectId, string methodSign, string retType, string paramCls[],
void* paramObj[], int numParam, void* retObj) {
// Send input parameters
int len = methodLength(paramCls, paramObj, numParam);
char method[len];
- methodToBytes(methodSign, paramCls, paramObj, method, numParam);
+ methodToBytes(objectId, methodSign, paramCls, paramObj, method, numParam);
// Send bytes
fflush(NULL);
rmiClient->sendBytes(method, len);
int IoTRMICall::methodLength(string paramCls[], void* paramObj[], int numParam) {
// Get byte arrays and calculate method bytes length
- // Start from the method Id...
- int methodLen = IoTRMIUtil::METHOD_ID_LEN;
+ // Start from the object Id + method Id...
+ int methodLen = IoTRMIUtil::OBJECT_ID_LEN + IoTRMIUtil::METHOD_ID_LEN;
for (int i = 0; i < numParam; i++) {
// Find the parameter length
int paramLen = rmiUtil->getTypeSize(paramCls[i]);
// Convert method and its parameters into bytes
-char* IoTRMICall::methodToBytes(string methodSign, string paramCls[],
+char* IoTRMICall::methodToBytes(int objectId, string methodSign, string paramCls[],
void* paramObj[], char* method, int numParam) {
- // Get method ID in bytes
+ // Get object Id in bytes
+ char objId[IoTRMIUtil::OBJECT_ID_LEN];
+ IoTRMIUtil::intToByteArray(objectId, objId);
+ memcpy(method, objId, IoTRMIUtil::OBJECT_ID_LEN);
+ int pos = IoTRMIUtil::OBJECT_ID_LEN;
+ // Get method Id in bytes
char methodId[IoTRMIUtil::METHOD_ID_LEN];
int methId = mapSign2MethodId.find(methodSign)->second;
IoTRMIUtil::intToByteArray(methId, methodId);
- memcpy(method, methodId, IoTRMIUtil::METHOD_ID_LEN);
- int pos = IoTRMIUtil::METHOD_ID_LEN;
+ memcpy(method + pos, methodId, IoTRMIUtil::METHOD_ID_LEN);
+ pos = pos + IoTRMIUtil::METHOD_ID_LEN;
// Get byte arrays and calculate method bytes length
for (int i = 0; i < numParam; i++) {
// Find the parameter length
// *************
// Helpers
// *************
-void IoTRMICall::getMethodIds(string methodSign[], int size) {
+void IoTRMICall::getMethodIds(const string methodSign[], const int size) {
for(int i = 0; i < size; i++) {
mapSign2MethodId[methodSign[i]] = i;
class IoTRMIObject {
public:
- IoTRMIObject(int _port, bool* _bResult, string _methodSign[], int _size);
+ IoTRMIObject(int _port, bool* _bResult, const string _methodSign[], const int _size);
~IoTRMIObject();
// Public methods
void sendReturnObj(void* retObj, string type);
- void getMethodBytes();
+ char* getMethodBytes();
+ int getMethodBytesLen();
+ void setMethodBytes(char* _methodBytes);
+ int getObjectId();
+ static int getObjectId(char* methodBytes);
string getSignature();
void** getMethodParams(string paramCls[], int numParam, void* paramObj[]);
int methodLen;
// Private methods
- void getMethodIds(string methodSign[], int size);
+ void getMethodIds(const string methodSign[], const int size);
};
// Constructor
-IoTRMIObject::IoTRMIObject(int _port, bool* _bResult, string _methodSign[], int _size) {
+IoTRMIObject::IoTRMIObject(int _port, bool* _bResult, const string _methodSign[], const int _size) {
rmiUtil = new IoTRMIUtil();
if (rmiUtil == NULL) {
// Get method bytes from the socket
-void IoTRMIObject::getMethodBytes() {
+char* IoTRMIObject::getMethodBytes() {
// Get method in bytes and update method length
methodBytes = rmiServer->receiveBytes(methodBytes, &methodLen);
fflush(NULL);
+ return methodBytes;
+}
+
+
+// Get method bytes length
+int IoTRMIObject::getMethodBytesLen() {
+
+ return methodLen;
+}
+
+
+// Get object Id from bytes
+int IoTRMIObject::getObjectId() {
+
+ char objectIdBytes[IoTRMIUtil::OBJECT_ID_LEN];
+ memcpy(objectIdBytes, methodBytes, IoTRMIUtil::OBJECT_ID_LEN);
+ // Get method signature
+ int objectId = 0;
+ IoTRMIUtil::byteArrayToInt(&objectId, objectIdBytes);
+
+ return objectId;
+}
+
+
+// Get object Id from bytes (static version)
+int IoTRMIObject::getObjectId(char* methodBytes) {
+
+ char objectIdBytes[IoTRMIUtil::OBJECT_ID_LEN];
+ memcpy(objectIdBytes, methodBytes, IoTRMIUtil::OBJECT_ID_LEN);
+ // Get method signature
+ int objectId = 0;
+ IoTRMIUtil::byteArrayToInt(&objectId, objectIdBytes);
+
+ return objectId;
+}
+
+
+// Set method bytes
+void IoTRMIObject::setMethodBytes(char* _methodBytes) {
+
+ // Set method bytes
+ methodBytes = _methodBytes;
}
// Get method Id
char methodIdBytes[IoTRMIUtil::METHOD_ID_LEN];
- memcpy(methodIdBytes, methodBytes, IoTRMIUtil::METHOD_ID_LEN);
- // Get method object
+ memcpy(methodIdBytes, methodBytes + IoTRMIUtil::OBJECT_ID_LEN, IoTRMIUtil::METHOD_ID_LEN);
+ // Get method signature
int methodId = 0;
IoTRMIUtil::byteArrayToInt(&methodId, methodIdBytes);
void** IoTRMIObject::getMethodParams(string paramCls[], int numParam, void* paramObj[]) {
// Byte scanning position
- int pos = IoTRMIUtil::METHOD_ID_LEN;
+ int pos = IoTRMIUtil::OBJECT_ID_LEN + 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
// *************
// Helpers
// *************
-void IoTRMIObject::getMethodIds(string methodSign[], int size) {
+void IoTRMIObject::getMethodIds(const string methodSign[], const int size) {
for(int i = 0; i < size; i++) {
mapMethodId2Sign[i] = methodSign[i];
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 CHAR_LEN = 2; // 2 bytes (we follow Java convention)
--- /dev/null
+#include <iostream>
+#include "CallBackInterface.hpp"
+
+using namespace std;
+
+class CallBack : public CallBackInterface {
+ public:
+ //CallBack();
+ CallBack(int _i);
+ //~CallBack();
+
+ int printInt();
+ void setInt(int _i);
+
+ private:
+ int intA;
+};
+
+
+// Constructor
+CallBack::CallBack(int _i) {
+
+ intA = _i;
+}
+
+
+int CallBack::printInt() {
+
+ cout << "Integer: " << intA << endl;
+ return intA;
+}
+
+
+void CallBack::setInt(int _i) {
+
+ intA = _i;
+}
+
+
--- /dev/null
+#include <iostream>
+
+using namespace std;
+
+class CallBackInterface {
+ public:
+ virtual int printInt() = 0;
+ virtual void setInt(int _i) = 0;
+};
+
--- /dev/null
+#include <iostream>
+#include "../IoTRMIObject.hpp"
+#include "CallBack.hpp"
+
+using namespace std;
+
+class CallBack_CBSkeleton : public CallBackInterface {
+ public:
+ CallBack_CBSkeleton(CallBackInterface* _cb, int _objectId);
+ ~CallBack_CBSkeleton();
+
+ void invokeMethod(IoTRMIObject* rmiObj);
+ int printInt();
+ void setInt(int _i);
+
+ const static int size = 2;
+ const static string methodSignatures[size];
+
+ private:
+ CallBackInterface *cb;
+ int objectId = 0;
+};
+
+
+const string CallBack_CBSkeleton::methodSignatures[CallBack_CBSkeleton::size] = {
+
+ "intprintInt()",
+ "voidsetInt(int)"
+};
+
+
+// Constructor
+CallBack_CBSkeleton::CallBack_CBSkeleton(CallBackInterface* _cb, int _objectId) {
+
+ cb = _cb;
+ objectId = _objectId;
+ cout << "Creating CallBack_Skeleton and waiting!" << endl;
+}
+
+
+CallBack_CBSkeleton::~CallBack_CBSkeleton() {
+
+}
+
+
+void CallBack_CBSkeleton::invokeMethod(IoTRMIObject* rmiObj) {
+
+ // Loop continuously waiting for incoming bytes
+ while (true) {
+
+ rmiObj->getMethodBytes();
+ string methodSign = rmiObj->getSignature();
+ cout << "Method sign: " << methodSign << endl;
+
+ if (methodSign.compare("intprintInt()") == 0) {
+ string paramCls[] = { };
+ int numParam = 0;
+ void* paramObj[] = { };
+ rmiObj->getMethodParams(paramCls, numParam, paramObj);
+ int retVal = printInt();
+ void* retObj = &retVal;
+ rmiObj->sendReturnObj(retObj, "int");
+ } else if (methodSign.compare("voidsetInt(int)") == 0) {
+ string paramCls[] = { "int" };
+ int numParam = 1;
+ int param1 = 1;
+ void* paramObj[] = { ¶m1 };
+ rmiObj->getMethodParams(paramCls, numParam, paramObj);
+ setInt(param1);
+ } else {
+ string error = "Signature not recognized: " + string(methodSign);
+ throw error;
+ }
+ }
+}
+
+
+int CallBack_CBSkeleton::printInt() {
+
+ return cb->printInt();
+}
+
+
+void CallBack_CBSkeleton::setInt(int _i) {
+
+ cb->setInt(_i);
+}
+
+
--- /dev/null
+#include <iostream>
+#include "CallBackInterface.hpp"
+#include "../IoTRMICall.hpp"
+
+using namespace std;
+
+class CallBack_CBStub : public CallBackInterface {
+ public:
+ CallBack_CBStub();
+ CallBack_CBStub(IoTRMICall* _rmiCall, int _objectId);
+ ~CallBack_CBStub();
+
+ int printInt();
+ void setInt(int _i);
+
+ const static int size = 2;
+ const static string methodSignatures[size];
+
+ private:
+
+ IoTRMICall *rmiCall;
+ int objectId = 0; // Default value is 0
+};
+
+
+const string CallBack_CBStub::methodSignatures[CallBack_CBStub::size] = {
+
+ "intprintInt()",
+ "voidsetInt(int)"
+};
+
+
+// Constructor
+CallBack_CBStub::CallBack_CBStub() {
+
+ rmiCall = NULL;
+}
+
+
+CallBack_CBStub::CallBack_CBStub(IoTRMICall* _rmiCall, int _objectId) {
+
+ objectId = _objectId;
+ rmiCall = _rmiCall;
+}
+
+
+CallBack_CBStub::~CallBack_CBStub() {
+
+ if (rmiCall != NULL) {
+ delete rmiCall;
+ rmiCall = NULL;
+ }
+}
+
+
+int CallBack_CBStub::printInt() {
+
+ int numParam = 0;
+ string sign = "intprintInt()";
+ string retType = "int";
+ string paramCls[] = { };
+ void* paramObj[] = { };
+ int retVal = 0;
+ void* retObj = &retVal;
+ rmiCall->remoteCall(objectId, sign, retType, paramCls, paramObj, numParam, retObj);
+ return retVal;
+}
+
+
+void CallBack_CBStub::setInt(int _i) {
+
+ int numParam = 1;
+ string sign = "voidsetInt(int)";
+ string retType = "void";
+ string paramCls[] = { "int" };
+ void* paramObj[] = { &_i };
+ void* retObj = NULL;
+ rmiCall->remoteCall(objectId, sign, retType, paramCls, paramObj, numParam, retObj);
+}
+
+
--- /dev/null
+#include <iostream>
+#include <string>
+#include "CallBack_Skeleton.hpp"
+
+using namespace std;
+
+int main(int argc, char *argv[])
+{
+
+ int port = 5010;
+ CallBackInterface *cb = new CallBack(23);
+ CallBack_Skeleton *cbSkel = new CallBack_Skeleton(cb, port);
+ //cbSkel->waitRequestInvokeMethod();
+
+ delete cb;
+ delete cbSkel;
+ return 0;
+}
--- /dev/null
+#include <iostream>
+#include "../IoTRMIObject.hpp"
+#include "CallBack.hpp"
+
+using namespace std;
+
+class CallBack_Skeleton : public CallBackInterface {
+ public:
+ CallBack_Skeleton(CallBackInterface* _cb, int _port);
+ ~CallBack_Skeleton();
+
+ void waitRequestInvokeMethod();
+ int printInt();
+ void setInt(int _i);
+
+ const static int size = 2;
+ const static string methodSignatures[size];
+
+ private:
+ CallBackInterface *cb;
+ IoTRMIObject *rmiObj;
+};
+
+
+const string CallBack_Skeleton::methodSignatures[CallBack_Skeleton::size] = {
+
+ "intprintInt()",
+ "voidsetInt(int)"
+};
+
+
+// Constructor
+CallBack_Skeleton::CallBack_Skeleton(CallBackInterface* _cb, int _port) {
+
+ bool _bResult = false;
+ cb = _cb;
+ rmiObj = new IoTRMIObject(_port, &_bResult, methodSignatures, size);
+ waitRequestInvokeMethod();
+}
+
+
+CallBack_Skeleton::~CallBack_Skeleton() {
+
+ if (rmiObj != NULL) {
+ delete rmiObj;
+ rmiObj = NULL;
+ }
+}
+
+
+void CallBack_Skeleton::waitRequestInvokeMethod() {
+
+ // Loop continuously waiting for incoming bytes
+ while (true) {
+
+ rmiObj->getMethodBytes();
+ string methodSign = rmiObj->getSignature();
+ cout << "Method sign: " << methodSign << endl;
+
+ if (methodSign.compare("intprintInt()") == 0) {
+ string paramCls[] = { };
+ int numParam = 0;
+ void* paramObj[] = { };
+ rmiObj->getMethodParams(paramCls, numParam, paramObj);
+ int retVal = printInt();
+ void* retObj = &retVal;
+ rmiObj->sendReturnObj(retObj, "int");
+ } else if (methodSign.compare("voidsetInt(int)") == 0) {
+ string paramCls[] = { "int" };
+ int numParam = 1;
+ int param1 = 1;
+ void* paramObj[] = { ¶m1 };
+ rmiObj->getMethodParams(paramCls, numParam, paramObj);
+ setInt(param1);
+ } else {
+ string error = "Signature not recognized: " + string(methodSign);
+ throw error;
+ }
+ }
+}
+
+
+int CallBack_Skeleton::printInt() {
+
+ return cb->printInt();
+}
+
+
+void CallBack_Skeleton::setInt(int _i) {
+
+ cb->setInt(_i);
+}
+
+
--- /dev/null
+#include <iostream>
+#include <string>
+#include "CallBack_Stub.hpp"
+
+using namespace std;
+
+int main(int argc, char *argv[])
+{
+
+ int port = 5010;
+ const char* address = "localhost";
+ int rev = 0;
+ bool bResult = false;
+
+ CallBackInterface *cbStub = new CallBack_Stub(port, address, rev, &bResult);
+ cout << "Return value: " << cbStub->printInt() << endl;
+ cbStub->setInt(123);
+ cout << "Return value: " << cbStub->printInt() << endl;
+
+ delete cbStub;
+
+ return 0;
+}
--- /dev/null
+#include <iostream>
+#include "CallBackInterface.hpp"
+#include "../IoTRMICall.hpp"
+
+using namespace std;
+
+class CallBack_Stub : public CallBackInterface {
+ public:
+ CallBack_Stub();
+ CallBack_Stub(int _port, const char* _address, int _rev, bool* _bResult);
+ ~CallBack_Stub();
+
+ int printInt();
+ void setInt(int _i);
+
+ const static int size = 2;
+ const static string methodSignatures[size];
+
+ private:
+
+ IoTRMICall *rmiCall;
+ string address;
+ int objectId = 0; // Default value is 0
+};
+
+
+const string CallBack_Stub::methodSignatures[CallBack_Stub::size] = {
+
+ "intprintInt()",
+ "voidsetInt(int)"
+};
+
+
+// Constructor
+CallBack_Stub::CallBack_Stub() {
+
+ address = "";
+ rmiCall = NULL;
+}
+
+
+CallBack_Stub::CallBack_Stub(int _port, const char* _address, int _rev, bool* _bResult) {
+
+ address = _address;
+ rmiCall = new IoTRMICall(_port, _address, _rev, _bResult, methodSignatures, size);
+}
+
+
+CallBack_Stub::~CallBack_Stub() {
+
+ if (rmiCall != NULL) {
+ delete rmiCall;
+ rmiCall = NULL;
+ }
+}
+
+
+int CallBack_Stub::printInt() {
+
+ int numParam = 0;
+ string sign = "intprintInt()";
+ string retType = "int";
+ string paramCls[] = { };
+ void* paramObj[] = { };
+ int retVal = 0;
+ void* retObj = &retVal;
+ rmiCall->remoteCall(objectId, sign, retType, paramCls, paramObj, numParam, retObj);
+ return retVal;
+}
+
+
+void CallBack_Stub::setInt(int _i) {
+
+ int numParam = 1;
+ string sign = "voidsetInt(int)";
+ string retType = "void";
+ string paramCls[] = { "int" };
+ void* paramObj[] = { &_i };
+ void* retObj = NULL;
+ rmiCall->remoteCall(objectId, sign, retType, paramCls, paramObj, numParam, retObj);
+}
+
+
input.push_back(987);*/
cout << "Return value: " << tc->sumArray(input) << endl;
-
delete tc;
+ vector<CallBackInterface*> test;
+ CallBackInterface *cb1 = new CallBack(12);
+ CallBackInterface *cb2 = new CallBack(22);
+ CallBackInterface *cb3 = new CallBack(32);
+ test.push_back(cb1);
+ test.push_back(cb2);
+ test.push_back(cb3);
+ for (CallBackInterface *cb : test) {
+ cout << "Test print: " << cb->printInt() << endl;
+ }
+
+ delete cb1;
+ delete cb2;
+ delete cb3;
+
return 0;
}
//int64_t sumArray(vector<int> newA);
int setAndGetA(int newA);
int setACAndGetA(string newC, int newA);
- //void registerCallback(CallBackInterface _cb);
- //int callBack();
+ void registerCallback(CallBackInterface* _cb);
+ void registerCallback(vector<CallBackInterface*> _cb);
+ int callBack();
private:
- int intA;
- float floatB;
- string stringC;
- //CallBackInterface cb;
+ int intA;
+ float floatB;
+ string stringC;
+ CallBackInterface *cb;
+ vector<CallBackInterface*> cbvec;
};
intA = 1;
floatB = 2;
stringC = "345";
- //cb = NULL;
+ cb = NULL;
+ // cbvec doesn't need to be initialized again
}
intA = _int;
floatB = _float;
stringC = _string;
- //cb = NULL;
+ cb = NULL;
+ // cbvec doesn't need to be initialized again
}
}
-/*void TestClass::registerCallback(CallBackInterface _cb) {
+void TestClass::registerCallback(CallBackInterface* _cb) {
cb = _cb;
}
+void TestClass::registerCallback(vector<CallBackInterface*> _cb) {
+
+ for (CallBackInterface* cb : _cb) {
+ cbvec.push_back(cb);
+ cout << "Registering callback object!" << endl;
+ }
+}
+
+
+//int TestClass::callBack() {
+// return cb.printInt();
+//}
+
+
int TestClass::callBack() {
- return cb.printInt();
-}*/
+ int sum = 0;
+ for (CallBackInterface* cb : cbvec) {
+ sum = sum + cb->printInt();
+ }
+}
#include <iostream>
#include <vector>
+#include "CallBack_CBSkeleton.hpp"
+//#include "CallBack.hpp"
using namespace std;
//virtual int64_t sumArray(vector<int> newA) = 0;
virtual int setAndGetA(int newA) = 0;
virtual int setACAndGetA(string newC, int newA) = 0;
- //virtual void registerCallback(CallBackInterface _cb);
- //virtual int callBack();
+ virtual void registerCallback(CallBackInterface* _cb) = 0;
+ virtual void registerCallback(vector<CallBackInterface*> _cb) = 0;
+ virtual int callBack() = 0;
};
TestClass_Skeleton(TestClassInterface* _tc, int _port);
~TestClass_Skeleton();
- void waitRequestInvokeMethod();
- void setA(int _int);
- void setB(float _float);
- void setC(string _string);
- string sumArray(vector<string> newA);
- //int64_t sumArray(vector<int> newA);
- int setAndGetA(int newA);
- int setACAndGetA(string newC, int newA);
- //void registerCallback(CallBackInterface _cb);
- //int callBack();
+ void waitRequestInvokeMethod();
+ void setA(int _int);
+ void setB(float _float);
+ void setC(string _string);
+ string sumArray(vector<string> newA);
+ //int64_t sumArray(vector<int> newA);
+ int setAndGetA(int newA);
+ int setACAndGetA(string newC, int newA);
+ void registerCallback(CallBackInterface* _cb);
+ void registerCallback(vector<CallBackInterface*> _cb);
+ int callBack();
+
+ const static int size = 9;
+ const static string methodSignatures[size];
private:
TestClassInterface *tc;
IoTRMIObject *rmiObj;
//CallBackInterface cbstub;
+};
+
- const static int size = 8;
- string methodSignatures[size] = {
-
- "voidsetA(int)",
- "voidsetB(float)",
- "voidsetC(string)",
- "sumArray(string[])",
- //"sumArray(int[])",
- "intsetAndGetA(int)",
- "intsetACAndGetA(string,int)",
- "intcallBack()",
- "voidregisterCallBack(CallBackInterface)"
- };
+const string TestClass_Skeleton::methodSignatures[TestClass_Skeleton::size] = {
+ "voidsetA(int)",
+ "voidsetB(float)",
+ "voidsetC(string)",
+ "sumArray(string[])",
+ //"sumArray(int[])",
+ "intsetAndGetA(int)",
+ "intsetACAndGetA(string,int)",
+ "intcallBack()",
+ "voidregisterCallBack(CallBackInterface)",
+ "voidregisterCallBack(CallBackInterface[])"
};
}
-/*void TestClass_Skeleton::registerCallback(CallBackInterface _cb) {
+void TestClass_Skeleton::registerCallback(CallBackInterface* _cb) {
+
+ tc->registerCallback(_cb);
+}
+
+
+void TestClass_Skeleton::registerCallback(vector<CallBackInterface*> _cb) {
tc->registerCallback(_cb);
}
int TestClass_Skeleton::callBack() {
- return tc->callBack();
-}*/
+ tc->callBack();
+}
+
const char* address = "localhost";
int rev = 0;
bool bResult = false;
+ vector<int> ports;
+ ports.push_back(12345);
+ //ports.push_back(13234);
- TestClassInterface *tcStub = new TestClass_Stub(port, address, rev, &bResult);
+ TestClassInterface *tcStub = new TestClass_Stub(port, address, rev, &bResult, ports);
cout << "Return value: " << tcStub->setAndGetA(123) << endl;
cout << "Return value: " << tcStub->setACAndGetA("string", 123) << endl;
vector<string> input;
#include <iostream>
#include "../IoTRMICall.hpp"
+#include "../IoTRMIObject.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(int _port, const char* _address, int _rev, bool* _bResult, vector<int> _ports);
~TestClass_Stub();
void setA(int _int);
//int64_t sumArray(vector<int> newA);
int setAndGetA(int newA);
int setACAndGetA(string newC, int newA);
- //void registerCallback(CallBackInterface _cb);
- //int callBack();
+ void registerCallback(CallBackInterface* _cb);
+ void registerCallback(vector<CallBackInterface*>_cb);
+ int callBack();
+ void init_CallBack();
+
+ const static int size = 9;
+ const static string methodSignatures[size];
private:
- int intA;
- float floatB;
- string stringC;
- //CallBackInterface cb;
- IoTRMICall *rmiCall;
- string address;
- //vector<int> ports;
-
- const static int size = 8;
- string methodSignatures[size] = {
-
- "voidsetA(int)",
- "voidsetB(float)",
- "voidsetC(string)",
- "sumArray(string[])",
- //"sumArray(int[])",
- "intsetAndGetA(int)",
- "intsetACAndGetA(string,int)",
- "intcallBack()",
- "voidregisterCallBack(CallBackInterface)"
- };
+ int intA;
+ float floatB;
+ string stringC;
+ //CallBackInterface cb;
+ IoTRMICall *rmiCall;
+ IoTRMIObject *rmiObj;
+ string address;
+ vector<int> ports;
+ map<int,CallBackInterface*> mapCBObj;
+
+ int objectId = 0; // Default value is 0
+};
+
+
+const string TestClass_Stub::methodSignatures[TestClass_Stub::size] = {
+ "voidsetA(int)",
+ "voidsetB(float)",
+ "voidsetC(string)",
+ "sumArray(string[])",
+ //"sumArray(int[])",
+ "intsetAndGetA(int)",
+ "intsetACAndGetA(string,int)",
+ "intcallBack()",
+ "voidregisterCallBack(CallBackInterface)",
+ "voidregisterCallBack(CallBackInterface[])"
};
}
-TestClass_Stub::TestClass_Stub(int _port, const char* _address, int _rev, bool* _bResult) {
+TestClass_Stub::TestClass_Stub(int _port, const char* _address, int _rev, bool* _bResult, vector<int> _ports) {
address = _address;
rmiCall = new IoTRMICall(_port, _address, _rev, _bResult, methodSignatures, size);
+ ports = _ports;
}
}
+// Callback handler thread
+void TestClass_Stub::init_CallBack() {
+
+ bool bResult = false;
+ rmiObj = new IoTRMIObject(ports[0], &bResult, CallBack_CBSkeleton::methodSignatures, CallBack_CBSkeleton::size);
+ while (true) {
+ char* method = rmiObj->getMethodBytes();
+
+ }
+}
+
+
void TestClass_Stub::setA(int _int) {
int numParam = 1;
string paramCls[] = { "int" };
void* paramObj[] = { &_int };
void* retObj = NULL;
- rmiCall->remoteCall(sign, retType, paramCls, paramObj, numParam, retObj);
+ rmiCall->remoteCall(objectId, sign, retType, paramCls, paramObj, numParam, retObj);
}
string paramCls[] = { "float" };
void* paramObj[] = { &_float };
void* retObj = NULL;
- rmiCall->remoteCall(sign, retType, paramCls, paramObj, numParam, retObj);
+ rmiCall->remoteCall(objectId, sign, retType, paramCls, paramObj, numParam, retObj);
}
string paramCls[] = { "string" };
void* paramObj[] = { &_string };
void* retObj = NULL;
- rmiCall->remoteCall(sign, retType, paramCls, paramObj, numParam, retObj);
+ rmiCall->remoteCall(objectId, sign, retType, paramCls, paramObj, numParam, retObj);
}
void* paramObj[] = { &newA };
string retVal = "";
void* retObj = &retVal;
- rmiCall->remoteCall(sign, retType, paramCls, paramObj, numParam, retObj);
+ rmiCall->remoteCall(objectId, sign, retType, paramCls, paramObj, numParam, retObj);
return retVal;
}
void* paramObj[] = { &newA };
int64_t retVal = 0;
void* retObj = &retVal;
- rmiCall->remoteCall(sign, retType, paramCls, paramObj, numParam, retObj);
+ rmiCall->remoteCall(objectId, sign, retType, paramCls, paramObj, numParam, retObj);
return retVal;
}*/
void* paramObj[] = { &newA };
int retVal = 0;
void* retObj = &retVal;
- rmiCall->remoteCall(sign, retType, paramCls, paramObj, numParam, retObj);
+ rmiCall->remoteCall(objectId, sign, retType, paramCls, paramObj, numParam, retObj);
return retVal;
}
void* paramObj[] = { &newC, &newA };
int retVal = 0;
void* retObj = &retVal;
- rmiCall->remoteCall(sign, retType, paramCls, paramObj, numParam, retObj);
+ rmiCall->remoteCall(objectId, sign, retType, paramCls, paramObj, numParam, retObj);
return retVal;
}
-/*void TestClass_Stub::registerCallback(CallBackInterface _cb) {
+void TestClass_Stub::registerCallback(CallBackInterface* _cb) {
- cb = _cb;
+ //Should implement the callback here
+}
+
+
+void TestClass_Stub::registerCallback(vector<CallBackInterface*> _cb) {
+
+ //Should implement the callback here for multiple callback objects
}
int TestClass_Stub::callBack() {
- return cb.printInt();
-}*/
+ int numParam = 0;
+ string sign = "intcallBack()";
+ string retType = "int";
+ string paramCls[] = { };
+ void* paramObj[] = { };
+ int retVal = 0;
+ void* retObj = &retVal;
+ rmiCall->remoteCall(objectId, sign, retType, paramCls, paramObj, numParam, retObj);
+ return retVal;
+}
while (true) {
byte[] method = rmiObj.getMethodBytes();
int objId = IoTRMIObject.getObjectId(method);
- CallBack_CBSkeleton skel = (CallBack_CBSkeleton) listCBObj.get(objId);
+ //CallBack_CBSkeleton skel = (CallBack_CBSkeleton) listCBObj.get(objId);
+ CallBackInterface cb = listCBObj.get(objId);
+ CallBack_CBSkeleton skel = null;
+ if (cb instanceof CallBack_CBSkeleton) { // in case we have multiple callback classes
+ skel = (CallBack_CBSkeleton) cb;
+ }
if (skel != null) {
rmiObj.setMethodBytes(method);
retObj = skel.invokeMethod(rmiObj);
};
thread.start();
- String sign = "registercallback";
+ String sign = "registercallback"; // can be any string
Class<?> retType = void.class;
// port, address, rev, and number of objects
Class<?>[] paramCls = new Class<?>[] { int.class, String.class, int.class };