Tizen IoT Extension SDK 1.0  1.0.1
Resource

The Resource API provides functions for interfaces for resource applications to be controlled by SmartThings Applications. More...

Typedefs

typedef struct
smartthings_resource_s * 
smartthings_resource_h
 The SmartThings resource handle. 1.
typedef void(* smartthings_resource_connection_status_cb )(smartthings_resource_h handle, smartthings_resource_connection_status_e status, void *user_data)
 Callback for status of connection to SmartThings Thing agent. 1.
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)
 Callback for handling request(GET/SET) messages. 1.
typedef void(* smartthings_resource_cloud_registration_status_cb )(smartthings_resource_h st_h, bool is_registered, void *user_data)
 Callback for status of resource registration to cloud. 1.

Enumerations

enum  smartthings_resource_error_e {
  SMARTTHINGS_RESOURCE_ERROR_NONE = TIZEN_ERROR_NONE, SMARTTHINGS_RESOURCE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, SMARTTHINGS_RESOURCE_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, SMARTTHINGS_RESOURCE_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED,
  SMARTTHINGS_RESOURCE_ERROR_NO_DATA = TIZEN_ERROR_NO_DATA, SMARTTHINGS_RESOURCE_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, SMARTTHINGS_RESOURCE_ERROR_OPERATION_FAILED = TIZEN_ERROR_UNKNOWN - 1, SMARTTHINGS_RESOURCE_ERROR_SERVICE_UNAVAILABLE = TIZEN_ERROR_UNKNOWN -2
}
 Enumeration for the SmartThings resource error. 1. More...
enum  smartthings_resource_req_type_e { SMARTTHINGS_RESOURCE_REQUEST_GET = 0, SMARTTHINGS_RESOURCE_REQUEST_SET = 1, SMARTTHINGS_RESOURCE_REQUEST_COLLECTION_GET = 2, SMARTTHINGS_RESOURCE_REQUEST_COLLECTION_SET = 3 }
 Enumeration for the request type of resource and collection resource. 1. More...
enum  smartthings_resource_connection_status_e { SMARTTHINGS_RESOURCE_CONNECTION_STATUS_CONNECTED = 0, SMARTTHINGS_RESOURCE_CONNECTION_STATUS_DISCONNECTED, SMARTTHINGS_RESOURCE_CONNECTION_STATUS_REJECTED }
 Enumeration for RPC connection status. 1. More...

Functions

int smartthings_resource_initialize (smartthings_resource_h *st_h, smartthings_resource_connection_status_cb connection_status_cb, void *user_data)
 Initializes a resource handle and connects to agent. 1 http://com.samsung.tizen.smartthings-thing/appdefined/smartthings-thing.resource
http://tizen.org/privilege/appmanager.launch
http://tizen.org/privilege/datasharing.
int smartthings_resource_deinitialize (smartthings_resource_h st_h)
 Deinitializes a resource handle and disconnects from the agent. 1.
int smartthings_resource_set_request_cb (smartthings_resource_h st_h, smartthings_resource_request_cb req_cb, void *user_data)
 Sets resource request callback. 1 http://com.samsung.tizen.smartthings-thing/appdefined/smartthings-thing.resource
http://tizen.org/privilege/appmanager.launch
http://tizen.org/privilege/datasharing.
int smartthings_resource_unset_request_cb (smartthings_resource_h st_h)
 Unsets resource request callback. 1 http://com.samsung.tizen.smartthings-thing/appdefined/smartthings-thing.resource
http://tizen.org/privilege/appmanager.launch
http://tizen.org/privilege/datasharing.
int smartthings_resource_send_response (smartthings_resource_h st_h, int req_id, const char *uri, smartthings_payload_h payload, bool result)
 Sends response for resource request message. 1 http://com.samsung.tizen.smartthings-thing/appdefined/smartthings-thing.resource
http://tizen.org/privilege/appmanager.launch
http://tizen.org/privilege/datasharing
http://tizen.org/privilege/internet.
int smartthings_resource_notify (smartthings_resource_h st_h, const char *uri, smartthings_payload_h payload)
 Notifies resource change. 1 http://com.samsung.tizen.smartthings-thing/appdefined/smartthings-thing.resource
http://tizen.org/privilege/appmanager.launch
http://tizen.org/privilege/datasharing
http://tizen.org/privilege/internet.
int smartthings_resource_get_uris (smartthings_resource_h st_h, int *count, char ***uris)
 Gets resource URIs. 1 http://com.samsung.tizen.smartthings-thing/appdefined/smartthings-thing.resource
http://tizen.org/privilege/appmanager.launch
http://tizen.org/privilege/datasharing.
int smartthings_resource_set_cloud_registration_status_cb (smartthings_resource_h st_h, smartthings_resource_cloud_registration_status_cb reg_cb, void *user_data)
 Sets cloud registration callback. 1 http://com.samsung.tizen.smartthings-thing/appdefined/smartthings-thing.resource
http://tizen.org/privilege/appmanager.launch
http://tizen.org/privilege/datasharing.
int smartthings_resource_unset_cloud_registration_status_cb (smartthings_resource_h st_h)
 Unsets cloud registration callback. 1 http://com.samsung.tizen.smartthings-thing/appdefined/smartthings-thing.resource
http://tizen.org/privilege/appmanager.launch
http://tizen.org/privilege/datasharing.

Detailed Description

The Resource API provides functions for interfaces for resource applications to be controlled by SmartThings Applications.

Overview

Required Header

#include <smartthings_resource.h>

The SmartThings Thing Resource API provides the following functionalities:


Typedef Documentation

typedef void(* smartthings_resource_cloud_registration_status_cb)(smartthings_resource_h st_h, bool is_registered, void *user_data)

Callback for status of resource registration to cloud. 1.

Remarks:
This callback will be called when status of resource registration is changed.
The st_h should not be released.
The st_h is the same object for which the callback was set/added.
The st_h will be released when smartthings_resource_deinitialize() is called.
The is_registered will be true when resources are registered to cloud.
Parameters:
[in]st_hThe SmartThings resource handle
[in]is_registeredThe status of resource registration to cloud
[in]user_dataThe user data passed from the callback registration function
See also:
smartthings_resource_set_cloud_registration_status_cb()
smartthings_resource_unset_cloud_registration_status_cb()

Callback for status of connection to SmartThings Thing agent. 1.

Remarks:
The handle should not be released.
The handle is the same object for which the callback was set/added.
The handle will be released when smartthings_deinitialize() is called.
When callback is called, user can see connection status as smartthings_connection_status_e enumeration value.
Parameters:
[in]resultThe result of connection operation
[in]handleThe SmartThings handle
[in]statusThe status of connection
[in]user_dataThe user data passed from the callback registration function
See also:
smartthings_resource_initialize()
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)

Callback for handling request(GET/SET) messages. 1.

Remarks:
The payload is NULL when req_type is SMARTTHINGS_RESOURCE_REQUEST_GET.
The payload can be used only in the callback. To use outside, make a copy.
The st_h should not be released.
The st_h is the same object for which the callback was set/added.
The st_h will be released when smartthings_resource_deinitialize() is called.
The payload should not be released.
The uri can be used only in the callback. To use outside, make a copy.
Parameters:
[in]st_hThe SmartThings resource handle
[in]req_idThe request ID of request message
[in]uriThe resource URI
[in]req_typeThe request type for request message
[in]payloadThe payload for SET request message
[in]user_dataThe user data passed from the callback registration function
See also:
smartthings_resource_set_request_cb()
smartthings_resource_unset_request_cb()

Enumeration Type Documentation

Enumeration for RPC connection status. 1.

Enumerator:
SMARTTHINGS_RESOURCE_CONNECTION_STATUS_CONNECTED 

Connection is connected

SMARTTHINGS_RESOURCE_CONNECTION_STATUS_DISCONNECTED 

Connection is disconnected

SMARTTHINGS_RESOURCE_CONNECTION_STATUS_REJECTED 

Connection is rejected

Enumeration for the SmartThings resource error. 1.

Enumerator:
SMARTTHINGS_RESOURCE_ERROR_NONE 

Successful

SMARTTHINGS_RESOURCE_ERROR_INVALID_PARAMETER 

Invalid parameter

SMARTTHINGS_RESOURCE_ERROR_OUT_OF_MEMORY 

Out of memory

SMARTTHINGS_RESOURCE_ERROR_PERMISSION_DENIED 

Permission denied

SMARTTHINGS_RESOURCE_ERROR_NO_DATA 

No data

SMARTTHINGS_RESOURCE_ERROR_NOT_SUPPORTED 

Not supported

SMARTTHINGS_RESOURCE_ERROR_OPERATION_FAILED 

Operation failed

SMARTTHINGS_RESOURCE_ERROR_SERVICE_UNAVAILABLE 

Service unavailable

Enumeration for the request type of resource and collection resource. 1.

Enumerator:
SMARTTHINGS_RESOURCE_REQUEST_GET 

Get request type

SMARTTHINGS_RESOURCE_REQUEST_SET 

Set request type

SMARTTHINGS_RESOURCE_REQUEST_COLLECTION_GET 

Get request type for collection

SMARTTHINGS_RESOURCE_REQUEST_COLLECTION_SET 

Set request type for collection


Function Documentation

Deinitializes a resource handle and disconnects from the agent. 1.

Parameters:
[in]st_hThe SmartThings resource handle
Returns:
0 on success, otherwise a negative error value
Return values:
SMARTTHINGS_RESOURCE_ERROR_NONESuccessful
SMARTTHINGS_RESOURCE_ERROR_INVALID_PARAMETERInvalid parameter
See also:
smartthings_resource_initialize()
int smartthings_resource_get_uris ( smartthings_resource_h  st_h,
int *  count,
char ***  uris 
)

Gets resource URIs. 1 http://com.samsung.tizen.smartthings-thing/appdefined/smartthings-thing.resource
http://tizen.org/privilege/appmanager.launch
http://tizen.org/privilege/datasharing.

Remarks:
The uris should be released using free().
Parameters:
[in]st_hThe SmartThings resource handle
[out]countThe resource count
[out]urisThe resource URI list
Returns:
0 on success, otherwise a negative error value
Return values:
SMARTTHINGS_RESOURCE_ERROR_NONESuccessful
SMARTTHINGS_RESOURCE_ERROR_INVALID_PARAMETERInvalid parameter
SMARTTHINGS_RESOURCE_ERROR_PERMISSION_DENIEDPermission denied
SMARTTHINGS_RESOURCE_ERROR_OPERATION_FAILEDOperation failed
SMARTTHINGS_RESOURCE_ERROR_SERVICE_UNAVAILABLEService unavailable
int smartthings_resource_initialize ( smartthings_resource_h st_h,
smartthings_resource_connection_status_cb  connection_status_cb,
void *  user_data 
)

Initializes a resource handle and connects to agent. 1 http://com.samsung.tizen.smartthings-thing/appdefined/smartthings-thing.resource
http://tizen.org/privilege/appmanager.launch
http://tizen.org/privilege/datasharing.

Remarks:
The st_h must be released using smartthings_resource_deinitialize().
Ths function returns SMARTTHINGS_RESOURCE_ERROR_PERMISSION_DENIED
if the application has no app-defined privilege for 'http://com.samsung.tizen.smartthings-thing/appdefined/smartthings-thing.resource'.
Parameters:
[out]st_hThe SmartThings resource handle to be newly created on success
[in]connection_status_cbThe connection status callback to register
[in]user_dataThe user data to be passed to the callback function
Returns:
0 on success, otherwise a negative error value
Return values:
SMARTTHINGS_RESOURCE_ERROR_NONESuccessful
SMARTTHINGS_RESOURCE_ERROR_INVALID_PARAMETERInvalid parameter
SMARTTHINGS_RESOURCE_ERROR_OUT_OF_MEMORYOut of memory
SMARTTHINGS_RESOURCE_ERROR_PERMISSION_DENIEDPermission denied
SMARTTHINGS_RESOURCE_ERROR_OPERATION_FAILEDOperation failed
SMARTTHINGS_RESOURCE_ERROR_NOT_SUPPORTEDNot supported
SMARTTHINGS_RESOURCE_ERROR_SERVICE_UNAVAILABLEService unavailable
See also:
smartthings_resource_deinitialize()
int smartthings_resource_notify ( smartthings_resource_h  st_h,
const char *  uri,
smartthings_payload_h  payload 
)

Notifies resource change. 1 http://com.samsung.tizen.smartthings-thing/appdefined/smartthings-thing.resource
http://tizen.org/privilege/appmanager.launch
http://tizen.org/privilege/datasharing
http://tizen.org/privilege/internet.

Parameters:
[in]st_hThe SmartThings resource handle
[in]uriThe resource URI
[in]payloadThe payload of response message
Returns:
0 on success, otherwise a negative error value
Return values:
SMARTTHINGS_RESOURCE_ERROR_NONESuccessful
SMARTTHINGS_RESOURCE_ERROR_INVALID_PARAMETERInvalid parameter
SMARTTHINGS_RESOURCE_ERROR_PERMISSION_DENIEDPermission denied
SMARTTHINGS_RESOURCE_ERROR_OPERATION_FAILEDOperation failed
SMARTTHINGS_RESOURCE_ERROR_SERVICE_UNAVAILABLEService unavailable
int smartthings_resource_send_response ( smartthings_resource_h  st_h,
int  req_id,
const char *  uri,
smartthings_payload_h  payload,
bool  result 
)

Sends response for resource request message. 1 http://com.samsung.tizen.smartthings-thing/appdefined/smartthings-thing.resource
http://tizen.org/privilege/appmanager.launch
http://tizen.org/privilege/datasharing
http://tizen.org/privilege/internet.

Parameters:
[in]st_hThe SmartThings resource handle
[in]req_idThe request ID of request message
[in]uriThe resource URI
[in]payloadThe payload of response message
[in]resultThe result of response
Returns:
0 on success, otherwise a negative error value
Return values:
SMARTTHINGS_RESOURCE_ERROR_NONESuccessful
SMARTTHINGS_RESOURCE_ERROR_INVALID_PARAMETERInvalid parameter
SMARTTHINGS_RESOURCE_ERROR_PERMISSION_DENIEDPermission denied
SMARTTHINGS_RESOURCE_ERROR_OPERATION_FAILEDOperation failed
SMARTTHINGS_RESOURCE_ERROR_SERVICE_UNAVAILABLEService unavailable

Sets cloud registration callback. 1 http://com.samsung.tizen.smartthings-thing/appdefined/smartthings-thing.resource
http://tizen.org/privilege/appmanager.launch
http://tizen.org/privilege/datasharing.

Parameters:
[in]st_hThe SmartThings resource handle
[in]reg_cbThe callback to register
[in]user_dataThe user data to be passed to the callback function
Returns:
0 on success, otherwise a negative error value
Return values:
SMARTTHINGS_RESOURCE_ERROR_NONESuccessful
SMARTTHINGS_RESOURCE_ERROR_INVALID_PARAMETERInvalid parameter
SMARTTHINGS_RESOURCE_ERROR_PERMISSION_DENIEDPermission denied
SMARTTHINGS_RESOURCE_ERROR_OPERATION_FAILEDOperation failed
SMARTTHINGS_RESOURCE_ERROR_SERVICE_UNAVAILABLEService unavailable
See also:
smartthings_resource_unset_cloud_registration_status_cb()

Sets resource request callback. 1 http://com.samsung.tizen.smartthings-thing/appdefined/smartthings-thing.resource
http://tizen.org/privilege/appmanager.launch
http://tizen.org/privilege/datasharing.

Parameters:
[in]st_hThe SmartThings resource handle
[in]req_cbThe request callback to register
[in]user_dataThe user data to be passed to the callback function
Returns:
0 on success, otherwise a negative error value
Return values:
SMARTTHINGS_RESOURCE_ERROR_NONESuccessful
SMARTTHINGS_RESOURCE_ERROR_INVALID_PARAMETERInvalid parameter
SMARTTHINGS_RESOURCE_ERROR_PERMISSION_DENIEDPermission denied
SMARTTHINGS_RESOURCE_ERROR_OPERATION_FAILEDOperation failed
SMARTTHINGS_RESOURCE_ERROR_SERVICE_UNAVAILABLEService unavailable
See also:
smartthings_resource_unset_request_cb()

Unsets cloud registration callback. 1 http://com.samsung.tizen.smartthings-thing/appdefined/smartthings-thing.resource
http://tizen.org/privilege/appmanager.launch
http://tizen.org/privilege/datasharing.

Parameters:
[in]st_hThe SmartThings resource handle
Returns:
0 on success, otherwise a negative error value
Return values:
SMARTTHINGS_RESOURCE_ERROR_NONESuccessful
SMARTTHINGS_RESOURCE_ERROR_INVALID_PARAMETERInvalid parameter
SMARTTHINGS_RESOURCE_ERROR_PERMISSION_DENIEDPermission denied
SMARTTHINGS_RESOURCE_ERROR_OPERATION_FAILEDOperation failed
SMARTTHINGS_RESOURCE_ERROR_SERVICE_UNAVAILABLEService unavailable
See also:
smartthings_resource_set_cloud_registration_status_cb()

Unsets resource request callback. 1 http://com.samsung.tizen.smartthings-thing/appdefined/smartthings-thing.resource
http://tizen.org/privilege/appmanager.launch
http://tizen.org/privilege/datasharing.

Parameters:
[in]st_hThe SmartThings resource handle
Returns:
0 on success, otherwise a negative error value
Return values:
SMARTTHINGS_RESOURCE_ERROR_NONESuccessful
SMARTTHINGS_RESOURCE_ERROR_INVALID_PARAMETERInvalid parameter
SMARTTHINGS_RESOURCE_ERROR_PERMISSION_DENIEDPermission denied
SMARTTHINGS_RESOURCE_ERROR_OPERATION_FAILEDOperation failed
SMARTTHINGS_RESOURCE_ERROR_SERVICE_UNAVAILABLEService unavailable
See also:
smartthings_resource_set_request_cb()
 All Files Functions Typedefs Enumerations Enumerator