Adding stub and skeleton for Lifxtest and LifxLightBulb; Creating build flow for...
[iot2.git] / iotjava / iotruntime / cpp / iotslave / ObjectFactory.hpp
1 #include "LifxLightBulb.cpp"
2 #include "LightBulb_Skeleton.cpp"
3 #include "LightBulbTest_Stub.cpp"
4
5
6 typedef void* create_t(string className, void** params);
7 typedef void destroy_t(void*);
8
9 // External creator/destroyer
10 extern "C" void* create(string className, void** params) {
11
12         if (className.compare("LifxLightBulb") == 0) {
13                 // Arguments: IoTSet<IoTDeviceAddress*>* _devAddress, string macAddress
14                 // We pass in a pointer to string and then we pass in just the value for the class
15                 return new LifxLightBulb((IoTSet<IoTDeviceAddress*>*) params[0], *((string*) params[1]));
16         } else if (className.compare("LightBulb_Skeleton") == 0) {
17                 // Arguments: LightBulb *_mainObj, string _callbackAddress, int _port
18                 // We pass in pointers to string and integer, and read the values again
19                 return new LightBulb_Skeleton((LightBulb*) params[0], *((string*) params[1]), *((int*) params[2]));
20         } else if (className.compare("LightBulbTest_Stub") == 0) {
21                 // int _port, const char* _skeletonAddress, string _callbackAddress, int _rev, bool* _bResult, vector<int> _ports
22                 // We pass in pointers to string and integer, and read the values again
23                 return new LightBulbTest_Stub(*((int*) params[0]), (const char*) params[1], *((string*) params[2]), *((int*) params[3]), 
24                                 (bool*) params[4], *((vector<int>*) params[5]));
25         } else {        // Class is not recognized
26                 cerr << "ObjectFactory: Class is not recognized: " << className << endl;
27                 exit(1);
28         }
29 }
30
31 extern "C" void destroy(string className, void* ob) {
32
33         if (ob != NULL) {       // Check that this pointer is not NULL
34
35                 if (className.compare("LifxLightBulb") == 0) {
36                         LifxLightBulb* obj = (LifxLightBulb*) ob;
37                         delete obj;
38                 } else if (className.compare("LightBulb_Skeleton") == 0) {
39                         LightBulb_Skeleton* obj = (LightBulb_Skeleton*) ob;
40                         delete obj;
41                 } else if (className.compare("LightBulbTest_Stub") == 0) {
42                         LightBulbTest_Stub* obj = (LightBulbTest_Stub*) ob;
43                         delete obj;
44                 } else {        // Class is not recognized
45                         cerr << "ObjectFactory: Class is not recognized: " << className << endl;
46                         exit(1);
47                 }
48         }
49 }
50
51 /*typedef LifxLightBulb* create_t(IoTSet<IoTDeviceAddress*>* _devAddress, string macAddress);
52 typedef void destroy_t(LifxLightBulb*);
53
54 // External creator/destroyer
55 extern "C" LifxLightBulb* create(IoTSet<IoTDeviceAddress*>* _devAddress, string macAddress) {
56         return new LifxLightBulb(_devAddress, macAddress);
57 }
58
59 extern "C" void destroy(LifxLightBulb* t) {
60         delete t;
61 }*/
62
63 //typedef LightBulb_Skeleton* create_t(LightBulb *_mainObj, string _callbackAddress, int _port);
64 //typedef void destroy_t(LightBulb_Skeleton*);
65
66 /*extern "C" LightBulb_Skeleton* create(LightBulb *_mainObj, string _callbackAddress, int _port) {
67         return new LightBulb_Skeleton(_mainObj, _callbackAddress, _port);
68 }
69
70 extern "C" void destroy(LightBulb_Skeleton* t) {
71         delete t;
72 }*/
73
74 //typedef LightBulbTest_Stub* create_t(int _port, const char* _skeletonAddress, string _callbackAddress, int _rev, bool* _bResult, vector<int> _ports);
75 //typedef void destroy_t(LightBulbTest_Stub*);
76
77 /*extern "C" LightBulbTest_Stub* create(int _port, const char* _skeletonAddress, string _callbackAddress, int _rev, bool* _bResult, vector<int> _ports) {
78         return new LightBulbTest_Stub(_port, _skeletonAddress, _callbackAddress, _rev, _bResult, _ports);
79 }
80
81 extern "C" void destroy(LightBulbTest_Stub* t) {
82         delete t;
83 }*/
84
85