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