replace : iotivity -> iotivity-sec
[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_COMMON_H_
22 #define _NS_CONSUMER_COMMON_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_HIGH_QOS
36 #define NS_RESOURCE_TYPE "x.org.iotivity.notification"
37 #define NS_RESOURCE_URI "/notification"
38 #define NS_INTERFACE_BASELINE "oic.if.baseline"
39 #define NS_RESOURCE_QUERY "/oic/res"
40
41 #define NS_DISCOVER_QUERY "/oic/res?rt=x.org.iotivity.notification"
42 #define NS_DEVICE_ID_LENGTH 37
43
44 typedef enum
45 {
46     NS_DISCOVER_DEFAULT, // will work for adapter_ip.
47     NS_DISCOVER_UDP,
48     NS_DISCOVER_TCP,
49     NS_DISCOVER_CLOUD
50 } NSConsumerDiscoverType;
51
52 typedef enum
53 {
54     NS_SELECTION_CONSUMER = 0,
55     NS_SELECTION_PROVIDER = 1
56 } NSSelector;
57
58 typedef struct NSProviderConnectionInfo
59 {
60     OCDevAddr * addr;
61
62     OCDoHandle messageHandle;
63     OCDoHandle syncHandle;
64
65     bool isCloudConnection;
66     bool isSubscribing;
67
68     struct NSProviderConnectionInfo * next;
69
70 } NSProviderConnectionInfo;
71
72 typedef struct
73 {
74     char providerId[NS_DEVICE_ID_LENGTH];
75
76     NSTopicLL * topicLL;
77
78     char * messageUri;
79     char * syncUri;
80     char * topicUri;
81
82     NSSelector accessPolicy;
83     NSProviderState state;
84
85     NSProviderConnectionInfo * connection;
86
87 } NSProvider_internal;
88
89 typedef struct
90 {
91     uint64_t messageId;
92     char providerId[NS_DEVICE_ID_LENGTH];
93     NSSyncType state;
94
95     NSProviderConnectionInfo * connection;
96
97 } NSSyncInfo_internal;
98
99 bool NSIsStartedConsumer();
100 void NSSetIsStartedConsumer(bool setValue);
101
102 void NSSetProviderChangedCb(NSProviderStateCallback cb);
103 void NSProviderChanged(NSProvider * provider, NSProviderState response);
104
105 void NSSetMessagePostedCb(NSMessageReceivedCallback  cb);
106 void NSMessagePost(NSMessage * obj);
107
108 void NSSetNotificationSyncCb(NSSyncInfoReceivedCallback cb);
109 void NSNotificationSync(NSSyncInfo * sync);
110
111 char ** NSGetConsumerId();
112 void NSSetConsumerId(char * cId);
113
114 char * NSMakeRequestUriWithConsumerId(const char * uri);
115
116 NSTask * NSMakeTask(NSTaskType, void *);
117 NSResult NSConsumerPushEvent(NSTask *);
118
119 NSMessage * NSGetMessage(OCRepPayload * payload);
120 NSMessage * NSCopyMessage(NSMessage *);
121 void NSRemoveMessage(NSMessage *);
122
123 void NSGetProviderPostClean(
124         char * pId, char * mUri, char * sUri, char * tUri, NSProviderConnectionInfo * connection);
125
126 NSProvider_internal * NSGetProvider(OCClientResponse * clientResponse);
127 NSProviderConnectionInfo * NSCreateProviderConnections(OCDevAddr *);
128 NSProviderConnectionInfo * NSCopyProviderConnections(NSProviderConnectionInfo *);
129 void NSRemoveConnections(NSProviderConnectionInfo *);
130
131 NSProvider_internal * NSCopyProvider_internal(NSProvider_internal *);
132 NSProvider * NSCopyProvider(NSProvider_internal *);
133 void NSRemoveProvider_internal(void *);
134 void NSRemoveProvider(NSProvider *);
135
136 NSTopicLL * NSCopyTopicNode(NSTopicLL *);
137 void NSRemoveTopicNode(NSTopicLL *);
138 NSResult NSInsertTopicNode(NSTopicLL *, NSTopicLL *);
139
140 NSTopicLL * NSCopyTopicLL(NSTopicLL *);
141 void NSRemoveTopicLL(NSTopicLL *);
142
143 OCStackResult NSInvokeRequest(OCDoHandle * handle,
144         OCMethod method, const OCDevAddr * addr,
145         const char * queryUrl, OCPayload * payload,
146         void * callbackFunc, void * callbackData,
147         OCClientContextDeleter cd, OCConnectivityType type);
148
149 bool NSOCResultToSuccess(OCStackResult ret);
150
151 #ifdef __cplusplus
152 }
153 #endif // __cplusplus
154
155 #endif // _NS_CONSUMER_COMMON_H_