Implement ZCL Thermostat cluster
authorsaerome kim <saerome.kim@samsung.com>
Sat, 4 Feb 2017 07:54:21 +0000 (16:54 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Thu, 11 May 2017 09:10:25 +0000 (18:10 +0900)
Change-Id: If9ccaabd96e4489b2363f035d1479e4d18ee8f6f
Signed-off-by: saerome kim <saerome.kim@samsung.com>
zigbee-daemon/zigbee-interface/src/zigbee_service_dbus_interface_zcl_thermostat.c
zigbee-daemon/zigbee-lib/src/drivers/zblib_driver_zcl_thermostat.c

index 75cae67..93baf04 100644 (file)
 
 #include <zblib_driver_zcl_thermostat.h>
 
+static void *_service_interface_ref_zigbee_zcl_thermostat(
+       ZigBeeServiceInterface *service_interface)
+{
+       ZigbeeObjectSkeleton *zigbee_object = NULL;
+       ZigbeeCustomData_t *custom_data = NULL;
+       ZigbeeZcl_thermostat *thermo_object = NULL;
+
+       custom_data = (ZigbeeCustomData_t *)zblib_service_interface_ref_user_data(service_interface);
+       if (NULL == custom_data) {
+               Z_LOGE("D-BUS service interface custom_data is NULL!");
+               return NULL;
+       }
+
+       /* Get zigbee object */
+       zigbee_object = g_hash_table_lookup(custom_data->objects, ZIGBEE_SERVICE_PATH);
+       if (NULL == zigbee_object) {
+               Z_LOGW("Cannot find ZigBee D-BUS interface object!", zigbee_object);
+               return NULL;
+       }
+
+       thermo_object = zigbee_object_get_zcl_thermostat(ZIGBEE_OBJECT(zigbee_object));
+       return thermo_object;
+}
+
 static void on_thermostat_get_local_temp_resp(ZigBeeServiceInterface *service_interface,
        guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
 {
        ZigbeeServiceInterfaceRespCbData_t *cb_data =
                (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
 
-       NOT_USED(cb_data);
+       ZigbeeZcl_thermostat *thermo_object = NULL;
+       GDBusMethodInvocation *invocation = NULL;
+
+       ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
+
        NOT_USED(service_interface);
        NOT_USED(request_id);
-       NOT_USED(resp_data);
-       NOT_USED(resp_data_len);
+
+       if (NULL == resp_data || 0 == resp_data_len) {
+               Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
+               g_free(cb_data);
+               return;
+       }
+
+       thermo_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+       zblib_check_null_free_and_ret("thermo_object", thermo_object, cb_data);
+
+       invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+       zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+       zigbee_zcl_thermostat_complete_get_local_temp(thermo_object, invocation,
+               payload->result);
+
+       g_free(cb_data);
 }
 
 static gboolean on_thermostat_get_local_temp(ZigbeeZcl_thermostat *thermostat_object,
@@ -99,11 +142,30 @@ static void on_thermostat_get_weekly_schedule_resp(ZigBeeServiceInterface *servi
        ZigbeeServiceInterfaceRespCbData_t *cb_data =
                (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
 
-       NOT_USED(cb_data);
+       ZigbeeZcl_thermostat *thermo_object = NULL;
+       GDBusMethodInvocation *invocation = NULL;
+
+       ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
+
        NOT_USED(service_interface);
        NOT_USED(request_id);
-       NOT_USED(resp_data);
-       NOT_USED(resp_data_len);
+
+       if (NULL == resp_data || 0 == resp_data_len) {
+               Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
+               g_free(cb_data);
+               return;
+       }
+
+       thermo_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+       zblib_check_null_free_and_ret("thermo_object", thermo_object, cb_data);
+
+       invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+       zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+       zigbee_zcl_thermostat_complete_get_weekly_schedule(thermo_object, invocation,
+               payload->result);
+
+       g_free(cb_data);
 }
 
 static gboolean on_thermostat_get_weekly_schedule(ZigbeeZcl_thermostat *thermostat_object,
@@ -176,11 +238,30 @@ static void on_thermostat_set_weekly_schedule_resp(ZigBeeServiceInterface *servi
        ZigbeeServiceInterfaceRespCbData_t *cb_data =
                (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
 
-       NOT_USED(cb_data);
+       ZigbeeZcl_thermostat *thermo_object = NULL;
+       GDBusMethodInvocation *invocation = NULL;
+
+       ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
+
        NOT_USED(service_interface);
        NOT_USED(request_id);
-       NOT_USED(resp_data);
-       NOT_USED(resp_data_len);
+
+       if (NULL == resp_data || 0 == resp_data_len) {
+               Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
+               g_free(cb_data);
+               return;
+       }
+
+       thermo_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+       zblib_check_null_free_and_ret("thermo_object", thermo_object, cb_data);
+
+       invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+       zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+       zigbee_zcl_thermostat_complete_set_weekly_schedule(thermo_object, invocation,
+               payload->result);
+
+       g_free(cb_data);
 }
 
 static gboolean on_thermostat_set_weekly_schedule(ZigbeeZcl_thermostat *thermostat_object,
@@ -266,11 +347,30 @@ static void on_thermostat_clear_weekly_schedule_resp(ZigBeeServiceInterface *ser
        ZigbeeServiceInterfaceRespCbData_t *cb_data =
                (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
 
-       NOT_USED(cb_data);
+       ZigbeeZcl_thermostat *thermo_object = NULL;
+       GDBusMethodInvocation *invocation = NULL;
+
+       ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
+
        NOT_USED(service_interface);
        NOT_USED(request_id);
-       NOT_USED(resp_data);
-       NOT_USED(resp_data_len);
+
+       if (NULL == resp_data || 0 == resp_data_len) {
+               Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
+               g_free(cb_data);
+               return;
+       }
+
+       thermo_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+       zblib_check_null_free_and_ret("thermo_object", thermo_object, cb_data);
+
+       invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+       zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+       zigbee_zcl_thermostat_complete_clear_weekly_schedule(thermo_object, invocation,
+               payload->result);
+
+       g_free(cb_data);
 }
 
 static gboolean on_thermostat_clear_weekly_schedule(ZigbeeZcl_thermostat *thermostat_object,
@@ -339,11 +439,30 @@ static void on_thermostat_setpoint_raise_lower_resp(ZigBeeServiceInterface *serv
        ZigbeeServiceInterfaceRespCbData_t *cb_data =
                (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
 
-       NOT_USED(cb_data);
+       ZigbeeZcl_thermostat *thermo_object = NULL;
+       GDBusMethodInvocation *invocation = NULL;
+
+       ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
+
        NOT_USED(service_interface);
        NOT_USED(request_id);
-       NOT_USED(resp_data);
-       NOT_USED(resp_data_len);
+
+       if (NULL == resp_data || 0 == resp_data_len) {
+               Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
+               g_free(cb_data);
+               return;
+       }
+
+       thermo_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+       zblib_check_null_free_and_ret("thermo_object", thermo_object, cb_data);
+
+       invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+       zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+       zigbee_zcl_thermostat_complete_setpoint_raise_lower(thermo_object, invocation,
+               payload->result);
+
+       g_free(cb_data);
 }
 
 static gboolean on_thermostat_setpoint_raise_lower(ZigbeeZcl_thermostat *thermostat_object,
@@ -405,15 +524,29 @@ static gboolean on_thermostat_setpoint_raise_lower(ZigbeeZcl_thermostat *thermos
 void zigbee_service_dbus_interface_zcl_thermostat_notification(ZigBeeServiceInterface *service_interface,
        guint noti_id, gpointer noti_data, guint noti_data_len, gpointer noti_cb_data)
 {
-       if (NULL == service_interface) {
-               Z_LOGE("service_interface is NULL");
+       ZigbeeZcl_thermostat *thermo_object;
+
+       zblib_check_null_ret("service_interface", service_interface);
+
+       if (NULL == noti_data || 0 == noti_data_len) {
+               Z_LOGE("noti_data=%p or noti_data_len=%d is null", noti_data, noti_data_len);
                return;
        }
 
-       NOT_USED(noti_id);
-       NOT_USED(noti_data);
-       NOT_USED(noti_data_len);
+       thermo_object = _service_interface_ref_zigbee_zcl_thermostat(service_interface);
+       zblib_check_null_ret("thermo_object", thermo_object);
+
        NOT_USED(noti_cb_data);
+
+       switch(noti_id) {
+       default:
+               Z_LOGE("Unexpected notification [%x]", noti_id);
+       break;
+       }
+
+       /* ZigbeeZcl_thermostat should be dereferenced */
+       g_object_unref(thermo_object);
+
 }
 
 gboolean zigbee_service_dbus_interface_zcl_thermostat_init(ZigBeeServiceInterface *service_interface,
index 435a495..31f1060 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <zblib.h>
 #include <zblib_driver.h>
+#include <zblib_plugin.h>
 #include <zblib_request.h>
 
 #include "zblib_driver_zcl_thermostat.h"
@@ -122,6 +123,7 @@ ZigBeeDriver *zblib_driver_zcl_thermostat_new(ZigBeePlugin *plugin,
        ZblibDriverZclThermostatOps_t *ops)
 {
        ZigBeeDriver *driver = NULL;
+       ZigBeeService *service = NULL;
        ZblibDriverZclThermostatPrivData_t *priv_data = NULL;
        gboolean ret;
 
@@ -137,6 +139,19 @@ ZigBeeDriver *zblib_driver_zcl_thermostat_new(ZigBeePlugin *plugin,
        /* Update private data */
        priv_data->ops = ops;
 
+       /* Link service to driver */
+       service = zblib_plugin_ref_service(plugin);
+       if (NULL == service) {
+               Z_LOGE("zblib_plugin_ref_service failed!");
+
+               /* Free allocated resources */
+               g_free(priv_data);
+               g_free(driver);
+
+               return NULL;
+       }
+       zblib_driver_link_service(driver, service);
+
        /* Link private data to driver */
        ret = zblib_driver_link_object(driver, priv_data);
        if (FALSE == ret) {