X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=iotjava%2Fiotrmi%2FC%2B%2B%2Fsample%2FTestClass.hpp;h=fe13e6e11c305e6ce8242264ec77c82e19cc021a;hb=e9a65a3fa878d7451ceb4f5a2cb1bc9ee846e035;hp=891e44e75d987b9f05883401953d74fe17a7e547;hpb=87ac04592d1d46c7474cad5b046fdf1ecef3dcd1;p=iot2.git diff --git a/iotjava/iotrmi/C++/sample/TestClass.hpp b/iotjava/iotrmi/C++/sample/TestClass.hpp index 891e44e..fe13e6e 100644 --- a/iotjava/iotrmi/C++/sample/TestClass.hpp +++ b/iotjava/iotrmi/C++/sample/TestClass.hpp @@ -1,5 +1,11 @@ +#ifndef _TESTCLASS_HPP__ +#define _TESTCLASS_HPP__ + #include +#include +#include #include "TestClassInterface.hpp" +#include "StructC.hpp" using namespace std; @@ -12,18 +18,25 @@ class TestClass : public TestClassInterface { void setA(int _int); void setB(float _float); void setC(string _string); - //string sumArray(vector newA); - int64_t sumArray(vector newA); + string sumArray(vector newA); + //int64_t sumArray(vector newA); int setAndGetA(int newA); int setACAndGetA(string newC, int newA); - //void registerCallback(CallBackInterface _cb); - //int callBack(); + void registerCallback(CallBackInterface* _cb); + void registerCallback(vector _cb); + int callBack(); + vector handleStruct(vector vecData); + vector handleEnum(vector vecEn); + + void thread1(); + void thread2(); private: - int intA; - float floatB; - string stringC; - //CallBackInterface cb; + int intA; + float floatB; + string stringC; + CallBackInterface *cb; + vector cbvec; }; @@ -33,7 +46,8 @@ TestClass::TestClass() { intA = 1; floatB = 2; stringC = "345"; - //cb = NULL; + cb = NULL; + // cbvec doesn't need to be initialized again } @@ -42,7 +56,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 } @@ -64,7 +79,7 @@ void TestClass::setC(string _string) { } -/*string TestClass::sumArray(vector newA) { +string TestClass::sumArray(vector newA) { string sum = ""; int len = newA.size(); @@ -72,10 +87,10 @@ void TestClass::setC(string _string) { sum = sum + newA[c]; } return sum; -}*/ +} -int64_t TestClass::sumArray(vector newA) { +/*int64_t TestClass::sumArray(vector newA) { int64_t sum = 0; int len = newA.size(); @@ -83,7 +98,7 @@ int64_t TestClass::sumArray(vector newA) { sum = sum + newA[c]; } return sum; -} +}*/ int TestClass::setAndGetA(int newA) { @@ -101,14 +116,87 @@ int TestClass::setACAndGetA(string newC, int newA) { } -/*void TestClass::registerCallback(CallBackInterface _cb) { +void TestClass::registerCallback(CallBackInterface* _cb) { cb = _cb; } +void TestClass::registerCallback(vector _cb) { + + for (CallBackInterface* cb : _cb) { + cbvec.push_back(cb); + cout << "Registering callback object!" << endl; + } +} + + +vector TestClass::handleStruct(vector vecData) { + + for (data dat : vecData) { + + cout << "Name: " << dat.name << endl; + cout << "Value: " << dat.value << endl; + cout << "Year: " << dat.year << endl; + } + data newData; + newData.name = "Anonymous"; + newData.value = 1.33; + newData.year = 2016; + vecData.push_back(newData); + + return vecData; +} + + +vector TestClass::handleEnum(vector vecEn) { + + for (EnumC en : vecEn) { + cout << "Enum: " << en << endl; + } + + return vecEn; +} + + +//int TestClass::callBack() { +// return cb.printInt(); +//} + +void TestClass::thread1() { + + CallBackInterface* cb = cbvec[0]; + for(int i = 0; i < 10; i++) { + cb->printInt(); + this_thread::sleep_for(chrono::seconds(1)); + } +} + +void TestClass::thread2() { + + CallBackInterface* cb = cbvec[1]; + for(int i = 0; i < 10; i++) { + cb->printInt(); + this_thread::sleep_for(chrono::seconds(1)); + } +} + int TestClass::callBack() { - return cb.printInt(); -}*/ + int sum = 0; + for (CallBackInterface* cb : cbvec) { + sum = sum + cb->printInt(); + } + + return sum; +/* thread th1 (&TestClass::thread1, this); + thread th2 (&TestClass::thread2, this); + + th1.join(); + th2.join(); + + return 1;*/ +} + +#endif