Merge "[CA] [All] URI support , Optimization , License verification" into connectivit...
[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  *          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.
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  *          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.
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 compilation options.
61  *
62  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
63  */
64 CAResult_t CAInitialize();
65
66 /**
67  * @brief   Terminate the connectivity abstraction module.
68  *          All threads, data structures are destroyed for next initializations.
69  */
70 void CATerminate();
71
72 /**
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)
77  */
78 CAResult_t CAStartListeningServer();
79
80 /**
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)
85  */
86 CAResult_t CAStartDiscoveryServer();
87
88 /**
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)
95  */
96 CAResult_t CARegisterHandler(CARequestCallback ReqHandler, CAResponseCallback RespHandler);
97
98 /**
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
103  *                          Remote endpoint
104  *                          for ex : coap://10.11.12.13:4545/resource_uri ( for IP)
105  *                          coap://10:11:12:13:45:45/resource_uri ( for BT)
106  * @param   connectivityType    [IN]    connectivity type of the endpoint
107  * @param   object  [OUT ]  Endpoint object which contains the above parsed data
108  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
109  */
110 CAResult_t CACreateRemoteEndpoint(const CAURI_t uri,
111         const CAConnectivityType_t connectivityType, CARemoteEndpoint_t **object);
112
113 /**
114  * @brief   API Destroy the remote endpoint created
115  * @param   object  [IN]    endpoint object created with CACreateRemoteEndpoint
116  */
117 void CADestroyRemoteEndpoint(CARemoteEndpoint_t *object);
118
119 /**
120  * @brief   Generating the token for the requests/response.
121  *          Token memory is created and destroyed by the calle.
122  * @param   token   [OUT]   token for the request
123  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
124  */
125 CAResult_t CAGenerateToken(CAToken_t *token);
126
127 /**
128  * @brief   Destroy the token generated by CAGenerateToken
129  * @param   token   [IN]    token for the request
130  */
131 void CADestroyToken(CAToken_t token);
132
133 /**
134  * @brief   Find the resource in the network. This API internally sends multicast messages on the
135  *          all connectivity adapters. Responses are delivered via response callbacks.
136  *
137  * @param   resourceUri [IN]    Uri to send multicast search request
138  * @param   token   [IN]    token for the request
139  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
140  */
141 CAResult_t CAFindResource(const CAURI_t resourceUri, const CAToken_t token);
142
143 /**
144  * @brief   Send control Request on a resource
145  * @param   object      [IN]    Remote Endpoint where the payload need to be sent.
146  *                              This Remote endpoint is delivered with Request or response callback.
147  * @param   requestInfo [IN ]   information for the request.
148  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
149  */
150 CAResult_t CASendRequest(const CARemoteEndpoint_t *object, CARequestInfo_t *requestInfo);
151
152 /**
153  * @brief   Send control Request on a resource to multicast group
154  * @param   object      [IN]    Group 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 ERROR CODES ( CAResult_t error codes in cacommon.h)
158  */
159 CAResult_t CASendRequestToAll(const CAGroupEndpoint_t *object,
160                               const CARequestInfo_t *requestInfo);
161
162 /**
163  * @brief   Send the response
164  * @param   object          [IN]    Remote Endpoint where the payload need to be sent.
165  *                                  This Remote endpoint is delivered with Request or response callback
166  * @param   responseInfo    [IN ]   information for the response
167  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
168  */
169 CAResult_t CASendResponse(const CARemoteEndpoint_t *object, CAResponseInfo_t *responseInfo);
170
171 /**
172  * @brief   Send notification to the remote object
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 ERROR CODES ( CAResult_t error codes in cacommon.h)
177  */
178 CAResult_t CASendNotification(const CARemoteEndpoint_t *object,
179                               CAResponseInfo_t *responseInfo);
180
181 /**
182  * @brief   for advertise the resource
183  * @param   resourceUri [IN]    URI to be advertised
184  * @param   token   [IN]    token for the request
185  * @param   options     [IN]    header options information
186  * @param   numOptions  [IN]    number of options
187  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
188  */
189 CAResult_t CAAdvertiseResource(const CAURI_t resourceUri, CAToken_t token,
190                                CAHeaderOption_t *options, uint8_t numOptions);
191
192 /**
193  * @brief   Select network to use
194  * @param   interestedNetwork   [IN]    Connectivity Type enum
195  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
196  */
197 CAResult_t CASelectNetwork(const uint32_t interestedNetwork);
198
199 /**
200  * @brief   Select network to unuse
201  * @param   nonInterestedNetwork    [IN]    Connectivity Type enum
202  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
203  */
204 CAResult_t CAUnSelectNetwork(const uint32_t nonInterestedNetwork);
205
206 /**
207  * @brief   Get network information
208  *          It should be destroyed by the caller as its Get Information.
209  * @param   info    [OUT]   LocalConnectivity objects
210  * @param   size    [OUT]   No Of Array objects
211  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
212  */
213 CAResult_t CAGetNetworkInformation(CALocalConnectivity_t **info, uint32_t *size);
214
215 /**
216  * @brief   for usage of singled threaded application.
217  * @return   CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
218  */
219 CAResult_t CAHandleRequestResponse();
220
221 #ifdef __cplusplus
222 } /* extern "C" */
223 #endif
224
225 #endif