1 //******************************************************************
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
27 #include <ocresource.h>
31 #include "occoaptoken.h"
34 typedef struct OCPresence {
35 // This is the TTL associated with presence
41 typedef struct OCMulticastNode {
44 struct OCMulticastNode * next;
47 extern OCMulticastNode * mcPresenceNodes;
49 typedef struct ClientCB {
50 // callback method defined in application address space
51 OCClientResponseHandler callBack;
52 // callback context data
54 // callback method to delete context data
55 OCClientContextDeleter deleteCallback;
56 // when a response is recvd with this token, above callback will be invoked
62 // Invocation handle tied to original call to OCDoResource()
64 // This is used to determine if all responses should be consumed or not.
65 // (For now, only pertains to OC_REST_OBSERVE_ALL Vs. OC_REST_OBSERVE functionality)
67 // This is the sequence identifier the server applies to the invocation tied to 'handle'.
68 uint32_t sequenceNumber;
69 // This is the request uri associated with the call back
70 unsigned char * requestUri;
71 // Struct to hold TTL info for presence
73 OCPresence * presence;
74 OCResourceType * filterResourceType;
76 // next node in this list
77 struct ClientCB *next;
80 extern struct ClientCB *cbList;
82 //-- AddClientCB -----------------------------------------------------------
85 * This method is used to add a client callback method in cbList.
87 * @param[out] clientCB
88 * The resulting node from making this call. Null if out of memory.
90 * address to client callback function.
92 * identifier for OTA CoAP comms.
94 * Masked in the public API as an 'invocation handle' - Used for callback management.
95 * @param[in] requestUri
96 * the resource uri of the request.
97 * @param[in] resourceType
98 * the resourceType associated with a presence request.
100 * @brief If the handle you're looking for does not exist, the stack will reply with a RST message.
102 * @retval OC_STACK_OK for Success, otherwise some error value
104 //------------------------------------------------------------------------
107 AddClientCB (ClientCB** clientCB, OCCallbackData* cbData,
108 CAToken_t * token, OCDoHandle *handle, OCMethod method,
109 unsigned char * requestUri, unsigned char * resourceTypeName);
111 AddClientCB (ClientCB** clientCB, OCCallbackData* cbData,
112 OCCoAPToken * token, OCDoHandle *handle, OCMethod method,
113 unsigned char * requestUri, unsigned char * resourceTypeName);
116 //-- DeleteClientCB -----------------------------------------------------------
119 * This method is used to remove a callback node from cbList.
122 * address to client callback node.
124 //------------------------------------------------------------------------
125 void DeleteClientCB(ClientCB *cbNode);
128 //-- GetClientCB ---------------------------------------------------------
131 * This method is used to search a cb node in cbList.
134 * token to search for.
136 * handle to search for.
137 * @param[in] requestUri
140 * @brief You can search by token OR by handle. Not both.
142 * @retval address of the node if found, otherwise NULL
144 //------------------------------------------------------------------------
146 ClientCB* GetClientCB(const CAToken_t * token, OCDoHandle handle, const unsigned char * requestUri);
148 ClientCB* GetClientCB(OCCoAPToken * token, OCDoHandle handle, const unsigned char * requestUri);
153 * Inserts a new resource type filter into this clientCB node.
155 * @param cbNode - the node to add the new resourceType filter to
156 * @param resourceTypeName - the value to create the new resourceType filter from
159 * OC_STACK_OK on success
160 * OC_STACK_ERROR with invalid parameters
161 * OC_STACK_NO_MEMORY when out of memory
164 OCStackResult InsertResourceTypeFilter(ClientCB * cbNode, const char * resourceTypeName);
165 #endif // WITH_PRESENCE
167 //-- DeleteClientCBList --------------------------------------------------
170 * This method is used to clear the cbList.
173 //------------------------------------------------------------------------
174 void DeleteClientCBList();
176 //-- FindAndDeleteClientCB -----------------------------------------------
179 * This method is used to verify the presence of a cb node in cbList
180 * and then delete it.
183 * address to client callback node.
185 //------------------------------------------------------------------------
186 void FindAndDeleteClientCB(ClientCB * cbNode);
190 * This method is used to search a multicast presence node from list.
193 * the uri of the request.
195 * @return OCMulticastNode
196 * The resulting node from making this call. Null if doesn't exist.
198 //------------------------------------------------------------------------
199 OCMulticastNode* GetMCPresenceNode(const unsigned char * uri);
203 * This method is used to add a multicast presence node to the list.
205 * @param[out] outnode
206 * The resulting node from making this call. Null if out of memory.
208 * the uri of the server.
210 * current nonce for the server
212 * @return OC_STACK_OK for Success, otherwise some error value
214 //------------------------------------------------------------------------
215 OCStackResult AddMCPresenceNode(OCMulticastNode** outnode, unsigned char* uri, uint32_t nonce);
217 #endif //OC_CLIENT_CB