Repo Merge: Moving resource API down a directory
[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 ClientCB {
36     // callback method defined in application address space
37     OCClientResponseHandler callBack;
38     // callback context data
39     void * context;
40     // callback method to delete context data
41     OCClientContextDeleter deleteCallback;
42     //  when a response is recvd with this token, above callback will be invoked
43     OCCoAPToken token;
44     // Invocation handle tied to original call to OCDoResource()
45     OCDoHandle handle;
46     // This is used to determine if all responses should be consumed or not.
47     // (For now, only pertains to OC_REST_OBSERVE_ALL Vs. OC_REST_OBSERVE functionality)
48     OCMethod method;
49     // This is the sequence identifier the server applies to the invocation tied to 'handle'.
50     uint32_t sequenceNumber;
51     // This is the request uri associated with the call back
52     unsigned char * requestUri;
53     // Struct to hold TTL info for presence
54     #ifdef WITH_PRESENCE
55     OCPresence * presence;
56     #endif
57     // next node in this list
58     struct ClientCB    *next;
59 } ClientCB;
60
61 extern struct ClientCB *cbList;
62
63 //-- AddClientCB -----------------------------------------------------------
64 /** @ingroup ocstack
65  *
66  * This method is used to add a client callback method in cbList.
67  *
68  * @param[out] clientCB
69  *              The resulting node from making this call. Null if out of memory.
70  * @param[in] cb
71  *              address to client callback function.
72  * @param[in] token
73  *              identifier for OTA CoAP comms.
74  * @param[in] handle
75  *              Masked in the public API as an 'invocation handle' - Used for callback management.
76  * @param[in] requestUri
77  *              the resource uri of the request.
78  *
79  * @brief If the handle you're looking for does not exist, the stack will reply with a RST message.
80  *
81  * @retval OC_STACK_OK for Success, otherwise some error value
82  */
83 //------------------------------------------------------------------------
84 OCStackResult AddClientCB(ClientCB** clientCB, OCCallbackData* cbData,
85         OCCoAPToken * token, OCDoHandle handle, OCMethod method,
86         unsigned char * requestUri);
87
88 //-- DeleteClientCB -----------------------------------------------------------
89 /** @ingroup ocstack
90  *
91  * This method is used to remove a callback node from cbList.
92  *
93  * @param[in] cbNode
94  *              address to client callback node.
95  */
96 //------------------------------------------------------------------------
97 void DeleteClientCB(ClientCB *cbNode);
98
99
100 //-- GetClientCB ---------------------------------------------------------
101 /** @ingroup ocstack
102  *
103  * This method is used to search a cb node in cbList.
104  *
105  * @param[in] token
106  *              token to search for.
107  * @param[in] handle
108  *              handle to search for.
109  * @param[in] requestUri
110  *              Uri to search for.
111  *
112  * @brief You can search by token OR by handle. Not both.
113  *
114  * @retval address of the node if found, otherwise NULL
115  */
116 //------------------------------------------------------------------------
117 ClientCB* GetClientCB(OCCoAPToken * token, OCDoHandle handle, unsigned char * requestUri);
118
119 //-- DeleteClientCBList --------------------------------------------------
120 /** @ingroup ocstack
121  *
122  * This method is used to clear the cbList.
123  *
124  */
125 //------------------------------------------------------------------------
126 void DeleteClientCBList();
127
128 //-- FindAndDeleteClientCB -----------------------------------------------
129 /** @ingroup ocstack
130  *
131  * This method is used to verify the presence of a cb node in cbList
132  * and then delete it.
133  *
134  * @param[in] cbNode
135  *              address to client callback node.
136  */
137 //------------------------------------------------------------------------
138 void FindAndDeleteClientCB(ClientCB * cbNode);
139
140 #endif //OC_CLIENT_CB