Revert "Development of CoAP-HTTP Proxy"
[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 (*CAKeepAliveConnectionCallback)(const CAEndpoint_t *object, bool isConnected);
73
74 /**
75  * Register connection status changes callback to process KeepAlive.
76  * connection informations are delivered these callbacks.
77  * @param[in]   ConnHandler     Connection status changes callback.
78  */
79 void CARegisterKeepAliveHandler(CAKeepAliveConnectionCallback ConnHandler);
80 #endif
81 /**
82  * Initialize the connectivity abstraction module.
83  * It will initialize adapters, thread pool and other modules based on the platform
84  * compilation options.
85  *
86  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_MEMORY_ALLOC_FAILED
87  */
88 CAResult_t CAInitialize();
89
90 /**
91  * Terminate the connectivity abstraction module.
92  * All threads, data structures are destroyed for next initializations.
93  */
94 void CATerminate();
95
96 /**
97  * Starts listening servers.
98  * This API is used by resource hosting server for listening multicast requests.
99  * Based on the adapters configurations, different kinds of servers are started.
100  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_STATUS_NOT_INITIALIZED
101  */
102 CAResult_t CAStartListeningServer();
103
104 /**
105  * Stops the server from receiving the multicast traffic. This is used by sleeping
106  * device to not receives the multicast traffic.
107  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_STATUS_NOT_INITIALIZED
108  */
109 CAResult_t CAStopListeningServer();
110
111 /**
112  * Starts discovery servers.
113  * This API is used by resource required clients for listening multicast requests.
114  * Based on the adapters configurations, different kinds of servers are started.
115  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_STATUS_NOT_INITIALIZED
116  */
117 CAResult_t CAStartDiscoveryServer();
118
119 /**
120  * Register request callbacks and response callbacks.
121  *          Requests and responses are delivered these callbacks.
122  * @param[in]   ReqHandler    Request callback ( for GET,PUT ..etc).
123  * @param[in]   RespHandler   Response Handler Callback.
124  * @param[in]   ErrorHandler  Error Handler Callback.
125  * @see     CARequestCallback
126  * @see     CAResponseCallback
127  * @see     CAErrorCallback
128  */
129 void CARegisterHandler(CARequestCallback ReqHandler, CAResponseCallback RespHandler,
130                        CAErrorCallback ErrorHandler);
131
132 /**
133  * Create an endpoint description.
134  * @param[in]   flags                 how the adapter should be used.
135  * @param[in]   adapter               which adapter to use.
136  * @param[in]   addr                  string representation of address.
137  * @param[in]   port                  port (for IP_ADAPTER).
138  * @param[out]  object                Endpoint which contains the above.
139  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_STATUS_INVALID_PARAM
140  * @remark  The created Remote endpoint can be freed using CADestroyEndpoint().
141  * @see     CADestroyEndpoint
142  */
143 CAResult_t CACreateEndpoint(CATransportFlags_t flags,
144                             CATransportAdapter_t adapter,
145                             const char *addr,
146                             uint16_t port,
147                             CAEndpoint_t **object);
148
149 /**
150  * Destroy the remote endpoint created.
151  * @param[in]   object   Remote Endpoint object created with CACreateEndpoint.
152  */
153 void CADestroyEndpoint(CAEndpoint_t *object);
154
155 /**
156  * Generating the token for matching the request and response.
157  * @param[out]  token            Token for the request.
158  * @param[in]   tokenLength      length of the token.
159  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED or
160  *          ::CA_MEMORY_ALLOC_FAILED or ::CA_STATUS_INVALID_PARAM
161  * @remark  Token memory is destroyed by the caller using CADestroyToken().
162  * @see     CADestroyToken
163  */
164 CAResult_t CAGenerateToken(CAToken_t *token, uint8_t tokenLength);
165
166 /**
167  * Destroy the token generated by CAGenerateToken.
168  * @param[in]   token    token to be freed.
169  */
170 void CADestroyToken(CAToken_t token);
171
172 /**
173  * Send control Request on a resource.
174  * @param[in]   object       Endpoint where the payload need to be sent.
175  *                           This endpoint is delivered with Request or response callback.
176  * @param[in]   requestInfo  Information for the request.
177  * @return ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_STATUS_NOT_INITIALIZED or
178            ::CA_SEND_FAILED or ::CA_STATUS_INVALID_PARAM or ::CA_MEMORY_ALLOC_FAILED
179  */
180 CAResult_t CASendRequest(const CAEndpoint_t *object, const CARequestInfo_t *requestInfo);
181
182 /**
183  * Send the response.
184  * @param[in]   object           Endpoint where the payload need to be sent.
185  *                               This endpoint is delivered with Request or response callback.
186  * @param[in]   responseInfo     Information for the response.
187  * @return ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_STATUS_NOT_INITIALIZED or
188            ::CA_SEND_FAILED or ::CA_STATUS_INVALID_PARAM or ::CA_MEMORY_ALLOC_FAILED
189  */
190 CAResult_t CASendResponse(const CAEndpoint_t *object, const CAResponseInfo_t *responseInfo);
191
192 /**
193  * Select network to use.
194  * @param[in]   interestedNetwork    Connectivity Type enum.
195  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_STATUS_NOT_INITIALIZED or
196  *          ::CA_NOT_SUPPORTED or ::CA_ADAPTER_NOT_ENABLED or ::CA_MEMORY_ALLOC_FAILED
197  */
198 CAResult_t CASelectNetwork(CATransportAdapter_t interestedNetwork);
199
200 /**
201  * Select network to unuse.
202  * @param[in]   nonInterestedNetwork     Connectivity Type enum.
203  * @return  ::CA_STATUS_OK or ::CA_NOT_SUPPORTED or ::CA_STATUS_FAILED or
204             ::CA_STATUS_NOT_INITIALIZED
205  */
206 CAResult_t CAUnSelectNetwork(CATransportAdapter_t nonInterestedNetwork);
207
208 /**
209  * Get network information.
210  * It should be destroyed by the caller as it Get Information.
211  * @param[out]   info     LocalConnectivity objects
212  * @param[out]   size     No Of Array objects
213  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_STATUS_NOT_INITIALIZED or
214  *          ::CA_STATUS_INVALID_PARAM or ::CA_MEMORY_ALLOC_FAILED
215  */
216 CAResult_t CAGetNetworkInformation(CAEndpoint_t **info, uint32_t *size);
217
218 /**
219  * To Handle the Request or Response.
220  * @return   ::CA_STATUS_OK or ::CA_STATUS_NOT_INITIALIZED
221  */
222 CAResult_t CAHandleRequestResponse();
223
224 #ifdef RA_ADAPTER
225 /**
226  * Set Remote Access information for XMPP Client.
227  * @param[in]   caraInfo          remote access info.
228  *
229  * @return  ::CA_STATUS_OK or ::CA_STATUS_INVALID_PARAM
230  */
231 CAResult_t CASetRAInfo(const CARAInfo_t *caraInfo);
232 #endif
233
234
235
236 #ifdef __cplusplus
237 } /* extern "C" */
238 #endif
239
240 #endif /* CA_INTERFACE_H_ */
241