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 * requestInfo contains different parameters for resource model to understand about the request.
42 * @param object [OUT] Endpoint object from which the request is received. It contains endpoint
43 * address based on the connectivity type.
44 * @param requestInfo [OUT] Identifier which needs to be sent with request.
46 typedef void (*CARequestCallback)(const CARemoteEndpoint_t *object,
47 const CARequestInfo_t *requestInfo);
50 * @brief Callback function type for response delivery.
51 * responseInfor contains different parameters for resource model to understand about the request.
52 * @param object [OUT] Endpoint object from which the response is received.
53 * @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 compilation options.
62 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
64 CAResult_t CAInitialize();
67 * @brief Terminate the connectivity abstraction module.
68 * All threads, data structures are destroyed for next initializations.
73 * @brief Starts listening servers.
74 * This API is used by resource hosting server for listening multicast requests.
75 * based on the adapters configurations , different kinds of servers are started.
76 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
78 CAResult_t CAStartListeningServer();
81 * @brief Starts discovery servers.
82 * This API is used by resource required clients for listening multicast requests.
83 * based on the adapters configurations , different kinds of servers are started.
84 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
86 CAResult_t CAStartDiscoveryServer();
89 * @brief Register request callbacks and response callbacks.
90 * requests and responses are delivered these callbacks .
91 * @see CARequestCallback CAResponseCallback
92 * @param ReqHandler [IN] Request callback ( for GET,PUT ..etc)
93 * @param RespHandler [IN] Response Handler Callback
94 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
96 CAResult_t CARegisterHandler(CARequestCallback ReqHandler, CAResponseCallback RespHandler);
99 * @brief Create a Remote endpoint if the URI is available already.
100 * for FindResource-> unicast requests , this API is used.
101 * FindResource(URI)-> CACreateRemoteEndpoint , CASendRequest(GET)
102 * @param uri [IN] Absolute URI of the resource to be used to generate the Remote endpoint
103 * for ex : coap://10.11.12.13:4545/resource_uri ( for IP)
104 * coap://10:11:12:13:45:45/resource_uri ( for BT)
105 * @param object [OUT ] Endpoint object which contains the above parsed data
106 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
108 CAResult_t CACreateRemoteEndpoint(const CAURI_t uri, CARemoteEndpoint_t **object);
111 * @brief API Destroy the remote endpoint created
112 * @param object [IN] endpoint object created with CACreateRemoteEndpoint
114 void CADestroyRemoteEndpoint(CARemoteEndpoint_t *object);
117 * @brief Generating the token for the requests/response.
118 * Token memory is created and destroyed by the calle.
119 * @param token [OUT] token for the request
120 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
122 CAResult_t CAGenerateToken(CAToken_t *token);
125 * @brief Destroy the token generated by CAGenerateToken
126 * @param token [IN] token for the request
128 void CADestroyToken(CAToken_t token);
131 * @brief Find the resource in the network. This API internally sends multicast messages on the
132 * all connectivity adapters. Responses are delivered via response callbacks.
134 * @param resourceUri [IN] Uri to send multicast search request
135 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
137 CAResult_t CAFindResource(const CAURI_t resourceUri, const CAToken_t token);
140 * @brief Send control Request on a resource
141 * @param object [IN] Remote Endpoint where the payload need to be sent.
142 * This Remote endpoint is delivered with Request or response callback.
143 * @param requestInfo [IN ] information for the request.
144 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
146 CAResult_t CASendRequest(const CARemoteEndpoint_t *object, CARequestInfo_t *requestInfo);
149 * @brief Sendi the response
150 * @param object [IN] Remote Endpoint where the payload need to be sent.
151 * This Remote endpoint is delivered with Request or response callback
152 * @param responseInfo [IN ] information for the response
153 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
155 CAResult_t CASendResponse(const CARemoteEndpoint_t *object, CAResponseInfo_t *responseInfo);
158 * @brief Send notification to the remote object
159 * @param object [IN] Remote Endpoint where the payload need to be sent.
160 * This Remote endpoint is delivered with Request or response callback.
161 * @param responseInfo [IN ] information for the response.
162 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
164 CAResult_t CASendNotification(const CARemoteEndpoint_t *object, CAResponseInfo_t *responseInfo);
167 * @brief for advertise the resource
168 * @param resourceUri [IN] URI to be advertised
169 * @param options [IN] header options information
170 * @param numOptions [IN] number of options
171 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
173 CAResult_t CAAdvertiseResource(const CAURI_t resourceUri, CAToken_t token, CAHeaderOption_t* options,
177 * @brief Select network to use
178 * @param interestedNetwork [IN] Connectivity Type enum
179 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
181 CAResult_t CASelectNetwork(const uint32_t interestedNetwork);
184 * @brief Select network to unuse
185 * @param nonInterestedNetwork [IN] Connectivity Type enum
186 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
188 CAResult_t CAUnSelectNetwork(const uint32_t nonInterestedNetwork);
191 * @brief Get network information
192 * It should be destroyed by the caller as its Get Information.
193 * @param info [OUT] LocalConnectivity objects
194 * @param size [OUT] No Of Array objects
195 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
197 CAResult_t CAGetNetworkInformation(CALocalConnectivity_t **info, uint32_t *size);
200 * @brief for usage of singled threaded application.
201 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
203 CAResult_t CAHandleRequestResponse();