Corrected @file tags and restored 'Files' section.
[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
23  *
24  * This file contains the APIs for Resource Model to use.
25  */
26
27 #ifndef __CA_INTERFACE_H_
28 #define __CA_INTERFACE_H_
29
30 /**
31  * Connectivity Abstraction Interface Description APIs.
32  */
33 #include "cacommon.h"
34
35 #ifdef __cplusplus
36 extern "C"
37 {
38 #endif
39
40 /**
41  * @brief   Callback function type for request delivery.
42  *          requestInfo contains different parameters for resource model to understand about the request.
43  * @param   object      [OUT]   Endpoint object from which the request is received. It contains endpoint
44  *                              address based on the connectivity type.
45  * @param   requestInfo [OUT]   Identifier which needs to be sent with request.
46  */
47 typedef void (*CARequestCallback)(CARemoteEndpoint_t* object, 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)(CARemoteEndpoint_t* object, CAResponseInfo_t* responseInfo);
56
57 /**
58  * @brief   Initialize the connectivity abstraction module.
59  *          It will initialize adapters, thread pool and other modules based on the platform compilation options.
60  *
61  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
62  */
63 CAResult_t CAInitialize();
64
65 /**
66  * @brief   Terminate the connectivity abstraction module.
67  *          All threads, data structures are destroyed for next initializations.
68  */
69 void CATerminate();
70
71 /**
72  * @brief   Starts listening servers.
73  *          This API is used by resource hosting server for listening multicast requests.
74  *          based on the adapters configurations , different kinds of servers are started.
75  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
76  */
77 CAResult_t CAStartListeningServer();
78
79 /**
80  * @brief   Starts discovery servers.
81  *          This API is used by resource required clients for listening multicast requests.
82  *          based on the adapters configurations , different kinds of servers are started.
83  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
84  */
85 CAResult_t CAStartDiscoveryServer();
86
87 /**
88  * @brief   Register request callbacks and response callbacks.
89  *          requests and responses are delivered these callbacks .
90  * @see     CARequestCallback CAResponseCallback
91  * @param   ReqHandler   [IN]    Request callback ( for GET,PUT ..etc)
92  * @param   RespHandler  [IN]    Response Handler Callback
93  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
94  */
95 CAResult_t CARegisterHandler(CARequestCallback ReqHandler, CAResponseCallback RespHandler);
96
97 /**
98  * @brief   Create a Remote endpoint if the URI is available already.
99  *          for FindResource-> unicast requests , this API is used.
100  *          FindResource(URI)-> CACreateRemoteEndpoint , CASendRequest(GET)
101  * @param   uri     [IN]    Absolute URI of the resource to be used to generate the Remote endpoint
102  *                          for ex : coap://10.11.12.13:4545/resource_uri ( for IP)
103  *                          coap://10:11:12:13:45:45/resource_uri ( for BT)
104  * @param   object  [OUT ]  Endpoint object which contains the above parsed data
105  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
106  */
107 CAResult_t CACreateRemoteEndpoint(const CAURI_t uri, CARemoteEndpoint_t** object);
108
109 /**
110  * @brief   API Destroy the remote endpoint created
111  * @param   object  [IN]    endpoint object created with CACreateRemoteEndpoint
112  */
113 void CADestroyRemoteEndpoint(CARemoteEndpoint_t* object);
114
115 /**
116  * @brief   Generating the token for the requests/response.
117  *          Token memory is created and destroyed by the calle.
118  * @param   token   [OUT]   token for the request
119  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
120  */
121 CAResult_t CAGenerateToken(CAToken_t* token);
122
123 /**
124  * @brief   Destroy the token generated by CAGenerateToken
125  * @param   token   [IN]    token for the request
126  */
127 void CADestroyToken(CAToken_t token);
128
129 /**
130  * @brief   Find the resource in the network. This API internally sends multicast messages on the
131  *          all connectivity adapters. Responses are delivered via response callbacks.
132  *
133  * @param   resourceUri [IN]    Uri to send multicast search request
134  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
135  */
136 CAResult_t CAFindResource(const CAURI_t resourceUri);
137
138 /**
139  * @brief   Send control Request on a resource
140  * @param   object      [IN]    Remote Endpoint where the payload need to be sent.
141  *                              This Remote endpoint is delivered with Request or response callback.
142  * @param   requestInfo [IN ]   information for the request.
143  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
144  */
145 CAResult_t CASendRequest(const CARemoteEndpoint_t* object, CARequestInfo_t* requestInfo);
146
147 /**
148  * @brief   Sendi the response
149  * @param   object          [IN]    Remote Endpoint where the payload need to be sent.
150  *                                  This Remote endpoint is delivered with Request or response callback
151  * @param   responseInfo    [IN ]   information for the response
152  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
153  */
154 CAResult_t CASendResponse(const CARemoteEndpoint_t* object, CAResponseInfo_t* responseInfo);
155
156 /**
157  * @brief   Send notification to the remote object
158  * @param   object          [IN]    Remote Endpoint where the payload need to be sent.
159  *                                  This Remote endpoint is delivered with Request or response callback.
160  * @param   responseInfo    [IN ]   information for the response.
161  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
162  */
163 CAResult_t CASendNotification(const CARemoteEndpoint_t* object, CAResponseInfo_t* responseInfo);
164
165 /**
166  * @brief   for advertise the resource
167  * @param   resourceUri [IN]    URI to be advertised
168  * @param   options     [IN]    header options information
169  * @param   numOptions  [IN]    number of options
170  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
171  */
172 CAResult_t CAAdvertiseResource(const CAURI_t resourceUri, CAHeaderOption_t* options,
173         uint8_t numOptions);
174
175 /**
176  * @brief   Select network to use
177  * @param   interestedNetwork   [IN]    Connectivity Type enum
178  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
179  */
180 CAResult_t CASelectNetwork(const uint32_t interestedNetwork);
181
182 /**
183  * @brief   Select network to unuse
184  * @param   nonInterestedNetwork    [IN]    Connectivity Type enum
185  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
186  */
187 CAResult_t CAUnSelectNetwork(const uint32_t nonInterestedNetwork);
188
189 /**
190  * @brief   Get network information
191  *          It should be destroyed by the caller as its Get Information.
192  * @param   info    [OUT]   LocalConnectivity objects
193  * @param   size    [OUT]   No Of Array objects
194  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
195  */
196 CAResult_t CAGetNetworkInformation(CALocalConnectivityt_t **info, uint32_t* size);
197
198 /**
199  * @brief   for usage of singled threaded application.
200  * @return   CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
201  */
202 CAResult_t CAHandleRequestResponse();
203
204 #ifdef __cplusplus
205 } /* extern "C" */
206 #endif
207
208 #endif