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
+ mkdir -p $(BIN_DIR)/iotrmi/C++/sample
#$(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/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 -pthread
-# $(G++) iotrmi/C++/sample/TestClass_Skeleton.cpp -o $(BIN_DIR)/iotrmi/C++/sample/TestClass_Skeleton.out --std=c++11 -pthread
+ $(G++) iotrmi/C++/sample/TestClass_Stub.cpp -o $(BIN_DIR)/iotrmi/C++/sample/TestClass_Stub.out --std=c++11 -pthread
+ $(G++) iotrmi/C++/sample/TestClass_Skeleton.cpp -o $(BIN_DIR)/iotrmi/C++/sample/TestClass_Skeleton.out --std=c++11 -pthread
#$(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
# $(G++) iotrmi/C++/sample/StructC.cpp -o ../bin/iotrmi/C++/sample/StructC.out --std=c++11
class IoTRMICall {
public:
- IoTRMICall(int _port, const char* _address, int _rev, bool* _bResult,
- const string _methodSign[], const int _size);
+ IoTRMICall(int _port, const char* _address, int _rev, bool* _bResult);
~IoTRMICall();
// Public methods
int methodLength(string paramCls[], void* paramObj[], int numParam);
- char* methodToBytes(int objectId, string methodSign, string paramCls[], void* paramObj[],
+ char* methodToBytes(int objectId, int methId, string paramCls[], void* paramObj[],
char* method, int numParam);
- void* remoteCall(int objectId, string methodSign, string retType, string paramCls[],
+ void* remoteCall(int objectId, int methodId, string retType, string paramCls[],
void* paramObj[], int numParam, void* retObj);
private:
// Constructor
-IoTRMICall::IoTRMICall(int _port, const char* _address, int _rev, bool* _bResult, const string _methodSign[], const int _size) {
+IoTRMICall::IoTRMICall(int _port, const char* _address, int _rev, bool* _bResult) {
- getMethodIds(_methodSign, _size);
rmiUtil = new IoTRMIUtil();
if (rmiUtil == NULL) {
perror("IoTRMICall: IoTRMIUtil isn't initialized!");
// Calls a method remotely by passing in parameters and getting a return object
-void* IoTRMICall::remoteCall(int objectId, string methodSign, string retType, string paramCls[],
+void* IoTRMICall::remoteCall(int objectId, int methodId, string retType, string paramCls[],
void* paramObj[], int numParam, void* retObj) {
// Critical section that is used by different objects
// Send input parameters
int len = methodLength(paramCls, paramObj, numParam);
char method[len];
- methodToBytes(objectId, methodSign, paramCls, paramObj, method, numParam);
+ methodToBytes(objectId, methodId, paramCls, paramObj, method, numParam);
// IoTRMIUtil::printBytes(method, len, false);
// Send bytes
fflush(NULL);
// Convert method and its parameters into bytes
-char* IoTRMICall::methodToBytes(int objectId, string methodSign, string paramCls[],
+char* IoTRMICall::methodToBytes(int objectId, int methId, string paramCls[],
void* paramObj[], char* method, int numParam) {
// Get object Id in bytes
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 + pos, methodId, IoTRMIUtil::METHOD_ID_LEN);
pos = pos + IoTRMIUtil::METHOD_ID_LEN;
return method;
}
-
-// *************
-// Helpers
-// *************
-void IoTRMICall::getMethodIds(const string methodSign[], const int size) {
-
- for(int i = 0; i < size; i++) {
- mapSign2MethodId[methodSign[i]] = i;
- }
-}
-
-
-
#endif
class IoTRMIObject {
public:
- IoTRMIObject(int _port, bool* _bResult, const string _methodSign[], const int _size);
+ IoTRMIObject(int _port, bool* _bResult);
~IoTRMIObject();
// Public methods
void sendReturnObj(void* retObj, string type);
void setMethodBytes(char* _methodBytes);
int getObjectId();
static int getObjectId(char* methodBytes);
- string getSignature();
+ int getMethodId();
void** getMethodParams(string paramCls[], int numParam, void* paramObj[]);
private:
- map<int,string> mapMethodId2Sign;
+ //map<int,string> mapMethodId2Sign;
IoTRMIUtil *rmiUtil;
IoTSocketServer *rmiServer;
char* methodBytes;
// Constructor
-IoTRMIObject::IoTRMIObject(int _port, bool* _bResult, const string _methodSign[], const int _size) {
+IoTRMIObject::IoTRMIObject(int _port, bool* _bResult) {
rmiUtil = new IoTRMIUtil();
if (rmiUtil == NULL) {
methodBytes = NULL;
methodLen = 0;
- getMethodIds(_methodSign, _size);
+ //getMethodIds(_methodSign, _size);
rmiServer = new IoTSocketServer(_port, _bResult);
if (rmiServer == NULL) {
// Set method bytes
-void IoTRMIObject::setMethodBytes(char* _methodBytes) {
+/*void IoTRMIObject::setMethodBytes(char* _methodBytes) {
// Set method bytes
methodBytes = _methodBytes;
-}
+}*/
-// Get signature from the method-Id-to-method-signature map
-string IoTRMIObject::getSignature() {
+// Get methodId
+int IoTRMIObject::getMethodId() {
// Get method Id
char methodIdBytes[IoTRMIUtil::METHOD_ID_LEN];
int methodId = 0;
IoTRMIUtil::byteArrayToInt(&methodId, methodIdBytes);
- return mapMethodId2Sign.find(methodId)->second;
+ return methodId;
}
}
-// *************
-// Helpers
-// *************
-void IoTRMIObject::getMethodIds(const string methodSign[], const int size) {
-
- for(int i = 0; i < size; i++) {
- mapMethodId2Sign[i] = methodSign[i];
- }
-}
-
-
#endif
cb = _cb;
objectId = _objectId;
- cout << "Creating CallBack_Skeleton and waiting!" << endl;
}
void CallBack_CBSkeleton::invokeMethod(IoTRMIObject* rmiObj) {
- string methodSign = rmiObj->getSignature();
+ int methodId = rmiObj->getMethodId();
- if (methodSign.compare("intprintInt()") == 0) {
- ___printInt(rmiObj);
- } else if (methodSign.compare("voidsetInt(int)") == 0) {
- ___setInt(rmiObj);
- } else {
- string error = "Signature not recognized: " + string(methodSign);
- throw error;
+ switch (methodId) {
+ case 0 : ___printInt(rmiObj); break;
+ case 1 : ___setInt(rmiObj); break;
+ default:
+ string error = "Method Id not recognized!";
+ throw error;
}
}
cout << "Got here in printInt()" << endl;
int numParam = 0;
- string sign = "intprintInt()";
+ int methodId = 0;
string retType = "int";
string paramCls[] = { };
void* paramObj[] = { };
int retVal = 0;
void* retObj = &retVal;
- rmiCall->remoteCall(objectId, sign, retType, paramCls, paramObj, numParam, retObj);
- cout << "Return value from printInt(): " << retVal << endl;
+ rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
return retVal;
}
void CallBack_CBStub::setInt(int _i) {
int numParam = 1;
- string sign = "voidsetInt(int)";
+ int methodId = 1;
string retType = "void";
string paramCls[] = { "int" };
void* paramObj[] = { &_i };
void* retObj = NULL;
- rmiCall->remoteCall(objectId, sign, retType, paramCls, paramObj, numParam, retObj);
+ rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
}
#endif
bool _bResult = false;
cb = _cb;
- rmiObj = new IoTRMIObject(_port, &_bResult, methodSignatures, size);
+ rmiObj = new IoTRMIObject(_port, &_bResult);
___waitRequestInvokeMethod();
}
while (true) {
rmiObj->getMethodBytes();
- string methodSign = rmiObj->getSignature();
- cout << "Method sign: " << methodSign << endl;
+ int methodId = rmiObj->getMethodId();
- if (methodSign.compare("intprintInt()") == 0) {
- ___printInt();
- } else if (methodSign.compare("voidsetInt(int)") == 0) {
- ___setInt();
- } else {
- string error = "Signature not recognized: " + string(methodSign);
- throw error;
+ switch (methodId) {
+ case 0 : ___printInt(); break;
+ case 1 : ___setInt(); break;
+ default:
+ string error = "Method Id not recognized!";
+ throw error;
}
}
}
CallBack_Stub::CallBack_Stub(int _port, const char* _address, int _rev, bool* _bResult) {
address = _address;
- rmiCall = new IoTRMICall(_port, _address, _rev, _bResult, methodSignatures, size);
+ rmiCall = new IoTRMICall(_port, _address, _rev, _bResult);
}
int CallBack_Stub::printInt() {
int numParam = 0;
- string sign = "intprintInt()";
+ int methodId = 0;
string retType = "int";
string paramCls[] = { };
void* paramObj[] = { };
int retVal = 0;
void* retObj = &retVal;
- rmiCall->remoteCall(objectId, sign, retType, paramCls, paramObj, numParam, retObj);
+ rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
return retVal;
}
void CallBack_Stub::setInt(int _i) {
int numParam = 1;
- string sign = "voidsetInt(int)";
+ int methodId = 1;
string retType = "void";
string paramCls[] = { "int" };
void* paramObj[] = { &_i };
void* retObj = NULL;
- rmiCall->remoteCall(objectId, sign, retType, paramCls, paramObj, numParam, retObj);
+ rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
}
#endif
const string TestClass_Skeleton::methodSignatures[TestClass_Skeleton::size] = {
- "voidsetA(int)",
- "voidsetB(float)",
- "voidsetC(string)",
- "sumArray(string[])",
+ "voidsetA(int)", // 0
+ "voidsetB(float)", // 1
+ "voidsetC(string)", // 2
+ "sumArray(string[])", // 3
//"sumArray(int[])",
- "intsetAndGetA(int)",
- "intsetACAndGetA(string,int)",
- "intcallBack()",
- "voidregisterCallBack(CallBackInterface)",
- "voidregisterCallBack(CallBackInterface[])",
- "registercallback",
- "handleStruct(StructJ[])",
- "structsize"
+ "intsetAndGetA(int)", // 4
+ "intsetACAndGetA(string,int)", // 5
+ "intcallBack()", // 6
+ "voidregisterCallBack(CallBackInterface)", // 7
+ "voidregisterCallBack(CallBackInterface[])", // 8
+ "registercallback", // 9
+ "handleStruct(StructJ[])", // 10
+ "structsize" // 11
};
bool _bResult = false;
tc = _tc;
- rmiObj = new IoTRMIObject(_port, &_bResult, methodSignatures, size);
+ rmiObj = new IoTRMIObject(_port, &_bResult);
___waitRequestInvokeMethod();
}
rmiObj->getMethodParams(paramCls, numParam, paramObj);
// Instantiate IoTRMICall object
bool bResult = false;
- rmiCall = new IoTRMICall(param1, param2.c_str(), param3, &bResult,
- CallBack_CBStub::methodSignatures, CallBack_CBStub::size);
+ rmiCall = new IoTRMICall(param1, param2.c_str(), param3, &bResult);
}
while (true) {
rmiObj->getMethodBytes();
- string methodSign = rmiObj->getSignature();
- cout << "Method sign: " << methodSign << endl;
+ int methodId = rmiObj->getMethodId();
- if (methodSign.compare("voidsetA(int)") == 0) {
- ___setA();
- } else if (methodSign.compare("voidsetB(float)") == 0) {
- ___setB();
- } else if (methodSign.compare("voidsetC(string)") == 0) {
- ___setC();
- } else if (methodSign.compare("sumArray(string[])") == 0) {
- ___sumArray();
- /*} else if (methodSign.compare("sumArray(int[])") == 0) {
- ____sumArray();*/
- } else if (methodSign.compare("intsetAndGetA(int)") == 0) {
- ___setAndGetA();
- } else if (methodSign.compare("intsetACAndGetA(string,int)") == 0) {
- ___setACAndGetA();
- } else if (methodSign.compare("voidregisterCallBack(CallBackInterface)") == 0) {
- //
- } else if (methodSign.compare("voidregisterCallBack(CallBackInterface[])") == 0) {
- ____registerCallback();
- } else if (methodSign.compare("registercallback") == 0) {
- ___regCB();
- } else if (methodSign.compare("intcallBack()") == 0) {
- ___callBack();
- // Handle struct
- } else if (methodSign.compare("structsize") == 0) {
- structsize1 = ___structSize();
- } else if (methodSign.compare("handleStruct(StructJ[])") == 0) {
- ___handleStruct(structsize1);
- } else {
- string error = "Signature unrecognized: " + string(methodSign);
- throw error;
+ switch (methodId) {
+ case 0: ___setA(); break;
+ case 1: ___setB(); break;
+ case 2: ___setC(); break;
+ case 3: ___sumArray(); break;
+ /* case 3: ____sumArray(); break;*/
+ case 4: ___setAndGetA(); break;
+ case 5: ___setACAndGetA(); break;
+ case 6: ___callBack(); break;
+ case 7: ___registerCallback(); break;
+ case 8: ____registerCallback(); break;
+ case 9: ___regCB(); break;
+ // Handle struct
+ case 10: ___handleStruct(structsize1); break;
+ case 11: structsize1 = ___structSize(); break;
+ default:
+ string error = "Method Id not recognized!";
+ throw error;
}
}
}
const string TestClass_Stub::methodSignatures[TestClass_Stub::size] = {
- "voidsetA(int)",
- "voidsetB(float)",
- "voidsetC(string)",
- "sumArray(string[])",
+ "voidsetA(int)", // 0
+ "voidsetB(float)", // 1
+ "voidsetC(string)", // 2
+ "sumArray(string[])", // 3
//"sumArray(int[])",
- "intsetAndGetA(int)",
- "intsetACAndGetA(string,int)",
- "intcallBack()",
- "voidregisterCallBack(CallBackInterface)",
- "voidregisterCallBack(CallBackInterface[])",
- "registercallback",
- "handleStruct(StructJ[])",
- "structsize"
+ "intsetAndGetA(int)", // 4
+ "intsetACAndGetA(string,int)", // 5
+ "intcallBack()", // 6
+ "voidregisterCallBack(CallBackInterface)", // 7
+ "voidregisterCallBack(CallBackInterface[])", // 8
+ "registercallback", // 9
+ "handleStruct(StructJ[])", // 10
+ "structsize" // 11
};
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);
+ rmiCall = new IoTRMICall(_port, _address, _rev, _bResult);
ports = _ports;
// Start thread
thread th1 (&TestClass_Stub::____init_CallBack, this);
void TestClass_Stub::____init_CallBack() {
bool bResult = false;
- rmiObj = new IoTRMIObject(ports[0], &bResult, CallBack_CBSkeleton::methodSignatures, CallBack_CBSkeleton::size);
+ rmiObj = new IoTRMIObject(ports[0], &bResult);
while (true) {
char* method = rmiObj->getMethodBytes();
int objId = IoTRMIObject::getObjectId(method);
void TestClass_Stub::____registerCallBack() {
int numParam = 3;
- string sign = "registercallback";
+ int methodId = 9;
string retType = "void";
string paramCls[] = { "int", "string", "int" };
int rev = 0;
void* paramObj[] = { &ports[0], &address, &rev };
void* retObj = NULL;
- rmiCall->remoteCall(objectId, sign, retType, paramCls, paramObj, numParam, retObj);
+ rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
}
void TestClass_Stub::setA(int _int) {
int numParam = 1;
- string sign = "voidsetA(int)";
+ int methodId = 0;
string retType = "void";
string paramCls[] = { "int" };
void* paramObj[] = { &_int };
void* retObj = NULL;
- rmiCall->remoteCall(objectId, sign, retType, paramCls, paramObj, numParam, retObj);
+ rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
}
void TestClass_Stub::setB(float _float) {
int numParam = 1;
- string sign = "voidsetB(float)";
+ int methodId = 1;
string retType = "void";
string paramCls[] = { "float" };
void* paramObj[] = { &_float };
void* retObj = NULL;
- rmiCall->remoteCall(objectId, sign, retType, paramCls, paramObj, numParam, retObj);
+ rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
}
void TestClass_Stub::setC(string _string) {
int numParam = 1;
- string sign = "voidsetC(string)";
+ int methodId = 2;
string retType = "void";
string paramCls[] = { "string" };
void* paramObj[] = { &_string };
void* retObj = NULL;
- rmiCall->remoteCall(objectId, sign, retType, paramCls, paramObj, numParam, retObj);
+ rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
}
string TestClass_Stub::sumArray(vector<string> newA) {
int numParam = 1;
- string sign = "sumArray(string[])";
+ int methodId = 3;
string retType = "string";
string paramCls[] = { "string[]" };
void* paramObj[] = { &newA };
string retVal = "";
void* retObj = &retVal;
- rmiCall->remoteCall(objectId, sign, retType, paramCls, paramObj, numParam, retObj);
+ rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
return retVal;
}
int TestClass_Stub::setAndGetA(int newA) {
int numParam = 1;
- string sign = "intsetAndGetA(int)";
+ int methodId = 4;
string retType = "int";
string paramCls[] = { "int" };
void* paramObj[] = { &newA };
int retVal = 0;
void* retObj = &retVal;
- rmiCall->remoteCall(objectId, sign, retType, paramCls, paramObj, numParam, retObj);
+ rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
return retVal;
}
int TestClass_Stub::setACAndGetA(string newC, int newA) {
int numParam = 2;
- string sign = "intsetACAndGetA(string,int)";
+ int methodId = 5;
string retType = "int";
string paramCls[] = { "string", "int" };
void* paramObj[] = { &newC, &newA };
int retVal = 0;
void* retObj = &retVal;
- rmiCall->remoteCall(objectId, sign, retType, paramCls, paramObj, numParam, retObj);
+ rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
return retVal;
}
}
int numParam = 1;
- string sign = "voidregisterCallBack(CallBackInterface[])";
+ int methodId = 8;
string retType = "void";
string paramCls[] = { "int" };
int param1 = _cb.size();
void* paramObj[] = { ¶m1 };
void* retObj = NULL;
- rmiCall->remoteCall(objectId, sign, retType, paramCls, paramObj, numParam, retObj);
+ rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
}
int TestClass_Stub::callBack() {
int numParam = 0;
- string sign = "intcallBack()";
+ int methodId = 6;
string retType = "int";
string paramCls[] = { };
void* paramObj[] = { };
int retVal = 0;
void* retObj = &retVal;
- rmiCall->remoteCall(objectId, sign, retType, paramCls, paramObj, numParam, retObj);
+ rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
return retVal;
}
void TestClass_Stub::handleStruct(vector<data> vecData) {
int numParam = 1;
- string sign = "structsize";
+ int methodId = 11;
string retType = "void";
string paramCls[] = { "int" };
int structsize = vecData.size();
void* paramObj[] = { &structsize };
void* retObj = NULL;
- rmiCall->remoteCall(objectId, sign, retType, paramCls, paramObj, numParam, retObj);
+ rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
int numParam2 = 3*vecData.size();
- string sign2 = "handleStruct(StructJ[])";
+ int methodId2 = 10;
string retType2 = "void";
string paramCls2[numParam2];
void* paramObj2[numParam2];
}
void* retObj2 = NULL;
cout << "In handle struct 3!" << endl;
- rmiCall->remoteCall(objectId, sign2, retType2, paramCls2, paramObj2, numParam2, retObj2);
+ rmiCall->remoteCall(objectId, methodId2, retType2, paramCls2, paramObj2, numParam2, retObj2);
}
/**
* setMethodBytes() sets bytes for method
*/
- public void setMethodBytes(byte[] _methodBytes) throws IOException {
+ /*public void setMethodBytes(byte[] _methodBytes) throws IOException {
// Set method bytes
methodBytes = _methodBytes;
- }
+ }*/
/**
case 0: ___printInt(rmiObj); break;
case 1: ___setInt(rmiObj); break;
default:
- throw new Error("Signature not recognized!");
+ throw new Error("Method Id not recognized!");
}
}
case 0: ___printInt(); break;
case 1: ___setInt(); break;
default:
- throw new Error("Signature not recognized!");
+ throw new Error("Method Id not recognized!");
}
}
}
+++ /dev/null
-package iotrmi.Java.sample;
-
-import java.io.IOException;
-import java.util.Set;
-import java.util.Arrays;
-import java.util.Map;
-import java.util.HashMap;
-
-import iotrmi.Java.IoTRMIObject;
-import iotrmi.Java.IoTRMICall;
-
-public class TestClass_CBSkeleton implements TestClassInterface {
-
- /**
- * Class Constants
- */
- private int objectId = 0; // Default value is 0
- private static int objIdCnt = 0; // Counter for callback object Ids
- private final static String[] methodSignatures = {
-
- "voidsetA(int)",
- "voidsetB(float)",
- "voidsetC(string)",
- "sumArray(string[])",
- "intsetAndGetA(int)",
- "intsetACAndGetA(string,int)",
- "intcallBack()",
- "voidregisterCallBack(CallBackInterface)",
- "voidregisterCallBack(CallBackInterface[])",
- "registercallback",
- "handleStruct(StructJ)"
- };
-
- private TestClassInterface tc;
- private int port;
- private CallBackInterface cbstub;
- private IoTRMICall rmiCall;
-
-
- /**
- * Constructors
- */
- public TestClass_CBSkeleton(TestClass _tc, int _objectId) throws
- ClassNotFoundException, InstantiationException,
- IllegalAccessException, IOException {
-
- tc = _tc;
- objectId = _objectId;
- System.out.println("Creating object with object Id: " + objectId);
- }
-
-
- // Callback object multiplexing
- public Object invokeMethod(IoTRMIObject rmiObj) throws IOException {
-
- String methodSign = rmiObj.getSignature();
- Object[] paramObj = null;
- Object retObj = null;
-
- if (methodSign.equals("voidsetA(int)")) {
- paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class },
- new Class<?>[] { null }, new Class<?>[] { null });
- setA((int) paramObj[0]);
- } else if (methodSign.equals("voidsetB(float)")) {
- paramObj = rmiObj.getMethodParams(new Class<?>[] { float.class },
- new Class<?>[] { null }, new Class<?>[] { null });
- setB((float) paramObj[0]);
- } else if (methodSign.equals("voidsetC(string)")) {
- paramObj = rmiObj.getMethodParams(new Class<?>[] { String.class },
- new Class<?>[] { null }, new Class<?>[] { null });
- setC((String) paramObj[0]);
- } else if (methodSign.equals("sumArray(string[])")) {
- paramObj = rmiObj.getMethodParams(new Class<?>[] { String[].class },
- new Class<?>[] { null }, new Class<?>[] { null });
- retObj = sumArray((String[]) paramObj[0]);
- } else if (methodSign.equals("intsetAndGetA(int)")) {
- paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class },
- new Class<?>[] { null }, new Class<?>[] { null });
- retObj = setAndGetA((int) paramObj[0]);
- } else if (methodSign.equals("intsetACAndGetA(string,int)")) {
- paramObj = rmiObj.getMethodParams(new Class<?>[] { String.class, int.class },
- new Class<?>[] { null, null }, new Class<?>[] { null, null });
- retObj = setACAndGetA((String) paramObj[0], (int) paramObj[1]);
- } else if (methodSign.equals("voidregisterCallBack(CallBackInterface)")) {
- paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class, String.class, int.class },
- new Class<?>[] { null, null, null }, new Class<?>[] { null, null, null });
- CallBackInterface cbstub = new CallBack_Stub((int) paramObj[0], (String) paramObj[1], (int) paramObj[2]);
- registerCallback((CallBackInterface) cbstub);
- } else if (methodSign.equals("voidregisterCallBack(CallBackInterface[])")) {
- paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class },
- new Class<?>[] { null }, new Class<?>[] { null });
- int numStubs = (int) paramObj[0];
- CallBackInterface[] stub = new CallBackInterface[numStubs];
- for (int objId = 0; objId < numStubs; objId++) {
- stub[objId] = new CallBack_CBStub(rmiCall, objIdCnt);
- objIdCnt++;
- }
- registerCallback(stub);
- } else if (methodSign.equals("intcallBack()")) {
- retObj = callBack();
- // Special option to register callback
- } else if (methodSign.equals("registercallback")) {
- paramObj = rmiObj.getMethodParams(new Class<?>[] { int.class, String.class, int.class },
- new Class<?>[] { null, null, null }, new Class<?>[] { null, null, null });
- String[] methodSignatures = CallBack_CBStub.getMethodSignatures();
- rmiCall = new IoTRMICall((int) paramObj[0], (String) paramObj[1], (int) paramObj[2], methodSignatures);
- System.out.println("Creating a new IoTRMICall object");
- } else
- throw new Error("Signature not recognized!");
-
- return retObj;
- }
-
-
- // Return method signatures
- public static String[] getMethodSignatures() {
-
- return methodSignatures;
- }
-
-
- public void setA(int _int) {
-
- tc.setA(_int);
- }
-
-
- public void setB(float _float) {
-
- tc.setB(_float);
- }
-
-
- public void setC(String _string) {
-
- tc.setC(_string);
- }
-
-
- public String sumArray(String[] newA) {
-
- return tc.sumArray(newA);
- }
-
-
- public int setAndGetA(int newA) {
-
- return tc.setAndGetA(newA);
- }
-
-
- public int setACAndGetA(String newC, int newA) {
-
- return tc.setACAndGetA(newC, newA);
- }
-
-
- public void registerCallback(CallBackInterface _cb) {
-
- tc.registerCallback(_cb);
- }
-
- public void registerCallback(CallBackInterface[] _cb) {
-
- tc.registerCallback(_cb);
- }
-
- public int callBack() {
-
- return tc.callBack();
- }
-
- public void handleStruct(StructJ[] data) {
-
- tc.handleStruct(data);
- }
-
-
- public static void main(String[] args) throws Exception {
-
- }
-}
+++ /dev/null
-package iotrmi.Java.sample;
-
-import java.io.IOException;
-import iotrmi.Java.IoTRMICall;
-import iotruntime.master.CommunicationHandler;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.ArrayList;
-
-import iotrmi.Java.IoTRMIObject;
-
-public class TestClass_CBStub implements TestClassInterface {
-
- /**
- * Class Properties
- */
- private IoTRMICall rmiCall;
- private String address;
- private int[] ports;
- private List<CallBackInterface> listCBObj;
- private IoTRMIObject rmiObj;
-
- /**
- * Class Constants
- */
- private final static int NUM_CB_OBJ = 1;
- private int objectId = 0; // Default value is 0
- private static int objIdCnt = 0; // Counter for callback object Ids
- private final static String[] methodSignatures = {
-
- "voidsetA(int)",
- "voidsetB(float)",
- "voidsetC(string)",
- "sumArray(string[])",
- "intsetAndGetA(int)",
- "intsetACAndGetA(string,int)",
- "intcallBack()",
- "voidregisterCallBack(CallBackInterface)",
- "voidregisterCallBack(CallBackInterface[])",
- "registercallback",
- "handleStruct(StructJ)"
- };
-
- /**
- * Constructors
- */
- // Assign rmiCall from outside
- public TestClass_CBStub(IoTRMICall _rmiCall, int _objectId, String _address, int[] _ports) throws IOException {
-
- address = _address;
- ports = _ports;
- objectId = _objectId;
- rmiCall = _rmiCall;
- listCBObj = new ArrayList<CallBackInterface>();
- init_CallBack();
- }
-
-
- /**
- * Instantiation of callback objects
- */
- public static int numCallbackObjects() {
-
- return NUM_CB_OBJ; // Generated by the IoTCompiler
- }
-
-
- // Return method signatures
- public static String[] getMethodSignatures() {
-
- return methodSignatures;
- }
-
-
- // Initialize callback
- public void init_CallBack() {
-
- Thread thread = new Thread() {
- public void run() {
- try{
- String[] methodSignatures = CallBack_CBSkeleton.getMethodSignatures();
- rmiObj = new IoTRMIObject(ports[0], methodSignatures);
- Object retObj = null;
- while (true) {
- byte[] method = rmiObj.getMethodBytes();
- int objId = IoTRMIObject.getObjectId(method);
- //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);
- }
- if (retObj != null) {
- rmiObj.sendReturnObj(retObj);
- }
- }
- } catch (Exception ex){
- ex.printStackTrace();
- throw new Error("Error instantiating class CallBack_Skeleton!");
- }
- }
- };
- thread.start();
-
- String sign = "registercallback";
- Class<?> retType = void.class;
- // port, address, rev, and number of objects
- Class<?>[] paramCls = new Class<?>[] { int.class, String.class, int.class };
- Object[] paramObj = new Object[] { ports[0], address, 0 };
- rmiCall.remoteCall(objectId, sign, retType, null, null, paramCls, paramObj);
- }
-
-
- // Single callback handling
- public void registerCallback(CallBackInterface _cb) {
-
- Thread thread = new Thread() {
- public void run() {
- try{
- CallBack_Skeleton cbskel = new CallBack_Skeleton(_cb, ports[0]);
- cbskel.waitRequestInvokeMethod();
- } catch (Exception ex){
- ex.printStackTrace();
- throw new Error("Error instantiating class CallBack_Skeleton!");
- }
- }
- };
- thread.start();
-
- String sign = "voidregisterCallBack(CallBackInterface)";
- Class<?> retType = void.class;
- // port, address, and rev
- Class<?>[] paramCls = new Class<?>[] { int.class, String.class, int.class };
- Object[] paramObj = new Object[] { ports[0], address, 0 };
- rmiCall.remoteCall(objectId, sign, retType, null, null, paramCls, paramObj);
- }
-
-
- public void registerCallback(CallBackInterface[] _cb) {
-
- try {
- //for (int objId = 0; objId < _cb.length; objId++) {
- for (CallBackInterface cb : _cb) {
- CallBack_CBSkeleton skel = new CallBack_CBSkeleton(cb, objIdCnt++);
- listCBObj.add(skel);
- }
- } catch (Exception ex){
- ex.printStackTrace();
- throw new Error("Class not found / instantiation / illegal access / IO error!");
- }
-
- String sign = "voidregisterCallBack(CallBackInterface[])";
- Class<?> retType = void.class;
- // port, address, rev, and number of objects
- Class<?>[] paramCls = new Class<?>[] { int.class };
- Object[] paramObj = new Object[] { _cb.length };
- rmiCall.remoteCall(objectId, sign, retType, null, null, paramCls, paramObj);
- }
-
-
- public void setA(int _int) {
-
- String sign = "voidsetA(int)";
- Class<?> retType = void.class;
- Class<?>[] paramCls = new Class<?>[] { int.class };
- Object[] paramObj = new Object[] { _int };
- rmiCall.remoteCall(objectId, sign, retType, null, null, paramCls, paramObj);
- }
-
-
- public void setB(float _float) {
-
- String sign = "voidsetB(float)";
- Class<?> retType = void.class;
- Class<?>[] paramCls = new Class<?>[] { float.class };
- Object[] paramObj = new Object[] { _float };
- rmiCall.remoteCall(objectId, sign, retType, null, null, paramCls, paramObj);
- }
-
-
- public void setC(String _string) {
-
- String sign = "voidsetC(string)";
- Class<?> retType = void.class;
- Class<?>[] paramCls = new Class<?>[] { String.class };
- Object[] paramObj = new Object[] { _string };
- rmiCall.remoteCall(objectId, sign, retType, null, null, paramCls, paramObj);
- }
-
-
- // Getters
- public String sumArray(String[] newA) {
-
- String sign = "sumArray(string[])";
- Class<?> retType = String.class;
- Class<?>[] paramCls = new Class<?>[] { String[].class };
- Object[] paramObj = new Object[] { newA };
- Object retObj = rmiCall.remoteCall(objectId, sign, retType, null, null, paramCls, paramObj);
- return (String)retObj;
- }
-
-
- public int setAndGetA(int newA) {
- String sign = "intsetAndGetA(int)";
- Class<?> retType = int.class;
- Class<?>[] paramCls = new Class<?>[] { int.class };
- Object[] paramObj = new Object[] { newA };
- Object retObj = rmiCall.remoteCall(objectId, sign, retType, null, null, paramCls, paramObj);
- return (int)retObj;
- }
-
-
- public int setACAndGetA(String newC, int newA) {
-
- String sign = "intsetACAndGetA(string,int)";
- Class<?> retType = int.class;
- Class<?>[] paramCls = new Class<?>[] { String.class, int.class };
- Object[] paramObj = new Object[] { newC, newA };
- Object retObj = rmiCall.remoteCall(objectId, sign, retType, null, null, paramCls, paramObj);
- return (int)retObj;
- }
-
-
- public int callBack() {
-
- String sign = "intcallBack()";
- Class<?> retType = int.class;
- Class<?>[] paramCls = new Class<?>[] { };
- Object[] paramObj = new Object[] { };
- Object retObj = rmiCall.remoteCall(objectId, sign, retType, null, null, paramCls, paramObj);
- return (int)retObj;
-
- }
-
- public void handleStruct(StructJ[] data) {
-
- }
-
-
- public static void main(String[] args) throws Exception {
-
- CommunicationHandler comHan = new CommunicationHandler(true);
- int numOfPorts = TestClass_Stub.numCallbackObjects();
- int[] ports = comHan.getCallbackPorts(numOfPorts);
-
- int port = 5010;
- String address = "localhost";
- int rev = 0;
-
- System.out.println("Allocated ports: " + Arrays.toString(ports));
-
- TestClass_Stub tcstub = new TestClass_Stub(port, address, rev, ports);
- System.out.println("Return value: " + tcstub.setAndGetA(123));
- System.out.println("Return value: " + tcstub.setACAndGetA("string", 123));
- System.out.println("Return value: " + tcstub.sumArray(new String[] { "123", "456", "987" }));
-
- CallBackInterface cb1 = new CallBack(23);
- CallBackInterface cb2 = new CallBack(33);
- CallBackInterface cb3 = new CallBack(43);
- CallBackInterface[] cb = { cb1, cb2, cb3 };
- tcstub.registerCallback(cb);
- System.out.println("Return value from callback: " + tcstub.callBack());
- CallBackInterface cb4 = new CallBack(10);
- CallBackInterface cb5 = new CallBack(11);
- CallBackInterface cb6 = new CallBack(12);
- CallBackInterface[] cbt = { cb4, cb5, cb6 };
- tcstub.registerCallback(cbt);
- System.out.println("Return value from callback: " + tcstub.callBack());
- }
-}
-
-
case 10: ___handleStruct(structsize1); break;
case 11: structsize1 = ___structSize(); break;
default:
- throw new Error("Signature not recognized!");
+ throw new Error("Method Id not recognized!");
}
}
}