Fixed klockwork memory leaks and modified the logs
[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 __WITH_DTLS__
35 #include "ocsecurityconfig.h"
36 #endif
37
38 #ifdef __cplusplus
39 extern "C"
40 {
41 #endif
42
43 /**
44  * @brief   Callback function type for request delivery.
45  * @param   object      [OUT] Endpoint object from which the request is received. It contains
46  *                            endpoint address based on the connectivity type.
47  * @param   requestInfo [OUT] Info for resource model to understand about the request.
48  * @return  NONE
49  */
50 typedef void (*CARequestCallback)(const CARemoteEndpoint_t *object,
51                                   const CARequestInfo_t *requestInfo);
52
53 /**
54  * @brief   Callback function type for response delivery.
55  * @param   object          [OUT] Endpoint object from which the response is received.
56  * @param   responseInfo    [OUT] Identifier which needs to be mapped with response.
57  * @return  NONE
58  */
59 typedef void (*CAResponseCallback)(const CARemoteEndpoint_t *object,
60                                    const CAResponseInfo_t *responseInfo);
61
62 #ifdef __WITH_DTLS__
63 /**
64  * @brief   Callback function type for getting DTLS credentials.
65  * @param   credInfo          [OUT] DTLS credentials info
66  * @return  NONE
67  */
68 typedef void (*CAGetDTLSCredentialsHandler)(OCDtlsPskCredsBlob **credInfo);
69 #endif //__WITH_DTLS__
70
71 /**
72  * @brief   Initialize the connectivity abstraction module.
73  *          It will initialize adapters, thread pool and other modules based on the platform
74  *          compilation options.
75  *
76  * @return  #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
77  */
78 CAResult_t CAInitialize();
79
80 /**
81  * @brief   Terminate the connectivity abstraction module.
82  *          All threads, data structures are destroyed for next initializations.
83  * @return  NONE
84  */
85 void CATerminate();
86
87 /**
88  * @brief   Starts listening servers.
89  *          This API is used by resource hosting server for listening multicast requests.
90  *          Based on the adapters configurations, different kinds of servers are started.
91  * @return  #CA_STATUS_OK or #CA_STATUS_FAILED
92  */
93 CAResult_t CAStartListeningServer();
94
95 /**
96  * @brief   Starts discovery servers.
97  *          This API is used by resource required clients for listening multicast requests.
98  *          Based on the adapters configurations, different kinds of servers are started.
99  * @return  #CA_STATUS_OK or #CA_STATUS_FAILED
100  */
101 CAResult_t CAStartDiscoveryServer();
102
103 /**
104  * @brief   Register request callbacks and response callbacks.
105  *          Requests and responses are delivered these callbacks .
106  * @param   ReqHandler   [IN] Request callback ( for GET,PUT ..etc)
107  * @param   RespHandler  [IN] Response Handler Callback
108  * @see     CARequestCallback
109  * @see     CAResponseCallback
110  */
111 void CARegisterHandler(CARequestCallback ReqHandler, CAResponseCallback RespHandler);
112
113 #ifdef __WITH_DTLS__
114 /**
115  * @brief   Register callback to get DTLS PSK credentials.
116  * @param   GetDTLSCredentials   [IN] GetDTLS Credetials callback
117  * @return  #CA_STATUS_OK
118  */
119 CAResult_t CARegisterDTLSCredentialsHandler(
120                                                    CAGetDTLSCredentialsHandler GetDTLSCredentials);
121 #endif //__WITH_DTLS__
122
123 /**
124  * @brief   Create a Remote endpoint if the URI is available already.
125  *          This is a Helper function which can be used before calling
126  *          CASendRequest / CASendNotification.
127  * @param   uri                 [IN]  Absolute URI of the resource to be used to generate the
128  *                                    Remote endpoint
129  *                                    \n For ex : coap://10.11.12.13:4545/resource_uri ( for IP)
130  *                                    \n coap://10:11:12:13:45:45/resource_uri ( for BT)
131  * @param   connectivityType    [IN]  Connectivity type of the endpoint
132  * @param   object              [OUT] Endpoint object which contains the above parsed data
133  * @return  #CA_STATUS_OK or #CA_STATUS_FAILED
134  * @remark  The created Remote endpoint can be freed using CADestroyRemoteEndpoint() API.
135  * @see     CADestroyRemoteEndpoint
136  */
137 CAResult_t CACreateRemoteEndpoint(const CAURI_t uri,
138                                   const CAConnectivityType_t connectivityType,
139                                   CARemoteEndpoint_t **object);
140
141 /**
142  * @brief   Destroy the remote endpoint created
143  * @param   object  [IN] Remote Endpoint object created with CACreateRemoteEndpoint
144  * @return  NONE
145  */
146 void CADestroyRemoteEndpoint(CARemoteEndpoint_t *object);
147
148 /**
149  * @brief   Generating the token for matching the request and response.
150  * @param   token   [OUT] Token for the request
151  * @return  #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
152  * @remark  Token memory is destroyed by the caller using CADestroyToken().
153  * @see     CADestroyToken
154  */
155 CAResult_t CAGenerateToken(CAToken_t *token);
156
157 /**
158  * @brief   Destroy the token generated by CAGenerateToken
159  * @param   token   [IN] Token for the request
160  * @return  NONE
161  */
162 void CADestroyToken(CAToken_t token);
163
164 /**
165  * @brief   Find the resource in the network. This API internally sends multicast messages on all
166  *          selected connectivity adapters. Responses are delivered via response callbacks.
167  *
168  * @param   resourceUri [IN] Uri to send multicast search request. Must contain only relative
169  *                           path of Uri to be search.
170  * @param   token       [IN] Token for the request
171  * @return  #CA_STATUS_OK or #CA_STATUS_FAILED
172  */
173 CAResult_t CAFindResource(const CAURI_t resourceUri, const CAToken_t token);
174
175 /**
176  * @brief   Send control Request on a resource
177  * @param   object      [IN] Remote Endpoint where the payload need to be sent.
178  *                           This Remote endpoint is delivered with Request or response callback.
179  * @param   requestInfo [IN] Information for the request.
180  * @return  #CA_STATUS_OK #CA_STATUS_FAILED #CA_MEMORY_ALLOC_FAILED
181  */
182 CAResult_t CASendRequest(const CARemoteEndpoint_t *object, CARequestInfo_t *requestInfo);
183
184 /**
185  * @brief   Send control Request on a resource to multicast group
186  * @param   object      [IN] Group Endpoint where the payload need to be sent.
187  *                           This Remote endpoint is delivered with Request or response callback.
188  * @param   requestInfo [IN] Information for the request.
189  * @return  #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
190  */
191 CAResult_t CASendRequestToAll(const CAGroupEndpoint_t *object,
192                               const CARequestInfo_t *requestInfo);
193
194 /**
195  * @brief   Send the response
196  * @param   object          [IN] Remote Endpoint where the payload need to be sent.
197  *                               This Remote endpoint is delivered with Request or response callback
198  * @param   responseInfo    [IN] Information for the response
199  * @return  #CA_STATUS_OK or  #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
200  */
201 CAResult_t CASendResponse(const CARemoteEndpoint_t *object, CAResponseInfo_t *responseInfo);
202
203 /**
204  * @brief   Send notification to the remote object
205  * @param   object          [IN] Remote Endpoint where the payload need to be sent.
206  *                               This Remote endpoint is delivered with Request or response callback.
207  * @param   responseInfo    [IN] Information for the response.
208  * @return  #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
209  */
210 CAResult_t CASendNotification(const CARemoteEndpoint_t *object,
211                               CAResponseInfo_t *responseInfo);
212
213 /**
214  * @brief   To advertise the resource
215  * @param   resourceUri [IN] URI to be advertised
216  * @param   token       [IN] Token for the request
217  * @param   options     [IN] Header options information
218  * @param   numOptions  [IN] Number of options
219  * @return  #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED
220  */
221 CAResult_t CAAdvertiseResource(const CAURI_t resourceUri, CAToken_t token,
222                                CAHeaderOption_t *options, uint8_t numOptions);
223
224 /**
225  * @brief   Select network to use
226  * @param   interestedNetwork   [IN] Connectivity Type enum
227  * @return  #CA_STATUS_OK or #CA_NOT_SUPPORTED or #CA_STATUS_FAILED or #CA_NOT_SUPPORTED
228  */
229 CAResult_t CASelectNetwork(const uint32_t interestedNetwork);
230
231 /**
232  * @brief   Select network to unuse
233  * @param   nonInterestedNetwork    [IN] Connectivity Type enum
234  * @return  #CA_STATUS_OK or #CA_NOT_SUPPORTED or #CA_STATUS_FAILED
235  */
236 CAResult_t CAUnSelectNetwork(const uint32_t nonInterestedNetwork);
237
238 /**
239  * @brief   Get network information
240  *          It should be destroyed by the caller as it Get Information.
241  * @param   info    [OUT] LocalConnectivity objects
242  * @param   size    [OUT] No Of Array objects
243  * @return  #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_STATUS_INVALID_PARAM or #CA_MEMORY_ALLOC_FAILED
244  */
245 CAResult_t CAGetNetworkInformation(CALocalConnectivity_t **info, uint32_t *size);
246
247 /**
248  * @brief    To Handle the Request or Response
249  * @return   #CA_STATUS_OK
250  */
251 CAResult_t CAHandleRequestResponse();
252
253 #ifdef __cplusplus
254 } /* extern "C" */
255 #endif
256
257 #endif