Merge branch 'master' into notification-service
[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 "NSCommon.h"
32 #include "NSStructs.h"
33 #include "ocstack.h"
34
35 #define NS_LOG_PRINTF 0
36
37 #define __NS_FILE__ ( strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__ )
38
39 const char * NS_CONVERT_LEVEL(int level);
40
41 // TODO fix ns log using oic log.
42 #ifdef TB_LOG
43 #include "logger.h"
44 #define NS_CONSUMER_LOG_V(level, format, ...) (OIC_LOG_V((level), __NS_FILE__, (format), __VA_ARGS__))
45 #define NS_CONSUMER_LOG(level, msg) (OIC_LOG((level), __NS_FILE__, (msg)))
46 #else
47 #include "logger.h"
48 #define NS_CONSUMER_LOG_V(level, format, ...) { \
49         printf("%s: %s ", NS_CONVERT_LEVEL(level), __NS_FILE__); \
50         printf((format), __VA_ARGS__); \
51         printf("\n"); }
52 #define NS_CONSUMER_LOG(level, msg) { \
53         printf("%s: %s ", NS_CONVERT_LEVEL(level), __NS_FILE__); \
54         printf((msg)); \
55         printf("\n"); }
56
57 #endif
58
59 #define NS_QOS OC_LOW_QOS
60 #define NS_RESOURCE_TYPE "oic.r.notification"
61 #define NS_RESOURCE_URI "/notification"
62 #define NS_INTERFACE_BASELINE "oic.if.baseline"
63 #define NS_INTERFACE_NOTIFICATION "oic.if.notification"
64 #define NS_RESOURCE_QUERY "/oic/res"
65
66 #define NS_DISCOVER_QUERY "/oic/res?rt=oic.r.notification"
67
68 typedef OCStackApplicationResult (*onRIResponseListener)(
69         void *, OCDoHandle, OCClientResponse *);
70
71 typedef enum
72 {
73     Read,
74     Dismiss,
75     Notification,
76 } NSConsumerMessageTypes;
77
78 typedef struct
79 {
80     // Mandatory
81     char * mId;
82     char * mTitle;
83
84     //Optional
85     char * mContentText;
86
87     OCDevAddr * addr;
88     char * syncUri;
89     NSConsumerMessageTypes type;
90 } NSMessage_consumer;
91
92 bool NSIsStartedConsumer();
93 void NSSetIsStartedConsumer(bool setValue);
94
95 void NSSetDiscoverProviderCb(NSProviderDiscoveredCallback cb);
96 void NSDiscoveredProvider(NSProvider * handle);
97
98 void NSSetNotificationPostedCb(NSNotificationReceivedCallback  cb);
99 void NSNotificationPost(NSProvider * provider, NSMessage * obj);
100
101 void NSSetNotificationSyncCb(NSSyncCallback cb);
102 void NSNotificationSync(NSProvider * provider, NSSync * sync);
103
104 onRIResponseListener NSGetResponseListener();
105 void NSSetResponseListener(onRIResponseListener cb);
106
107 NSTask * NSMakeTask(NSTaskType, void *);
108
109 NSResult NSConsumerPushEvent(NSTask *);
110
111 NSMessage_consumer * NSCopyMessage(NSMessage_consumer *);
112 void NSRemoveMessage(NSMessage_consumer *);
113
114 OCStackResult NSRequestToResourceIntrospection(OCDoHandle * handle,
115         OCMethod method, const OCDevAddr * addr,
116         const char * queryUrl, OCPayload * payload, void * callback);
117
118 #ifdef __cplusplus
119 }
120 #endif // __cplusplus
121
122 #endif // _NS_CONSUMER_CONSTANTS_H_