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"
41 * Data structure For presence Discovery.
42 * This is the TTL associated with presence.
44 typedef struct OCPresence
55 #endif // WITH_PRESENCE
58 * Forward declaration of resource type.
60 typedef struct resourcetype_t OCResourceType;
64 * Data structure for holding client's callback context, methods and Time to Live,
65 * connectivity Types, presence and resource type, request uri etc.
68 typedef struct ClientCB {
69 /** callback method defined in application address space. */
70 OCClientResponseHandler callBack;
72 /** callback context data. */
75 /** callback method to delete context data. */
76 OCClientContextDeleter deleteCallback;
78 /** when a response is recvd with this token, above callback will be invoked. */
81 /** a response is recvd with this token length.*/
84 /** Invocation handle tied to original call to OCDoResource().*/
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).*/
91 /** This is the sequence identifier the server applies to the invocation tied to 'handle'.*/
92 uint32_t sequenceNumber;
94 /** The canonical form of the request uri associated with the call back.*/
97 /** Remote address complete.*/
100 /** Struct to hold TTL info for presence.*/
103 OCPresence * presence;
104 OCResourceType * filterResourceType;
107 /** The connectivity type on which the request was sent on.*/
108 OCConnectivityType conType;
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.*/
116 /** next node in this list.*/
117 struct ClientCB *next;
121 * Linked list of ClientCB node.
123 extern struct ClientCB *cbList;
127 * This method is used to add a client callback method in cbList.
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.
141 * @note If the handle you're looking for does not exist, the stack will reply with a RST message.
143 * @return OC_STACK_OK for Success, otherwise some error value.
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);
153 * This method is used to remove a callback node from cbList.
155 * @param[in] cbNode Address to client callback node.
157 void DeleteClientCB(ClientCB *cbNode);
162 * This method is used to search and retrieve a cb node in cbList.
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.
169 * @brief You can search by token OR by handle, but not both.
171 * @return address of the node if found, otherwise NULL
173 ClientCB* GetClientCB(const CAToken_t token, uint8_t tokenLength,
174 OCDoHandle handle, const char * requestUri);
178 * Inserts a new resource type filter into this cb node.
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.
184 * OC_STACK_OK on success
185 * OC_STACK_ERROR with invalid parameters
186 * OC_STACK_NO_MEMORY when out of memory
189 OCStackResult InsertResourceTypeFilter(ClientCB * cbNode, char * resourceTypeName);
190 #endif // WITH_PRESENCE
194 * This method is used to clear the cbList.
197 void DeleteClientCBList();
201 * This method is used to verify the presence of a cb node in cbList
202 * and then delete it.
204 * @param[in] cbNode Address to client callback node.
206 void FindAndDeleteClientCB(ClientCB * cbNode);
208 #endif //OC_CLIENT_CB