1 //*******************************************************************
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
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
11 // http://www.apache.org/licenses/LICENSE-2.0
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.
20 // ******************************************************************/
26 * This file contains the definition and types for client's callback mode and functions.
36 #include "ocresource.h"
40 * Data structure For presence Discovery.
41 * This is the TTL associated with presence.
43 typedef struct OCPresence
56 * Forward declaration of resource type.
58 typedef struct resourcetype_t OCResourceType;
62 * Data structure for holding client's callback context, methods and Time to Live,
63 * connectivity Types, presence and resource type, request uri etc.
66 typedef struct ClientCB {
67 /** callback method defined in application address space. */
68 OCClientResponseHandler callBack;
70 /** callback context data. */
73 /** callback method to delete context data. */
74 OCClientContextDeleter deleteCallback;
76 /** when a response is recvd with this token, above callback will be invoked. */
79 /** a response is recvd with this token length.*/
82 /** Invocation handle tied to original call to OCDoResource().*/
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).*/
89 /** This is the sequence identifier the server applies to the invocation tied to 'handle'.*/
90 uint32_t sequenceNumber;
92 /** The canonical form of the request uri associated with the call back.*/
95 /** Remote address complete.*/
98 /** Struct to hold TTL info for presence.*/
101 OCPresence * presence;
102 OCResourceType * filterResourceType;
105 /** The connectivity type on which the request was sent on.*/
106 OCConnectivityType conType;
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.*/
114 /** next node in this list.*/
115 struct ClientCB *next;
119 * Linked list of ClientCB node.
121 extern struct ClientCB *cbList;
125 * This method is used to add a client callback method in cbList.
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.
139 * @note If the handle you're looking for does not exist, the stack will reply with a RST message.
141 * @return OC_STACK_OK for Success, otherwise some error value.
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);
151 * This method is used to remove a callback node from cbList.
153 * @param[in] cbNode Address to client callback node.
155 void DeleteClientCB(ClientCB *cbNode);
160 * This method is used to search and retrieve a cb node in cbList.
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.
167 * @brief You can search by token OR by handle, but not both.
169 * @return address of the node if found, otherwise NULL
171 ClientCB* GetClientCB(const CAToken_t token, uint8_t tokenLength,
172 OCDoHandle handle, const char * requestUri);
176 * Inserts a new resource type filter into this cb node.
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.
182 * OC_STACK_OK on success
183 * OC_STACK_ERROR with invalid parameters
184 * OC_STACK_NO_MEMORY when out of memory
187 OCStackResult InsertResourceTypeFilter(ClientCB * cbNode, char * resourceTypeName);
188 #endif // WITH_PRESENCE
192 * This method is used to clear the cbList.
195 void DeleteClientCBList();
199 * This method is used to verify the presence of a cb node in cbList
200 * and then delete it.
202 * @param[in] cbNode Address to client callback node.
204 void FindAndDeleteClientCB(ClientCB * cbNode);
206 #endif //OC_CLIENT_CB