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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
26 #include <occoaptoken.h>
27 #include <ocresource.h>
32 typedef struct OCPresence {
33 // This is the TTL associated with presence
39 typedef struct OCMulticastNode {
42 struct OCMulticastNode * next;
45 extern OCMulticastNode * mcPresenceNodes;
47 typedef struct ClientCB {
48 // callback method defined in application address space
49 OCClientResponseHandler callBack;
50 // callback context data
52 // callback method to delete context data
53 OCClientContextDeleter deleteCallback;
54 // when a response is recvd with this token, above callback will be invoked
60 // Invocation handle tied to original call to OCDoResource()
62 // This is used to determine if all responses should be consumed or not.
63 // (For now, only pertains to OC_REST_OBSERVE_ALL Vs. OC_REST_OBSERVE functionality)
65 // This is the sequence identifier the server applies to the invocation tied to 'handle'.
66 uint32_t sequenceNumber;
67 // This is the request uri associated with the call back
68 unsigned char * requestUri;
69 // Struct to hold TTL info for presence
71 OCPresence * presence;
72 OCResourceType * filterResourceType;
74 // next node in this list
75 struct ClientCB *next;
78 extern struct ClientCB *cbList;
80 //-- AddClientCB -----------------------------------------------------------
83 * This method is used to add a client callback method in cbList.
85 * @param[out] clientCB
86 * The resulting node from making this call. Null if out of memory.
88 * address to client callback function.
90 * identifier for OTA CoAP comms.
92 * Masked in the public API as an 'invocation handle' - Used for callback management.
93 * @param[in] requestUri
94 * the resource uri of the request.
95 * @param[in] resourceType
96 * the resourceType associated with a presence request.
98 * @brief If the handle you're looking for does not exist, the stack will reply with a RST message.
100 * @retval OC_STACK_OK for Success, otherwise some error value
102 //------------------------------------------------------------------------
105 AddClientCB (ClientCB** clientCB, OCCallbackData* cbData,
106 CAToken_t * token, OCDoHandle *handle, OCMethod method,
107 unsigned char * requestUri, unsigned char * resourceTypeName);
109 AddClientCB (ClientCB** clientCB, OCCallbackData* cbData,
110 OCCoAPToken * token, OCDoHandle *handle, OCMethod method,
111 unsigned char * requestUri, unsigned char * resourceTypeName);
114 //-- DeleteClientCB -----------------------------------------------------------
117 * This method is used to remove a callback node from cbList.
120 * address to client callback node.
122 //------------------------------------------------------------------------
123 void DeleteClientCB(ClientCB *cbNode);
126 //-- GetClientCB ---------------------------------------------------------
129 * This method is used to search a cb node in cbList.
132 * token to search for.
134 * handle to search for.
135 * @param[in] requestUri
138 * @brief You can search by token OR by handle. Not both.
140 * @retval address of the node if found, otherwise NULL
142 //------------------------------------------------------------------------
144 ClientCB* GetClientCB(CAToken_t * token, OCDoHandle handle, const unsigned char * requestUri);
146 ClientCB* GetClientCB(OCCoAPToken * token, OCDoHandle handle, const unsigned char * requestUri);
151 * Inserts a new resource type filter into this clientCB node.
153 * @param cbNode - the node to add the new resourceType filter to
154 * @param resourceTypeName - the value to create the new resourceType filter from
157 * OC_STACK_OK on success
158 * OC_STACK_ERROR with invalid parameters
159 * OC_STACK_NO_MEMORY when out of memory
162 OCStackResult InsertResourceTypeFilter(ClientCB * cbNode, const char * resourceTypeName);
163 #endif // WITH_PRESENCE
165 //-- DeleteClientCBList --------------------------------------------------
168 * This method is used to clear the cbList.
171 //------------------------------------------------------------------------
172 void DeleteClientCBList();
174 //-- FindAndDeleteClientCB -----------------------------------------------
177 * This method is used to verify the presence of a cb node in cbList
178 * and then delete it.
181 * address to client callback node.
183 //------------------------------------------------------------------------
184 void FindAndDeleteClientCB(ClientCB * cbNode);
188 * This method is used to search a multicast presence node from list.
191 * the uri of the request.
193 * @return OCMulticastNode
194 * The resulting node from making this call. Null if doesn't exist.
196 //------------------------------------------------------------------------
197 OCMulticastNode* GetMCPresenceNode(const unsigned char * uri);
201 * This method is used to add a multicast presence node to the list.
203 * @param[out] outnode
204 * The resulting node from making this call. Null if out of memory.
206 * the uri of the server.
208 * current nonce for the server
210 * @return OC_STACK_OK for Success, otherwise some error value
212 //------------------------------------------------------------------------
213 OCStackResult AddMCPresenceNode(OCMulticastNode** outnode, unsigned char* uri, uint32_t nonce);
215 #endif //OC_CLIENT_CB