Implement ZCL Level Control cluster
authorsaerome kim <saerome.kim@samsung.com>
Fri, 3 Feb 2017 07:40:37 +0000 (16:40 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Thu, 11 May 2017 09:10:25 +0000 (18:10 +0900)
Change-Id: Id7c272f21b1ab351bb1d7cdd66cbe491ffc21081
Signed-off-by: saerome kim <saerome.kim@samsung.com>
common/include/zigbee_zcl_level_control_type.h
zigbee-daemon/zigbee-interface/src/zigbee_service_dbus_interface_zcl_level_control.c
zigbee-daemon/zigbee-lib/src/drivers/zblib_driver_zcl_level_control.c
zigbee-daemon/zigbee-lib/src/zblib_request.c

index a2ecee5..3d6c1ac 100644 (file)
@@ -51,7 +51,7 @@ typedef struct {
        short node_id; /**< Node ID */
        char endpoint; /**< Endpoint */
        char step_mode; /**< Step mode */
-       char move_mode; /**< Move mode */
+       char step_size; /**< Step size */
        short transition_time; /**< Transition time */
 } ZigbeeZclLevelControlStep_t;
 
@@ -85,7 +85,7 @@ typedef struct {
        short node_id; /**< Node ID */
        char endpoint; /**< Endpoint */
        char step_mode; /**< Step mode */
-       char move_mode; /**< Move mode */
+       char step_size; /**< Step size */
        short transition_time; /**< Transition time */
 } ZigbeeZclLevelControlStepWithOnOff_t;
 
index 3b785dc..941f9f0 100644 (file)
 
 #include <zblib_driver_zcl_level_control.h>
 
+static void *_service_interface_ref_zigbee_zcl_level_control(
+       ZigBeeServiceInterface *service_interface)
+{
+       ZigbeeObjectSkeleton *zigbee_object = NULL;
+       ZigbeeCustomData_t *custom_data = NULL;
+       ZigbeeZcl_level_control *level_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;
+       }
+
+       level_object = zigbee_object_get_zcl_level_control(ZIGBEE_OBJECT(zigbee_object));
+       return level_object;
+}
+
 static void on_level_control_move_to_level_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_level_control *level_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;
+       }
+
+       level_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+       zblib_check_null_free_and_ret("level_object", level_object, cb_data);
+
+       invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+       zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+       zigbee_zcl_level_control_complete_move_to_level(level_object, invocation, payload->result);
+
+       g_free(cb_data);
 }
 
 static gboolean on_level_control_move_to_level(ZigbeeZcl_level_control *level_control_object,
@@ -95,11 +137,29 @@ static void on_level_control_move_resp(ZigBeeServiceInterface *service_interface
        ZigbeeServiceInterfaceRespCbData_t *cb_data =
                (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
 
-       NOT_USED(cb_data);
+       ZigbeeZcl_level_control *level_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;
+       }
+
+       level_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+       zblib_check_null_free_and_ret("level_object", level_object, cb_data);
+
+       invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+       zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+       zigbee_zcl_level_control_complete_move(level_object, invocation, payload->result);
+
+       g_free(cb_data);
 }
 
 static gboolean on_level_control_move(ZigbeeZcl_level_control *level_control_object,
@@ -164,11 +224,29 @@ static void on_level_control_step_resp(ZigBeeServiceInterface *service_interface
        ZigbeeServiceInterfaceRespCbData_t *cb_data =
                (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
 
-       NOT_USED(cb_data);
+       ZigbeeZcl_level_control *level_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;
+       }
+
+       level_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+       zblib_check_null_free_and_ret("level_object", level_object, cb_data);
+
+       invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+       zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+       zigbee_zcl_level_control_complete_step(level_object, invocation, payload->result);
+
+       g_free(cb_data);
 }
 
 static gboolean on_level_control_step(ZigbeeZcl_level_control *level_control_object,
@@ -176,7 +254,7 @@ static gboolean on_level_control_step(ZigbeeZcl_level_control *level_control_obj
        gshort node_id,
        gchar endpoint,
        gchar step_mode,
-       gchar move_mode,
+       gchar step_size,
        gshort transition_time,
        gpointer user_data)
 {
@@ -192,7 +270,7 @@ static gboolean on_level_control_step(ZigbeeZcl_level_control *level_control_obj
        req.node_id = node_id;
        req.endpoint = endpoint;
        req.step_mode = step_mode;
-       req.move_mode = move_mode;
+       req.step_size = step_size;
        req.transition_time = transition_time;
 
        /* Allocate response callback data */
@@ -235,11 +313,30 @@ static void on_level_control_move_to_level_with_on_off_resp(ZigBeeServiceInterfa
        ZigbeeServiceInterfaceRespCbData_t *cb_data =
                (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
 
-       NOT_USED(cb_data);
+       ZigbeeZcl_level_control *level_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;
+       }
+
+       level_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+       zblib_check_null_free_and_ret("level_object", level_object, cb_data);
+
+       invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+       zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+       zigbee_zcl_level_control_complete_move_to_level_with_on_off(level_object, invocation,
+               payload->result);
+
+       g_free(cb_data);
 }
 
 static gboolean on_level_control_move_to_level_with_on_off(
@@ -305,11 +402,30 @@ static void on_level_control_move_with_on_off_resp(ZigBeeServiceInterface *servi
        ZigbeeServiceInterfaceRespCbData_t *cb_data =
                (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
 
-       NOT_USED(cb_data);
+       ZigbeeZcl_level_control *level_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;
+       }
+
+       level_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+       zblib_check_null_free_and_ret("level_object", level_object, cb_data);
+
+       invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+       zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+       zigbee_zcl_level_control_complete_move_with_on_off(level_object, invocation,
+               payload->result);
+
+       g_free(cb_data);
 }
 
 static gboolean on_level_control_move_with_on_off(
@@ -375,11 +491,30 @@ static void on_level_control_step_with_on_off_resp(ZigBeeServiceInterface *servi
        ZigbeeServiceInterfaceRespCbData_t *cb_data =
                (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
 
-       NOT_USED(cb_data);
+       ZigbeeZcl_level_control *level_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;
+       }
+
+       level_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+       zblib_check_null_free_and_ret("level_object", level_object, cb_data);
+
+       invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+       zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+       zigbee_zcl_level_control_complete_step_with_on_off(level_object, invocation,
+               payload->result);
+
+       g_free(cb_data);
 }
 
 static gboolean on_level_control_step_with_on_off(
@@ -388,7 +523,7 @@ static gboolean on_level_control_step_with_on_off(
        gshort node_id,
        gchar endpoint,
        gchar step_mode,
-       gchar move_mode,
+       gchar step_size,
        gshort transition_time,
        gpointer user_data)
 {
@@ -404,7 +539,7 @@ static gboolean on_level_control_step_with_on_off(
        req.node_id = node_id;
        req.endpoint = endpoint;
        req.step_mode = step_mode;
-       req.move_mode = move_mode;
+       req.step_size = step_size;
        req.transition_time = transition_time;
 
        /* Allocate response callback data */
@@ -447,11 +582,29 @@ static void on_level_control_stop_resp(ZigBeeServiceInterface *service_interface
        ZigbeeServiceInterfaceRespCbData_t *cb_data =
                (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
 
-       NOT_USED(cb_data);
+       ZigbeeZcl_level_control *level_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;
+       }
+
+       level_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+       zblib_check_null_free_and_ret("level_object", level_object, cb_data);
+
+       invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+       zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+       zigbee_zcl_level_control_complete_stop(level_object, invocation, payload->result);
+
+       g_free(cb_data);
 }
 
 static gboolean on_level_control_stop(ZigbeeZcl_level_control *level_control_object,
@@ -509,15 +662,28 @@ static gboolean on_level_control_stop(ZigbeeZcl_level_control *level_control_obj
 void zigbee_service_dbus_interface_zcl_level_control_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_level_control *level_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);
+       level_object = _service_interface_ref_zigbee_zcl_level_control(service_interface);
+       zblib_check_null_ret("level_object", level_object);
+
        NOT_USED(noti_cb_data);
+
+       switch(noti_id) {
+       default:
+               Z_LOGE("Unexpected notification [%x]", noti_id);
+       break;
+       }
+
+       /* ZigbeeZcl_level_control should be dereferenced */
+       g_object_unref(level_object);
 }
 
 gboolean zigbee_service_dbus_interface_zcl_level_control_init(ZigBeeServiceInterface *service_interface,
index 9ea1099..1369cac 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_level_control.h"
@@ -138,6 +139,7 @@ ZigBeeDriver *zblib_driver_zcl_level_control_new(ZigBeePlugin *plugin,
        ZblibDriverZclLevelControlOps_t *ops)
 {
        ZigBeeDriver *driver = NULL;
+       ZigBeeService *service = NULL;
        ZblibDriverZclLevelControlPrivData_t *priv_data = NULL;
        gboolean ret;
 
@@ -153,6 +155,19 @@ ZigBeeDriver *zblib_driver_zcl_level_control_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) {
index e222e6a..3bbc5cf 100644 (file)
@@ -630,7 +630,7 @@ static gpointer __zblib_request_create_zcl_level_control_request_data(guint requ
                        req->node_id = in_req->node_id;
                        req->endpoint = in_req->endpoint;
                        req->step_mode = in_req->step_mode;
-                       req->move_mode = in_req->move_mode;
+                       req->step_size = in_req->step_size;
                        req->transition_time = in_req->transition_time;
                }
 
@@ -694,7 +694,7 @@ static gpointer __zblib_request_create_zcl_level_control_request_data(guint requ
                        req->node_id = in_req->node_id;
                        req->endpoint = in_req->endpoint;
                        req->step_mode = in_req->step_mode;
-                       req->move_mode = in_req->move_mode;
+                       req->step_size = in_req->step_size;
                        req->transition_time = in_req->transition_time;
                }