#include <zblib.h>
#include <zblib_driver.h>
+#include <zblib_request.h>
#include "zblib_driver_alarm.h"
ZblibDriverAlarmOps_t *ops; /**< Operations */
} ZblibDriverAlarmPrivData_t;
-static gboolean __zblib_driver_alarm_dispatcher(ZigBeeDriver *driver)
+static gboolean __zblib_driver_alarm_dispatcher(ZigBeeDriver *driver, guint request_id)
{
- if (NULL == driver) {
- Z_LOGE("driver is NULL");
- return FALSE;
+ ZigBeeService *service = NULL;
+ ZblibDriverAlarmPrivData_t *priv_data = NULL;
+ ZblibDriverAlarmOps_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_ALARM_OPS_GET_ALARM_COUNT: {
+ zblib_check_null_ret_error("ops->get_alarm_count",
+ ops->get_alarm_count, FALSE);
+
+ ret = ops->get_alarm_count(driver, request_id);
}
+ break;
+
+ case ZBLIB_ALARM_OPS_RESET_ALARM: {
+ zblib_check_null_ret_error("ops->reset_alarm",
+ ops->reset_alarm, FALSE);
+
+ ret = ops->reset_alarm(driver, request_id);
+ }
+ break;
+
+ case ZBLIB_ALARM_OPS_RESET_ALL_ALARM: {
+ zblib_check_null_ret_error("ops->reset_all_alarm",
+ ops->reset_all_alarm, FALSE);
- return TRUE;
+ ret = ops->reset_all_alarm(driver, request_id);
+ }
+ break;
+
+ case ZBLIB_ALARM_OPS_ALARM: {
+ zblib_check_null_ret_error("ops->alarm",
+ ops->alarm, FALSE);
+
+ ret = ops->alarm(driver, request_id);
+ }
+ break;
+
+ case ZBLIB_ALARM_OPS_RESET_ALARM_LOG: {
+ zblib_check_null_ret_error("ops->reset_alarm_log",
+ ops->reset_alarm_log, FALSE);
+
+ ret = ops->reset_alarm_log(driver, request_id);
+ }
+ break;
+
+ case ZBLIB_ALARM_OPS_GET_ALARM: {
+ zblib_check_null_ret_error("ops->get_alarm",
+ ops->get_alarm, FALSE);
+
+ ret = ops->get_alarm(driver, request_id);
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ Z_LOGD("ret: [%d]", ret);
+
+ return ret;
}
static void __zblib_driver_alarm_free_hook(ZigBeeDriver *driver)
{
ZblibDriverAlarmPrivData_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);
ZblibDriverAlarmPrivData_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_ALARM);
- 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(ZblibDriverAlarmPrivData_t));
void zblib_driver_alarm_free(ZigBeeDriver *driver)
{
- if (NULL == driver) {
- Z_LOGE("driver is NULL");
- return;
- }
+ zblib_check_null_ret("driver", driver);
/* Free driver */
zblib_driver_free(driver);