iotivity 0.9.0
[platform/upstream/iotivity.git] / service / soft-sensor-manager / SSMCore / src / Common / PlatformLayer.h
1 #ifndef _PlatformLayer_H_
2 #define _PlatformLayer_H_
3
4 #include <sstream>
5 #include <algorithm>
6 #include <iterator>
7 #include <assert.h>
8 #include <string>
9 #include <exception>
10 #include <set>
11 #include <stdint.h>
12 #include <string.h>
13 #include <list>
14 #include <vector>
15 #include <map>
16 #include <fstream>
17
18 #if defined(WIN32)
19
20 #include <Windows.h>
21 #include <Shlwapi.h>
22 #pragma comment(lib, "Shlwapi.lib")
23 #pragma comment(lib, "../Outputs/sqlite3.lib")
24
25 #elif defined(LINUX)
26
27 #include <stdio.h>
28 #include <errno.h>
29 #include <sys/time.h>
30 #include <deque>
31 #include <dlfcn.h>
32 #include <semaphore.h>
33
34 #if defined(ANDROID)
35
36 #include <android/log.h>
37
38 #elif defined(TIZEN)
39
40 #endif
41
42 #endif
43
44
45 #define LOCATION_SSM_DB ":memory:"
46 #define RAPIDXML_STATIC_POOL_SIZE 4*1024
47 #define DEFAULT_PATH_SOFT_SENSORS "SoftSensorDescription.xml"
48 #define LOCATION_SSM_DB_DUMP ""
49 //#define LOCATION_SSM_DB_DUMP "myBackup.db"
50
51
52 #if defined(WIN32)
53
54 #define PRINT_LOG(strError) printf("[SSM] %s:%d %s\n", __FUNCTION__, __LINE__, strError)
55 #define REPORT_MESSAGE(tag, msg) printf("[%s] %s\n", tag, msg)
56
57 #elif defined(LINUX)
58
59 #if defined(ANDROID)
60
61 void ReportMessage(const char *tag, const char *msg);
62 #define REPORT_MESSAGE(tag, msg) ReportMessage(tag, msg)
63 #define PRINT_LOG(strError) __android_log_print(ANDROID_LOG_ERROR, "[SSM]", "%s:%d %s", __PRETTY_FUNCTION__, __LINE__, strError)
64
65 #elif defined(TIZEN)
66
67 #define REPORT_MESSAGE(tag, msg) printf("[%s] %s\n", tag, msg)
68 #define PRINT_LOG(strError) printf("[SSM] %s:%d %s\n", __FUNCTION__, __LINE__, strError)
69
70 #else //Default linux
71
72 #define REPORT_MESSAGE(tag, msg) printf("[%s] %s\n", tag, msg)
73 #define PRINT_LOG(strError) printf("[SSM] %s:%d %s\n", __FUNCTION__, __LINE__, strError)
74
75 #endif
76
77 #endif
78
79
80
81 #define SSM_VOID_ASSERT(Exp, STRErrorMsg) \
82     { \
83     if(!(Exp)) \
84         { \
85         PRINT_LOG(STRErrorMsg); \
86         assert(0); \
87         return; \
88         } \
89     }
90
91 #define SSM_RESULT_ASSERT(Exp, STRErrorMsg, Result) \
92     { \
93     if(!(Exp)) \
94         { \
95         PRINT_LOG(STRErrorMsg); \
96         assert(0); \
97         return Result; \
98         } \
99     }
100
101 #define SSM_CLEANUP_ASSERT(Exp) \
102     { \
103     if((res = (Exp)) != SSM_S_OK) \
104         { \
105         PRINT_LOG(GetSSMError(res)); \
106         assert(0); \
107         goto CLEANUP; \
108         } \
109     }
110
111 #define SSM_CLEANUP_COND_ASSERT(Exp, Cond, STRErrorMsg) \
112     { \
113     if(Exp != Cond) \
114         { \
115         PRINT_LOG(STRErrorMsg); \
116         assert(0); \
117         goto CLEANUP; \
118         } \
119     }
120
121 #define SSM_CLEANUP_NULL_ASSERT(Val) \
122     { \
123     if(!(Val)) \
124         { \
125         PRINT_LOG("NULL value"); \
126         assert(Val); \
127         goto CLEANUP; \
128         } \
129     }
130
131 #define CLEAN_STACKVARIABLE(val) memset(&val, 0, sizeof(val))
132 #define SAFE_RELEASE(p) {if(p != NULL){p->release();p = NULL;}else{;/*NULL*/}}
133 #define SAFE_DELETE(p) {if(p != NULL){delete p;p = NULL;}else{;/*NULL*/}}
134 #define SAFE_ARRAY_DELETE(p) {if(p != NULL){delete [] p;p = NULL;}else{;/*NULL*/}}
135
136 #include "ObjectManager.h"
137 #include "ThreadManager.h"
138 #include "SSMInterface/SSMModelDefinition.h"
139
140 typedef std::vector<std::string> StringVec;
141 typedef std::vector<int> IntVec;
142
143 /**
144 * @fn createInstance
145 * @brief Create instance using given OID (Object ID).
146 *         After using the IBase object, you must call Release method.
147 *
148 * @param [in] const OID& objectID - objectID
149 * @param [out] IBase** ppObject - reference pointer to get instance pointer
150 * @return SSMRESULT
151 * @warning
152 * @exception
153 * @see
154 */
155 INTERFACE_DECLSPEC SSMRESULT CreateInstance(IN const OID &objectID, OUT IBase **ppObject);
156
157 /**
158 * @fn createGlobalInstance
159 * @brief Create global instance using given OID (Object ID).
160 *        The instance is managed by global instance map.
161 *         After using the IBase object, you must call Release method.
162 *
163 * @param [in] const OID& objectID - objectID
164 * @param [out] IBase** ppObject - reference pointer to get instance pointer
165 * @return SSMRESULT
166 * @warning
167 * @exception
168 * @see
169 */
170 INTERFACE_DECLSPEC SSMRESULT CreateGlobalInstance(IN const OID &objectID, OUT IBase **ppObject);
171
172 INTERFACE_DECLSPEC SSMRESULT CreateGlobalInstanceRepo();
173
174 INTERFACE_DECLSPEC SSMRESULT DestroyGlobalInstanceRepo();
175
176 #endif