Updated sturcture of consumer.
[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 #define NS_QOS OC_LOW_QOS
36 #define NS_RESOURCE_TYPE "oic.r.notification"
37 #define NS_RESOURCE_URI "/notification"
38 #define NS_INTERFACE_BASELINE "oic.if.baseline"
39 #define NS_INTERFACE_NOTIFICATION "oic.if.notification"
40 #define NS_RESOURCE_QUERY "/oic/res"
41
42 #define NS_DISCOVER_QUERY "/oic/res?rt=oic.r.notification"
43
44 #define NS_VERTIFY_NOT_NULL_V(obj) { if ((obj) == NULL) \
45     { \
46         NS_LOG_V(ERROR, "%s : obj is null", __func__); \
47         return; \
48     }}
49
50 #define NS_VERTIFY_NOT_NULL(obj, retVal) { if ((obj) == NULL) \
51     { \
52         NS_LOG_V(ERROR, "%s : obj is null", __func__); \
53         return (retVal); \
54     }}
55
56 #define NS_VERTIFY_NOT_NULL_WITH_POST_CLEANING(obj, retVal, func) { \
57     if ((obj) == NULL) \
58     { \
59         NS_LOG_V(ERROR, "%s : obj is null", __func__); \
60         NS_LOG(ERROR, "execute deletion"); \
61         (func); \
62         return (retVal); \
63     }}
64
65 #define NS_VERTIFY_STACK_OK_V(obj) { OCStackResult _ret = (obj); \
66     if ( _ret != OC_STACK_OK) \
67     { \
68         NS_LOG_V(ERROR, "%s : obj is not OC_STACK_OK : %d", __func__, _ret); \
69         return; \
70     }}
71
72 #define NS_VERTIFY_STACK_OK(obj, retVal) { OCStackResult _ret = (obj); \
73     if ( _ret != OC_STACK_OK) \
74     { \
75         NS_LOG_V(ERROR, "%s : obj is not OC_STACK_OK : %d", __func__, _ret); \
76         return (retVal); \
77     }}
78
79 #define NS_VERTIFY_STACK_OK_WITH_POST_CLEANING(obj, retVal, func) { \
80     OCStackResult _ret = (obj); \
81     if ( _ret != OC_STACK_OK) \
82     { \
83         NS_LOG_V(ERROR, "%s : obj is not OC_STACK_OK : %d", __func__, _ret); \
84         (func); \
85         return (retVal); \
86     }}
87
88 typedef enum
89 {
90     Read,
91     Dismiss,
92     Notification,
93 } NSConsumerMessageTypes;
94
95 typedef struct
96 {
97     // Mandatory
98     uint64_t messageId;
99     char * providerId;
100     
101     //optional
102     NSMessageType type;
103     char * dateTime;
104     uint64_t ttl;
105     char * title;
106     char * contentText;
107     char * sourceName;
108     NSMediaContents mediaContents;
109
110     //Optional
111     OCDevAddr * addr;
112     char * syncUri;
113     NSConsumerMessageTypes messageTypes;
114 } NSMessage_consumer;
115
116 bool NSIsStartedConsumer();
117 void NSSetIsStartedConsumer(bool setValue);
118
119 void NSSetDiscoverProviderCb(NSProviderDiscoveredCallback cb);
120 void NSDiscoveredProvider(NSProvider * handle);
121
122 void NSSetNotificationPostedCb(NSNotificationReceivedCallback  cb);
123 void NSNotificationPost(NSProvider * provider, NSMessage * obj);
124
125 void NSSetNotificationSyncCb(NSSyncCallback cb);
126 void NSNotificationSync(NSProvider * provider, NSSyncInfo * sync);
127
128 NSTask * NSMakeTask(NSTaskType, void *);
129
130 NSResult NSConsumerPushEvent(NSTask *);
131
132 NSMessage_consumer * NSCopyMessage(NSMessage_consumer *);
133 void NSRemoveMessage(NSMessage_consumer *);
134
135 OCStackResult NSInvokeRequest(OCDoHandle * handle,
136         OCMethod method, const OCDevAddr * addr,
137         const char * queryUrl, OCPayload * payload,
138         void * callbackFunc, void * callbackData);
139
140 #ifdef __cplusplus
141 }
142 #endif // __cplusplus
143
144 #endif // _NS_CONSUMER_CONSTANTS_H_