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