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