summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/st-resource.c41
1 files changed, 29 insertions, 12 deletions
diff --git a/src/st-resource.c b/src/st-resource.c
index 4c5d626..c23c8d6 100644
--- a/src/st-resource.c
+++ b/src/st-resource.c
@@ -27,6 +27,7 @@
static smartthings_resource_h st_res_h;
static smartthings_resource_connection_status_e st_res_status;
+static int st_cloud_reg_status;
static sensor_data *resource_sd;
static const char * _resource_error_to_str(smartthings_resource_error_e err)
@@ -73,7 +74,7 @@ static bool _handle_get_lidar(smartthings_payload_h resp_payload, void *user_dat
_D("Received a GET request for LIDAR");
- if (!sensor_data_get_uint(resource_sd, &value))
+ if (sensor_data_get_uint(resource_sd, &value))
return false;
err = smartthings_payload_set_double(resp_payload, SENSOR_LIDAR_KEY, value);
@@ -129,27 +130,39 @@ static void __request_cb(smartthings_resource_h handle, int id,
if (smartthings_payload_destroy(resp_payload))
_E("smartthings_payload_destroy() failed");
+}
- return;
+void _cloud_reg_status_cb(smartthings_resource_h handle, bool is_registered, void *user_data)
+{
+ _D("registered [%d]", is_registered);
+ st_cloud_reg_status = is_registered;
}
static void _resource_connection_status_cb(
smartthings_resource_h handle,
smartthings_resource_connection_status_e status, void *user_data)
{
+ int err = SMARTTHINGS_RESOURCE_ERROR_NONE;
st_res_status = status;
_D("status=[%d]", status);
- if (status == SMARTTHINGS_RESOURCE_CONNECTION_STATUS_CONNECTED) {
- int err = SMARTTHINGS_RESOURCE_ERROR_NONE;
- err = smartthings_resource_set_request_cb(handle, __request_cb, NULL);
- if (err != SMARTTHINGS_RESOURCE_ERROR_NONE) {
- _E("smartthings_resource_set_request_cb() is failed, [%s]",
- _resource_error_to_str(err));
- return;
- }
- } else {
+ if (status != SMARTTHINGS_RESOURCE_CONNECTION_STATUS_CONNECTED) {
_E("connection failed");
+ return;
+ }
+
+ err = smartthings_resource_set_request_cb(handle, __request_cb, NULL);
+ if (err != SMARTTHINGS_RESOURCE_ERROR_NONE) {
+ _E("smartthings_resource_set_request_cb() is failed, [%s]",
+ _resource_error_to_str(err));
+ return;
+ }
+
+ err = smartthings_resource_set_cloud_registration_status_cb(handle, _cloud_reg_status_cb, NULL);
+ if (err != SMARTTHINGS_RESOURCE_ERROR_NONE) {
+ _E("smartthings_resource_set_cloud_registration_status_cb() is failed, [%s]",
+ _resource_error_to_str(err));
+ return;
}
}
@@ -160,7 +173,8 @@ __data_changed_cb(sensor_data *sd, sensor_data_type_e type, void *user_data)
int err = SMARTTHINGS_RESOURCE_ERROR_NONE;
smartthings_payload_h resp_payload = NULL;
- if (st_res_status != SMARTTHINGS_RESOURCE_CONNECTION_STATUS_CONNECTED) {
+ if (st_res_status != SMARTTHINGS_RESOURCE_CONNECTION_STATUS_CONNECTED
+ || !st_cloud_reg_status) {
_D("resource not connected yet");
return;
}
@@ -198,12 +212,14 @@ int st_resource_destroy(void)
return 0;
smartthings_resource_unset_request_cb(st_res_h);
+ smartthings_resource_unset_cloud_registration_status_cb(st_res_h);
smartthings_resource_deinitialize(st_res_h);
sensor_data_changed_cb_set(resource_sd, NULL, NULL);
st_res_h = NULL;
st_res_status = SMARTTHINGS_RESOURCE_CONNECTION_STATUS_DISCONNECTED;
+ st_cloud_reg_status = 0;
return 0;
}
@@ -229,6 +245,7 @@ int st_resource_create(sensor_data *sd)
st_res_h = res_h;
st_res_status = SMARTTHINGS_RESOURCE_CONNECTION_STATUS_DISCONNECTED;
+ st_cloud_reg_status = 0;
resource_sd = sd;
sensor_data_changed_cb_set(sd, __data_changed_cb, st_res_h);