Implement ZCL Poll Control cluster
authorsaerome kim <saerome.kim@samsung.com>
Fri, 3 Feb 2017 09:00:23 +0000 (18:00 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Thu, 11 May 2017 09:10:25 +0000 (18:10 +0900)
Change-Id: Idb4242563a6f3ad75127932616596d60dcfb2f27
Signed-off-by: saerome kim <saerome.kim@samsung.com>
common/include/zigbee_zcl_poll_control_type.h
zigbee-daemon/zigbee-interface/src/zigbee_service_dbus_interface_zcl_ias_zone.c
zigbee-daemon/zigbee-interface/src/zigbee_service_dbus_interface_zcl_poll_control.c
zigbee-daemon/zigbee-lib/include/zblib_driver_zcl_ias_zone.h
zigbee-daemon/zigbee-lib/include/zblib_driver_zcl_poll_control.h
zigbee-daemon/zigbee-lib/src/drivers/zblib_driver_zcl_poll_control.c

index 28f994a..02cabf1 100644 (file)
 
 #include <zigbee_types.h>
 
+/* -----------------------------------------------------------------------------
+ * For Requests
+ * ---------------------------------------------------------------------------*/
+
 /**
  * @brief Definition for ZCL poll control check in response structure.
  * @since_tizen 3.0
@@ -61,4 +65,18 @@ typedef struct {
        unsigned int new_short_poll_interval; /**< New short poll interval */
 } ZigbeeZclPollControlSetShortPollInterval_t;
 
+/* -----------------------------------------------------------------------------
+ * For Notification
+ * ---------------------------------------------------------------------------*/
+
+/**
+ * @brief Definition for ZCL poll control set short poll interval structure.
+ * @since_tizen 3.0
+ */
+typedef struct {
+       short node_id; /**< Node ID */
+       char src_ep; /**< Source endpoint */
+} ZigbeeZclPollControlCheckinResponseNoti_t;
+
+
 #endif /* __ZIGBEE_ZCL_POLL_CONTROL_TYPE_H__ */
index 5a921e7..bba7711 100644 (file)
@@ -148,7 +148,7 @@ void zigbee_service_dbus_interface_zcl_ias_zone_notification(ZigBeeServiceInterf
        NOT_USED(noti_cb_data);
 
        switch(noti_id) {
-       case ZBLIB_ZCL_IAS_ZONE_NOTI_ZONE_STATUS_CHANGE_NOTI: {
+       case ZBLIB_ZCL_IAS_ZONE_NOTI_ZONE_STATUS_CHANGE: {
                ZigbeeZclIasZoneStatusChangeNoti_t *rsp =
                        (ZigbeeZclIasZoneStatusChangeNoti_t*)noti_data;
 
index 2665911..2ecf836 100644 (file)
 
 #include <zblib_driver_zcl_poll_control.h>
 
+static void *_service_interface_ref_zigbee_zcl_poll_control(
+       ZigBeeServiceInterface *service_interface)
+{
+       ZigbeeObjectSkeleton *zigbee_object = NULL;
+       ZigbeeCustomData_t *custom_data = NULL;
+       ZigbeeZcl_poll_control *poll_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;
+       }
+
+       poll_object = zigbee_object_get_zcl_poll_control(ZIGBEE_OBJECT(zigbee_object));
+       return poll_object;
+}
+
 static void on_zcl_poll_control_check_in_response_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_poll_control *poll_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;
+       }
+
+       poll_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+       zblib_check_null_free_and_ret("poll_object", poll_object, cb_data);
+
+       invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+       zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+       zigbee_zcl_poll_control_complete_check_in_response(poll_object, invocation, payload->result);
+
+       g_free(cb_data);
 }
 
 static gboolean on_zcl_poll_control_check_in_response(ZigbeeZcl_poll_control *zcl_poll_control_object,
@@ -95,11 +137,29 @@ static void on_zcl_poll_control_fast_poll_stop_resp(ZigBeeServiceInterface *serv
        ZigbeeServiceInterfaceRespCbData_t *cb_data =
                (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
 
-       NOT_USED(cb_data);
+       ZigbeeZcl_poll_control *poll_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;
+       }
+
+       poll_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+       zblib_check_null_free_and_ret("poll_object", poll_object, cb_data);
+
+       invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+       zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+       zigbee_zcl_poll_control_complete_fast_poll_stop(poll_object, invocation, payload->result);
+
+       g_free(cb_data);
 }
 
 static gboolean on_zcl_poll_control_fast_poll_stop(ZigbeeZcl_poll_control *zcl_poll_control_object,
@@ -160,11 +220,29 @@ static void on_zcl_poll_control_set_long_poll_interval_resp(ZigBeeServiceInterfa
        ZigbeeServiceInterfaceRespCbData_t *cb_data =
                (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
 
-       NOT_USED(cb_data);
+       ZigbeeZcl_poll_control *poll_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;
+       }
+
+       poll_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+       zblib_check_null_free_and_ret("poll_object", poll_object, cb_data);
+
+       invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+       zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+       zigbee_zcl_poll_control_complete_set_long_poll_interval(poll_object, invocation, payload->result);
+
+       g_free(cb_data);
 }
 
 static gboolean on_zcl_poll_control_set_long_poll_interval(ZigbeeZcl_poll_control *zcl_poll_control_object,
@@ -227,11 +305,29 @@ static void on_zcl_poll_control_set_short_poll_interval_resp(ZigBeeServiceInterf
        ZigbeeServiceInterfaceRespCbData_t *cb_data =
                (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
 
-       NOT_USED(cb_data);
+       ZigbeeZcl_poll_control *poll_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;
+       }
+
+       poll_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+       zblib_check_null_free_and_ret("poll_object", poll_object, cb_data);
+
+       invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+       zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+       zigbee_zcl_poll_control_complete_set_short_poll_interval(poll_object, invocation, payload->result);
+
+       g_free(cb_data);
 }
 
 static gboolean on_zcl_poll_control_set_short_poll_interval(ZigbeeZcl_poll_control *zcl_poll_control_object,
@@ -291,15 +387,37 @@ static gboolean on_zcl_poll_control_set_short_poll_interval(ZigbeeZcl_poll_contr
 void zigbee_service_dbus_interface_zcl_poll_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_poll_control *poll_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);
+       poll_object = _service_interface_ref_zigbee_zcl_poll_control(service_interface);
+       zblib_check_null_ret("poll_object", poll_object);
+
        NOT_USED(noti_cb_data);
+
+       switch(noti_id) {
+       case ZBLIB_ZCL_POLL_CONTROL_NOTI_CHECKIN_RESPONSE: {
+               ZigbeeZclPollControlCheckinResponseNoti_t *rsp =
+                       (ZigbeeZclPollControlCheckinResponseNoti_t*)noti_data;
+
+               Z_LOGD("checkin_response from : [0x%X]", rsp->node_id);
+
+               zigbee_zcl_poll_control_emit_checkin_response(poll_object, rsp->node_id, rsp->src_ep);
+       }
+       break;
+       default:
+               Z_LOGE("Unexpected notification [%x]", noti_id);
+       break;
+       }
+
+       /* ZigbeeZcl_poll_control should be dereferenced */
+       g_object_unref(poll_object);
 }
 
 gboolean zigbee_service_dbus_interface_zcl_poll_control_init(ZigBeeServiceInterface *service_interface,
index 09d9c8d..db8aaa6 100644 (file)
@@ -31,7 +31,7 @@ typedef enum {
 
 /**< ZigBee 'ZCL IAS zone' notification IDs */
 typedef enum {
-       ZBLIB_ZCL_IAS_ZONE_NOTI_ZONE_STATUS_CHANGE_NOTI = 1, /**< Zone status change notification */
+       ZBLIB_ZCL_IAS_ZONE_NOTI_ZONE_STATUS_CHANGE = 1, /**< Zone status change notification */
        ZBLIB_ZCL_IAS_ZONE_NOTI_ENROLL_REQUEST, /**< Enroll Request Notification */
 } ZblibZclIasZoneNoti_e;
 
index 3a8edd5..c04aa9b 100644 (file)
@@ -35,6 +35,11 @@ typedef enum {
        ZBLIB_ZCL_POLL_CONTROL_OPS_SET_SHORT_POLL_INTERVAL, /**< Set short poll interval */
 } ZblibZclPollControlOps_e;
 
+/**< ZigBee 'ZCL IAS zone' notification IDs */
+typedef enum {
+       ZBLIB_ZCL_POLL_CONTROL_NOTI_CHECKIN_RESPONSE = 1, /**< Checkin response notification */
+} ZblibZclPollControlNoti_e;
+
 /* ZigBee 'Zcl poll control' driver APIs */
 ZigBeeDriver *zblib_driver_zcl_poll_control_new(ZigBeePlugin *plugin,
        const gchar *driver_name,
index a93ec00..4d964bd 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_poll_control.h"
@@ -114,6 +115,7 @@ ZigBeeDriver *zblib_driver_zcl_poll_control_new(ZigBeePlugin *plugin,
        ZblibDriverZclPollControlOps_t *ops)
 {
        ZigBeeDriver *driver = NULL;
+       ZigBeeService *service = NULL;
        ZblibDriverZclPollControlPrivData_t *priv_data = NULL;
        gboolean ret;
 
@@ -129,6 +131,19 @@ ZigBeeDriver *zblib_driver_zcl_poll_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) {