keepalive for coap over tcp
[platform/upstream/iotivity.git] / resource / csdk / connectivity / api / cainterface.h
1 /* ****************************************************************
2  *
3  * Copyright 2014 Samsung Electronics 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  * @file
23  *
24  * This file contains the APIs for Resource Model to use.
25  */
26
27 #ifndef CA_INTERFACE_H_
28 #define CA_INTERFACE_H_
29
30 /**
31  * Connectivity Abstraction Interface APIs.
32  */
33 #include "cacommon.h"
34 #include "casecurityinterface.h"
35
36 #ifdef __cplusplus
37 extern "C"
38 {
39 #endif
40
41 #ifdef RA_ADAPTER
42
43 /**
44  * Callback for bound JID
45  * @param[out]   jid           Boud Jabber Identifier.
46  */
47 typedef void (*CAJidBoundCallback)(char *jid);
48
49 /**
50  * CA Remote Access information for XMPP Client
51  *
52  */
53 typedef struct
54 {
55     char *hostName;     /**< XMPP server hostname */
56     uint16_t port;      /**< XMPP server serivce port */
57     char *xmppDomain;  /**< XMPP login domain */
58     char *userName;     /**< login username */
59     char *password;     /**< login password */
60     char *resource;     /**< specific resource for login */
61     char *userJid;     /**< specific JID for login */
62     CAJidBoundCallback jidBoundCallback;  /**< callback when JID bound */
63 } CARAInfo_t;
64
65 #endif //RA_ADAPTER
66
67 #ifdef TCP_ADAPTER
68 /**
69  * Callback function to pass the connection information from CA to RI.
70  * @param[out]   object           remote device information.
71  */
72 typedef void (*CAKeepAliveConnectedCallback)(const CAEndpoint_t *object);
73
74 /**
75  * Callback function to pass the disconnection information from CA to RI.
76  * @param[out]   object           remote device information.
77  */
78 typedef void (*CAKeepAliveDisconnectedCallback)(const CAEndpoint_t *object);
79
80 /**
81  * Register connected callback and disconnected callback to process KeepAlive.
82  * connection informations are delivered these callbacks.
83  * @param[in]   ConnHandler     Connected callback.
84  * @param[in]   DisconnHandler  Disconnected Callback.
85  */
86 void CARegisterKeepAliveHandler(CAKeepAliveConnectedCallback ConnHandler,
87                                 CAKeepAliveDisconnectedCallback DisconnHandler);
88 #endif
89 /**
90  * Initialize the connectivity abstraction module.
91  * It will initialize adapters, thread pool and other modules based on the platform
92  * compilation options.
93  *
94  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_MEMORY_ALLOC_FAILED
95  */
96 CAResult_t CAInitialize();
97
98 /**
99  * Terminate the connectivity abstraction module.
100  * All threads, data structures are destroyed for next initializations.
101  */
102 void CATerminate();
103
104 /**
105  * Starts listening servers.
106  * This API is used by resource hosting server for listening multicast requests.
107  * Based on the adapters configurations, different kinds of servers are started.
108  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED
109  */
110 CAResult_t CAStartListeningServer();
111
112 /**
113  * Stops the server from receiving the multicast traffic. This is used by sleeping
114  * device to not receives the multicast traffic.
115  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED
116  */
117 CAResult_t CAStopListeningServer();
118
119 /**
120  * Starts discovery servers.
121  * This API is used by resource required clients for listening multicast requests.
122  * Based on the adapters configurations, different kinds of servers are started.
123  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED
124  */
125 CAResult_t CAStartDiscoveryServer();
126
127 /**
128  * Register request callbacks and response callbacks.
129  *          Requests and responses are delivered these callbacks.
130  * @param[in]   ReqHandler    Request callback ( for GET,PUT ..etc).
131  * @param[in]   RespHandler   Response Handler Callback.
132  * @see     CARequestCallback
133  * @see     CAResponseCallback
134  * @see     CAErrorCallback
135  */
136 void CARegisterHandler(CARequestCallback ReqHandler, CAResponseCallback RespHandler,
137                        CAErrorCallback ErrorHandler);
138
139 /**
140  * Create an endpoint description.
141  * @param[in]   flags                 how the adapter should be used.
142  * @param[in]   adapter               which adapter to use.
143  * @param[in]   addr                  string representation of address.
144  * @param[in]   port                  port (for IP_ADAPTER).
145  * @param[in]   endpoint              Endpoint which contains the above.
146  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED
147  * @remark  The created Remote endpoint can be freed using CADestroyEndpoint().
148  * @see     CADestroyEndpoint
149  */
150 CAResult_t CACreateEndpoint(CATransportFlags_t flags,
151                             CATransportAdapter_t adapter,
152                             const char *addr,
153                             uint16_t port,
154                             CAEndpoint_t **object);
155
156 /**
157  * Destroy the remote endpoint created.
158  * @param[in]   object   Remote Endpoint object created with CACreateEndpoint.
159  */
160 void CADestroyEndpoint(CAEndpoint_t *object);
161
162 /**
163  * Generating the token for matching the request and response.
164  * @param[in]   token            Token for the request.
165  * @param[in]   tokenLength      length of the token.
166  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED or
167  *          ::CA_MEMORY_ALLOC_FAILED or ::CA_STATUS_NOT_INITIALIZED
168  * @remark  Token memory is destroyed by the caller using CADestroyToken().
169  * @see     CADestroyToken
170  */
171 CAResult_t CAGenerateToken(CAToken_t *token, uint8_t tokenLength);
172
173 /**
174  * Destroy the token generated by CAGenerateToken.
175  * @param[in]   token    token to be freed.
176  */
177 void CADestroyToken(CAToken_t token);
178
179 /**
180  * Send control Request on a resource.
181  * @param[in]   object       Endpoint where the payload need to be sent.
182  *                           This endpoint is delivered with Request or response callback.
183  * @param[in]   requestInfo  Information for the request.
184  * @return  ::CA_STATUS_OK ::CA_STATUS_FAILED ::CA_MEMORY_ALLOC_FAILED
185  */
186 CAResult_t CASendRequest(const CAEndpoint_t *object, const CARequestInfo_t *requestInfo);
187
188 /**
189  * Send the response.
190  * @param[in]   object           Endpoint where the payload need to be sent.
191  *                               This endpoint is delivered with Request or response callback.
192  * @param[in]   responseInfo     Information for the response.
193  * @return  ::CA_STATUS_OK or  ::CA_STATUS_FAILED or ::CA_MEMORY_ALLOC_FAILED
194  */
195 CAResult_t CASendResponse(const CAEndpoint_t *object, const CAResponseInfo_t *responseInfo);
196
197 /**
198  * Select network to use.
199  * @param[in]   interestedNetwork    Connectivity Type enum.
200  * @return  ::CA_STATUS_OK or ::CA_NOT_SUPPORTED or
201  *          ::CA_STATUS_FAILED or ::CA_NOT_SUPPORTED
202  */
203 CAResult_t CASelectNetwork(CATransportAdapter_t interestedNetwork);
204
205 /**
206  * Select network to unuse.
207  * @param[in]   nonInterestedNetwork     Connectivity Type enum.
208  * @return  ::CA_STATUS_OK or ::CA_NOT_SUPPORTED or ::CA_STATUS_FAILED
209  */
210 CAResult_t CAUnSelectNetwork(CATransportAdapter_t nonInterestedNetwork);
211
212 /**
213  * Get network information.
214  * It should be destroyed by the caller as it Get Information.
215  * @param[out]   info     LocalConnectivity objects
216  * @param[out]   size     No Of Array objects
217  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED or
218  *          ::CA_STATUS_INVALID_PARAM or ::CA_MEMORY_ALLOC_FAILED
219  */
220 CAResult_t CAGetNetworkInformation(CAEndpoint_t **info, uint32_t *size);
221
222 /**
223  * To Handle the Request or Response.
224  * @return   ::CA_STATUS_OK
225  */
226 CAResult_t CAHandleRequestResponse();
227
228 #ifdef RA_ADAPTER
229 /**
230  * Set Remote Access information for XMPP Client.
231  * @param[in]   caraInfo          remote access info.
232  *
233  * @return  ::CA_STATUS_OK
234  */
235 CAResult_t CASetRAInfo(const CARAInfo_t *caraInfo);
236 #endif
237
238
239
240 #ifdef __cplusplus
241 } /* extern "C" */
242 #endif
243
244 #endif /* CA_INTERFACE_H_ */
245