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_alarm.h"
27 ZblibDriverAlarmOps_t *ops; /**< Operations */
28 } ZblibDriverAlarmPrivData_t;
30 static gboolean __zblib_driver_alarm_dispatcher(ZigBeeDriver *driver, guint request_id)
32 ZigBeeService *service = NULL;
37 Z_LOGE("driver is NULL");
41 service = zblib_driver_ref_service(driver);
42 if (NULL == service) {
43 Z_LOGE("service is NULL");
47 /* Fetch request_type using request_id */
48 request_type = zblib_request_ref_request_type_by_request_id(service, request_id);
51 ops_id = zblib_request_get_ops_id(request_type);
53 case ZBLIB_ALARM_OPS_GET_ALARM_COUNT: {
57 case ZBLIB_ALARM_OPS_RESET_ALARM: {
61 case ZBLIB_ALARM_OPS_RESET_ALL_ALARM: {
65 case ZBLIB_ALARM_OPS_ALARM: {
69 case ZBLIB_ALARM_OPS_RESET_ALARM_LOG: {
73 case ZBLIB_ALARM_OPS_GET_ALARM: {
84 static void __zblib_driver_alarm_free_hook(ZigBeeDriver *driver)
86 ZblibDriverAlarmPrivData_t *priv_data = NULL;
89 Z_LOGE("driver is NULL");
93 /* Fetch private data */
94 priv_data = zblib_driver_ref_object(driver);
95 if (NULL == priv_data) {
96 Z_LOGE("priv_data is NULL");
104 ZigBeeDriver *zblib_driver_alarm_new(ZigBeePlugin *plugin,
105 const gchar *driver_name,
106 ZblibDriverAlarmOps_t *ops)
108 ZigBeeDriver *driver = NULL;
109 ZblibDriverAlarmPrivData_t *priv_data = NULL;
112 if (NULL == plugin) {
113 Z_LOGE("plugin is NULL");
117 /* Create new driver */
118 driver = zblib_driver_new(plugin, driver_name, ZBLIB_DRIVER_TYPE_ALARM);
119 if (NULL == driver) {
120 Z_LOGE("driver is NULL");
124 /* Allocate memory for private data */
125 priv_data = g_malloc0(sizeof(ZblibDriverAlarmPrivData_t));
127 /* Update private data */
128 priv_data->ops = ops;
130 /* Link private data to driver */
131 ret = zblib_driver_link_object(driver, priv_data);
133 Z_LOGE("zblib_driver_link_object failed!");
135 /* Free allocated resources */
142 /* Set operations dispatcher function */
143 ret = zblib_driver_set_dispatcher(driver, __zblib_driver_alarm_dispatcher);
145 Z_LOGE("zblib_driver_set_dispatcher failed!");
147 /* Free allocated resources */
154 /* Set free hook function */
155 ret = zblib_driver_set_free_hook(driver, __zblib_driver_alarm_free_hook);
157 Z_LOGE("zblib_driver_set_free_hook failed!");
159 /* Free allocated resources */
169 void zblib_driver_alarm_free(ZigBeeDriver *driver)
171 if (NULL == driver) {
172 Z_LOGE("driver is NULL");
177 zblib_driver_free(driver);