Implement ZCL OnOff Cluster
authorJiwan Kim <ji-wan.kim@samsung.com>
Wed, 1 Feb 2017 09:18:30 +0000 (18:18 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Thu, 11 May 2017 09:10:25 +0000 (18:10 +0900)
Change-Id: Ib7c0bc4de5b45527435294a6ab1144fab3672eb1
Signed-off-by: Jiwan Kim <ji-wan.kim@samsung.com>
common/include/zigbee_zcl_on_off_type.h
zigbee-daemon/zigbee-interface/introspection/zcl-on-off.xml
zigbee-daemon/zigbee-interface/src/zigbee_service_dbus_interface_zcl_on_off.c
zigbee-daemon/zigbee-lib/include/zblib_driver_zcl_on_off.h
zigbee-daemon/zigbee-lib/src/drivers/zblib_driver_zcl_on_off.c

index 148ba2c..99bf544 100644 (file)
 
 #include <zigbee_types.h>
 
+/* -----------------------------------------------------------------------------
+ * For Requests
+ * ---------------------------------------------------------------------------*/
+
 /**
  * @brief Definition for ZCL on/off set on/off structure.
  * @since_tizen 3.0
@@ -40,4 +44,16 @@ typedef struct {
        char endpoint; /**< Endpoint */
 } ZigbeeZclOnOffGetOnOffState_t;
 
+/* -----------------------------------------------------------------------------
+ * For Notifications
+ * ---------------------------------------------------------------------------*/
+
+/**
+ * @brief Definition for state of ZCL on/off structure.
+ * @since_tizen 3.0
+ */
+typedef struct {
+       char state; /**< ON/OFF state */
+} ZigbeeZclOnOffOnOffState_t;
+
 #endif /* __ZIGBEE_ZCL_ON_OFF_TYPE_H__ */
index b4d595c..33b4159 100644 (file)
@@ -13,7 +13,7 @@
                </method>
 
                <signal name='on_off_state'>
-                       <arg type='y' name='status'/>
+                       <arg type='y' name='state'/>
                </signal>
        </interface>
 </node>
index ce4603f..ab6a7b9 100644 (file)
 
 #include <zblib_driver_zcl_on_off.h>
 
+static void *_service_interface_ref_zigbee_zcl_on_off(ZigBeeServiceInterface *service_interface)
+{
+       ZigbeeObjectSkeleton *zigbee_object = NULL;
+       ZigbeeCustomData_t *custom_data = NULL;
+       ZigbeeZcl_on_off *on_off_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;
+       }
+
+       on_off_object = zigbee_object_get_zcl_on_off(ZIGBEE_OBJECT(zigbee_object));
+       return on_off_object;
+}
+
 static void on_on_off_set_on_off_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_on_off *on_off_object;
+       GDBusMethodInvocation *invocation;
+       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 is null");
+               return;
+       }
+
+       on_off_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+       zblib_check_null_free_and_ret("on_off_object", on_off_object, cb_data);
+
+       invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+       zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+       zigbee_zcl_on_off_complete_set_on_off(on_off_object, invocation,
+               payload->result);
+
+       g_free(cb_data);
 }
 
 static gboolean on_on_off_set_on_off(ZigbeeZcl_on_off *on_off_object,
@@ -93,11 +133,28 @@ static void on_on_off_get_on_off_state_resp(ZigBeeServiceInterface *service_inte
        ZigbeeServiceInterfaceRespCbData_t *cb_data =
                (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
 
-       NOT_USED(cb_data);
+       ZigbeeZcl_on_off *on_off_object;
+       GDBusMethodInvocation *invocation;
+       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 is null");
+               return;
+       }
+
+       on_off_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+       zblib_check_null_free_and_ret("on_off_object", on_off_object, cb_data);
+
+       invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+       zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+       zigbee_zcl_on_off_complete_get_on_off_state(on_off_object, invocation,
+               payload->result);
+
+       g_free(cb_data);
 }
 
 static gboolean on_on_off_get_on_off_state(ZigbeeZcl_on_off *on_off_object,
@@ -155,15 +212,37 @@ static gboolean on_on_off_get_on_off_state(ZigbeeZcl_on_off *on_off_object,
 void zigbee_service_dbus_interface_zcl_on_off_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_on_off *on_off_object = NULL;
+
+       zblib_check_null_ret("service_interface", service_interface);
+
+       if (NULL == noti_data || 0 == noti_data_len) {
+               Z_LOGE("noti_data is NULL");
                return;
        }
 
-       NOT_USED(noti_id);
-       NOT_USED(noti_data);
-       NOT_USED(noti_data_len);
+       on_off_object = _service_interface_ref_zigbee_zcl_on_off(service_interface);
+       zblib_check_null_ret("on_off_object", on_off_object);
+
        NOT_USED(noti_cb_data);
+
+       switch(noti_id) {
+       case ZBLIB_ZCL_ON_OFF_NOTI_ON_OFF_STATE: {
+               ZigbeeZclOnOffOnOffState_t *state_t =
+                       (ZigbeeZclOnOffOnOffState_t*)noti_data;
+
+               Z_LOGD("on off state : [0x%X]", state_t->state);
+
+               zigbee_zcl_on_off_emit_on_off_state(on_off_object, state_t->state);
+       break;
+       }
+       default:
+               Z_LOGE("Unexpected notification [%x]", noti_id);
+       break;
+       }
+
+       /* ZigbeeZcl_on_off should be dereferenced */
+       g_object_unref(on_off_object);
 }
 
 gboolean zigbee_service_dbus_interface_zcl_on_off_init(ZigBeeServiceInterface *service_interface,
index b3d2ed2..d06ef3b 100644 (file)
@@ -31,6 +31,11 @@ typedef enum {
        ZBLIB_ZCL_ON_OFF_OPS_GET_ON_OFF_STATE, /**< Get ON OFF state */
 } ZblibZclOnOffOps_e;
 
+/**< ZigBee 'ZCL on off' notification IDs */
+typedef enum {
+       ZBLIB_ZCL_ON_OFF_NOTI_ON_OFF_STATE = 1, /**< On Off state */
+} ZblibZclOnOffNoti_e;
+
 /* ZigBee 'ZCL on off' driver APIs */
 ZigBeeDriver *zblib_driver_zcl_on_off_new(ZigBeePlugin *plugin,
        const gchar *driver_name,
index 177346d..d2098bd 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_on_off.h"
@@ -97,6 +98,7 @@ ZigBeeDriver *zblib_driver_zcl_on_off_new(ZigBeePlugin *plugin,
        const gchar *driver_name,
        ZblibDriverZclOnOffOps_t *ops)
 {
+       ZigBeeService *service = NULL;
        ZigBeeDriver *driver = NULL;
        ZblibDriverZclOnOffPrivData_t *priv_data = NULL;
        gboolean ret;
@@ -113,6 +115,19 @@ ZigBeeDriver *zblib_driver_zcl_on_off_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) {