2 * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
4 * Contact: Suresh Kumar N (suresh.n@samsung.com)
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 #include <zblib_driver.h>
21 #include <zblib_request.h>
23 #include "zblib_driver_zcl_scene.h"
27 ZblibDriverZclSceneOps_t *ops; /**< Operations */
28 } ZblibDriverZclScenePrivData_t;
30 static gboolean __zblib_driver_zcl_scene_dispatcher(ZigBeeDriver *driver, guint request_id)
32 ZigBeeService *service = NULL;
33 ZblibDriverZclScenePrivData_t *priv_data = NULL;
34 ZblibDriverZclSceneOps_t *ops = NULL;
39 zblib_check_null_ret_error("driver", driver, FALSE);
41 service = zblib_driver_ref_service(driver);
42 zblib_check_null_ret_error("service", service, FALSE);
44 /* Fetch private data */
45 priv_data = zblib_driver_ref_object(driver);
46 zblib_check_null_ret_error("priv_data", priv_data, FALSE);
49 zblib_check_null_ret_error("ops", ops, FALSE);
51 /* Fetch request_type using request_id */
52 request_type = zblib_request_ref_request_type_by_request_id(service, request_id);
55 ops_id = zblib_request_get_ops_id(request_type);
57 case ZBLIB_ZCL_SCENE_OPS_ADD_SCENE: {
58 zblib_check_null_ret_error("ops->add_scene",
59 ops->add_scene, FALSE);
61 ret = ops->add_scene(driver, request_id);
65 case ZBLIB_ZCL_SCENE_OPS_VIEW_SCENE: {
66 zblib_check_null_ret_error("ops->view_scene",
67 ops->view_scene, FALSE);
69 ret = ops->view_scene(driver, request_id);
73 case ZBLIB_ZCL_SCENE_OPS_REMOVE_SCENE: {
74 zblib_check_null_ret_error("ops->remove_scene",
75 ops->remove_scene, FALSE);
77 ret = ops->remove_scene(driver, request_id);
81 case ZBLIB_ZCL_SCENE_OPS_STORE_SCENE: {
82 zblib_check_null_ret_error("ops->store_scene",
83 ops->store_scene, FALSE);
85 ret = ops->store_scene(driver, request_id);
89 case ZBLIB_ZCL_SCENE_OPS_RECALL_SCENE: {
90 zblib_check_null_ret_error("ops->recall_scene",
91 ops->recall_scene, FALSE);
93 ret = ops->recall_scene(driver, request_id);
97 case ZBLIB_ZCL_SCENE_OPS_REMOVE_ALL_SCENE: {
98 zblib_check_null_ret_error("ops->remove_all_scene",
99 ops->remove_all_scene, FALSE);
101 ret = ops->remove_all_scene(driver, request_id);
105 case ZBLIB_ZCL_SCENE_OPS_GET_SCENE_MEMBERSHIP: {
106 zblib_check_null_ret_error("ops->get_scene_membership",
107 ops->get_scene_membership, FALSE);
109 ret = ops->get_scene_membership(driver, request_id);
117 Z_LOGD("ret: [%d]", ret);
122 static void __zblib_driver_zcl_scene_free_hook(ZigBeeDriver *driver)
124 ZblibDriverZclScenePrivData_t *priv_data = NULL;
126 zblib_check_null_ret("driver", driver);
128 /* Fetch private data */
129 priv_data = zblib_driver_ref_object(driver);
130 zblib_check_null_ret("priv_data", priv_data);
136 ZigBeeDriver *zblib_driver_zcl_scene_new(ZigBeePlugin *plugin,
137 const gchar *driver_name,
138 ZblibDriverZclSceneOps_t *ops)
140 ZigBeeDriver *driver = NULL;
141 ZblibDriverZclScenePrivData_t *priv_data = NULL;
144 zblib_check_null_ret_error("plugin", plugin, NULL);
146 /* Create new driver */
147 driver = zblib_driver_new(plugin, driver_name, ZBLIB_DRIVER_TYPE_ZCL_SCENE);
148 zblib_check_null_ret_error("driver", driver, NULL);
150 /* Allocate memory for private data */
151 priv_data = g_malloc0(sizeof(ZblibDriverZclScenePrivData_t));
153 /* Update private data */
154 priv_data->ops = ops;
156 /* Link private data to driver */
157 ret = zblib_driver_link_object(driver, priv_data);
159 Z_LOGE("zblib_driver_link_object failed!");
161 /* Free allocated resources */
168 /* Set operations dispatcher function */
169 ret = zblib_driver_set_dispatcher(driver, __zblib_driver_zcl_scene_dispatcher);
171 Z_LOGE("zblib_driver_set_dispatcher failed!");
173 /* Free allocated resources */
180 /* Set free hook function */
181 ret = zblib_driver_set_free_hook(driver, __zblib_driver_zcl_scene_free_hook);
183 Z_LOGE("zblib_driver_set_free_hook failed!");
185 /* Free allocated resources */
195 void zblib_driver_zcl_scene_free(ZigBeeDriver *driver)
197 zblib_check_null_ret("driver", driver);
200 zblib_driver_free(driver);