#define _TESTCLASS_STUB_HPP__
#include <iostream>
+#include <set>
#include <thread>
#include "../IoTRMICall.hpp"
#include "../IoTRMIObject.hpp"
void registerCallback(CallBackInterface* _cb);
void registerCallback(vector<CallBackInterface*>_cb);
int callBack();
- void handleStruct(vector<data> vecData);
+ vector<data> handleStruct(vector<data> vecData);
+ vector<EnumC> handleEnum(vector<EnumC> vecEn);
void ____init_CallBack(); // thread
void ____registerCallBack(); // tell the other side that we are ready
- const static int size = 12;
- const static string methodSignatures[size];
+ //exception_ptr teptr = nullptr;
private:
int intA;
string stringC;
//CallBackInterface cb;
IoTRMICall *rmiCall;
- IoTRMIObject *rmiObj;
string address;
vector<int> ports;
- vector<CallBackInterface*> vecCBObj;
+ const static int objectId = 0; // Default value is 0
- int objectId = 0; // Default value is 0
+ // Specific for callbacks
+ IoTRMIObject *rmiObj;
+ vector<CallBackInterface*> vecCBObj;
static int objIdCnt;
+ // Callback permission
+ const static set<int> set0Allowed;
};
int TestClass_Stub::objIdCnt = 0;
-const string TestClass_Stub::methodSignatures[TestClass_Stub::size] = {
- "voidsetA(int)", // 0
- "voidsetB(float)", // 1
- "voidsetC(string)", // 2
- "sumArray(string[])", // 3
- //"sumArray(int[])",
- "intsetAndGetA(int)", // 4
- "intsetACAndGetA(string,int)", // 5
- "intcallBack()", // 6
- "voidregisterCallBack(CallBackInterface)", // 7
- "voidregisterCallBack(CallBackInterface[])", // 8
- "registercallback", // 9
- "handleStruct(StructJ[])", // 10
- "structsize" // 11
-};
+const set<int> TestClass_Stub::set0Allowed { 0, 1 };
TestClass_Stub::TestClass_Stub() {
rmiCall = new IoTRMICall(_port, _address, _rev, _bResult);
ports = _ports;
// Start thread
+ /*if (teptr) {
+ try {
+ thread th1 (&TestClass_Stub::____init_CallBack, this);
+ th1.detach();
+ } catch(const exception&) {
+ cout << "Got here!" << endl;
+ throw exception();
+ }
+ }*/
thread th1 (&TestClass_Stub::____init_CallBack, this);
th1.detach();
//th1.join();
delete rmiObj;
rmiObj = NULL;
}
+ // Special for callbacks!!!
for(CallBackInterface* cb : vecCBObj) {
delete cb;
cb = NULL;
rmiObj = new IoTRMIObject(ports[0], &bResult);
while (true) {
char* method = rmiObj->getMethodBytes();
+ int methodId = IoTRMIObject::getMethodId(method);
+ // Permission check
+ // Complain if the method is not allowed
+ if (set0Allowed.find(methodId) == set0Allowed.end()) {
+ cerr << "TestClass_Skeleton: This object is not allowed to access method " << methodId << endl;
+ exit(-1);
+ //throw exception();
+ //teptr = current_exception();
+ }
int objId = IoTRMIObject::getObjectId(method);
if (objId < vecCBObj.size()) { // Check if still within range
CallBack_CBSkeleton* skel =
}
-void TestClass_Stub::handleStruct(vector<data> vecData) {
+vector<data> TestClass_Stub::handleStruct(vector<data> vecData) {
int numParam = 1;
int methodId = 11;
int numParam2 = 3*vecData.size();
int methodId2 = 10;
- string retType2 = "void";
+ string retType2 = "int";
string paramCls2[numParam2];
void* paramObj2[numParam2];
int pos = 0;
paramCls2[pos] = "int";
paramObj2[pos] = &vecData[i].year; pos++;
}
- void* retObj2 = NULL;
- cout << "In handle struct 3!" << endl;
+ // RETURN STRUCT OBJECT
+ // Get length of struct array
+ int structsize1 = 0;
+ void* retObj2 = { &structsize1 };
+ // IF we don't have returned struct objects, then it's just "void* retObj2 = NULL;"
rmiCall->remoteCall(objectId, methodId2, retType2, paramCls2, paramObj2, numParam2, retObj2);
+ cout << "Struct length: " << structsize1 << endl;
+
+ // Get the returned objects
+ string retCls[3*structsize1];
+ void* retObj3[3*structsize1];
+ int numRet = 3*structsize1;
+ // define array of everything
+ string param1[structsize1];
+ float param2[structsize1];
+ int param3[structsize1];
+ pos = 0;
+ for(int i=0; i < structsize1; i++) {
+ retCls[pos] = "string";
+ retObj3[pos++] = ¶m1[i];
+ retCls[pos] = "float";
+ retObj3[pos++] = ¶m2[i];
+ retCls[pos] = "int";
+ retObj3[pos++] = ¶m3[i];
+ }
+ rmiCall->getStructObjects(retCls, numRet, retObj3);
+ vector<data> dat(structsize1);
+ pos = 0;
+ for (int i=0; i < structsize1; i++) {
+ dat[i].name = param1[i];
+ dat[i].value = param2[i];
+ dat[i].year = param3[i];
+ }
+
+ return dat;
}
+vector<EnumC> TestClass_Stub::handleEnum(vector<EnumC> vecEn) {
+
+ int numParam = 1;
+ int numEl = vecEn.size();
+ int methodId = 12;
+ string retType = "int[]";
+ string paramCls[] = { "int[]" };
+ // Need to define this container for integer version of enum
+ vector<int> paramInt(numEl);
+ for(int i = 0; i < numEl; i++) {
+ paramInt[i] = (int) vecEn[i]; // cast enum to integer
+ }
+ void* paramObj[] = { ¶mInt };
+ // if no return value just
+ // void* retObj2 = NULL;
+ // This is with return value:
+ vector<int> retEnumInt;
+ void* retObj = &retEnumInt;
+ rmiCall->remoteCall(objectId, methodId, retType, paramCls, paramObj, numParam, retObj);
+ int enumsize1 = retEnumInt.size();
+ vector<EnumC> retVal(enumsize1);
+ for (int i=0; i < enumsize1; i++) {
+ retVal[i] = (EnumC) retEnumInt[i];
+ }
+ return retVal;
+}
+
+
+
#endif