Adding object ID and tons of minor adjustments for callback support
[iot2.git] / iotjava / iotrmi / C++ / sample / TestClass.hpp
index 272f1c8c319a6c425e52c9823419aa858923e67f..efa4f2ae6b8561c61ef90175786be7965b75683f 100644 (file)
@@ -16,14 +16,16 @@ class TestClass : public TestClassInterface {
                //int64_t                               sumArray(vector<int> newA);
                int                                     setAndGetA(int newA);
                int                                     setACAndGetA(string newC, int newA);
-               //void                          registerCallback(CallBackInterface _cb);
-               //int                           callBack();
+               void                            registerCallback(CallBackInterface* _cb);
+               void                            registerCallback(vector<CallBackInterface*> _cb);
+               int                                     callBack();
 
        private:                
-               int                                     intA;
-               float                           floatB;
-               string                          stringC;
-               //CallBackInterface cb;
+               int                                                     intA;
+               float                                           floatB;
+               string                                          stringC;
+               CallBackInterface                       *cb;
+               vector<CallBackInterface*>      cbvec;
 
 };
 
@@ -33,7 +35,8 @@ TestClass::TestClass() {
        intA = 1;
        floatB = 2;
        stringC = "345";
-       //cb = NULL;
+       cb = NULL;
+       // cbvec doesn't need to be initialized again
 }
 
 
@@ -42,7 +45,8 @@ TestClass::TestClass(int _int, float _float, string _string) {
        intA = _int;
        floatB = _float;
        stringC = _string;
-       //cb = NULL;
+       cb = NULL;
+       // cbvec doesn't need to be initialized again
 }
 
 
@@ -101,14 +105,31 @@ int TestClass::setACAndGetA(string newC, int newA) {
 }
 
 
-/*void TestClass::registerCallback(CallBackInterface _cb) {
+void TestClass::registerCallback(CallBackInterface* _cb) {
 
        cb = _cb;
 }
 
 
+void TestClass::registerCallback(vector<CallBackInterface*> _cb) {
+
+       for (CallBackInterface* cb : _cb) {
+               cbvec.push_back(cb);
+               cout << "Registering callback object!" << endl;
+       }
+}
+
+
+//int TestClass::callBack() {
+//     return cb.printInt();
+//}
+
+
 int TestClass::callBack() {
 
-       return cb.printInt();
-}*/
+       int sum = 0;
+       for (CallBackInterface* cb : cbvec) {
+               sum = sum + cb->printInt();
+       }
+}