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