1 /* ****************************************************************
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 ******************************************************************/
24 * This file contains the APIs for Resource Model to use.
27 #ifndef CA_INTERFACE_H_
28 #define CA_INTERFACE_H_
31 * Connectivity Abstraction Interface APIs.
34 #include "casecurityinterface.h"
44 * Callback for bound JID
45 * @param[out] jid Boud Jabber Identifier.
47 typedef void (*CAJidBoundCallback)(char *jid);
50 * CA Remote Access information for XMPP Client
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 */
69 * Callback function to pass the connection information from CA to RI.
70 * @param[out] object remote device information.
71 * @param[out] isConnected Whether keepalive message needs to be sent.
72 * @param[out] isClient Host Mode of Operation.
74 typedef void (*CAKeepAliveConnectionCallback)(const CAEndpoint_t *object, bool isConnected,
78 * Register connection status changes callback to process KeepAlive.
79 * connection informations are delivered these callbacks.
80 * @param[in] ConnHandler Connection status changes callback.
82 void CARegisterKeepAliveHandler(CAKeepAliveConnectionCallback ConnHandler);
85 * Initialize the connectivity abstraction module.
86 * It will initialize adapters, thread pool and other modules based on the platform
87 * compilation options.
88 * @param[in] transportType transport type to initialize.
89 * @return ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_MEMORY_ALLOC_FAILED
91 CAResult_t CAInitialize(CATransportAdapter_t transportType);
94 * Terminate the connectivity abstraction module.
95 * All threads, data structures are destroyed for next initializations.
100 * Starts listening servers.
101 * This API is used by resource hosting server for listening multicast requests.
102 * Based on the adapters configurations, different kinds of servers are started.
103 * @return ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_STATUS_NOT_INITIALIZED
105 CAResult_t CAStartListeningServer();
108 * Stops the server from receiving the multicast traffic. This is used by sleeping
109 * device to not receives the multicast traffic.
110 * @return ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_STATUS_NOT_INITIALIZED
112 CAResult_t CAStopListeningServer();
115 * Starts discovery servers.
116 * This API is used by resource required clients for listening multicast requests.
117 * Based on the adapters configurations, different kinds of servers are started.
118 * @return ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_STATUS_NOT_INITIALIZED
120 CAResult_t CAStartDiscoveryServer();
123 * Register request callbacks and response callbacks.
124 * Requests and responses are delivered these callbacks.
125 * @param[in] ReqHandler Request callback ( for GET,PUT ..etc).
126 * @param[in] RespHandler Response Handler Callback.
127 * @param[in] ErrorHandler Error Handler Callback.
128 * @see CARequestCallback
129 * @see CAResponseCallback
130 * @see CAErrorCallback
132 void CARegisterHandler(CARequestCallback ReqHandler, CAResponseCallback RespHandler,
133 CAErrorCallback ErrorHandler);
136 * Create an endpoint description.
137 * @param[in] flags how the adapter should be used.
138 * @param[in] adapter which adapter to use.
139 * @param[in] addr string representation of address.
140 * @param[in] port port (for IP_ADAPTER).
141 * @param[out] object Endpoint which contains the above.
142 * @return ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_STATUS_INVALID_PARAM
143 * @remark The created Remote endpoint can be freed using CADestroyEndpoint().
144 * @see CADestroyEndpoint
146 CAResult_t CACreateEndpoint(CATransportFlags_t flags,
147 CATransportAdapter_t adapter,
150 CAEndpoint_t **object);
153 * Destroy the remote endpoint created.
154 * @param[in] object Remote Endpoint object created with CACreateEndpoint.
156 void CADestroyEndpoint(CAEndpoint_t *object);
159 * Generating the token for matching the request and response.
160 * @param[out] token Token for the request.
161 * @param[in] tokenLength length of the token.
162 * @return ::CA_STATUS_OK or ::CA_STATUS_FAILED or
163 * ::CA_MEMORY_ALLOC_FAILED or ::CA_STATUS_INVALID_PARAM
164 * @remark Token memory is destroyed by the caller using CADestroyToken().
165 * @see CADestroyToken
167 CAResult_t CAGenerateToken(CAToken_t *token, uint8_t tokenLength);
170 * Destroy the token generated by CAGenerateToken.
171 * @param[in] token token to be freed.
173 void CADestroyToken(CAToken_t token);
176 * Send control Request on a resource.
177 * @param[in] object Endpoint where the payload need to be sent.
178 * This endpoint is delivered with Request or response callback.
179 * @param[in] requestInfo Information for the request.
180 * @return ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_STATUS_NOT_INITIALIZED or
181 ::CA_SEND_FAILED or ::CA_STATUS_INVALID_PARAM or ::CA_MEMORY_ALLOC_FAILED
183 CAResult_t CASendRequest(const CAEndpoint_t *object, const CARequestInfo_t *requestInfo);
187 * @param[in] object Endpoint where the payload need to be sent.
188 * This endpoint is delivered with Request or response callback.
189 * @param[in] responseInfo Information for the response.
190 * @return ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_STATUS_NOT_INITIALIZED or
191 ::CA_SEND_FAILED or ::CA_STATUS_INVALID_PARAM or ::CA_MEMORY_ALLOC_FAILED
193 CAResult_t CASendResponse(const CAEndpoint_t *object, const CAResponseInfo_t *responseInfo);
196 * Select network to use.
197 * @param[in] interestedNetwork Connectivity Type enum.
198 * @return ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_STATUS_NOT_INITIALIZED or
199 * ::CA_NOT_SUPPORTED or ::CA_ADAPTER_NOT_ENABLED or ::CA_MEMORY_ALLOC_FAILED
201 CAResult_t CASelectNetwork(CATransportAdapter_t interestedNetwork);
204 * Select network to unuse.
205 * @param[in] nonInterestedNetwork Connectivity Type enum.
206 * @return ::CA_STATUS_OK or ::CA_NOT_SUPPORTED or ::CA_STATUS_FAILED or
207 ::CA_STATUS_NOT_INITIALIZED
209 CAResult_t CAUnSelectNetwork(CATransportAdapter_t nonInterestedNetwork);
212 * Get network information.
213 * It should be destroyed by the caller as it Get Information.
214 * @param[out] info LocalConnectivity objects
215 * @param[out] size No Of Array objects
216 * @return ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_STATUS_NOT_INITIALIZED or
217 * ::CA_STATUS_INVALID_PARAM or ::CA_MEMORY_ALLOC_FAILED
219 CAResult_t CAGetNetworkInformation(CAEndpoint_t **info, uint32_t *size);
222 * To Handle the Request or Response.
223 * @return ::CA_STATUS_OK or ::CA_STATUS_NOT_INITIALIZED
225 CAResult_t CAHandleRequestResponse();
229 * Set Remote Access information for XMPP Client.
230 * @param[in] caraInfo remote access info.
232 * @return ::CA_STATUS_OK or ::CA_STATUS_INVALID_PARAM
234 CAResult_t CASetRAInfo(const CARAInfo_t *caraInfo);
239 * This function sets uri being used for proxy.
241 * @param uri NULL terminated resource uri for CoAP-HTTP Proxy.
243 * @return ::CA_STATUS_OK or ::CA_STATUS_INVALID_PARAM
245 CAResult_t CASetProxyUri(const char *uri);
248 #ifdef WITH_PROCESS_EVENT
249 void CARegisterProcessEvent(oc_event event);
256 #endif /* CA_INTERFACE_H_ */