Imported Upstream version 0.9.1
[platform/upstream/iotivity.git] / resource / csdk / stack / include / internal / occlientcb.h
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Mobile Communications GmbH 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
22 #ifndef OC_CLIENT_CB
23 #define OC_CLIENT_CB
24
25 #include "ocstack.h"
26
27 #include "ocresource.h"
28 #include "cacommon.h"
29
30 typedef struct OCPresence
31 {
32     // This is the TTL associated with presence
33     uint32_t TTL;
34     uint32_t * timeOut;
35     uint32_t TTLlevel;
36 } OCPresence;
37
38 typedef struct OCMulticastNode
39 {
40     char * uri;
41     uint32_t nonce;
42     struct OCMulticastNode * next;
43 } OCMulticastNode;
44
45 typedef struct resourcetype_t OCResourceType;
46
47 typedef struct ClientCB {
48     // callback method defined in application address space
49     OCClientResponseHandler callBack;
50     // callback context data
51     void * context;
52     // callback method to delete context data
53     OCClientContextDeleter deleteCallback;
54     //  when a response is recvd with this token, above callback will be invoked
55     CAToken_t token;
56     // a response is recvd with this token length
57     uint8_t tokenLength;
58     // Invocation handle tied to original call to OCDoResource()
59     OCDoHandle handle;
60     // This is used to determine if all responses should be consumed or not.
61     // (For now, only pertains to OC_REST_OBSERVE_ALL Vs. OC_REST_OBSERVE functionality)
62     OCMethod method;
63     // This is the sequence identifier the server applies to the invocation tied to 'handle'.
64     uint32_t sequenceNumber;
65     // This is the request uri associated with the call back
66     char * requestUri;
67     // Struct to hold TTL info for presence
68     #ifdef WITH_PRESENCE
69     OCPresence * presence;
70     OCResourceType * filterResourceType;
71     #endif
72     // The connectivity type on which the request was sent on.
73     OCConnectivityType conType;
74     // The TTL for this callback. Holds the time till when this callback can
75     // still be used. TTL is set to 0 when the callback is for presence and observe.
76     // Presence has ttl mechanism in the "presence" member of this struct and observes
77     // can be explicitly cancelled.
78     uint32_t TTL;
79     // next node in this list
80     struct ClientCB    *next;
81 } ClientCB;
82
83 extern struct ClientCB *cbList;
84
85 /** @ingroup ocstack
86  *
87  * This method is used to add a client callback method in cbList.
88  *
89  * @param[out] clientCB
90  *              The resulting node from making this call. Null if out of memory.
91  * @param[in] cbData
92  *              address to client callback function.
93  * @param[in] token
94  *              identifier for OTA CoAP comms.
95  * @param[in] handle
96  *              Masked in the public API as an 'invocation handle' - Used for callback management.
97  * @param[in] method
98  *              OCMethod via which this client callback is expected to operate
99  * @param[in] requestUri
100  *              the resource uri of the request.
101  * @param[in] resourceType
102  *              the resourceType associated with a presence request.
103  * @param[in] conType
104  *              the connectivity type on which the associated request for this clientCB was sent on.
105  * @param[in] ttl
106  *              time to live in coap_ticks for the callback.
107  * @brief If the handle you're looking for does not exist, the stack will reply with a RST message.
108  *
109  * @return OC_STACK_OK for Success, otherwise some error value
110  */
111 OCStackResult
112 AddClientCB (ClientCB** clientCB, OCCallbackData* cbData,
113              CAToken_t token, uint8_t tokenLength,
114              OCDoHandle *handle, OCMethod method,
115              char * requestUri, char * resourceTypeName, OCConnectivityType conType, uint32_t ttl);
116
117 /** @ingroup ocstack
118  *
119  * This method is used to remove a callback node from cbList.
120  *
121  * @param[in] cbNode
122  *              address to client callback node.
123  */
124 void DeleteClientCB(ClientCB *cbNode);
125
126
127 /** @ingroup ocstack
128  *
129  * This method is used to search and retrieve a cb node in cbList.
130  *
131  * @param[in] token
132  *              token to search for.
133  * @param[in] handle
134  *              handle to search for.
135  * @param[in] requestUri
136  *              Uri to search for.
137  *
138  * @brief You can search by token OR by handle, but not both.
139  *
140  * @return address of the node if found, otherwise NULL
141  */
142 ClientCB* GetClientCB(const CAToken_t token, uint8_t tokenLength,
143         OCDoHandle handle, const char * requestUri);
144
145 /**
146  * Inserts a new resource type filter into this cb node.
147  *
148  * @param[in] cbNode
149  *              the node to add the new resourceType filter to
150  * @param[in] resourceTypeName
151  *              the value to create the new resourceType filter from
152  *
153  * @return
154  *      OC_STACK_OK on success
155  *      OC_STACK_ERROR with invalid parameters
156  *      OC_STACK_NO_MEMORY when out of memory
157  */
158 #ifdef WITH_PRESENCE
159 OCStackResult InsertResourceTypeFilter(ClientCB * cbNode, char * resourceTypeName);
160 #endif // WITH_PRESENCE
161
162 /** @ingroup ocstack
163  *
164  * This method is used to clear the cbList.
165  *
166  */
167 void DeleteClientCBList();
168
169 /** @ingroup ocstack
170  *
171  * This method is used to verify the presence of a cb node in cbList
172  * and then delete it.
173  *
174  * @param[in] cbNode
175  *              address to client callback node.
176  */
177 void FindAndDeleteClientCB(ClientCB * cbNode);
178
179 /** @ingroup ocstack
180  *
181  * This method is used to search a multicast presence node from list.
182  *
183  * @param[in]  uri
184  *              the uri of the request.
185  *
186  * @return OCMulticastNode
187  *              The resulting node from making this call. Null if doesn't exist.
188  */
189 //------------------------------------------------------------------------
190 OCMulticastNode* GetMCPresenceNode(const char * uri);
191
192 /** @ingroup ocstack
193  *
194  * This method is used to add a multicast presence node to the list.
195  *
196  * @param[out] outnode
197  *              The resulting node from making this call. Null if out of memory.
198  * @param[in] uri
199  *              the uri of the server.
200  * @param[in] nonce
201  *              current nonce for the server
202  *
203  * @return OC_STACK_OK for Success, otherwise some error value
204  */
205 //------------------------------------------------------------------------
206 OCStackResult AddMCPresenceNode(OCMulticastNode** outnode, char* uri, uint32_t nonce);
207
208 #endif //OC_CLIENT_CB
209