Move macro from consumer common to NSConstant.h
[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               4
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
69 #define NS_ROOT_TYPE               "oic.r.notification"
70 #define NS_COLLECTION_MESSAGE_TYPE "oic.r.notification.message"
71 #define NS_COLLECTION_SYNC_TYPE    "oic.r.notification.sync"
72
73 #define NS_DEFAULT_INTERFACE       "oic.if.baseline"
74
75 #define NS_ROOT_URI                "/notification"
76 #define NS_COLLECTION_MESSAGE_URI  "/notification/message"
77 #define NS_COLLECTION_SYNC_URI     "/notification/sync"
78
79 #define NS_QUERY_SEPARATOR         "&;"
80 #define NS_KEY_VALUE_DELIMITER     "="
81
82 #define NS_QUERY_CONSUMER_ID       "consumerid"
83 #define NS_QUERY_PROVIDER_ID       "providerid"
84
85 #define NS_QUERY_ID_SIZE           10
86
87 #define NS_POLICY_PROVIDER         1
88 #define NS_POLICY_CONSUMER         0
89
90 #define NS_VERIFY_NOT_NULL_V(obj) \
91     { \
92         if ((obj) == NULL) \
93         { \
94             NS_LOG_V(ERROR, "%s : %s is null", __func__, #obj); \
95             return; \
96         } \
97     }
98
99 #define NS_VERIFY_NOT_NULL(obj, retVal) \
100     { \
101         if ((obj) == NULL) \
102         { \
103             NS_LOG_V(ERROR, "%s : %s is null", __func__, #obj); \
104             return (retVal); \
105         } \
106     }
107
108 #define NS_VERIFY_NOT_NULL_WITH_POST_CLEANING_V(obj, func) \
109     { \
110         if ((obj) == NULL) \
111         { \
112             NS_LOG_V(ERROR, "%s : %s is null", __func__, #obj); \
113             NS_LOG(ERROR, "execute deletion"); \
114             (func); \
115             return; \
116         } \
117     }
118
119 #define NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(obj, retVal, func) \
120     { \
121         if ((obj) == NULL) \
122         { \
123             NS_LOG_V(ERROR, "%s : %s is null", __func__, #obj); \
124             NS_LOG(ERROR, "execute deletion"); \
125             (func); \
126             return (retVal); \
127         } \
128     }
129
130 #define NS_VERIFY_STACK_SUCCESS_V(obj) \
131     { \
132         bool _ret = (obj); \
133         if ( _ret != true) \
134         { \
135             NS_LOG_V(ERROR, "%s : %s is not OC_STACK_OK : %d", __func__, #obj, _ret); \
136             return; \
137         } \
138     }
139
140 #define NS_VERIFY_STACK_SUCCESS(obj, retVal) \
141     { \
142         bool _ret = (obj); \
143         if ( _ret != true) \
144         { \
145             NS_LOG_V(ERROR, "%s : %s is not OC_STACK_OK : %d", __func__, #obj, _ret); \
146             return (retVal); \
147         } \
148     }
149
150 #define NS_VERIFY_STACK_SUCCESS_WITH_POST_CLEANING(obj, retVal, func) \
151     { \
152         bool _ret = (obj); \
153         if ( _ret != true) \
154         { \
155             NS_LOG_V(ERROR, "%s : %s is not OC_STACK_OK : %d", __func__, #obj, _ret); \
156             (func); \
157             return (retVal); \
158         } \
159     }
160
161 #define NSOICFree(obj) \
162     { \
163         if ((obj)) \
164         { \
165             OICFree((obj)); \
166             (obj) = NULL; \
167             NS_LOG_V(DEBUG, "%s : %s Removed", __func__, #obj); \
168         } \
169     }
170
171
172 typedef enum eConnectionState
173 {
174     DISCONNECTED = 0,
175     CONNECTED = 1,
176
177 } NSConnectionState;
178
179 typedef enum eSchedulerType
180 {
181     CALLBACK_RESPONSE_SCHEDULER = 0,
182     DISCOVERY_SCHEDULER = 1,
183     SUBSCRIPTION_SCHEDULER = 2,
184     NOTIFICATION_SCHEDULER = 3,
185 } NSSchedulerType;
186
187 typedef enum eTaskType
188 {
189     TASK_REGISTER_RESOURCE = 1000,
190     TASK_PUBLISH_RESOURCE = 1001,
191
192     TASK_START_PRESENCE = 2000,
193     TASK_STOP_PRESENCE = 2001,
194
195     TASK_RECV_SUBSCRIPTION = 3000,
196     TASK_RECV_UNSUBSCRIPTION = 3001,
197     TASK_SEND_POLICY = 3002,
198     TASK_SEND_ALLOW = 3003,
199     TASK_SEND_DENY = 3004,
200     TASK_SYNC_SUBSCRIPTION = 3005,
201
202     TASK_SEND_NOTIFICATION = 4000,
203     TASK_SEND_PENDING_NOTI = 4001,
204
205     TASK_RECV_SYNCINFO = 5000,
206     TASK_RECV_READ = 5001,
207     TASK_RECV_DISMISS = 5003,
208     TASK_SEND_SYNCINFO = 5099,
209     TASK_MAKE_SYNCINFO = 5100,
210     TASK_SEND_READ = 5101,
211     TASK_SEND_DISMISS = 5102,
212
213     TASK_CONSUMER_REQ_DISCOVER = 8001,
214     TASK_CONSUMER_REQ_SUBSCRIBE = 8002,
215     TASK_CONSUMER_REQ_SUBSCRIBE_CANCEL = 8003,
216     TASK_CONSUMER_RECV_SUBSCRIBE_CONFIRMED = 8004,
217     TASK_CONSUMER_RECV_MESSAGE = 8101,
218
219     TASK_CONSUMER_PROVIDER_DISCOVERED = 8201,
220     TASK_CONSUMER_PROVIDER_DELETED = 8202,
221     TASK_CONSUMER_RECV_CONFIRM = 8206,
222
223     TASK_EVENT_CONNECTED = 9000,
224     TASK_EVENT_CONNECTED_TCP = 9001,
225     TASK_EVENT_DISCONNECTED = 9002,
226
227     TASK_CB_SUBSCRIPTION = 10000,
228     TASK_CB_SYNC = 10001,
229
230 } NSTaskType;
231
232 typedef enum eCache
233 {
234     NS_CONSUMER_BLACKLIST = 0,
235     NS_CONSUMER_WHITELIST = 1,
236
237 } NSCache;
238
239 typedef enum eCacheType
240 {
241     NS_PROVIDER_CACHE_SUBSCRIBER = 1000,
242     NS_PROVIDER_CACHE_MESSAGE = 1001,
243
244     NS_CONSUMER_CACHE_PROVIDER = 2000,
245     NS_CONSUMER_CACHE_MESSAGE = 2001,
246 } NSCacheType;
247
248 typedef enum eResourceType
249 {
250     NS_RESOURCE_MESSAGE = 1000,
251     NS_RESOURCE_SYNC = 1001,
252 } NSResourceType;
253
254 #endif /* _NS_CONSTANTS_H_ */