Adding permission check and error throw in C++
[iot2.git] / iotjava / iotrmi / C++ / sample / TestClass_Skeleton.hpp
index bfb5ac088d1d2536f56d10ab3365188698ed0679..9ea8bab47648fa0dd3667c3a7b3e415f2c51be18 100644 (file)
@@ -2,6 +2,8 @@
 #define _TESTCLASS_SKELETON_HPP__
 
 #include <iostream>
+#include <exception>
+#include <set>
 #include "../IoTRMIObject.hpp"
 #include "../IoTRMICall.hpp"
 #include "CallBack_CBStub.hpp"
@@ -49,6 +51,11 @@ class TestClass_Skeleton : public TestClassInterface {
        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;
@@ -56,6 +63,11 @@ class TestClass_Skeleton : public TestClassInterface {
 };
 
 
+// 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;
 
 
@@ -393,7 +405,24 @@ void TestClass_Skeleton::___waitRequestInvokeMethod() {
        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;