Imported Upstream version 0.9.1
[platform/upstream/iotivity.git] / service / soft-sensor-manager / SSMCore / src / Common / PlatformLayer.h
1 /******************************************************************
2 *
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
4 *
5 *
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 *      http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 ******************************************************************/
20 #ifndef _PlatformLayer_H_
21 #define _PlatformLayer_H_
22
23 #include <sstream>
24 #include <algorithm>
25 #include <iterator>
26 #include <assert.h>
27 #include <string>
28 #include <exception>
29 #include <set>
30 #include <stdint.h>
31 #include <string.h>
32 #include <list>
33 #include <vector>
34 #include <map>
35 #include <fstream>
36
37 #if defined(WIN32)
38
39 #include <Windows.h>
40 #include <Shlwapi.h>
41 #pragma comment(lib, "Shlwapi.lib")
42 #pragma comment(lib, "../Outputs/sqlite3.lib")
43
44 #elif defined(LINUX)
45
46 #include <stdio.h>
47 #include <errno.h>
48 #include <sys/time.h>
49 #include <deque>
50 #include <dlfcn.h>
51 #include <semaphore.h>
52
53 #if defined(ANDROID)
54
55 #include <android/log.h>
56
57 #elif defined(TIZEN)
58
59 #include <dlog.h>
60
61 #endif
62
63 #endif
64
65
66 #define LOCATION_SSM_DB ":memory:"
67 #define RAPIDXML_STATIC_POOL_SIZE 4*1024
68 #define DEFAULT_PATH_SOFT_SENSORS "SoftSensorDescription.xml"
69 #define LOCATION_SSM_DB_DUMP ""
70 //#define LOCATION_SSM_DB_DUMP "myBackup.db"
71
72
73 #if defined(WIN32)
74
75 #define PRINT_LOG(strError) printf("[SSM] %s:%d %s\n", __FUNCTION__, __LINE__, strError)
76 #define REPORT_MESSAGE(tag, msg) printf("[%s] %s\n", tag, msg)
77
78 #elif defined(LINUX)
79
80 #if defined(ANDROID)
81
82 void ReportMessage(const char *tag, const char *msg);
83 #define REPORT_MESSAGE(tag, msg) ReportMessage(tag, msg)
84 #define PRINT_LOG(strError) __android_log_print(ANDROID_LOG_ERROR, "[SSM]", "%s:%d %s", __PRETTY_FUNCTION__, __LINE__, strError)
85
86 #elif defined(TIZEN)
87
88 void ReportMessage(const char *tag, const char *msg);
89 #define REPORT_MESSAGE(tag, msg) ReportMessage(tag, msg)
90 #define PRINT_LOG(strError) dlog_print(DLOG_DEBUG, "SSM", "%s:%d %s", __PRETTY_FUNCTION__, __LINE__, strError)
91
92 #else //Default linux
93
94 #define REPORT_MESSAGE(tag, msg) printf("[%s] %s\n", tag, msg)
95 #define PRINT_LOG(strError) printf("[SSM] %s:%d %s\n", __PRETTY_FUNCTION__, __LINE__, strError)
96
97 #endif
98
99 #endif
100
101
102
103 #define SSM_VOID_ASSERT(Exp, STRErrorMsg) \
104     { \
105     if(!(Exp)) \
106         { \
107         PRINT_LOG(STRErrorMsg); \
108         assert(0); \
109         return; \
110         } \
111     }
112
113 #define SSM_RESULT_ASSERT(Exp, STRErrorMsg, Result) \
114     { \
115     if(!(Exp)) \
116         { \
117         PRINT_LOG(STRErrorMsg); \
118         assert(0); \
119         return Result; \
120         } \
121     }
122
123 #define SSM_CLEANUP_ASSERT(Exp) \
124     { \
125     if((res = (Exp)) != SSM_S_OK) \
126         { \
127         PRINT_LOG(GetSSMError(res)); \
128         assert(0); \
129         goto CLEANUP; \
130         } \
131     }
132
133 #define SSM_CLEANUP_COND_ASSERT(Exp, Cond, STRErrorMsg) \
134     { \
135     if(Exp != Cond) \
136         { \
137         PRINT_LOG(STRErrorMsg); \
138         assert(0); \
139         goto CLEANUP; \
140         } \
141     }
142
143 #define SSM_CLEANUP_NULL_ASSERT(Val) \
144     { \
145     if(!(Val)) \
146         { \
147         PRINT_LOG("NULL value"); \
148         assert(Val); \
149         goto CLEANUP; \
150         } \
151     }
152
153 #define CLEAN_STACKVARIABLE(val) memset(&val, 0, sizeof(val))
154 #define SAFE_RELEASE(p) {if(p != NULL){p->release();p = NULL;}else{;/*NULL*/}}
155 #define SAFE_DELETE(p) {if(p != NULL){delete p;p = NULL;}else{;/*NULL*/}}
156 #define SAFE_ARRAY_DELETE(p) {if(p != NULL){delete [] p;p = NULL;}else{;/*NULL*/}}
157
158 #include "ObjectManager.h"
159 #include "ThreadManager.h"
160 #include "SSMInterface/SSMModelDefinition.h"
161
162 typedef std::vector<std::string> StringVec;
163 typedef std::vector<int> IntVec;
164
165 /**
166 * @fn createInstance
167 * @brief Create instance using given OID (Object ID).
168 *         After using the IBase object, you must call Release method.
169 *
170 * @param [in] const OID& objectID - objectID
171 * @param [out] IBase** ppObject - reference pointer to get instance pointer
172 * @return SSMRESULT
173 * @warning
174 * @exception
175 * @see
176 */
177 INTERFACE_DECLSPEC SSMRESULT CreateInstance(const OID &objectID, IBase **ppObject);
178
179 /**
180 * @fn createGlobalInstance
181 * @brief Create global instance using given OID (Object ID).
182 *        The instance is managed by global instance map.
183 *         After using the IBase object, you must call Release method.
184 *
185 * @param [in] const OID& objectID - objectID
186 * @param [out] IBase** ppObject - reference pointer to get instance pointer
187 * @return SSMRESULT
188 * @warning
189 * @exception
190 * @see
191 */
192 INTERFACE_DECLSPEC SSMRESULT CreateGlobalInstance(const OID &objectID, IBase **ppObject);
193
194 INTERFACE_DECLSPEC SSMRESULT CreateGlobalInstanceRepo();
195
196 INTERFACE_DECLSPEC SSMRESULT DestroyGlobalInstanceRepo();
197
198 #endif