int getObjectId();
static int getObjectId(char* methodBytes);
int getMethodId();
+ static int getMethodId(char* methodBytes);
void** getMethodParams(string paramCls[], int numParam, void* paramObj[]);
private:
}
+// Get methodId from bytes (static version)
+int IoTRMIObject::getMethodId(char* methodBytes) {
+
+ // Get method Id
+ char methodIdBytes[IoTRMIUtil::METHOD_ID_LEN];
+ memcpy(methodIdBytes, methodBytes + IoTRMIUtil::OBJECT_ID_LEN, IoTRMIUtil::METHOD_ID_LEN);
+ // Get method signature
+ int methodId = 0;
+ IoTRMIUtil::byteArrayToInt(&methodId, methodIdBytes);
+
+ return methodId;
+}
+
+
// Get method parameters and return an array of parameter objects
//
// For primitive objects:
private:
CallBackInterface *cb;
- int objectId = 0;
+ int objectId = 0;
};
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);
+ TestClassInterface *tc;
+ TestClass_Skeleton *tcSkel;
+ try {
+ int port = 5010;
+ tc = new TestClass(3, 5.0, "7911");
+ tcSkel = new TestClass_Skeleton(tc, port);
+ } catch(const exception&) {
+ return EXIT_FAILURE;
+ }
//tcSkel->waitRequestInvokeMethod();
delete tc;
#define _TESTCLASS_SKELETON_HPP__
#include <iostream>
+#include <exception>
+#include <set>
#include "../IoTRMIObject.hpp"
#include "../IoTRMICall.hpp"
#include "CallBack_CBStub.hpp"
private:
TestClassInterface *tc;
IoTRMIObject *rmiObj;
+ // Permission setup
+ const static int object0Id;
+ //const static int object0Permission[];
+ const static set<int> set0Allowed;
+
IoTRMICall *rmiCall;
static int objIdCnt;
vector<CallBackInterface*> vecCBObj;
};
+// Permission setup
+const int TestClass_Skeleton::object0Id = 0;
+//const int TestClass_Skeleton::object0Permission[] = {0, 1, 2, 3, 4, 5};
+const set<int> TestClass_Skeleton::set0Allowed {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
+
int TestClass_Skeleton::objIdCnt = 0;
while (true) {
rmiObj->getMethodBytes();
+ int _objectId = rmiObj->getObjectId();
int methodId = rmiObj->getMethodId();
+ if (_objectId == object0Id) {
+ // Multiplex based on object Id
+ // 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();
+ }
+ // If we have more than 1 object Id...
+ //else if (_objectId == object1Id) {
+
+ } else {
+ cerr << "TestClass_Skeleton: Unrecognizable object Id: " << _objectId << endl;
+ throw exception();
+ //exit(1);
+ }
switch (methodId) {
case 0: ___setA(); break;
using namespace std;
+static exception_ptr teptr = nullptr;
+
int main(int argc, char *argv[])
{
cout << "Return value: " << tcStub->sumArray(input) << endl;
- /*CallBackInterface *cb1 = new CallBack(23);
+ CallBackInterface *cb1 = new CallBack(23);
CallBackInterface *cb2 = new CallBack(33);
CallBackInterface *cb3 = new CallBack(43);
vector<CallBackInterface*> cb;
cbsec.push_back(cb6);
tcStub->registerCallback(cbsec);
cout << "Return value from callback: " << tcStub->callBack() << endl;
-*/
+
vector<data> dataset;
data testdata;
#define _TESTCLASS_STUB_HPP__
#include <iostream>
+#include <set>
#include <thread>
#include "../IoTRMICall.hpp"
#include "../IoTRMIObject.hpp"
void ____init_CallBack(); // thread
void ____registerCallBack(); // tell the other side that we are ready
+ //exception_ptr teptr = nullptr;
+
private:
int intA;
float floatB;
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
-// thread th1 (&TestClass_Stub::____init_CallBack, this);
-// th1.detach();
+ /*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();
-// ____registerCallBack();
+ ____registerCallBack();
}
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 =