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.
19 #include "zigbee_service_interface_common.h"
21 #include <zblib_driver_zcl_ias_zone.h>
23 static void *_service_interface_ref_zigbee_zcl_ias_zone(ZigBeeServiceInterface *service_interface)
25 ZigbeeObjectSkeleton *zigbee_object = NULL;
26 ZigbeeCustomData_t *custom_data = NULL;
27 ZigbeeZcl_ias_zone *ias_object = NULL;
29 custom_data = (ZigbeeCustomData_t *)zblib_service_interface_ref_user_data(service_interface);
30 if (NULL == custom_data) {
31 Z_LOGE("D-BUS service interface custom_data is NULL!");
35 /* Get zigbee object */
36 zigbee_object = g_hash_table_lookup(custom_data->objects, ZIGBEE_SERVICE_PATH);
37 if (NULL == zigbee_object) {
38 Z_LOGW("Cannot find ZigBee D-BUS interface object!", zigbee_object);
42 ias_object = zigbee_object_get_zcl_ias_zone(ZIGBEE_OBJECT(zigbee_object));
46 static void on_zclias_control_enroll_response_resp(ZigBeeServiceInterface *service_interface,
47 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
49 ZigbeeServiceInterfaceRespCbData_t *cb_data =
50 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
52 ZigbeeZcl_ias_zone *ias_object = NULL;
53 GDBusMethodInvocation *invocation = NULL;
55 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
57 NOT_USED(service_interface);
60 if (NULL == resp_data || 0 == resp_data_len) {
61 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
66 ias_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
67 zblib_check_null_free_and_ret("ias_object", ias_object, cb_data);
69 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
70 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
72 zigbee_zcl_ias_zone_complete_enroll_response(ias_object, invocation, payload->result);
77 static gboolean on_zclias_control_enroll_response(ZigbeeZcl_ias_zone *zclias_control_object,
78 GDBusMethodInvocation *invocation,
85 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
86 ZigbeeZclIasZoneEnrollResponse_t req;
87 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
91 memset(&req, 0x0, sizeof(ZigbeeZclIasZoneEnrollResponse_t));
93 /* Update request structure */
94 req.node_id = node_id;
95 req.dest_ep = dest_ep;
96 req.enroll_code = enroll_code;
97 req.zone_id = zone_id;
99 /* Allocate response callback data */
101 zigbee_service_dbus_interface_create_resp_cb_data(zclias_control_object,
102 invocation, NULL, 0);
103 if (NULL == resp_cb_data) {
104 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
106 /* Send failure response */
107 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
112 /* Dispatch request */
113 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
114 ZBLIB_DRIVER_TYPE_ZCL_IAS_ZONE,
115 ZBLIB_ZCL_IAS_ZONE_OPS_ENROLL_RESPONSE,
117 on_zclias_control_enroll_response_resp, resp_cb_data);
119 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
121 /* Free response callback data */
122 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
124 /* Send failure response */
125 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
133 void zigbee_service_dbus_interface_zcl_ias_zone_notification(ZigBeeServiceInterface *service_interface,
134 guint noti_id, gpointer noti_data, guint noti_data_len, gpointer noti_cb_data)
136 ZigbeeZcl_ias_zone *ias_object;
138 zblib_check_null_ret("service_interface", service_interface);
140 if (NULL == noti_data || 0 == noti_data_len) {
141 Z_LOGE("noti_data=%p or noti_data_len=%d is null", noti_data, noti_data_len);
145 ias_object = _service_interface_ref_zigbee_zcl_ias_zone(service_interface);
146 zblib_check_null_ret("ias_object", ias_object);
148 NOT_USED(noti_cb_data);
151 case ZBLIB_ZCL_IAS_ZONE_NOTI_ZONE_STATUS_CHANGE: {
152 ZigbeeZclIasZoneStatusChangeNoti_t *rsp =
153 (ZigbeeZclIasZoneStatusChangeNoti_t*)noti_data;
155 Z_LOGD("status_change_rpt from : [0x%X]", rsp->node_id);
157 zigbee_zcl_ias_zone_emit_status_change_rpt(ias_object, rsp->node_id, rsp->src_ep,
158 rsp->zone_status, rsp->extended_status, rsp->zone_id, rsp->delay);
161 case ZBLIB_ZCL_IAS_ZONE_NOTI_ENROLL_REQUEST: {
162 ZigbeeZclIasEnrollRequestNoti_t *rsp =
163 (ZigbeeZclIasEnrollRequestNoti_t*)noti_data;
165 Z_LOGD("enroll_request from : [0x%X]", rsp->node_id);
167 zigbee_zcl_ias_zone_emit_enroll_request(ias_object, rsp->node_id, rsp->src_ep,
168 rsp->zone_type, rsp->mfg_code);
172 Z_LOGE("Unexpected notification [%x]", noti_id);
176 /* ZigbeeZcl_ias_zone should be dereferenced */
177 g_object_unref(ias_object);
180 gboolean zigbee_service_dbus_interface_zcl_ias_zone_init(ZigBeeServiceInterface *service_interface,
181 ZigbeeObjectSkeleton *zigbee_object)
183 ZigbeeZcl_ias_zone *zclias_control_object;
185 if (NULL == service_interface) {
186 Z_LOGE("service_interface is NULL");
190 zclias_control_object = zigbee_zcl_ias_zone_skeleton_new();
191 zigbee_object_skeleton_set_zcl_ias_zone(zigbee_object, zclias_control_object);
192 g_object_unref(zclias_control_object);
194 Z_LOGI("zclias_control_object: [%p]", zclias_control_object);
197 * Register signal handlers for 'zclias_control' interface
199 g_signal_connect(zclias_control_object,
200 "handle-enroll-response",
201 G_CALLBACK(on_zclias_control_enroll_response), service_interface);