Implement ZCL Group cluster
authorsaerome kim <saerome.kim@samsung.com>
Thu, 2 Feb 2017 13:20:18 +0000 (22:20 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Thu, 11 May 2017 09:10:25 +0000 (18:10 +0900)
Change-Id: Ibc5b662e3e406af602789ebb8c8c40034bcea71b
Signed-off-by: saerome kim <saerome.kim@samsung.com>
common/include/zigbee_zcl_group_type.h
zigbee-daemon/zigbee-interface/introspection/zcl-group.xml
zigbee-daemon/zigbee-interface/src/zigbee_service_dbus_interface_zcl_group.c
zigbee-daemon/zigbee-lib/include/zblib_driver_zcl_group.h
zigbee-daemon/zigbee-lib/src/drivers/zblib_driver_zcl_group.c

index d15219a..e89df85 100644 (file)
 
 #include <zigbee_types.h>
 
+/* --------------------------------------------------------------------------------------
+ * For Request
+ * -------------------------------------------------------------------------------------*/
+
 /**
  * @brief Definition for ZCL Group add group structure.
  * @since_tizen 3.0
@@ -83,4 +87,55 @@ typedef struct {
        char group_name[ZIGBEE_ZCL_GROUP_NAME_MAX_LEN + 1]; /**< Group name (NULL terminated) */
 } ZigbeeZclGroupAddGroupIfIdentifying_t;
 
+/* --------------------------------------------------------------------------------------
+ * For Notifications
+ * -------------------------------------------------------------------------------------*/
+
+/**
+ * @brief Definition for ZCL Group add group response structure.
+ * @since_tizen 3.0
+ */
+typedef struct {
+       short node_id; /**< Node ID */
+       char src_ep; /**< Source endpoint */
+       char status; /**< Status code */
+       short group_id; /**< Group ID */
+} ZigbeeZclGroupAddGroupNoti_t;
+
+/**
+ * @brief Definition for ZCL Group view group structure.
+ * @since_tizen 3.0
+ */
+typedef struct {
+       short node_id; /**< Node ID */
+       char src_ep; /**< Source endpoint */
+       char status; /**< Status code */
+       short group_id; /**< Group ID */
+       char group_name[ZIGBEE_ZCL_GROUP_NAME_MAX_LEN + 1]; /**< Group name (NULL terminated) */
+} ZigbeeZclGroupViewGroupNoti_t;
+
+/**
+ * @brief Definition for ZCL Group get group membership structure.
+ * @since_tizen 3.0
+ */
+typedef struct {
+       short node_id; /**< Node ID */
+       char src_ep; /**< Source endpoint */
+       char capacity; /**< Capacity of group */
+       char group_count; /**< Group ID */
+       short *group_list; /**< Group list */
+} ZigbeeZclGroupGetGroupMembershipNoti_t;
+
+/**
+ * @brief Definition for ZCL Group remove structure.
+ * @since_tizen 3.0
+ */
+typedef struct {
+       short node_id; /**< Node ID */
+       char src_ep; /**< Source endpoint */
+       char status; /**< Status code */
+       short group_id; /**< Group ID */
+} ZigbeeZclGroupRemoveGroupNoti_t;
+
+
 #endif /* __ZIGBEE_ZCL_GROUP_TYPE_H__ */
index bba87d5..7723f2e 100644 (file)
@@ -4,7 +4,7 @@
                        <arg type='q' name='nodeId' direction='in'/>
                        <arg type='y' name='dst_ep' direction='in'/>
                        <arg type='q' name='group_id' direction='in'/>
-                       <arg type='ay' name='group_name' direction='in'/>
+                       <arg type='a(y)' name='group_name' direction='in'/>
                        <arg type='i' name='result' direction='out'/>
                </method>
                <method name='view_group'>
                        <arg type='q' name='nodeId' direction='in'/>
                        <arg type='y' name='dst_ep' direction='in'/>
                        <arg type='i' name='result' direction='out'/>
-                       <arg type='y' name='status' direction='out'/>
                </method>
                <method name='add_group_if_identifying'>
                        <arg type='q' name='nodeId' direction='in'/>
                        <arg type='y' name='dst_ep' direction='in'/>
                        <arg type='q' name='group_id' direction='in'/>
-                       <arg type='ay' name='group_name' direction='in'/>
+                       <arg type='a(y)' name='group_name' direction='in'/>
                        <arg type='i' name='result' direction='out'/>
                </method>
 
index 07ec59c..833162d 100644 (file)
 
 #include <zblib_driver_zcl_group.h>
 
+static void *_service_interface_ref_zigbee_zcl_group(ZigBeeServiceInterface *service_interface)
+{
+       ZigbeeObjectSkeleton *zigbee_object = NULL;
+       ZigbeeCustomData_t *custom_data = NULL;
+       ZigbeeZcl_group *group_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;
+       }
+
+       group_object = zigbee_object_get_zcl_group(ZIGBEE_OBJECT(zigbee_object));
+       return group_object;
+}
+
 static void on_zcl_group_add_group_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_group *group_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;
+       }
+
+       group_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+       zblib_check_null_free_and_ret("group_object", group_object, cb_data);
+
+       invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+       zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+       zigbee_zcl_group_complete_add_group(group_object, invocation, payload->result);
+
+       g_free(cb_data);
 }
 
 static gboolean on_zcl_group_add_group(ZigbeeZcl_group *zcl_group_object,
@@ -56,8 +97,10 @@ static gboolean on_zcl_group_add_group(ZigbeeZcl_group *zcl_group_object,
        req.node_id = node_id;
        req.dest_ep = dest_ep;
        req.group_id = group_id;
-       g_variant_get(group_name, "ay", &iter);
-       while (g_variant_iter_loop(iter, "y", req.group_name[i])) {
+
+
+       g_variant_get(group_name, "a(y)", &iter);
+       while (g_variant_iter_loop(iter, "(y)", &req.group_name[i])) {
                i++;
                if (i >= ZIGBEE_ZCL_GROUP_NAME_MAX_LEN + 1)
                        break;
@@ -103,11 +146,29 @@ static void on_zcl_group_view_group_resp(ZigBeeServiceInterface *service_interfa
        ZigbeeServiceInterfaceRespCbData_t *cb_data =
                (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
 
-       NOT_USED(cb_data);
+       ZigbeeZcl_group *group_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;
+       }
+
+       group_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+       zblib_check_null_free_and_ret("group_object", group_object, cb_data);
+
+       invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+       zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+       zigbee_zcl_group_complete_view_group(group_object, invocation, payload->result);
+
+       g_free(cb_data);
 }
 
 static gboolean on_zcl_group_view_group(ZigbeeZcl_group *zcl_group_object,
@@ -170,11 +231,29 @@ static void on_zcl_group_get_group_membership_resp(ZigBeeServiceInterface *servi
        ZigbeeServiceInterfaceRespCbData_t *cb_data =
                (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
 
-       NOT_USED(cb_data);
+       ZigbeeZcl_group *group_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;
+       }
+
+       group_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+       zblib_check_null_free_and_ret("group_object", group_object, cb_data);
+
+       invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+       zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+       zigbee_zcl_group_complete_get_group_membership(group_object, invocation, payload->result);
+
+       g_free(cb_data);
 }
 
 static gboolean on_zcl_group_get_group_membership(ZigbeeZcl_group *zcl_group_object,
@@ -252,11 +331,29 @@ static void on_zcl_group_remove_group_resp(ZigBeeServiceInterface *service_inter
        ZigbeeServiceInterfaceRespCbData_t *cb_data =
                (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
 
-       NOT_USED(cb_data);
+       ZigbeeZcl_group *group_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;
+       }
+
+       group_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+       zblib_check_null_free_and_ret("group_object", group_object, cb_data);
+
+       invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+       zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+       zigbee_zcl_group_complete_remove_group(group_object, invocation, payload->result);
+
+       g_free(cb_data);
 }
 
 static gboolean on_zcl_group_remove_group(ZigbeeZcl_group *zcl_group_object,
@@ -319,11 +416,29 @@ static void on_zcl_group_remove_all_group_resp(ZigBeeServiceInterface *service_i
        ZigbeeServiceInterfaceRespCbData_t *cb_data =
                (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
 
-       NOT_USED(cb_data);
+       ZigbeeZcl_group *group_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;
+       }
+
+       group_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+       zblib_check_null_free_and_ret("group_object", group_object, cb_data);
+
+       invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+       zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+       zigbee_zcl_group_complete_remove_all_group(group_object, invocation, payload->result);
+
+       g_free(cb_data);
 }
 
 static gboolean on_zcl_group_remove_all_group(ZigbeeZcl_group *zcl_group_object,
@@ -384,11 +499,29 @@ static void on_zcl_group_add_group_if_identifying_resp(ZigBeeServiceInterface *s
        ZigbeeServiceInterfaceRespCbData_t *cb_data =
                (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
 
-       NOT_USED(cb_data);
+       ZigbeeZcl_group *group_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;
+       }
+
+       group_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+       zblib_check_null_free_and_ret("group_object", group_object, cb_data);
+
+       invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+       zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+       zigbee_zcl_group_complete_add_group_if_identifying(group_object, invocation, payload->result);
+
+       g_free(cb_data);
 }
 
 static gboolean on_zcl_group_add_group_if_identifying(ZigbeeZcl_group *zcl_group_object,
@@ -414,8 +547,8 @@ static gboolean on_zcl_group_add_group_if_identifying(ZigbeeZcl_group *zcl_group
        req.node_id = node_id;
        req.dest_ep = dest_ep;
        req.group_id = group_id;
-       g_variant_get(group_name, "ay", &iter);
-       while (g_variant_iter_loop(iter, "y", req.group_name[i])) {
+       g_variant_get(group_name, "a(y)", &iter);
+       while (g_variant_iter_loop(iter, "(y)", &req.group_name[i])) {
                i++;
                if (i >= ZIGBEE_ZCL_GROUP_NAME_MAX_LEN + 1)
                        break;
@@ -458,15 +591,79 @@ static gboolean on_zcl_group_add_group_if_identifying(ZigbeeZcl_group *zcl_group
 void zigbee_service_dbus_interface_zcl_group_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_group *group_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);
+       group_object = _service_interface_ref_zigbee_zcl_group(service_interface);
+       zblib_check_null_ret("group_object", group_object);
+
        NOT_USED(noti_cb_data);
+
+       switch(noti_id) {
+       case ZBLIB_SERVICE_NOTI_ADD_GROUP_RSP: {
+               ZigbeeZclGroupAddGroupNoti_t *rsp =
+                       (ZigbeeZclGroupAddGroupNoti_t*)noti_data;
+
+               Z_LOGD("add_group_rsp from : [0x%X]", rsp->node_id);
+
+               zigbee_zcl_group_emit_add_group_rsp(group_object, rsp->node_id, rsp->src_ep,
+                       rsp->status, rsp->group_id);
+       }
+       break;
+       case ZBLIB_SERVICE_NOTI_VIEW_GROUP_RSP: {
+               ZigbeeZclGroupViewGroupNoti_t *rsp =
+                       (ZigbeeZclGroupViewGroupNoti_t*)noti_data;
+
+               Z_LOGD("view_group_rsp from : [0x%X]", rsp->node_id);
+
+               zigbee_zcl_group_emit_view_group_rsp(group_object, rsp->node_id, rsp->src_ep,
+                       rsp->status, rsp->group_id, rsp->group_name);
+       }
+       break;
+       case ZBLIB_SERVICE_NOTI_GET_GROUP_MEMBERSHIP_RSP: {
+               int i;
+               GVariant* group_list = NULL;
+               GVariantBuilder *attr_builder = NULL;
+
+               ZigbeeZclGroupGetGroupMembershipNoti_t *rsp =
+                       (ZigbeeZclGroupGetGroupMembershipNoti_t*)noti_data;
+
+               Z_LOGD("get_group_membership_rsp from : [0x%X]", rsp->node_id);
+
+               attr_builder = g_variant_builder_new(G_VARIANT_TYPE("aq"));
+
+               for (i = 0; i < rsp->group_count; i++)
+                       g_variant_builder_add(attr_builder, "q", rsp->group_list[i]);
+               group_list = g_variant_builder_end(attr_builder);
+               g_variant_builder_unref(attr_builder);
+
+               zigbee_zcl_group_emit_get_group_membership_rsp(group_object, rsp->node_id,
+                       rsp->src_ep, rsp->capacity, rsp->group_count, group_list);
+       }
+       break;
+       case ZBLIB_SERVICE_NOTI_REMOVE_GROUP_RSP: {
+               ZigbeeZclGroupRemoveGroupNoti_t *rsp =
+                       (ZigbeeZclGroupRemoveGroupNoti_t*)noti_data;
+
+               Z_LOGD("remove_group_rsp from : [0x%X]", rsp->node_id);
+
+               zigbee_zcl_group_emit_remove_group_rsp(group_object, rsp->node_id, rsp->src_ep,
+                       rsp->status, rsp->group_id);
+       }
+       break;
+       default:
+               Z_LOGE("Unexpected notification [%x]", noti_id);
+       break;
+       }
+
+       /* ZigbeeZcl_group should be dereferenced */
+       g_object_unref(group_object);
 }
 
 gboolean zigbee_service_dbus_interface_zcl_group_init(ZigBeeServiceInterface *service_interface,
index e353513..24987a0 100644 (file)
@@ -39,6 +39,14 @@ typedef enum {
        ZBLIB_ZCL_GROUP_OPS_ADD_GROUP_IF_IDENTIFYING, /**< Add group if identifying */
 } ZblibZclGroupOps_e;
 
+/**< ZigBee 'ZCL Group' notification IDs */
+typedef enum {
+       ZBLIB_SERVICE_NOTI_ADD_GROUP_RSP = 1, /**< Add group response */
+       ZBLIB_SERVICE_NOTI_VIEW_GROUP_RSP, /**< View group response */
+       ZBLIB_SERVICE_NOTI_GET_GROUP_MEMBERSHIP_RSP, /**< Get group membership response */
+       ZBLIB_SERVICE_NOTI_REMOVE_GROUP_RSP, /**< Remove group response */
+} ZblibZclGroupNoti_e;
+
 /* ZigBee 'Zcl group' driver APIs */
 ZigBeeDriver *zblib_driver_zcl_group_new(ZigBeePlugin *plugin,
        const gchar *driver_name,
index 5866faf..5d6da34 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_group.h"
@@ -130,6 +131,7 @@ ZigBeeDriver *zblib_driver_zcl_group_new(ZigBeePlugin *plugin,
        ZblibDriverZclGroupOps_t *ops)
 {
        ZigBeeDriver *driver = NULL;
+       ZigBeeService *service = NULL;
        ZblibDriverZclGroupPrivData_t *priv_data = NULL;
        gboolean ret;
 
@@ -145,6 +147,19 @@ ZigBeeDriver *zblib_driver_zcl_group_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) {