Cleaning up drivers/Cpp, Cpp/Lifxtest, virtuals, and iotrmi/C++ (revisiting the C...
[iot2.git] / iotjava / iotruntime / cpp / iotslave / ObjectFactory.hpp
1 #include "LifxLightBulb.cpp"
2 #include "LightBulb_Skeleton.cpp"
3 #include "LightBulbTest_Stub.cpp"
4 #include "IoTSet.hpp"
5
6
7 //typedef void* create_t(string className, void** params);
8 //typedef void destroy_t(void*);
9
10
11 // Transferring members of IoTSet<void*> into IoTSet<IoTDeviceAddress*>
12 IoTSet<IoTDeviceAddress*>* createDeviceAddressSet(unordered_set<void*>* iotSet) {
13
14         unordered_set<IoTDeviceAddress*>* devSet = new unordered_set<IoTDeviceAddress*>();
15         //for (auto itr = iotSet->begin(); itr != iotSet->end(); ++itr) {
16         for (unordered_set<void*>::const_iterator itr = iotSet->begin(); itr != iotSet->end(); ++itr) {
17                 IoTDeviceAddress* deviceAddress = (IoTDeviceAddress*) *itr;
18                 devSet->insert(deviceAddress);
19         }
20         IoTSet<IoTDeviceAddress*>* iotDevSet = new IoTSet<IoTDeviceAddress*>(devSet);
21
22         delete iotSet;
23         return iotDevSet;
24 }
25
26
27 /*
28 // External creator/destroyer
29 extern "C" void* create(string className, void** params) {
30
31         if (className.compare("LifxLightBulb") == 0) {
32                 // Arguments: IoTSet<IoTDeviceAddress*>* _devAddress, string macAddress
33                 // We pass in a pointer to string and then we pass in just the value for the class
34                 return new LifxLightBulb((IoTSet<IoTDeviceAddress*>*) params[0], *((string*) params[1]));
35         } else if (className.compare("LightBulb_Skeleton") == 0) {
36                 // Arguments: LightBulb *_mainObj, string _callbackAddress, int _port
37                 // We pass in pointers to string and integer, and read the values again
38                 return new LightBulb_Skeleton((LightBulb*) params[0], *((string*) params[1]), *((int*) params[2]));
39         } else if (className.compare("LightBulbTest_Stub") == 0) {
40                 // int _port, const char* _skeletonAddress, string _callbackAddress, int _rev, bool* _bResult, vector<int> _ports
41                 // We pass in pointers to string and integer, and read the values again
42                 return new LightBulbTest_Stub(*((int*) params[0]), (const char*) params[1], *((string*) params[2]), *((int*) params[3]), 
43                                 (bool*) params[4], *((vector<int>*) params[5]));
44         } else {        // Class is not recognized
45                 cerr << "ObjectFactory: Class is not recognized: " << className << endl;
46                 exit(1);
47         }
48 }
49
50 extern "C" void destroy(string className, void* ob) {
51
52         if (ob != NULL) {       // Check that this pointer is not NULL
53
54                 if (className.compare("LifxLightBulb") == 0) {
55                         LifxLightBulb* obj = (LifxLightBulb*) ob;
56                         delete obj;
57                 } else if (className.compare("LightBulb_Skeleton") == 0) {
58                         LightBulb_Skeleton* obj = (LightBulb_Skeleton*) ob;
59                         delete obj;
60                 } else if (className.compare("LightBulbTest_Stub") == 0) {
61                         LightBulbTest_Stub* obj = (LightBulbTest_Stub*) ob;
62                         delete obj;
63                 } else {        // Class is not recognized
64                         cerr << "ObjectFactory: Class is not recognized: " << className << endl;
65                         exit(1);
66                 }
67         }
68 }
69 */
70