3cbfbf42b7b5dfbc1a4618c0708ead956c14b7b1
[platform/upstream/iotivity.git] / service / notification / src / common / NSConstants.h
1 //******************************************************************
2 //
3 // Copyright 2016 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
21 #ifndef _NS_CONSTANTS_H_
22 #define _NS_CONSTANTS_H_
23
24 #define __PRINTLOG 0
25 #define __NS_FILE__ ( strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__ )
26
27 #include "logger.h"
28
29 #ifdef TB_LOG
30 #ifdef __TIZEN__
31 #include <dlog.h>
32 #ifdef LOG_TAG
33 #undef LOG_TAG
34 #endif // LOG_TAG
35 #define LOG_TAG "NotificationService"
36 #define NS_CONVERT_LEVEL(level) ( \
37         ((level) == 0) ? DLOG_DEBUG : \
38         ((level) == 1) ? DLOG_INFO : \
39         ((level) == 2) ? DLOG_WARN : \
40     ((level) == 3) ? DLOG_ERROR : DLOG_ERROR)
41 #define NS_LOG_V(level, format, ...) (dlog_print(NS_CONVERT_LEVEL(level), LOG_TAG, (format), __VA_ARGS__))
42 #define NS_LOG(level, msg) (dlog_print(NS_CONVERT_LEVEL(level), LOG_TAG, (msg)))
43 #else // __TIZEN__
44 #define NS_LOG_V(level, format, ...) (OIC_LOG_V((level), __NS_FILE__, (format), __VA_ARGS__))
45 #define NS_LOG(level, msg) (OIC_LOG((level), __NS_FILE__, (msg)))
46 #endif // __TIZEN__
47 #else // TB_LOG
48 #if (__PRINTLOG == 1)
49 #define NS_CONVERT_LEVEL(level) ( \
50         ((level) == 0) ? "DEBUG" : \
51         ((level) == 1) ? "INFO" : \
52         ((level) == 2) ? "WARNING" : \
53     ((level) == 3) ? "ERROR" : "FATAL")
54 #define NS_LOG_V(level, format, ...) \
55     { \
56         printf("%s: %s ", NS_CONVERT_LEVEL(level), __NS_FILE__); \
57         printf((format), __VA_ARGS__); \
58         printf("\n"); \
59     }
60 #define NS_LOG(level, msg) \
61     { \
62         printf("%s: %s ", NS_CONVERT_LEVEL(level), __NS_FILE__); \
63         printf((msg)); \
64         printf("\n"); \
65     }
66 #else // (__PRINTLOG == 1)
67 #define NS_CONVERT_LEVEL(level)
68 #define NS_LOG(level, msg)
69 #define NS_LOG_V(level, format, ...) NS_LOG((level), ((format), __VA_ARGS__))
70 #endif // (__PRINTLOG == 1)
71 #endif // TB_LOG
72
73 #define NS_TAG                     "IOT_NOTI"
74
75 // SCHEDULE //
76 #define THREAD_COUNT               5
77
78 // NOTIOBJ //
79 #define NOTIOBJ_TITLE_KEY          "title"
80 #define NOTIOBJ_ID_KEY             "id"
81 #define NOTOOBJ_CONTENT_KEY        "contenttext"
82
83 #define DISCOVERY_TAG              "NS_PROVIDER_DISCOVERY"
84 #define SUBSCRIPTION_TAG           "NS_PROVIDER_SUBSCRIPTION"
85 #define INTERFACE_TAG              "NS_PROVIDER_INTERFACE"
86 #define NOTIFICATION_TAG           "NS_PROVIDER_NOTIFICATION"
87 #define SCHEDULER_TAG              "NS_PROVIDER_SCHEDULER"
88 #define LISTENER_TAG               "NS_PROVIDER_LISTENER"
89 #define RESOURCE_TAG               "NS_PROVIDER_RESOURCE"
90 #define TOPIC_TAG                  "NS_PROVIDER_TOPIC"
91
92 #define NS_ROOT_TYPE               "oic.wk.notification"
93 #define NS_COLLECTION_MESSAGE_TYPE "oic.wk.notification.message"
94 #define NS_COLLECTION_SYNC_TYPE    "oic.wk.notification.sync"
95 #define NS_COLLECTION_TOPIC_TYPE   "oic.wk.notification.topic"
96
97 #define NS_INTERFACE_READ          "oic.if.r"
98 #define NS_INTERFACE_READWRITE     "oic.if.rw"
99 #define NS_INTERFACE_BASELINE       "oic.if.baseline"
100
101 #define NS_ROOT_URI                "/notification"
102 #define NS_COLLECTION_MESSAGE_URI  "/notification/message"
103 #define NS_COLLECTION_SYNC_URI     "/notification/sync"
104 #define NS_COLLECTION_TOPIC_URI    "/notification/topic"
105
106 #define NS_QUERY_SEPARATOR         "&;"
107 #define NS_KEY_VALUE_DELIMITER     "="
108
109 #define NS_QUERY_CONSUMER_ID       "consumerid"
110 #define NS_QUERY_PROVIDER_ID       "providerid"
111 #define NS_QUERY_INTERFACE         "if"
112
113 #define NS_QUERY_ID_SIZE           10
114
115 #define NS_POLICY_PROVIDER         1
116 #define NS_POLICY_CONSUMER         0
117
118 #define NS_RD_PUBLISH_QUERY        "/oic/rd?rt=oic.wk.rdpub"
119
120 #define NS_VERIFY_NOT_NULL_V(obj) \
121     { \
122         if ((obj) == NULL) \
123         { \
124             NS_LOG_V(ERROR, "%s : %s is null", __func__, #obj); \
125             return; \
126         } \
127     }
128
129 #define NS_VERIFY_NOT_NULL(obj, retVal) \
130     { \
131         if ((obj) == NULL) \
132         { \
133             NS_LOG_V(ERROR, "%s : %s is null", __func__, #obj); \
134             return (retVal); \
135         } \
136     }
137
138 #define NS_VERIFY_NOT_NULL_WITH_POST_CLEANING_V(obj, func) \
139     { \
140         if ((obj) == NULL) \
141         { \
142             NS_LOG_V(ERROR, "%s : %s is null", __func__, #obj); \
143             NS_LOG(ERROR, "execute deletion"); \
144             (func); \
145             return; \
146         } \
147     }
148
149 #define NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(obj, retVal, func) \
150     { \
151         if ((obj) == NULL) \
152         { \
153             NS_LOG_V(ERROR, "%s : %s is null", __func__, #obj); \
154             NS_LOG(ERROR, "execute deletion"); \
155             (func); \
156             return (retVal); \
157         } \
158     }
159
160 #define NS_VERIFY_STACK_SUCCESS_V(obj) \
161     { \
162         bool _ret = (obj); \
163         if ( _ret != true) \
164         { \
165             NS_LOG_V(ERROR, "%s : %s is not OC_STACK_OK : %d", __func__, #obj, _ret); \
166             return; \
167         } \
168     }
169
170 #define NS_VERIFY_STACK_SUCCESS(obj, retVal) \
171     { \
172         bool _ret = (obj); \
173         if ( _ret != true) \
174         { \
175             NS_LOG_V(ERROR, "%s : %s is not OC_STACK_OK : %d", __func__, #obj, _ret); \
176             return (retVal); \
177         } \
178     }
179
180 #define NS_VERIFY_STACK_SUCCESS_WITH_POST_CLEANING(obj, retVal, func) \
181     { \
182         bool _ret = (obj); \
183         if ( _ret != true) \
184         { \
185             NS_LOG_V(ERROR, "%s : %s is not OC_STACK_OK : %d", __func__, #obj, _ret); \
186             (func); \
187             return (retVal); \
188         } \
189     }
190
191 #define NSOICFree(obj) \
192     { \
193         if ((obj)) \
194         { \
195             OICFree((obj)); \
196             (obj) = NULL; \
197             NS_LOG_V(DEBUG, "%s : %s Removed", __func__, #obj); \
198         } \
199     }
200
201 #define VERSION        "1.2.1"
202
203 #define NS_ATTRIBUTE_VERSION "version"
204 #define NS_ATTRIBUTE_POLICY "subcontrollability"
205 #define NS_ATTRIBUTE_MESSAGE "messageuri"
206 #define NS_ATTRIBUTE_SYNC "syncuri"
207 #define NS_ATTRIBUTE_TOPIC "topicuri"
208 #define NS_ATTRIBUTE_MESSAGE_ID "messageid"
209 #define NS_ATTRIBUTE_PROVIDER_ID "providerid"
210 #define NS_ATTRIBUTE_CONSUMER_ID "consumerid"
211 #define NS_ATTRIBUTE_TOPIC_LIST "topiclist"
212 #define NS_ATTRIBUTE_TOPIC_NAME "topicname"
213 #define NS_ATTRIBUTE_TOPIC_SELECTION "topicstate"
214 #define NS_ATTRIBUTE_TITLE "title"
215 #define NS_ATTRIBUTE_TEXT "contenttext"
216 #define NS_ATTRIBUTE_SOURCE "source"
217 #define NS_ATTRIBUTE_STATE "state"
218 #define NS_ATTRIBUTE_DEVICE "device"
219 #define NS_ATTRIBUTE_TYPE "type"
220 #define NS_ATTRIBUTE_DATETIME "datetime"
221 #define NS_ATTRIBUTE_TTL "ttl"
222 #define NS_ATTRIBUTE_ICON_IMAGE "iconimage"
223
224 typedef enum eConnectionState
225 {
226     DISCONNECTED = 0,
227     CONNECTED = 1,
228
229 } NSConnectionState;
230
231 typedef enum eSchedulerType
232 {
233     CALLBACK_RESPONSE_SCHEDULER = 0,
234     DISCOVERY_SCHEDULER = 1,
235     SUBSCRIPTION_SCHEDULER = 2,
236     NOTIFICATION_SCHEDULER = 3,
237     TOPIC_SCHEDULER = 4,
238 } NSSchedulerType;
239
240 typedef enum eTaskType
241 {
242     TASK_REGISTER_RESOURCE = 1000,
243     TASK_PUBLISH_RESOURCE = 1001,
244
245     TASK_START_PRESENCE = 2000,
246     TASK_STOP_PRESENCE = 2001,
247
248     TASK_RECV_SUBSCRIPTION = 3000,
249     TASK_RECV_UNSUBSCRIPTION = 3001,
250     TASK_SEND_POLICY = 3002,
251     TASK_SEND_ALLOW = 3003,
252     TASK_SEND_DENY = 3004,
253     TASK_SYNC_SUBSCRIPTION = 3005,
254
255     TASK_SEND_NOTIFICATION = 4000,
256     TASK_SEND_PENDING_NOTI = 4001,
257
258     TASK_RECV_SYNCINFO = 5000,
259     TASK_RECV_READ = 5001,
260     TASK_RECV_DISMISS = 5003,
261     TASK_SEND_SYNCINFO = 5099,
262     TASK_MAKE_SYNCINFO = 5100,
263     TASK_SEND_READ = 5101,
264     TASK_SEND_DISMISS = 5102,
265
266     TASK_CONSUMER_REQ_DISCOVER = 8001,
267     TASK_CONSUMER_REQ_SUBSCRIBE = 8002,
268     TASK_CONSUMER_REQ_SUBSCRIBE_CANCEL = 8003,
269     TASK_CONSUMER_SENT_REQ_OBSERVE = 8004,
270     TASK_CONSUMER_RECV_PROVIDER_CHANGED = 8005,
271     TASK_CONSUMER_RECV_MESSAGE = 8101,
272
273     TASK_CONSUMER_PROVIDER_DISCOVERED = 8201,
274     TASK_CONSUMER_PROVIDER_DELETED = 8202,
275     TASK_CONSUMER_RECV_CONFIRM = 8206,
276
277     TASK_CONSUMER_REQ_TOPIC_URI = 8299,
278     TASK_CONSUMER_REQ_TOPIC_LIST = 8300,
279     TASK_CONSUMER_RECV_TOPIC_LIST = 8031,
280     TASK_CONSUMER_SELECT_TOPIC_LIST = 8303,
281
282     TASK_EVENT_CONNECTED = 9000,
283     TASK_EVENT_CONNECTED_TCP = 9001,
284     TASK_EVENT_DISCONNECTED = 9002,
285
286     TASK_CB_SUBSCRIPTION = 10000,
287     TASK_CB_SYNC = 10001,
288
289     TASK_SEND_TOPICS = 11000,
290     TASK_REGISTER_TOPIC = 11001,
291     TASK_UNREGISTER_TOPIC = 11002,
292     TASK_SUBSCRIBE_TOPIC = 11003,
293     TASK_UNSUBSCRIBE_TOPIC = 11004,
294     TASK_POST_TOPIC = 11005,
295     TASK_GET_TOPICS = 11006,
296     TAST_GET_CONSUMER_TOPICS = 11007
297
298 } NSTaskType;
299
300 typedef enum eCache
301 {
302     NS_CONSUMER_BLACKLIST = 0,
303     NS_CONSUMER_WHITELIST = 1,
304
305 } NSCache;
306
307 typedef enum eCacheType
308 {
309     NS_PROVIDER_CACHE_SUBSCRIBER = 1000,
310     NS_PROVIDER_CACHE_MESSAGE = 1001,
311     NS_PROVIDER_CACHE_CONSUMER_TOPIC_NAME = 1002,
312     NS_PROVIDER_CACHE_CONSUMER_TOPIC_CID = 1003,
313     NS_PROVIDER_CACHE_REGISTER_TOPIC = 1004,
314     NS_PROVIDER_CACHE_SUBSCRIBER_OBSERVE_ID = 1005,
315
316     NS_CONSUMER_CACHE_PROVIDER = 2000,
317     NS_CONSUMER_CACHE_MESSAGE = 2001,
318 } NSCacheType;
319
320 typedef enum eResourceType
321 {
322     NS_RESOURCE_MESSAGE = 1000,
323     NS_RESOURCE_SYNC = 1001,
324     NS_RESOURCE_TOPIC = 1002,
325 } NSResourceType;
326
327 typedef enum eInterfaceType
328 {
329     NS_INTERFACE_TYPE_READ = 1,
330     NS_INTERFACE_TYPE_READWRITE = 2,
331 } NSInterfaceType;
332
333 #endif /* _NS_CONSTANTS_H_ */