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