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)(CARemoteEndpoint_t* object, CARequestInfo_t* requestInfo);
49 * @brief Callback function type for response delivery.
50 * responseInfor contains different parameters for resource model to understand about the request.
51 * @param object [OUT] Endpoint object from which the response is received.
52 * @param responseInfo [OUT] Identifier which needs to be mapped with response.
54 typedef void (*CAResponseCallback)(CARemoteEndpoint_t* object, CAResponseInfo_t* responseInfo);
57 * @brief Initialize the connectivity abstraction module.
58 * It will initialize adapters, thread pool and other modules based on the platform compilation options.
60 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
62 CAResult_t CAInitialize();
65 * @brief Terminate the connectivity abstraction module.
66 * All threads, data structures are destroyed for next initializations.
71 * @brief Starts listening servers.
72 * This API is used by resource hosting server for listening multicast requests.
73 * based on the adapters configurations , different kinds of servers are started.
74 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
76 CAResult_t CAStartListeningServer();
79 * @brief Starts discovery servers.
80 * This API is used by resource required clients for listening multicast requests.
81 * based on the adapters configurations , different kinds of servers are started.
82 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
84 CAResult_t CAStartDiscoveryServer();
87 * @brief Register request callbacks and response callbacks.
88 * requests and responses are delivered these callbacks .
89 * @see CARequestCallback CAResponseCallback
90 * @param ReqHandler [IN] Request callback ( for GET,PUT ..etc)
91 * @param RespHandler [IN] Response Handler Callback
92 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
94 CAResult_t CARegisterHandler(CARequestCallback ReqHandler, CAResponseCallback RespHandler);
97 * @brief Create a Remote endpoint if the URI is available already.
98 * for FindResource-> unicast requests , this API is used.
99 * FindResource(URI)-> CACreateRemoteEndpoint , CASendRequest(GET)
100 * @param uri [IN] Absolute URI of the resource to be used to generate the Remote endpoint
101 * for ex : coap://10.11.12.13:4545/resource_uri ( for IP)
102 * coap://10:11:12:13:45:45/resource_uri ( for BT)
103 * @param object [OUT ] Endpoint object which contains the above parsed data
104 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
106 CAResult_t CACreateRemoteEndpoint(const CAURI_t uri, CARemoteEndpoint_t** object);
109 * @brief API Destroy the remote endpoint created
110 * @param object [IN] endpoint object created with CACreateRemoteEndpoint
112 void CADestroyRemoteEndpoint(CARemoteEndpoint_t* object);
115 * @brief Generating the token for the requests/response.
116 * Token memory is created and destroyed by the calle.
117 * @param token [OUT] token for the request
118 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
120 CAResult_t CAGenerateToken(CAToken_t* token);
123 * @brief Destroy the token generated by CAGenerateToken
124 * @param token [IN] token for the request
126 void CADestroyToken(CAToken_t token);
129 * @brief Find the resource in the network. This API internally sends multicast messages on the
130 * all connectivity adapters. Responses are delivered via response callbacks.
132 * @param resourceUri [IN] Uri to send multicast search request
133 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
135 CAResult_t CAFindResource(const CAURI_t resourceUri);
138 * @brief Send control Request on a resource
139 * @param object [IN] Remote Endpoint where the payload need to be sent.
140 * This Remote endpoint is delivered with Request or response callback.
141 * @param requestInfo [IN ] information for the request.
142 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
144 CAResult_t CASendRequest(const CARemoteEndpoint_t* object, CARequestInfo_t* requestInfo);
147 * @brief Sendi the response
148 * @param object [IN] Remote Endpoint where the payload need to be sent.
149 * This Remote endpoint is delivered with Request or response callback
150 * @param responseInfo [IN ] information for the response
151 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
153 CAResult_t CASendResponse(const CARemoteEndpoint_t* object, CAResponseInfo_t* responseInfo);
156 * @brief Send notification to the remote object
157 * @param object [IN] Remote Endpoint where the payload need to be sent.
158 * This Remote endpoint is delivered with Request or response callback.
159 * @param responseInfo [IN ] information for the response.
160 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
162 CAResult_t CASendNotification(const CARemoteEndpoint_t* object, CAResponseInfo_t* responseInfo);
165 * @brief for advertise the resource
166 * @param resourceUri [IN] URI to be advertised
167 * @param options [IN] header options information
168 * @param numOptions [IN] number of options
169 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
171 CAResult_t CAAdvertiseResource(const CAURI_t resourceUri, CAHeaderOption_t* options,
175 * @brief Select network to use
176 * @param interestedNetwork [IN] Connectivity Type enum
177 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
179 CAResult_t CASelectNetwork(const uint32_t interestedNetwork);
182 * @brief Select network to unuse
183 * @param nonInterestedNetwork [IN] Connectivity Type enum
184 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
186 CAResult_t CAUnSelectNetwork(const uint32_t nonInterestedNetwork);
189 * @brief Get network information
190 * It should be destroyed by the caller as its Get Information.
191 * @param info [OUT] LocalConnectivity objects
192 * @param size [OUT] No Of Array objects
193 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
195 CAResult_t CAGetNetworkInformation(CALocalConnectivityt_t **info, uint32_t* size);
198 * @brief for usage of singled threaded application.
199 * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
201 CAResult_t CAHandleRequestResponse();