#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
+ //exception_ptr teptr = nullptr;
+
private:
int intA;
float floatB;
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 set<int> TestClass_Stub::set0Allowed { 0, 1 };
+
+
TestClass_Stub::TestClass_Stub() {
address = "";
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;
+ // 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;
}