summaryrefslogtreecommitdiff
path: root/inc/smartthings_resource.h
blob: 962339bf32b1e969296ba9540cd79c1abd904c92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
 /*
 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef __SAMSUNG_EXPERIENCE_SERVICE_SMARTTHINGS_RESOURCE_H__
#define __SAMSUNG_EXPERIENCE_SERVICE_SMARTTHINGS_RESOURCE_H__

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <tizen.h>
#include <smartthings_payload.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @file smartthings_resource.h
 */

/**
 * @addtogroup CAPI_SMARTTHINGS_THING_RESOURCE_MODULE
 * @{
 */

/**
 * @brief Enumeration for the SmartThings resource error.
 * @since_ses 1
 */
typedef enum {
	SMARTTHINGS_RESOURCE_ERROR_NONE = TIZEN_ERROR_NONE,                                /**< Successful */
	SMARTTHINGS_RESOURCE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,      /**< Invalid parameter */
	SMARTTHINGS_RESOURCE_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY,              /**< Out of memory */
	SMARTTHINGS_RESOURCE_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED,      /**< Permission denied */
	SMARTTHINGS_RESOURCE_ERROR_NO_DATA = TIZEN_ERROR_NO_DATA,                          /**< No data */
	SMARTTHINGS_RESOURCE_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED,			   /**< Not supported */
	SMARTTHINGS_RESOURCE_ERROR_OPERATION_FAILED = TIZEN_ERROR_UNKNOWN - 1,             /**< Operation failed */
	SMARTTHINGS_RESOURCE_ERROR_SERVICE_UNAVAILABLE = TIZEN_ERROR_UNKNOWN -2            /**< Service unavailable */
} smartthings_resource_error_e;

/**
 * @brief Enumeration for the request type of resource and collection resource.
 * @since_ses 1
 */
typedef enum {
	SMARTTHINGS_RESOURCE_REQUEST_GET = 0,              /**< Get request type */
	SMARTTHINGS_RESOURCE_REQUEST_SET = 1,              /**< Set request type */
	SMARTTHINGS_RESOURCE_REQUEST_COLLECTION_GET = 2,   /**< Get request type for collection */
	SMARTTHINGS_RESOURCE_REQUEST_COLLECTION_SET = 3    /**< Set request type for collection */
} smartthings_resource_req_type_e;

/**
 * @brief Enumeration for RPC connection status.
 * @since_ses 1
 */
typedef enum {
	SMARTTHINGS_RESOURCE_CONNECTION_STATUS_CONNECTED = 0,          /**< Connection is connected */
	SMARTTHINGS_RESOURCE_CONNECTION_STATUS_DISCONNECTED,           /**< Connection is disconnected */
	SMARTTHINGS_RESOURCE_CONNECTION_STATUS_REJECTED,               /**< Connection is rejected */
} smartthings_resource_connection_status_e;

/**
 * @brief The SmartThings resource handle.
 * @since_ses 1
 */
typedef struct smartthings_resource_s *smartthings_resource_h;

/**
 * @brief Callback for status of connection to SmartThings Thing agent.
  * @details The following error codes can be received: \n
	#SMARTTHINGS_RESOURCE_ERROR_NONE:                               Success \n
	#SMARTTHINGS_RESOURCE_ERROR_PERMISSION_DENIED:      Permission denied \n
	#SMARTTHINGS_RESOURCE_ERROR_SERVICE_UNAVAILABLE:   Service unavailable \n
 * @since_ses 1
 *
 * @remarks The @a handle should not be released.
 * @remarks The @a handle is the same object for which the callback was set/added.
 * @remarks The @a handle will be released when smartthings_deinitialize() is called.
 * @remarks When callback is called, user can see result as #smartthings_resource_error_e enumeration value.
 * @remarks When callback is called, user can see connection status as #smartthings_connection_status_e enumeration value.
 *
 * @param[in] result The result of connection operation
 * @param[in] handle The SmartThings handle
 * @param[in] status The status of connection
 * @param[in] user_data The user data passed from the callback registration function
 *
 * @see smartthings_resource_initialize()
 */
typedef void (*smartthings_resource_connection_status_cb)(smartthings_resource_error_e result, smartthings_resource_h handle, smartthings_resource_connection_status_e status, void *user_data);


/**
 * @brief Callback for handling request(GET/SET) messages.
 * @since_ses 1
 *
 * @remarks The @a payload is NULL when @a req_type is #SMARTTHINGS_RESOURCE_REQUEST_GET.
 * @remarks The @a payload can be used only in the callback. To use outside, make a copy.
 * @remarks The @a st_h should not be released.
 * @remarks The @a st_h is the same object for which the callback was set/added.
 * @remarks The @a st_h will be released when smartthings_resource_deinitialize() is called.
 * @remarks The @a payload should not be released.
 * @remarks The @a uri can be used only in the callback. To use outside, make a copy.
 *
 * @param[in] st_h The SmartThings resource handle
 * @param[in] req_id The request ID of request message
 * @param[in] uri The resource URI
 * @param[in] req_type The request type for request message
 * @param[in] payload The payload for SET request message
 * @param[in] user_data The user data passed from the callback registration function
 *
 * @see smartthings_resource_set_request_cb()
 * @see smartthings_resource_unset_request_cb()
 */
typedef void (*smartthings_resource_request_cb)(smartthings_resource_h st_h, int req_id, const char *uri,
												smartthings_resource_req_type_e req_type,
												smartthings_payload_h payload, void *user_data);

/**
 * @brief Callback for status of resource registration to cloud.
 * @since_ses 1
 *
 * @remarks This callback will be called when status of resource registration is changed.
 * @remarks The @a st_h should not be released.
 * @remarks The @a st_h is the same object for which the callback was set/added.
 * @remarks The @a st_h will be released when smartthings_resource_deinitialize() is called.
 * @remarks The @a is_registered will be true when resources are registered to cloud.
 *
 * @param[in] st_h The SmartThings resource handle
 * @param[in] is_registered The status of resource registration to cloud
 * @param[in] user_data The user data passed from the callback registration function
 *
 * @see smartthings_resource_set_cloud_registration_status_cb()
 * @see smartthings_resource_unset_cloud_registration_status_cb()
 */
typedef void (*smartthings_resource_cloud_registration_status_cb)(smartthings_resource_h st_h, bool is_registered, void *user_data);


/**
 * @brief Initializes a resource handle and connects to agent.
 * @since_ses 1
 * @privilege %http://com.samsung.tizen.smartthings-thing/appdefined/smartthings-thing.resource \n
 *            %http://tizen.org/privilege/appmanager.launch \n
 *            %http://tizen.org/privilege/datasharing
 *
 * @remarks The @a st_h must be released using smartthings_resource_deinitialize().
 * @remarks Ths function returns #SMARTTHINGS_RESOURCE_ERROR_PERMISSION_DENIED\n
 *          if the application has no app-defined privilege for 'http://com.samsung.tizen.smartthings-thing/appdefined/smartthings-thing.resource'.
 *
 * @param[out] st_h The SmartThings resource handle to be newly created on success
 * @param[in] connection_status_cb The connection status callback to register
 * @param[in] user_data The user data to be passed to the callback function
 *
 * @return @c 0 on success,
 *         otherwise a negative error value
 * @retval #SMARTTHINGS_RESOURCE_ERROR_NONE Successful
 * @retval #SMARTTHINGS_RESOURCE_ERROR_INVALID_PARAMETER Invalid parameter
 * @retval #SMARTTHINGS_RESOURCE_ERROR_OUT_OF_MEMORY Out of memory
 * @retval #SMARTTHINGS_RESOURCE_ERROR_PERMISSION_DENIED Permission denied
 * @retval #SMARTTHINGS_RESOURCE_ERROR_OPERATION_FAILED Operation failed
 * @retval #SMARTTHINGS_RESOURCE_ERROR_NOT_SUPPORTED Not supported
 * @retval #SMARTTHINGS_RESOURCE_ERROR_SERVICE_UNAVAILABLE Service unavailable
 *
 * @see smartthings_resource_deinitialize()
 */
int smartthings_resource_initialize(smartthings_resource_h *st_h,
								   smartthings_resource_connection_status_cb connection_status_cb,
								   void *user_data);

/**
 * @brief Deinitializes a resource handle and disconnects from the agent.
 * @since_ses 1
 *
 * @param[in] st_h The SmartThings resource handle
 *
 * @return @c 0 on success,
 *         otherwise a negative error value
 * @retval #SMARTTHINGS_RESOURCE_ERROR_NONE Successful
 * @retval #SMARTTHINGS_RESOURCE_ERROR_INVALID_PARAMETER Invalid parameter
 *
 * @see smartthings_resource_initialize()
 */
int smartthings_resource_deinitialize(smartthings_resource_h st_h);

/**
 * @brief Sets resource request callback.
 * @since_ses 1
 * @privilege %http://com.samsung.tizen.smartthings-thing/appdefined/smartthings-thing.resource \n
 *            %http://tizen.org/privilege/appmanager.launch \n
 *            %http://tizen.org/privilege/datasharing
 *
 * @param[in] st_h The SmartThings resource handle
 * @param[in] req_cb The request callback to register
 * @param[in] user_data The user data to be passed to the callback function
 *
 * @return @c 0 on success,
 *         otherwise a negative error value
 * @retval #SMARTTHINGS_RESOURCE_ERROR_NONE Successful
 * @retval #SMARTTHINGS_RESOURCE_ERROR_INVALID_PARAMETER Invalid parameter
 * @retval #SMARTTHINGS_RESOURCE_ERROR_PERMISSION_DENIED Permission denied
 * @retval #SMARTTHINGS_RESOURCE_ERROR_OPERATION_FAILED Operation failed
 * @retval #SMARTTHINGS_RESOURCE_ERROR_SERVICE_UNAVAILABLE Service unavailable
 *
 * @see smartthings_resource_unset_request_cb()
 */
int smartthings_resource_set_request_cb(smartthings_resource_h st_h,
								smartthings_resource_request_cb req_cb,
								void *user_data);

/**
 * @brief Unsets resource request callback.
 * @since_ses 1
 * @privilege %http://com.samsung.tizen.smartthings-thing/appdefined/smartthings-thing.resource \n
 *            %http://tizen.org/privilege/appmanager.launch \n
 *            %http://tizen.org/privilege/datasharing
 *
 * @param[in] st_h The SmartThings resource handle
 *
 * @return @c 0 on success,
 *         otherwise a negative error value
 * @retval #SMARTTHINGS_RESOURCE_ERROR_NONE Successful
 * @retval #SMARTTHINGS_RESOURCE_ERROR_INVALID_PARAMETER Invalid parameter
 * @retval #SMARTTHINGS_RESOURCE_ERROR_PERMISSION_DENIED Permission denied
 * @retval #SMARTTHINGS_RESOURCE_ERROR_OPERATION_FAILED Operation failed
 * @retval #SMARTTHINGS_RESOURCE_ERROR_SERVICE_UNAVAILABLE Service unavailable
 *
 * @see smartthings_resource_set_request_cb()
 */
int smartthings_resource_unset_request_cb(smartthings_resource_h st_h);

/**
 * @brief Sends response for resource request message.
 * @since_ses 1
 * @privilege %http://com.samsung.tizen.smartthings-thing/appdefined/smartthings-thing.resource \n
 *            %http://tizen.org/privilege/appmanager.launch \n
 *            %http://tizen.org/privilege/datasharing \n
 *            %http://tizen.org/privilege/internet
 *
 * @param[in] st_h The SmartThings resource handle
 * @param[in] req_id The request ID of request message
 * @param[in] uri The resource URI
 * @param[in] payload The payload of response message
 * @param[in] result The result of response
 *
 * @return @c 0 on success,
 *         otherwise a negative error value
 * @retval #SMARTTHINGS_RESOURCE_ERROR_NONE Successful
 * @retval #SMARTTHINGS_RESOURCE_ERROR_INVALID_PARAMETER Invalid parameter
 * @retval #SMARTTHINGS_RESOURCE_ERROR_PERMISSION_DENIED Permission denied
 * @retval #SMARTTHINGS_RESOURCE_ERROR_OPERATION_FAILED Operation failed
 * @retval #SMARTTHINGS_RESOURCE_ERROR_SERVICE_UNAVAILABLE Service unavailable
 */
int smartthings_resource_send_response(smartthings_resource_h st_h, int req_id, const char *uri, smartthings_payload_h payload, bool result);

/**
 * @brief Notifies resource change.
 * @since_ses 1
 * @privilege %http://com.samsung.tizen.smartthings-thing/appdefined/smartthings-thing.resource \n
 *            %http://tizen.org/privilege/appmanager.launch \n
 *            %http://tizen.org/privilege/datasharing \n
 *            %http://tizen.org/privilege/internet
 *
 * @param[in] st_h The SmartThings resource handle
 * @param[in] uri The resource URI
 * @param[in] payload The payload of response message
 *
 * @return @c 0 on success,
 *         otherwise a negative error value
 * @retval #SMARTTHINGS_RESOURCE_ERROR_NONE Successful
 * @retval #SMARTTHINGS_RESOURCE_ERROR_INVALID_PARAMETER Invalid parameter
 * @retval #SMARTTHINGS_RESOURCE_ERROR_PERMISSION_DENIED Permission denied
 * @retval #SMARTTHINGS_RESOURCE_ERROR_OPERATION_FAILED Operation failed
 * @retval #SMARTTHINGS_RESOURCE_ERROR_SERVICE_UNAVAILABLE Service unavailable
 */
int smartthings_resource_notify(smartthings_resource_h st_h, const char *uri, smartthings_payload_h payload);

/**
 * @brief Gets resource URIs.
 * @since_ses 1
 * @privilege %http://com.samsung.tizen.smartthings-thing/appdefined/smartthings-thing.resource \n
 *            %http://tizen.org/privilege/appmanager.launch \n
 *            %http://tizen.org/privilege/datasharing
 *
 * @remarks The @a uris should be released using free().
 *
 * @param[in] st_h The SmartThings resource handle
 * @param[out] count The resource count
 * @param[out] uris The resource URI list
 *
 * @return @c 0 on success,
 *         otherwise a negative error value
 * @retval #SMARTTHINGS_RESOURCE_ERROR_NONE Successful
 * @retval #SMARTTHINGS_RESOURCE_ERROR_INVALID_PARAMETER Invalid parameter
 * @retval #SMARTTHINGS_RESOURCE_ERROR_PERMISSION_DENIED Permission denied
 * @retval #SMARTTHINGS_RESOURCE_ERROR_OPERATION_FAILED Operation failed
 * @retval #SMARTTHINGS_RESOURCE_ERROR_SERVICE_UNAVAILABLE Service unavailable
 */
int smartthings_resource_get_uris(smartthings_resource_h st_h, int *count, char ***uris);

/**
 * @brief Sets cloud registration callback.
 * @since_ses 1
 * @privilege %http://com.samsung.tizen.smartthings-thing/appdefined/smartthings-thing.resource \n
 *            %http://tizen.org/privilege/appmanager.launch \n
 *            %http://tizen.org/privilege/datasharing
 *
 * @param[in] st_h The SmartThings resource handle
 * @param[in] reg_cb The callback to register
 * @param[in] user_data The user data to be passed to the callback function
 *
 * @return @c 0 on success,
 *         otherwise a negative error value
 * @retval #SMARTTHINGS_RESOURCE_ERROR_NONE Successful
 * @retval #SMARTTHINGS_RESOURCE_ERROR_INVALID_PARAMETER Invalid parameter
 * @retval #SMARTTHINGS_RESOURCE_ERROR_PERMISSION_DENIED Permission denied
 * @retval #SMARTTHINGS_RESOURCE_ERROR_OPERATION_FAILED Operation failed
 * @retval #SMARTTHINGS_RESOURCE_ERROR_SERVICE_UNAVAILABLE Service unavailable
 *
 * @see smartthings_resource_unset_cloud_registration_status_cb()
 */
int smartthings_resource_set_cloud_registration_status_cb(smartthings_resource_h st_h,
								smartthings_resource_cloud_registration_status_cb reg_cb,
								void *user_data);

/**
 * @brief Unsets cloud registration callback.
 * @since_ses 1
 * @privilege %http://com.samsung.tizen.smartthings-thing/appdefined/smartthings-thing.resource \n
 *            %http://tizen.org/privilege/appmanager.launch \n
 *            %http://tizen.org/privilege/datasharing
 *
 * @param[in] st_h The SmartThings resource handle
 *
 * @return @c 0 on success,
 *         otherwise a negative error value
 * @retval #SMARTTHINGS_RESOURCE_ERROR_NONE Successful
 * @retval #SMARTTHINGS_RESOURCE_ERROR_INVALID_PARAMETER Invalid parameter
 * @retval #SMARTTHINGS_RESOURCE_ERROR_PERMISSION_DENIED Permission denied
 * @retval #SMARTTHINGS_RESOURCE_ERROR_OPERATION_FAILED Operation failed
 * @retval #SMARTTHINGS_RESOURCE_ERROR_SERVICE_UNAVAILABLE Service unavailable
 *
 * @see smartthings_resource_set_cloud_registration_status_cb()
 */
int smartthings_resource_unset_cloud_registration_status_cb(smartthings_resource_h st_h);


/**
 * @}
 */

#ifdef __cplusplus
}
#endif

#endif /* __SAMSUNG_EXPERIENCE_SERVICE_SMARTTHINGS_RESOURCE_H__ */