Merge "Implemented libcoap's tinyDTLS interface"
[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     #endif
65     // next node in this list
66     struct ClientCB    *next;
67 } ClientCB;
68
69 extern struct ClientCB *cbList;
70
71 //-- AddClientCB -----------------------------------------------------------
72 /** @ingroup ocstack
73  *
74  * This method is used to add a client callback method in cbList.
75  *
76  * @param[out] clientCB
77  *              The resulting node from making this call. Null if out of memory.
78  * @param[in] cb
79  *              address to client callback function.
80  * @param[in] token
81  *              identifier for OTA CoAP comms.
82  * @param[in] handle
83  *              Masked in the public API as an 'invocation handle' - Used for callback management.
84  * @param[in] requestUri
85  *              the resource uri of the request.
86  *
87  * @brief If the handle you're looking for does not exist, the stack will reply with a RST message.
88  *
89  * @retval OC_STACK_OK for Success, otherwise some error value
90  */
91 //------------------------------------------------------------------------
92 OCStackResult AddClientCB(ClientCB** clientCB, OCCallbackData* cbData,
93         OCCoAPToken * token, OCDoHandle handle, OCMethod method,
94         unsigned char * requestUri);
95
96 //-- DeleteClientCB -----------------------------------------------------------
97 /** @ingroup ocstack
98  *
99  * This method is used to remove a callback node from cbList.
100  *
101  * @param[in] cbNode
102  *              address to client callback node.
103  */
104 //------------------------------------------------------------------------
105 void DeleteClientCB(ClientCB *cbNode);
106
107
108 //-- GetClientCB ---------------------------------------------------------
109 /** @ingroup ocstack
110  *
111  * This method is used to search a cb node in cbList.
112  *
113  * @param[in] token
114  *              token to search for.
115  * @param[in] handle
116  *              handle to search for.
117  * @param[in] requestUri
118  *              Uri to search for.
119  *
120  * @brief You can search by token OR by handle. Not both.
121  *
122  * @retval address of the node if found, otherwise NULL
123  */
124 //------------------------------------------------------------------------
125 ClientCB* GetClientCB(OCCoAPToken * token, OCDoHandle handle, unsigned char * requestUri);
126
127 //-- DeleteClientCBList --------------------------------------------------
128 /** @ingroup ocstack
129  *
130  * This method is used to clear the cbList.
131  *
132  */
133 //------------------------------------------------------------------------
134 void DeleteClientCBList();
135
136 //-- FindAndDeleteClientCB -----------------------------------------------
137 /** @ingroup ocstack
138  *
139  * This method is used to verify the presence of a cb node in cbList
140  * and then delete it.
141  *
142  * @param[in] cbNode
143  *              address to client callback node.
144  */
145 //------------------------------------------------------------------------
146 void FindAndDeleteClientCB(ClientCB * cbNode);
147
148 /** @ingroup ocstack
149  *
150  * This method is used to search a multicast presence node from list.
151  *
152  * @param[in]  uri
153  *              the uri of the request.
154  *
155  * @return OCMulticastNode
156  *              The resulting node from making this call. Null if doesn't exist.
157  */
158 //------------------------------------------------------------------------
159 OCMulticastNode* GetMCPresenceNode(unsigned char * uri);
160
161 /** @ingroup ocstack
162  *
163  * This method is used to add a multicast presence node to the list.
164  *
165  * @param[out] outnode
166  *              The resulting node from making this call. Null if out of memory.
167  * @param[in] uri
168  *              the uri of the server.
169  * @param[in] nonce
170  *              current nonce for the server
171  *
172  * @return OC_STACK_OK for Success, otherwise some error value
173  */
174 //------------------------------------------------------------------------
175 OCStackResult AddMCPresenceNode(OCMulticastNode** outnode, unsigned char* uri, uint32_t nonce);
176
177 #endif //OC_CLIENT_CB