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_identify.h>
24 static void *_service_interface_ref_zigbee_zcl_identify(ZigBeeServiceInterface *service_interface)
26 ZigbeeObjectSkeleton *zigbee_object = NULL;
27 ZigbeeCustomData_t *custom_data = NULL;
28 ZigbeeZcl_identify *id_object = NULL;
30 custom_data = (ZigbeeCustomData_t *)zblib_service_interface_ref_user_data(service_interface);
31 if (NULL == custom_data) {
32 Z_LOGE("D-BUS service interface custom_data is NULL!");
36 /* Get zigbee object */
37 zigbee_object = g_hash_table_lookup(custom_data->objects, ZIGBEE_SERVICE_PATH);
38 if (NULL == zigbee_object) {
39 Z_LOGW("Cannot find ZigBee D-BUS interface object!", zigbee_object);
43 id_object = zigbee_object_get_zcl_identify(ZIGBEE_OBJECT(zigbee_object));
48 static void on_zclidentify_control_identify_resp(ZigBeeServiceInterface *service_interface,
49 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
51 ZigbeeServiceInterfaceRespCbData_t *cb_data =
52 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
54 ZigbeeZcl_identify *id_object = NULL;
55 GDBusMethodInvocation *invocation = NULL;
57 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
59 NOT_USED(service_interface);
62 if (NULL == resp_data || 0 == resp_data_len) {
63 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
68 id_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
69 zblib_check_null_free_and_ret("id_object", id_object, cb_data);
71 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
72 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
74 zigbee_zcl_identify_complete_identify(id_object, invocation, payload->result);
79 static gboolean on_zclidentify_control_identify(ZigbeeZcl_identify *zclidentify_control_object,
80 GDBusMethodInvocation *invocation,
86 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
87 ZigbeeZclIdentifyIdentify_t req;
88 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
92 memset(&req, 0x0, sizeof(ZigbeeZclIdentifyIdentify_t));
94 /* Update request structure */
95 req.node_id = node_id;
96 req.dest_ep = dest_ep;
97 req.identify_time = identifytime;
99 /* Allocate response callback data */
101 zigbee_service_dbus_interface_create_resp_cb_data(zclidentify_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_IDENTIFY,
115 ZBLIB_ZCL_IDENTIFY_OPS_IDENTIFY,
117 on_zclidentify_control_identify_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 static void on_zclidentify_control_query_resp(ZigBeeServiceInterface *service_interface,
134 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
136 ZigbeeServiceInterfaceRespCbData_t *cb_data =
137 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
139 ZigbeeZcl_identify *id_object = NULL;
140 GDBusMethodInvocation *invocation = NULL;
142 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
144 NOT_USED(service_interface);
145 NOT_USED(request_id);
147 if (NULL == resp_data || 0 == resp_data_len) {
148 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
153 id_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
154 zblib_check_null_free_and_ret("id_object", id_object, cb_data);
156 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
157 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
159 zigbee_zcl_identify_complete_query(id_object, invocation, payload->result);
164 static gboolean on_zclidentify_control_query(ZigbeeZcl_identify *zclidentify_control_object,
165 GDBusMethodInvocation *invocation,
170 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
171 ZigbeeZclIdentifyQuery_t req;
172 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
176 memset(&req, 0x0, sizeof(ZigbeeZclIdentifyQuery_t));
178 /* Update request structure */
179 req.node_id = node_id;
180 req.dest_ep = dest_ep;
182 /* Allocate response callback data */
184 zigbee_service_dbus_interface_create_resp_cb_data(zclidentify_control_object,
185 invocation, NULL, 0);
186 if (NULL == resp_cb_data) {
187 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
189 /* Send failure response */
190 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
195 /* Dispatch request */
196 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
197 ZBLIB_DRIVER_TYPE_ZCL_IDENTIFY,
198 ZBLIB_ZCL_IDENTIFY_OPS_QUERY,
200 on_zclidentify_control_query_resp, resp_cb_data);
202 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
204 /* Free response callback data */
205 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
207 /* Send failure response */
208 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
216 void zigbee_service_dbus_interface_zcl_identify_notification(ZigBeeServiceInterface *service_interface,
217 guint noti_id, gpointer noti_data, guint noti_data_len, gpointer noti_cb_data)
219 ZigbeeZcl_identify *id_object;
221 zblib_check_null_ret("service_interface", service_interface);
223 if (NULL == noti_data || 0 == noti_data_len) {
224 Z_LOGE("noti_data=%p or noti_data_len=%d is null", noti_data, noti_data_len);
228 id_object = _service_interface_ref_zigbee_zcl_identify(service_interface);
229 zblib_check_null_ret("id_object", id_object);
231 NOT_USED(noti_cb_data);
234 case ZBLIB_ZCL_IDENTIFY_NOTI_QUERY_RSP: {
235 ZigbeeZclIdentifyQueryNoti_t *rsp = (ZigbeeZclIdentifyQueryNoti_t*)noti_data;
237 Z_LOGD("query_rsp from : [0x%X]", rsp->node_id);
239 zigbee_zcl_identify_emit_query_rsp(id_object, rsp->node_id, rsp->identify_time);
243 Z_LOGE("Unexpected notification [%x]", noti_id);
247 /* ZigbeeZcl_identify should be dereferenced */
248 g_object_unref(id_object);
252 gboolean zigbee_service_dbus_interface_zcl_identify_init(ZigBeeServiceInterface *service_interface,
253 ZigbeeObjectSkeleton *zigbee_object)
255 ZigbeeZcl_identify *zclidentify_control_object;
257 if (NULL == service_interface) {
258 /* LCOV_EXCL_START */
259 Z_LOGE("service_interface is NULL");
264 zclidentify_control_object = zigbee_zcl_identify_skeleton_new();
265 zigbee_object_skeleton_set_zcl_identify(zigbee_object, zclidentify_control_object);
266 g_object_unref(zclidentify_control_object);
268 Z_LOGI("zclidentify_control_object: [%p]", zclidentify_control_object);
271 * Register signal handlers for 'zclidentify_control' interface
273 g_signal_connect(zclidentify_control_object,
275 G_CALLBACK(on_zclidentify_control_identify), service_interface);
277 g_signal_connect(zclidentify_control_object,
279 G_CALLBACK(on_zclidentify_control_query), service_interface);