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