Updated for consumer APIs.
[platform/upstream/iotivity.git] / service / notification / src / consumer / NSConsumerCommon.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_CONSUMER_CONSTANTS_H_
22 #define _NS_CONSUMER_CONSTANTS_H_
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif // __cplusplus
27
28 #include <stdio.h>
29 #include <stdbool.h>
30
31 #include "NSConsumerInterface.h"
32 #include "NSStructs.h"
33 #include "ocstack.h"
34
35
36 #define NS_QOS OC_LOW_QOS
37 #define NS_RESOURCE_TYPE "oic.r.notification"
38 #define NS_RESOURCE_URI "/notification"
39 #define NS_INTERFACE_BASELINE "oic.if.baseline"
40 #define NS_INTERFACE_NOTIFICATION "oic.if.notification"
41 #define NS_RESOURCE_QUERY "/oic/res"
42
43 #define NS_DISCOVER_QUERY "/oic/res?rt=oic.r.notification"
44 #define NS_DEVICE_ID_LENGTH 37
45
46 #define NS_VERIFY_NOT_NULL_V(obj) \
47     { \
48         if ((obj) == NULL) \
49         { \
50             NS_LOG_V(ERROR, "%s : %s is null", __func__, #obj); \
51             return; \
52         } \
53     }
54
55 #define NS_VERIFY_NOT_NULL(obj, retVal) \
56     { \
57         if ((obj) == NULL) \
58         { \
59             NS_LOG_V(ERROR, "%s : %s is null", __func__, #obj); \
60             return (retVal); \
61         } \
62     }
63
64 #define NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(obj, retVal, func) \
65     { \
66         if ((obj) == NULL) \
67         { \
68             NS_LOG_V(ERROR, "%s : %s is null", __func__, #obj); \
69             NS_LOG(ERROR, "execute deletion"); \
70             (func); \
71             return (retVal); \
72         } \
73     }
74
75 #define NS_VERIFY_STACK_OK_V(obj) \
76     { \
77         OCStackResult _ret = (obj); \
78         if ( _ret != OC_STACK_OK) \
79         { \
80             NS_LOG_V(ERROR, "%s : %s is not OC_STACK_OK : %d", __func__, #obj, _ret); \
81             return; \
82         } \
83     }
84
85 #define NS_VERIFY_STACK_OK(obj, retVal) \
86     { \
87         OCStackResult _ret = (obj); \
88         if ( _ret != OC_STACK_OK) \
89         { \
90             NS_LOG_V(ERROR, "%s : %s is not OC_STACK_OK : %d", __func__, #obj, _ret); \
91             return (retVal); \
92         } \
93     }
94
95 #define NS_VERIFY_STACK_OK_WITH_POST_CLEANING(obj, retVal, func) \
96     { \
97         OCStackResult _ret = (obj); \
98         if ( _ret != OC_STACK_OK) \
99         { \
100             NS_LOG_V(ERROR, "%s : %s is not OC_STACK_OK : %d", __func__, #obj, _ret); \
101             (func); \
102             return (retVal); \
103         } \
104     }
105
106 #define NSOICFree(obj) \
107     { \
108         if ((obj)) \
109         { \
110             OICFree((obj)); \
111             (obj) = NULL; \
112             NS_LOG_V(DEBUG, "%s : %s Removed", __func__, #obj); \
113         } \
114     }
115
116 typedef enum
117 {
118     Read,
119     Dismiss,
120     Notification,
121 } NSConsumerMessageTypes;
122
123 typedef struct
124 {
125     char providerId[37];
126
127     char * messageUri;
128     char * syncUri;
129
130     OCDoHandle messageHandle;
131     OCDoHandle syncHandle;
132     OCDevAddr * addr;
133     NSAccessPolicy accessPolicy;
134
135 } NSProvider_internal;
136
137 typedef struct
138 {
139     // Mandatory
140     uint64_t messageId;
141     char providerId[37];
142
143     //optional
144     NSMessageType type;
145     char * dateTime;
146     uint64_t ttl;
147     char * title;
148     char * contentText;
149     char * sourceName;
150     NSMediaContents mediaContents;
151
152     OCDevAddr * addr;
153     NSConsumerMessageTypes messageTypes;
154 } NSMessage_consumer;
155
156 bool NSIsStartedConsumer();
157 void NSSetIsStartedConsumer(bool setValue);
158
159 void NSSetDiscoverProviderCb(NSProviderDiscoveredCallback cb);
160 void NSDiscoveredProvider(NSProvider * provider);
161
162 void NSSetSubscriptionAcceptedCb(NSSubscriptionAcceptedCallback cb);
163 void NSSubscriptionAccepted(NSProvider * provider);
164
165 void NSSetMessagePostedCb(NSMessageReceivedCallback  cb);
166 void NSMessagePost(NSMessage * obj);
167
168 void NSSetNotificationSyncCb(NSSyncInfoReceivedCallback cb);
169 void NSNotificationSync(NSSyncInfo * sync);
170
171 char ** NSGetConsumerId();
172 void NSSetConsumerId(char * cId);
173
174 char * NSMakeRequestUriWithConsumerId(const char * uri);
175
176 NSTask * NSMakeTask(NSTaskType, void *);
177
178 NSResult NSConsumerPushEvent(NSTask *);
179
180 NSMessage_consumer * NSCopyMessage(NSMessage_consumer *);
181 void NSRemoveMessage(NSMessage_consumer *);
182
183 OCStackResult NSInvokeRequest(OCDoHandle * handle,
184         OCMethod method, const OCDevAddr * addr,
185         const char * queryUrl, OCPayload * payload,
186         void * callbackFunc, void * callbackData);
187
188 #ifdef __cplusplus
189 }
190 #endif // __cplusplus
191
192 #endif // _NS_CONSUMER_CONSTANTS_H_