Renamed submodule 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(obj, retVal) { if ((obj) == NULL) \
45     { \
46         NS_LOG_V(ERROR, "%s : obj is null", __func__); \
47         return (retVal); \
48     }}
49
50 #define NS_VERTIFY_NOT_NULL_WITH_POST_CLEANING(obj, retVal, func) { \
51     if ((obj) == NULL) \
52     { \
53         NS_LOG_V(ERROR, "%s : obj is null", __func__); \
54         NS_LOG(ERROR, "execute deletion"); \
55         (func); \
56         return (retVal); \
57     }}
58
59 #define NS_VERTIFY_STACK_OK(obj, retVal) { if ((obj) != OC_STACK_OK) \
60     { \
61         NS_LOG_V(ERROR, "%s : obj is not OC_STACK_OK", __func__); \
62         return (retVal); \
63     }}
64
65 typedef enum
66 {
67     Read,
68     Dismiss,
69     Notification,
70 } NSConsumerMessageTypes;
71
72 typedef struct
73 {
74     // Mandatory
75     char * mId;
76     char * mTitle;
77
78     //Optional
79     char * mContentText;
80     char * mSource;
81
82     OCDevAddr * addr;
83     char * syncUri;
84     NSConsumerMessageTypes type;
85 } NSMessage_consumer;
86
87 bool NSIsStartedConsumer();
88 void NSSetIsStartedConsumer(bool setValue);
89
90 void NSSetDiscoverProviderCb(NSProviderDiscoveredCallback cb);
91 void NSDiscoveredProvider(NSProvider * handle);
92
93 void NSSetNotificationPostedCb(NSNotificationReceivedCallback  cb);
94 void NSNotificationPost(NSProvider * provider, NSMessage * obj);
95
96 void NSSetNotificationSyncCb(NSSyncCallback cb);
97 void NSNotificationSync(NSProvider * provider, NSSync * sync);
98
99 NSTask * NSMakeTask(NSTaskType, void *);
100
101 NSResult NSConsumerPushEvent(NSTask *);
102
103 NSMessage_consumer * NSCopyMessage(NSMessage_consumer *);
104 void NSRemoveMessage(NSMessage_consumer *);
105
106 OCStackResult NSInvokeRequest(OCDoHandle * handle,
107         OCMethod method, const OCDevAddr * addr,
108         const char * queryUrl, OCPayload * payload,
109         void * callbackFunc, void * callbackData);
110
111 #ifdef __cplusplus
112 }
113 #endif // __cplusplus
114
115 #endif // _NS_CONSUMER_CONSTANTS_H_