1 #ifndef _IOTSLAVE_HPP__
2 #define _IOTSLAVE_HPP__
8 #include <dlfcn.h> // For dlopen, dlsym, etc.
10 #include "ObjectFactory.hpp"
13 #include "IRelation.hpp"
14 #include "IoTRelation.hpp"
17 /** Class IoTSlave is a communication class
18 * that interacts with IoTSlave.java to set up C++
19 * objects in Sentinel.
21 * @author Rahmadi Trimananda <rtrimana @ uci.edu>
25 // Enumeration of master-slave communication codes
32 CREATE_NEW_IOTRELATION,
35 GET_ADD_IOTSET_OBJECT,
36 GET_DEVICE_IOTSET_OBJECT,
38 GET_IOTRELATION_FIRST_OBJECT,
39 GET_IOTRELATION_SECOND_OBJECT,
40 GET_ZB_DEV_IOTSET_OBJECT,
42 REINITIALIZE_IOTSET_FIELD,
43 REINITIALIZE_IOTRELATION_FIELD,
52 const static int RCVBUFSIZE = 1024; // Size of receive buffer
53 const static string FILEPATH; // File path
54 const static string FILEEXT; // File extension
55 const static string SOEXT; // Shared object (.so) extension
56 const static string STRINGCLASS; // String class
57 const static string INTCLASS; // Int class
58 const static string CREATEFUNCTION; // The create function in class
59 const static string DESTROYFUNCTION; // The destroy function in class
65 string objectClassName;
66 string objectInterfaceName;
67 string objectSkelClass; // Need to send from Java IoTSlave: sMessage.getObjectInterfaceName() + SKEL_CLASS_SUFFIX
71 void* object; // Handler of object
73 ofstream log; // Log the messages
74 vector<string> args; // Hold the arguments for constructor (in string format)
75 vector<string> argClasses; // Hold the argument classes
77 create_t* create_object;
78 destroy_t* destroy_object;
82 IoTSlave(string _serverAddress, int _serverPort, string _objectName);
85 string getServerAddress();
87 string getObjectName();
88 void sendInteger(int intSend);
90 void sendString(string strSend);
94 bool recvEndTransfer();
96 void createObject(); // Create driver object
97 void createMainObject(); // Create main object
98 void createNewIoTSet();
99 void getDeviceIoTSetObject();
102 // Private helper functions
103 int* byteToInt(int* result, char* bytes);
104 char* intToByteArray(int i, char* bytes);
105 char* recvIter(char* recvBuffer, int recvLen);
106 void* getObjectConverted(void* retObj, string object, string objectClass);
107 void openFile(string fileName);
108 void writeToFile(string logMsg);
110 void instantiateObject(string objectClassName);
113 // Constant initialization
114 const string IoTSlave::FILEPATH = "./";
115 const string IoTSlave::FILEEXT = "_cpp.log";
116 const string IoTSlave::SOEXT = ".so";
117 const string IoTSlave::STRINGCLASS = "string";
118 const string IoTSlave::INTCLASS = "int";
119 const string IoTSlave::CREATEFUNCTION = "create";
120 const string IoTSlave::DESTROYFUNCTION = "destroy";