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_plugin.h>
22 #include <zblib_request.h>
24 #include "zblib_driver_zcl_poll_control.h"
28 ZblibDriverZclPollControlOps_t *ops; /**< Operations */
29 } ZblibDriverZclPollControlPrivData_t;
31 static gboolean __zblib_driver_zcl_poll_control_dispatcher(ZigBeeDriver *driver, guint request_id)
33 ZigBeeService *service = NULL;
34 ZblibDriverZclPollControlPrivData_t *priv_data = NULL;
35 ZblibDriverZclPollControlOps_t *ops = NULL;
40 zblib_check_null_ret_error("driver", driver, FALSE);
42 service = zblib_driver_ref_service(driver);
43 zblib_check_null_ret_error("service", service, FALSE);
45 /* Fetch private data */
46 priv_data = zblib_driver_ref_object(driver);
47 zblib_check_null_ret_error("priv_data", priv_data, FALSE);
50 zblib_check_null_ret_error("ops", ops, FALSE);
52 /* Fetch request_type using request_id */
53 request_type = zblib_request_ref_request_type_by_request_id(service, request_id);
56 ops_id = zblib_request_get_ops_id(request_type);
58 case ZBLIB_ZCL_POLL_CONTROL_OPS_CHECK_IN_RESPONSE: {
59 zblib_check_null_ret_error("ops->check_in_response",
60 ops->check_in_response, FALSE);
62 ret = ops->check_in_response(driver, request_id);
66 case ZBLIB_ZCL_POLL_CONTROL_OPS_FAST_POLL_STOP: {
67 zblib_check_null_ret_error("ops->fast_poll_stop",
68 ops->fast_poll_stop, FALSE);
70 ret = ops->fast_poll_stop(driver, request_id);
74 case ZBLIB_ZCL_POLL_CONTROL_OPS_SET_LONG_POLL_INTERVAL: {
75 zblib_check_null_ret_error("ops->set_long_poll_interval",
76 ops->set_long_poll_interval, FALSE);
78 ret = ops->set_long_poll_interval(driver, request_id);
82 case ZBLIB_ZCL_POLL_CONTROL_OPS_SET_SHORT_POLL_INTERVAL: {
83 zblib_check_null_ret_error("ops->set_short_poll_interval",
84 ops->set_short_poll_interval, FALSE);
86 ret = ops->set_short_poll_interval(driver, request_id);
94 Z_LOGD("ret: [%d]", ret);
99 static void __zblib_driver_zcl_poll_control_free_hook(ZigBeeDriver *driver)
101 ZblibDriverZclPollControlPrivData_t *priv_data = NULL;
103 zblib_check_null_ret("driver", driver);
105 /* Fetch private data */
106 priv_data = zblib_driver_ref_object(driver);
107 zblib_check_null_ret("priv_data", priv_data);
113 ZigBeeDriver *zblib_driver_zcl_poll_control_new(ZigBeePlugin *plugin,
114 const gchar *driver_name,
115 ZblibDriverZclPollControlOps_t *ops)
117 ZigBeeDriver *driver = NULL;
118 ZigBeeService *service = NULL;
119 ZblibDriverZclPollControlPrivData_t *priv_data = NULL;
122 zblib_check_null_ret_error("plugin", plugin, NULL);
124 /* Create new driver */
125 driver = zblib_driver_new(plugin, driver_name, ZBLIB_DRIVER_TYPE_ZCL_POLL_CONTROL);
126 zblib_check_null_ret_error("driver", driver, NULL);
128 /* Allocate memory for private data */
129 priv_data = g_malloc0(sizeof(ZblibDriverZclPollControlPrivData_t));
131 /* Update private data */
132 priv_data->ops = ops;
134 /* Link service to driver */
135 service = zblib_plugin_ref_service(plugin);
136 if (NULL == service) {
137 Z_LOGE("zblib_plugin_ref_service failed!");
139 /* Free allocated resources */
145 zblib_driver_link_service(driver, service);
147 /* Link private data to driver */
148 ret = zblib_driver_link_object(driver, priv_data);
150 Z_LOGE("zblib_driver_link_object failed!");
152 /* Free allocated resources */
159 /* Set operations dispatcher function */
160 ret = zblib_driver_set_dispatcher(driver, __zblib_driver_zcl_poll_control_dispatcher);
162 Z_LOGE("zblib_driver_set_dispatcher failed!");
164 /* Free allocated resources */
171 /* Set free hook function */
172 ret = zblib_driver_set_free_hook(driver, __zblib_driver_zcl_poll_control_free_hook);
174 Z_LOGE("zblib_driver_set_free_hook failed!");
176 /* Free allocated resources */
186 void zblib_driver_zcl_poll_control_free(ZigBeeDriver *driver)
188 zblib_check_null_ret("driver", driver);
191 zblib_driver_free(driver);