Create topic resource
[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 __NS_FILE__ ( strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__ )
25
26 #ifdef TB_LOG
27 #include "logger.h"
28 #define NS_LOG_V(level, format, ...) (OIC_LOG_V((level), __NS_FILE__, (format), __VA_ARGS__))
29 #define NS_LOG(level, msg) (OIC_LOG((level), __NS_FILE__, (msg)))
30 #else
31 #include "logger.h"
32 #define NS_CONVERT_LEVEL(level) ( \
33         ((level) == 0) ? "DEBUG" : \
34         ((level) == 1) ? "INFO" : \
35         ((level) == 2) ? "WARNING" : \
36     ((level) == 3) ? "ERROR" : "FATAL")
37 #define NS_LOG_V(level, format, ...) \
38     { \
39         printf("%s: %s ", NS_CONVERT_LEVEL(level), __NS_FILE__); \
40         printf((format), __VA_ARGS__); \
41         printf("\n"); \
42     }
43 #define NS_LOG(level, msg) \
44     { \
45         printf("%s: %s ", NS_CONVERT_LEVEL(level), __NS_FILE__); \
46         printf((msg)); \
47         printf("\n"); \
48     }
49 #endif
50
51 #define NS_TAG                     "IOT_NOTI"
52
53 // SCHEDULE //
54 #define THREAD_COUNT               5
55
56 // NOTIOBJ //
57 #define NOTIOBJ_TITLE_KEY          "title"
58 #define NOTIOBJ_ID_KEY             "id"
59 #define NOTOOBJ_CONTENT_KEY        "contentText"
60
61 #define DISCOVERY_TAG              "NS_PROVIDER_DISCOVERY"
62 #define SUBSCRIPTION_TAG           "NS_PROVIDER_SUBSCRIPTION"
63 #define INTERFACE_TAG              "NS_PROVIDER_INTERFACE"
64 #define NOTIFICATION_TAG           "NS_PROVIDER_NOTIFICATION"
65 #define SCHEDULER_TAG              "NS_PROVIDER_SCHEDULER"
66 #define LISTENER_TAG               "NS_PROVIDER_LISTENER"
67 #define RESOURCE_TAG               "NS_PROVIDER_RESOURCE"
68 #define TOPIC_TAG                  "NS_PROVIDER_TOPIC"
69
70 #define NS_ROOT_TYPE               "oic.r.notification"
71 #define NS_COLLECTION_MESSAGE_TYPE "oic.r.notification.message"
72 #define NS_COLLECTION_SYNC_TYPE    "oic.r.notification.sync"
73 #define NS_COLLECTION_TOPIC_TYPE   "oic.r.notification.topic"
74
75 #define NS_DEFAULT_INTERFACE       "oic.if.baseline"
76
77 #define NS_ROOT_URI                "/notification"
78 #define NS_COLLECTION_MESSAGE_URI  "/notification/message"
79 #define NS_COLLECTION_SYNC_URI     "/notification/sync"
80 #define NS_COLLECTION_TOPIC_URI    "/notification/topic"
81
82 #define NS_QUERY_SEPARATOR         "&;"
83 #define NS_KEY_VALUE_DELIMITER     "="
84
85 #define NS_QUERY_CONSUMER_ID       "consumerid"
86 #define NS_QUERY_PROVIDER_ID       "providerid"
87
88 #define NS_QUERY_ID_SIZE           10
89
90 #define NS_POLICY_PROVIDER         1
91 #define NS_POLICY_CONSUMER         0
92
93 #define NS_VERIFY_NOT_NULL_V(obj) \
94     { \
95         if ((obj) == NULL) \
96         { \
97             NS_LOG_V(ERROR, "%s : %s is null", __func__, #obj); \
98             return; \
99         } \
100     }
101
102 #define NS_VERIFY_NOT_NULL(obj, retVal) \
103     { \
104         if ((obj) == NULL) \
105         { \
106             NS_LOG_V(ERROR, "%s : %s is null", __func__, #obj); \
107             return (retVal); \
108         } \
109     }
110
111 #define NS_VERIFY_NOT_NULL_WITH_POST_CLEANING_V(obj, func) \
112     { \
113         if ((obj) == NULL) \
114         { \
115             NS_LOG_V(ERROR, "%s : %s is null", __func__, #obj); \
116             NS_LOG(ERROR, "execute deletion"); \
117             (func); \
118             return; \
119         } \
120     }
121
122 #define NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(obj, retVal, func) \
123     { \
124         if ((obj) == NULL) \
125         { \
126             NS_LOG_V(ERROR, "%s : %s is null", __func__, #obj); \
127             NS_LOG(ERROR, "execute deletion"); \
128             (func); \
129             return (retVal); \
130         } \
131     }
132
133 #define NS_VERIFY_STACK_SUCCESS_V(obj) \
134     { \
135         bool _ret = (obj); \
136         if ( _ret != true) \
137         { \
138             NS_LOG_V(ERROR, "%s : %s is not OC_STACK_OK : %d", __func__, #obj, _ret); \
139             return; \
140         } \
141     }
142
143 #define NS_VERIFY_STACK_SUCCESS(obj, retVal) \
144     { \
145         bool _ret = (obj); \
146         if ( _ret != true) \
147         { \
148             NS_LOG_V(ERROR, "%s : %s is not OC_STACK_OK : %d", __func__, #obj, _ret); \
149             return (retVal); \
150         } \
151     }
152
153 #define NS_VERIFY_STACK_SUCCESS_WITH_POST_CLEANING(obj, retVal, func) \
154     { \
155         bool _ret = (obj); \
156         if ( _ret != true) \
157         { \
158             NS_LOG_V(ERROR, "%s : %s is not OC_STACK_OK : %d", __func__, #obj, _ret); \
159             (func); \
160             return (retVal); \
161         } \
162     }
163
164 #define NSOICFree(obj) \
165     { \
166         if ((obj)) \
167         { \
168             OICFree((obj)); \
169             (obj) = NULL; \
170             NS_LOG_V(DEBUG, "%s : %s Removed", __func__, #obj); \
171         } \
172     }
173
174
175 typedef enum eConnectionState
176 {
177     DISCONNECTED = 0,
178     CONNECTED = 1,
179
180 } NSConnectionState;
181
182 typedef enum eSchedulerType
183 {
184     CALLBACK_RESPONSE_SCHEDULER = 0,
185     DISCOVERY_SCHEDULER = 1,
186     SUBSCRIPTION_SCHEDULER = 2,
187     NOTIFICATION_SCHEDULER = 3,
188     TOPIC_SCHEDULER = 4,
189 } NSSchedulerType;
190
191 typedef enum eTaskType
192 {
193     TASK_REGISTER_RESOURCE = 1000,
194     TASK_PUBLISH_RESOURCE = 1001,
195
196     TASK_START_PRESENCE = 2000,
197     TASK_STOP_PRESENCE = 2001,
198
199     TASK_RECV_SUBSCRIPTION = 3000,
200     TASK_RECV_UNSUBSCRIPTION = 3001,
201     TASK_SEND_POLICY = 3002,
202     TASK_SEND_ALLOW = 3003,
203     TASK_SEND_DENY = 3004,
204     TASK_SYNC_SUBSCRIPTION = 3005,
205
206     TASK_SEND_NOTIFICATION = 4000,
207     TASK_SEND_PENDING_NOTI = 4001,
208
209     TASK_RECV_SYNCINFO = 5000,
210     TASK_RECV_READ = 5001,
211     TASK_RECV_DISMISS = 5003,
212     TASK_SEND_SYNCINFO = 5099,
213     TASK_MAKE_SYNCINFO = 5100,
214     TASK_SEND_READ = 5101,
215     TASK_SEND_DISMISS = 5102,
216
217     TASK_CONSUMER_REQ_DISCOVER = 8001,
218     TASK_CONSUMER_REQ_SUBSCRIBE = 8002,
219     TASK_CONSUMER_REQ_SUBSCRIBE_CANCEL = 8003,
220     TASK_CONSUMER_RECV_SUBSCRIBE_CONFIRMED = 8004,
221     TASK_CONSUMER_RECV_MESSAGE = 8101,
222
223     TASK_CONSUMER_PROVIDER_DISCOVERED = 8201,
224     TASK_CONSUMER_PROVIDER_DELETED = 8202,
225     TASK_CONSUMER_RECV_CONFIRM = 8206,
226
227     TASK_EVENT_CONNECTED = 9000,
228     TASK_EVENT_CONNECTED_TCP = 9001,
229     TASK_EVENT_DISCONNECTED = 9002,
230
231     TASK_CB_SUBSCRIPTION = 10000,
232     TASK_CB_SYNC = 10001,
233
234     TASK_SEND_TOPICS = 11000,
235     TASK_SELECT_TOPICS = 11001,
236     TASK_SET_TOPICS = 11002,
237
238 } NSTaskType;
239
240 typedef enum eCache
241 {
242     NS_CONSUMER_BLACKLIST = 0,
243     NS_CONSUMER_WHITELIST = 1,
244
245 } NSCache;
246
247 typedef enum eCacheType
248 {
249     NS_PROVIDER_CACHE_SUBSCRIBER = 1000,
250     NS_PROVIDER_CACHE_MESSAGE = 1001,
251     NS_PROVIDER_CACHE_TOPIC = 1002,
252
253     NS_CONSUMER_CACHE_PROVIDER = 2000,
254     NS_CONSUMER_CACHE_MESSAGE = 2001,
255 } NSCacheType;
256
257 typedef enum eResourceType
258 {
259     NS_RESOURCE_MESSAGE = 1000,
260     NS_RESOURCE_SYNC = 1001,
261     NS_RESOURCE_TOPIC = 1002,
262 } NSResourceType;
263
264 typedef enum eResponse
265 {
266     NS_ALLOW = 1,
267     NS_DENY = 2,
268     NS_TOPIC = 3,
269
270 } NSResponse;
271
272
273 #endif /* _NS_CONSTANTS_H_ */