Implement module dispatcher functions
[platform/core/connectivity/zigbee-manager.git] / zigbee-daemon / zigbee-lib / src / drivers / zblib_driver_zcl_scene.c
index c036e64..0663447 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <zblib.h>
 #include <zblib_driver.h>
+#include <zblib_request.h>
 
 #include "zblib_driver_zcl_scene.h"
 
@@ -26,31 +27,107 @@ typedef struct {
        ZblibDriverZclSceneOps_t *ops; /**< Operations */
 } ZblibDriverZclScenePrivData_t;
 
-static gboolean __zblib_driver_zcl_scene_dispatcher(ZigBeeDriver *driver)
+static gboolean __zblib_driver_zcl_scene_dispatcher(ZigBeeDriver *driver, guint request_id)
 {
-       if (NULL == driver) {
-               Z_LOGE("driver is NULL");
-               return FALSE;
+       ZigBeeService *service = NULL;
+       ZblibDriverZclScenePrivData_t *priv_data = NULL;
+       ZblibDriverZclSceneOps_t *ops = NULL;
+       guint request_type;
+       guint ops_id;
+       gboolean ret = FALSE;
+
+       zblib_check_null_ret_error("driver", driver, FALSE);
+
+       service = zblib_driver_ref_service(driver);
+       zblib_check_null_ret_error("service", service, FALSE);
+
+       /* Fetch private data */
+       priv_data = zblib_driver_ref_object(driver);
+       zblib_check_null_ret_error("priv_data", priv_data, FALSE);
+
+       ops = priv_data->ops;
+       zblib_check_null_ret_error("ops", ops, FALSE);
+
+       /* Fetch request_type using request_id */
+       request_type = zblib_request_ref_request_type_by_request_id(service, request_id);
+
+       /* Fetch ops ID */
+       ops_id = zblib_request_get_ops_id(request_type);
+       switch (ops_id) {
+       case ZBLIB_ZCL_SCENE_OPS_ADD_SCENE: {
+               zblib_check_null_ret_error("ops->add_scene",
+                       ops->add_scene, FALSE);
+
+               ret = ops->add_scene(driver, request_id);
+       }
+       break;
+
+       case ZBLIB_ZCL_SCENE_OPS_VIEW_SCENE: {
+               zblib_check_null_ret_error("ops->view_scene",
+                       ops->view_scene, FALSE);
+
+               ret = ops->view_scene(driver, request_id);
+       }
+       break;
+
+       case ZBLIB_ZCL_SCENE_OPS_REMOVE_SCENE: {
+               zblib_check_null_ret_error("ops->remove_scene",
+                       ops->remove_scene, FALSE);
+
+               ret = ops->remove_scene(driver, request_id);
+       }
+       break;
+
+       case ZBLIB_ZCL_SCENE_OPS_STORE_SCENE: {
+               zblib_check_null_ret_error("ops->store_scene",
+                       ops->store_scene, FALSE);
+
+               ret = ops->store_scene(driver, request_id);
        }
+       break;
 
-       return TRUE;
+       case ZBLIB_ZCL_SCENE_OPS_RECALL_SCENE: {
+               zblib_check_null_ret_error("ops->recall_scene",
+                       ops->recall_scene, FALSE);
+
+               ret = ops->recall_scene(driver, request_id);
+       }
+       break;
+
+       case ZBLIB_ZCL_SCENE_OPS_REMOVE_ALL_SCENE: {
+               zblib_check_null_ret_error("ops->remove_all_scene",
+                       ops->remove_all_scene, FALSE);
+
+               ret = ops->remove_all_scene(driver, request_id);
+       }
+       break;
+
+       case ZBLIB_ZCL_SCENE_OPS_GET_SCENE_MEMBERSHIP: {
+               zblib_check_null_ret_error("ops->get_scene_membership",
+                       ops->get_scene_membership, FALSE);
+
+               ret = ops->get_scene_membership(driver, request_id);
+       }
+       break;
+
+       default:
+       break;
+       }
+
+       Z_LOGD("ret: [%d]", ret);
+
+       return ret;
 }
 
 static void __zblib_driver_zcl_scene_free_hook(ZigBeeDriver *driver)
 {
        ZblibDriverZclScenePrivData_t *priv_data = NULL;
 
-       if (NULL == driver) {
-               Z_LOGE("driver is NULL");
-               return;
-       }
+       zblib_check_null_ret("driver", driver);
 
        /* Fetch private data */
        priv_data = zblib_driver_ref_object(driver);
-       if (NULL == priv_data) {
-               Z_LOGE("priv_data is NULL");
-               return;
-       }
+       zblib_check_null_ret("priv_data", priv_data);
 
        /* Free resources */
        g_free(priv_data);
@@ -64,17 +141,11 @@ ZigBeeDriver *zblib_driver_zcl_scene_new(ZigBeePlugin *plugin,
        ZblibDriverZclScenePrivData_t *priv_data = NULL;
        gboolean ret;
 
-       if (NULL == plugin) {
-               Z_LOGE("plugin is NULL");
-               return NULL;
-       }
+       zblib_check_null_ret_error("plugin", plugin, NULL);
 
        /* Create new driver */
        driver = zblib_driver_new(plugin, driver_name, ZBLIB_DRIVER_TYPE_ZCL_SCENE);
-       if (NULL == driver) {
-               Z_LOGE("driver is NULL");
-               return NULL;
-       }
+       zblib_check_null_ret_error("driver", driver, NULL);
 
        /* Allocate memory for private data */
        priv_data = g_malloc0(sizeof(ZblibDriverZclScenePrivData_t));
@@ -123,10 +194,7 @@ ZigBeeDriver *zblib_driver_zcl_scene_new(ZigBeePlugin *plugin,
 
 void zblib_driver_zcl_scene_free(ZigBeeDriver *driver)
 {
-       if (NULL == driver) {
-               Z_LOGE("driver is NULL");
-               return;
-       }
+       zblib_check_null_ret("driver", driver);
 
        /* Free driver */
        zblib_driver_free(driver);