Modified consumer internal function call flow.
[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_VERTIFY_NOT_NULL_V(obj) \
47     { \
48         if ((obj) == NULL) \
49         { \
50             NS_LOG_V(ERROR, "%s : obj is null", __func__); \
51             return; \
52         } \
53     }
54
55 #define NS_VERTIFY_NOT_NULL(obj, retVal) \
56     { \
57         if ((obj) == NULL) \
58         { \
59             NS_LOG_V(ERROR, "%s : obj is null", __func__); \
60             return (retVal); \
61         } \
62     }
63
64 #define NS_VERTIFY_NOT_NULL_WITH_POST_CLEANING(obj, retVal, func) \
65     { \
66         if ((obj) == NULL) \
67         { \
68             NS_LOG_V(ERROR, "%s : obj is null", __func__); \
69             NS_LOG(ERROR, "execute deletion"); \
70             (func); \
71             return (retVal); \
72         } \
73     }
74
75 #define NS_VERTIFY_STACK_OK_V(obj) \
76     { \
77         OCStackResult _ret = (obj); \
78         if ( _ret != OC_STACK_OK) \
79         { \
80             NS_LOG_V(ERROR, "%s : obj is not OC_STACK_OK : %d", __func__, _ret); \
81             return; \
82         } \
83     }
84
85 #define NS_VERTIFY_STACK_OK(obj, retVal) \
86     { \
87         OCStackResult _ret = (obj); \
88         if ( _ret != OC_STACK_OK) \
89         { \
90             NS_LOG_V(ERROR, "%s : obj is not OC_STACK_OK : %d", __func__, _ret); \
91             return (retVal); \
92         } \
93     }
94
95 #define NS_VERTIFY_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 : obj is not OC_STACK_OK : %d", __func__, _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         } \
113     }
114
115 typedef enum
116 {
117     Read,
118     Dismiss,
119     Notification,
120 } NSConsumerMessageTypes;
121
122 typedef struct
123 {
124     char providerId[37];
125
126     char * messageUri;
127     char * syncUri;
128
129     OCDoHandle messageHandle;
130     OCDoHandle syncHandle;
131     OCDevAddr * addr;
132     NSAccessPolicy accessPolicy;
133
134 } NSProvider_internal;
135
136 typedef struct
137 {
138     // Mandatory
139     uint64_t messageId;
140     char * providerId;
141
142     //optional
143     NSMessageType type;
144     char * dateTime;
145     uint64_t ttl;
146     char * title;
147     char * contentText;
148     char * sourceName;
149     NSMediaContents mediaContents;
150
151     OCDevAddr * addr;
152     NSConsumerMessageTypes messageTypes;
153 } NSMessage_consumer;
154
155 bool NSIsStartedConsumer();
156 void NSSetIsStartedConsumer(bool setValue);
157
158 void NSSetDiscoverProviderCb(NSProviderDiscoveredCallback cb);
159 void NSDiscoveredProvider(NSProvider * handle);
160
161 void NSSetMessagePostedCb(NSNotificationReceivedCallback  cb);
162 void NSMessagePost(NSProvider * provider, NSMessage * obj);
163
164 void NSSetNotificationSyncCb(NSSyncCallback cb);
165 void NSNotificationSync(NSProvider * provider, NSSyncInfo * sync);
166
167 char ** NSGetConsumerId();
168 void NSSetConsumerId(char * cId);
169
170 char * NSGetQuery(const char * uri);
171
172 NSTask * NSMakeTask(NSTaskType, void *);
173
174 NSResult NSConsumerPushEvent(NSTask *);
175
176 NSMessage_consumer * NSCopyMessage(NSMessage_consumer *);
177 void NSRemoveMessage(NSMessage_consumer *);
178
179 OCStackResult NSInvokeRequest(OCDoHandle * handle,
180         OCMethod method, const OCDevAddr * addr,
181         const char * queryUrl, OCPayload * payload,
182         void * callbackFunc, void * callbackData);
183
184 #ifdef __cplusplus
185 }
186 #endif // __cplusplus
187
188 #endif // _NS_CONSUMER_CONSTANTS_H_