IoT-243 Connectivity Abstraction single-threaded module missing definition for CASend...
[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 cainterface.h
23  * @brief This file contains the APIs for Resource Model to use
24  */
25
26 #ifndef __CA_INTERFACE_H_
27 #define __CA_INTERFACE_H_
28
29 /**
30  * Connectivity Abstraction Interface Description APIs.
31  */
32 #include "cacommon.h"
33
34 #ifdef __cplusplus
35 extern "C"
36 {
37 #endif
38
39 /**
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.
44  * @return  NONE
45  */
46 typedef void (*CARequestCallback)(const CARemoteEndpoint_t *object,
47                                   const CARequestInfo_t *requestInfo);
48
49 /**
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.
53  * @return  NONE
54  */
55 typedef void (*CAResponseCallback)(const CARemoteEndpoint_t *object,
56                                    const CAResponseInfo_t *responseInfo);
57
58 /**
59  * @brief   Initialize the connectivity abstraction module.
60  *          It will initialize adapters, thread pool and other modules based on the platform
61  *          compilation options.
62  *
63  * @return  #CA_STATUS_OK or Appropriate error code
64  */
65 CAResult_t CAInitialize();
66
67 /**
68  * @brief   Terminate the connectivity abstraction module.
69  *          All threads, data structures are destroyed for next initializations.
70  * @return  NONE
71  */
72 void CATerminate();
73
74 /**
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
79  */
80 CAResult_t CAStartListeningServer();
81
82 /**
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
87  */
88 CAResult_t CAStartDiscoveryServer();
89
90 /**
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
97  */
98 void CARegisterHandler(CARequestCallback ReqHandler, CAResponseCallback RespHandler);
99
100 /**
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
105  *                                    Remote endpoint
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
113  */
114 CAResult_t CACreateRemoteEndpoint(const CAURI_t uri,
115                                   const CAConnectivityType_t connectivityType,
116                                   CARemoteEndpoint_t **object);
117
118 /**
119  * @brief   Destroy the remote endpoint created
120  * @param   object  [IN] Remote Endpoint object created with CACreateRemoteEndpoint
121  * @return  NONE
122  */
123 void CADestroyRemoteEndpoint(CARemoteEndpoint_t *object);
124
125 /**
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
131  */
132 CAResult_t CAGenerateToken(CAToken_t *token);
133
134 /**
135  * @brief   Destroy the token generated by CAGenerateToken
136  * @param   token   [IN] Token for the request
137  * @return  NONE
138  */
139 void CADestroyToken(CAToken_t token);
140
141 /**
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.
144  *
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
149  */
150 CAResult_t CAFindResource(const CAURI_t resourceUri, const CAToken_t token);
151
152 /**
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
158  */
159 CAResult_t CASendRequest(const CARemoteEndpoint_t *object, CARequestInfo_t *requestInfo);
160
161 /**
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
167  */
168 CAResult_t CASendRequestToAll(const CAGroupEndpoint_t *object,
169                               const CARequestInfo_t *requestInfo);
170
171 /**
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
177  */
178 CAResult_t CASendResponse(const CARemoteEndpoint_t *object, CAResponseInfo_t *responseInfo);
179
180 /**
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
186  */
187 CAResult_t CASendNotification(const CARemoteEndpoint_t *object,
188                               CAResponseInfo_t *responseInfo);
189
190 /**
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
197  */
198 CAResult_t CAAdvertiseResource(const CAURI_t resourceUri, CAToken_t token,
199                                CAHeaderOption_t *options, uint8_t numOptions);
200
201 /**
202  * @brief   Select network to use
203  * @param   interestedNetwork   [IN] Connectivity Type enum
204  * @return  #CA_STATUS_OK or Appropriate error code
205  */
206 CAResult_t CASelectNetwork(const uint32_t interestedNetwork);
207
208 /**
209  * @brief   Select network to unuse
210  * @param   nonInterestedNetwork    [IN] Connectivity Type enum
211  * @return  #CA_STATUS_OK or Appropriate error code
212  */
213 CAResult_t CAUnSelectNetwork(const uint32_t nonInterestedNetwork);
214
215 /**
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
221  */
222 CAResult_t CAGetNetworkInformation(CALocalConnectivity_t **info, uint32_t *size);
223
224 /**
225  * @brief    To Handle the Request or Response
226  * @return   #CA_STATUS_OK or Appropriate error code
227  */
228 CAResult_t CAHandleRequestResponse();
229
230 #ifdef __cplusplus
231 } /* extern "C" */
232 #endif
233
234 #endif