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