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