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 ******************************************************************/
23 * @brief This file contains the APIs for Resource Model to use
26 #ifndef __CA_INTERFACE_H_
27 #define __CA_INTERFACE_H_
30 * Connectivity Abstraction Interface Description APIs.
40 * @brief Callback function type for request delivery.
41 * @param object [OUT] Endpoint object from which the request is received. It contains
42 * endpoint address based on the connectivity type.
43 * @param requestInfo [OUT] Info for resource model to understand about the request.
46 typedef void (*CARequestCallback)(const CARemoteEndpoint_t *object,
47 const CARequestInfo_t *requestInfo);
50 * @brief Callback function type for response delivery.
51 * @param object [OUT] Endpoint object from which the response is received.
52 * @param responseInfo [OUT] Identifier which needs to be mapped with response.
55 typedef void (*CAResponseCallback)(const CARemoteEndpoint_t *object,
56 const CAResponseInfo_t *responseInfo);
59 * @brief Initialize the connectivity abstraction module.
60 * It will initialize adapters, thread pool and other modules based on the platform
61 * compilation options.
63 * @return #CA_STATUS_OK or Appropriate error code
65 CAResult_t CAInitialize();
68 * @brief Terminate the connectivity abstraction module.
69 * All threads, data structures are destroyed for next initializations.
75 * @brief Starts listening servers.
76 * This API is used by resource hosting server for listening multicast requests.
77 * Based on the adapters configurations, different kinds of servers are started.
78 * @return #CA_STATUS_OK or Appropriate error code
80 CAResult_t CAStartListeningServer();
83 * @brief Starts discovery servers.
84 * This API is used by resource required clients for listening multicast requests.
85 * Based on the adapters configurations, different kinds of servers are started.
86 * @return #CA_STATUS_OK or Appropriate error code
88 CAResult_t CAStartDiscoveryServer();
91 * @brief Register request callbacks and response callbacks.
92 * Requests and responses are delivered these callbacks .
93 * @param ReqHandler [IN] Request callback ( for GET,PUT ..etc)
94 * @param RespHandler [IN] Response Handler Callback
95 * @see CARequestCallback
96 * @see CAResponseCallback
98 void CARegisterHandler(CARequestCallback ReqHandler, CAResponseCallback RespHandler);
101 * @brief Create a Remote endpoint if the URI is available already.
102 * This is a Helper function which can be used before calling
103 * CASendRequest / CASendNotification.
104 * @param uri [IN] Absolute URI of the resource to be used to generate the
106 * \n For ex : coap://10.11.12.13:4545/resource_uri ( for IP)
107 * \n coap://10:11:12:13:45:45/resource_uri ( for BT)
108 * @param connectivityType [IN] Connectivity type of the endpoint
109 * @param object [OUT] Endpoint object which contains the above parsed data
110 * @return #CA_STATUS_OK or Appropriate error code
111 * @remark The created Remote endpoint can be freed using CADestroyRemoteEndpoint() API.
112 * @see CADestroyRemoteEndpoint
114 CAResult_t CACreateRemoteEndpoint(const CAURI_t uri,
115 const CAConnectivityType_t connectivityType,
116 CARemoteEndpoint_t **object);
119 * @brief Destroy the remote endpoint created
120 * @param object [IN] Remote Endpoint object created with CACreateRemoteEndpoint
123 void CADestroyRemoteEndpoint(CARemoteEndpoint_t *object);
126 * @brief Generating the token for matching the request and response.
127 * @param token [OUT] Token for the request
128 * @return #CA_STATUS_OK or Appropriate error code
129 * @remark Token memory is destroyed by the caller using CADestroyToken().
130 * @see CADestroyToken
132 CAResult_t CAGenerateToken(CAToken_t *token);
135 * @brief Destroy the token generated by CAGenerateToken
136 * @param token [IN] Token for the request
139 void CADestroyToken(CAToken_t token);
142 * @brief Find the resource in the network. This API internally sends multicast messages on all
143 * selected connectivity adapters. Responses are delivered via response callbacks.
145 * @param resourceUri [IN] Uri to send multicast search request. Must contain only relative
146 * path of Uri to be search.
147 * @param token [IN] Token for the request
148 * @return #CA_STATUS_OK or Appropriate error code
150 CAResult_t CAFindResource(const CAURI_t resourceUri, const CAToken_t token);
153 * @brief Send control Request on a resource
154 * @param object [IN] Remote Endpoint where the payload need to be sent.
155 * This Remote endpoint is delivered with Request or response callback.
156 * @param requestInfo [IN] Information for the request.
157 * @return #CA_STATUS_OK or Appropriate error code
159 CAResult_t CASendRequest(const CARemoteEndpoint_t *object, CARequestInfo_t *requestInfo);
162 * @brief Send control Request on a resource to multicast group
163 * @param object [IN] Group Endpoint where the payload need to be sent.
164 * This Remote endpoint is delivered with Request or response callback.
165 * @param requestInfo [IN] Information for the request.
166 * @return #CA_STATUS_OK or Appropriate error code
168 CAResult_t CASendRequestToAll(const CAGroupEndpoint_t *object,
169 const CARequestInfo_t *requestInfo);
172 * @brief Send the response
173 * @param object [IN] Remote Endpoint where the payload need to be sent.
174 * This Remote endpoint is delivered with Request or response callback
175 * @param responseInfo [IN] Information for the response
176 * @return #CA_STATUS_OK or Appropriate error code
178 CAResult_t CASendResponse(const CARemoteEndpoint_t *object, CAResponseInfo_t *responseInfo);
181 * @brief Send notification to the remote object
182 * @param object [IN] Remote Endpoint where the payload need to be sent.
183 * This Remote endpoint is delivered with Request or response callback.
184 * @param responseInfo [IN] Information for the response.
185 * @return #CA_STATUS_OK or Appropriate error code
187 CAResult_t CASendNotification(const CARemoteEndpoint_t *object,
188 CAResponseInfo_t *responseInfo);
191 * @brief To advertise the resource
192 * @param resourceUri [IN] URI to be advertised
193 * @param token [IN] Token for the request
194 * @param options [IN] Header options information
195 * @param numOptions [IN] Number of options
196 * @return #CA_STATUS_OK or Appropriate error code
198 CAResult_t CAAdvertiseResource(const CAURI_t resourceUri, CAToken_t token,
199 CAHeaderOption_t *options, uint8_t numOptions);
202 * @brief Select network to use
203 * @param interestedNetwork [IN] Connectivity Type enum
204 * @return #CA_STATUS_OK or Appropriate error code
206 CAResult_t CASelectNetwork(const uint32_t interestedNetwork);
209 * @brief Select network to unuse
210 * @param nonInterestedNetwork [IN] Connectivity Type enum
211 * @return #CA_STATUS_OK or Appropriate error code
213 CAResult_t CAUnSelectNetwork(const uint32_t nonInterestedNetwork);
216 * @brief Get network information
217 * It should be destroyed by the caller as it Get Information.
218 * @param info [OUT] LocalConnectivity objects
219 * @param size [OUT] No Of Array objects
220 * @return #CA_STATUS_OK or Appropriate error code
222 CAResult_t CAGetNetworkInformation(CALocalConnectivity_t **info, uint32_t *size);
225 * @brief To Handle the Request or Response
226 * @return #CA_STATUS_OK or Appropriate error code
228 CAResult_t CAHandleRequestResponse();