Update consumer logic for stopped provider.
[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 "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 #define NS_DEVICE_ID_LENGTH 37
44
45 typedef enum
46 {
47     NS_DISCOVER_DEFAULT, // will work for adapter_ip.
48     NS_DISCOVER_UDP,
49     NS_DISCOVER_TCP,
50     NS_DISCOVER_CLOUD
51 } NSConsumerDiscoverType;
52
53 typedef enum
54 {
55     NS_SELECTION_CONSUMER = 0,
56     NS_SELECTION_PROVIDER = 1
57 } NSSelector;
58
59 typedef struct NSProviderConnectionInfo
60 {
61     OCDevAddr * addr;
62
63     OCDoHandle messageHandle;
64     OCDoHandle syncHandle;
65
66     bool isCloudConnection;
67     bool isSubscribing;
68
69     struct NSProviderConnectionInfo * next;
70
71 } NSProviderConnectionInfo;
72
73 typedef struct
74 {
75     char providerId[NS_DEVICE_ID_LENGTH];
76
77     NSTopicLL * topicLL;
78
79     char * messageUri;
80     char * syncUri;
81     char * topicUri;
82
83     NSSelector accessPolicy;
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 typedef struct
100 {
101     NSSyncType status;
102     NSMessage * msg;
103
104 } NSStoreMessage;
105
106 bool NSIsStartedConsumer();
107 void NSSetIsStartedConsumer(bool setValue);
108
109 void NSSetProviderChangedCb(NSProviderStateCallback cb);
110 void NSProviderChanged(NSProvider * provider, NSProviderState response);
111
112 void NSSetMessagePostedCb(NSMessageReceivedCallback  cb);
113 void NSMessagePost(NSMessage * obj);
114
115 void NSSetNotificationSyncCb(NSSyncInfoReceivedCallback cb);
116 void NSNotificationSync(NSSyncInfo * sync);
117
118 char ** NSGetConsumerId();
119 void NSSetConsumerId(char * cId);
120
121 char * NSMakeRequestUriWithConsumerId(const char * uri);
122
123 NSTask * NSMakeTask(NSTaskType, void *);
124
125 NSResult NSConsumerPushEvent(NSTask *);
126
127 NSMessage * NSCopyMessage(NSMessage *);
128 void NSRemoveMessage(NSMessage *);
129
130 NSProviderConnectionInfo * NSCreateProviderConnections(OCDevAddr *);
131 NSProviderConnectionInfo * NSCopyProviderConnections(NSProviderConnectionInfo *);
132 void NSRemoveConnections(NSProviderConnectionInfo *);
133
134 NSProvider_internal * NSCopyProvider_internal(NSProvider_internal *);
135 NSProvider * NSCopyProvider(NSProvider_internal *);
136 void NSRemoveProvider_internal(NSProvider_internal *);
137 void NSRemoveProvider(NSProvider *);
138
139 NSSyncInfo_internal * NSCopySyncInfo(NSSyncInfo_internal *);
140 void NSRemoveSyncInfo(NSSyncInfo_internal *);
141
142 NSTopicLL * NSCopyTopicNode(NSTopicLL *);
143 void NSRemoveTopicNode(NSTopicLL *);
144 NSResult NSInsertTopicNode(NSTopicLL *, NSTopicLL *);
145
146 NSTopicLL * NSCopyTopicLL(NSTopicLL *);
147 void NSRemoveTopicLL(NSTopicLL *);
148
149 OCStackResult NSInvokeRequest(OCDoHandle * handle,
150         OCMethod method, const OCDevAddr * addr,
151         const char * queryUrl, OCPayload * payload,
152         void * callbackFunc, void * callbackData, OCConnectivityType type);
153
154 bool NSOCResultToSuccess(OCStackResult ret);
155
156 #ifdef __cplusplus
157 }
158 #endif // __cplusplus
159
160 #endif // _NS_CONSUMER_COMMON_H_