Modifying version number for building on tizen 3.0
[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)(CARemoteEndpoint_t* object, CARequestInfo_t* requestInfo);
47
48 /**
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.
53  */
54 typedef void (*CAResponseCallback)(CARemoteEndpoint_t* object, CAResponseInfo_t* responseInfo);
55
56 /**
57  * @brief   Initialize the connectivity abstraction module.
58  *          It will initialize adapters, thread pool and other modules based on the platform compilation options.
59  *
60  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
61  */
62 CAResult_t CAInitialize();
63
64 /**
65  * @brief   Terminate the connectivity abstraction module.
66  *          All threads, data structures are destroyed for next initializations.
67  */
68 void CATerminate();
69
70 /**
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)
75  */
76 CAResult_t CAStartListeningServer();
77
78 /**
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)
83  */
84 CAResult_t CAStartDiscoveryServer();
85
86 /**
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)
93  */
94 CAResult_t CARegisterHandler(CARequestCallback ReqHandler, CAResponseCallback RespHandler);
95
96 /**
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)
105  */
106 CAResult_t CACreateRemoteEndpoint(const CAURI_t uri, CARemoteEndpoint_t** object);
107
108 /**
109  * @brief   API Destroy the remote endpoint created
110  * @param   object  [IN]    endpoint object created with CACreateRemoteEndpoint
111  */
112 void CADestroyRemoteEndpoint(CARemoteEndpoint_t* object);
113
114 /**
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)
119  */
120 CAResult_t CAGenerateToken(CAToken_t* token);
121
122 /**
123  * @brief   Destroy the token generated by CAGenerateToken
124  * @param   token   [IN]    token for the request
125  */
126 void CADestroyToken(CAToken_t token);
127
128 /**
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.
131  *
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)
134  */
135 CAResult_t CAFindResource(const CAURI_t resourceUri);
136
137 /**
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)
143  */
144 CAResult_t CASendRequest(const CARemoteEndpoint_t* object, CARequestInfo_t* requestInfo);
145
146 /**
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)
152  */
153 CAResult_t CASendResponse(const CARemoteEndpoint_t* object, CAResponseInfo_t* responseInfo);
154
155 /**
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)
161  */
162 CAResult_t CASendNotification(const CARemoteEndpoint_t* object, CAResponseInfo_t* responseInfo);
163
164 /**
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)
170  */
171 CAResult_t CAAdvertiseResource(const CAURI_t resourceUri, CAHeaderOption_t* options,
172         uint8_t numOptions);
173
174 /**
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)
178  */
179 CAResult_t CASelectNetwork(const uint32_t interestedNetwork);
180
181 /**
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)
185  */
186 CAResult_t CAUnSelectNetwork(const uint32_t nonInterestedNetwork);
187
188 /**
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)
194  */
195 CAResult_t CAGetNetworkInformation(CALocalConnectivityt_t **info, uint32_t* size);
196
197 /**
198  * @brief   for usage of singled threaded application.
199  * @return   CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
200  */
201 CAResult_t CAHandleRequestResponse();
202
203 #ifdef __cplusplus
204 } /* extern "C" */
205 #endif
206
207 #endif