Fix build warnings
[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 #ifndef OC_CLIENT_CB
23 #define OC_CLIENT_CB
24
25 #include <ocstack.h>
26
27 #include <ocresource.h>
28 #ifdef CA_INT
29 #include "cacommon.h"
30 #else
31 #include "occoaptoken.h"
32 #endif
33
34 typedef struct OCPresence {
35     // This is the TTL associated with presence
36     uint32_t TTL;
37     uint32_t * timeOut;
38     uint32_t TTLlevel;
39 }OCPresence;
40
41 typedef struct OCMulticastNode {
42     unsigned char * uri;
43     uint32_t nonce;
44     struct OCMulticastNode * next;
45 } OCMulticastNode;
46
47 extern OCMulticastNode * mcPresenceNodes;
48
49 typedef struct ClientCB {
50     // callback method defined in application address space
51     OCClientResponseHandler callBack;
52     // callback context data
53     void * context;
54     // callback method to delete context data
55     OCClientContextDeleter deleteCallback;
56     //  when a response is recvd with this token, above callback will be invoked
57 #ifdef CA_INT
58     CAToken_t token;
59 #else // CA_INT
60     OCCoAPToken token;
61 #endif // CA_INT
62     // Invocation handle tied to original call to OCDoResource()
63     OCDoHandle handle;
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)
66     OCMethod method;
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
72     #ifdef WITH_PRESENCE
73     OCPresence * presence;
74     OCResourceType * filterResourceType;
75     #endif
76     // next node in this list
77     struct ClientCB    *next;
78 } ClientCB;
79
80 extern struct ClientCB *cbList;
81
82 //-- AddClientCB -----------------------------------------------------------
83 /** @ingroup ocstack
84  *
85  * This method is used to add a client callback method in cbList.
86  *
87  * @param[out] clientCB
88  *              The resulting node from making this call. Null if out of memory.
89  * @param[in] cb
90  *              address to client callback function.
91  * @param[in] token
92  *              identifier for OTA CoAP comms.
93  * @param[in] handle
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.
99  *
100  * @brief If the handle you're looking for does not exist, the stack will reply with a RST message.
101  *
102  * @retval OC_STACK_OK for Success, otherwise some error value
103  */
104 //------------------------------------------------------------------------
105 OCStackResult
106 #ifdef CA_INT
107 AddClientCB (ClientCB** clientCB, OCCallbackData* cbData,
108              CAToken_t * token, OCDoHandle *handle, OCMethod method,
109              unsigned char * requestUri, unsigned char * resourceTypeName);
110 #else // CA_INT
111 AddClientCB (ClientCB** clientCB, OCCallbackData* cbData,
112              OCCoAPToken * token, OCDoHandle *handle, OCMethod method,
113              unsigned char * requestUri, unsigned char * resourceTypeName);
114 #endif // CA_INT
115
116 //-- DeleteClientCB -----------------------------------------------------------
117 /** @ingroup ocstack
118  *
119  * This method is used to remove a callback node from cbList.
120  *
121  * @param[in] cbNode
122  *              address to client callback node.
123  */
124 //------------------------------------------------------------------------
125 void DeleteClientCB(ClientCB *cbNode);
126
127
128 //-- GetClientCB ---------------------------------------------------------
129 /** @ingroup ocstack
130  *
131  * This method is used to search a cb node in cbList.
132  *
133  * @param[in] token
134  *              token to search for.
135  * @param[in] handle
136  *              handle to search for.
137  * @param[in] requestUri
138  *              Uri to search for.
139  *
140  * @brief You can search by token OR by handle. Not both.
141  *
142  * @retval address of the node if found, otherwise NULL
143  */
144 //------------------------------------------------------------------------
145 #ifdef CA_INT
146 ClientCB* GetClientCB(const CAToken_t * token, OCDoHandle handle, const unsigned char * requestUri);
147 #else // CA_INT
148 ClientCB* GetClientCB(OCCoAPToken * token, OCDoHandle handle, const unsigned char * requestUri);
149 #endif // CA_INT
150
151
152 /**
153  * Inserts a new resource type filter into this clientCB node.
154  *
155  * @param cbNode - the node to add the new resourceType filter to
156  * @param resourceTypeName - the value to create the new resourceType filter from
157  *
158  * @return
159  *      OC_STACK_OK on success
160  *      OC_STACK_ERROR with invalid parameters
161  *      OC_STACK_NO_MEMORY when out of memory
162  */
163 #ifdef WITH_PRESENCE
164 OCStackResult InsertResourceTypeFilter(ClientCB * cbNode, const char * resourceTypeName);
165 #endif // WITH_PRESENCE
166
167 //-- DeleteClientCBList --------------------------------------------------
168 /** @ingroup ocstack
169  *
170  * This method is used to clear the cbList.
171  *
172  */
173 //------------------------------------------------------------------------
174 void DeleteClientCBList();
175
176 //-- FindAndDeleteClientCB -----------------------------------------------
177 /** @ingroup ocstack
178  *
179  * This method is used to verify the presence of a cb node in cbList
180  * and then delete it.
181  *
182  * @param[in] cbNode
183  *              address to client callback node.
184  */
185 //------------------------------------------------------------------------
186 void FindAndDeleteClientCB(ClientCB * cbNode);
187
188 /** @ingroup ocstack
189  *
190  * This method is used to search a multicast presence node from list.
191  *
192  * @param[in]  uri
193  *              the uri of the request.
194  *
195  * @return OCMulticastNode
196  *              The resulting node from making this call. Null if doesn't exist.
197  */
198 //------------------------------------------------------------------------
199 OCMulticastNode* GetMCPresenceNode(const unsigned char * uri);
200
201 /** @ingroup ocstack
202  *
203  * This method is used to add a multicast presence node to the list.
204  *
205  * @param[out] outnode
206  *              The resulting node from making this call. Null if out of memory.
207  * @param[in] uri
208  *              the uri of the server.
209  * @param[in] nonce
210  *              current nonce for the server
211  *
212  * @return OC_STACK_OK for Success, otherwise some error value
213  */
214 //------------------------------------------------------------------------
215 OCStackResult AddMCPresenceNode(OCMulticastNode** outnode, unsigned char* uri, uint32_t nonce);
216
217 #endif //OC_CLIENT_CB