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>
23 static void *_service_interface_ref_zigbee_zcl_identify(ZigBeeServiceInterface *service_interface)
25 ZigbeeObjectSkeleton *zigbee_object = NULL;
26 ZigbeeCustomData_t *custom_data = NULL;
27 ZigbeeZcl_identify *id_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 id_object = zigbee_object_get_zcl_identify(ZIGBEE_OBJECT(zigbee_object));
47 static void on_zclidentify_control_identify_resp(ZigBeeServiceInterface *service_interface,
48 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
50 ZigbeeServiceInterfaceRespCbData_t *cb_data =
51 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
53 ZigbeeZcl_identify *id_object = NULL;
54 GDBusMethodInvocation *invocation = NULL;
56 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
58 NOT_USED(service_interface);
61 if (NULL == resp_data || 0 == resp_data_len) {
62 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
67 id_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
68 zblib_check_null_free_and_ret("id_object", id_object, cb_data);
70 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
71 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
73 zigbee_zcl_identify_complete_identify(id_object, invocation, payload->result);
78 static gboolean on_zclidentify_control_identify(ZigbeeZcl_identify *zclidentify_control_object,
79 GDBusMethodInvocation *invocation,
85 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
86 ZigbeeZclIdentifyIdentify_t req;
87 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
91 memset(&req, 0x0, sizeof(ZigbeeZclIdentifyIdentify_t));
93 /* Update request structure */
94 req.node_id = node_id;
95 req.dest_ep = dest_ep;
96 req.identify_time = identifytime;
98 /* Allocate response callback data */
100 zigbee_service_dbus_interface_create_resp_cb_data(zclidentify_control_object,
101 invocation, NULL, 0);
102 if (NULL == resp_cb_data) {
103 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
105 /* Send failure response */
106 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
111 /* Dispatch request */
112 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
113 ZBLIB_DRIVER_TYPE_ZCL_IDENTIFY,
114 ZBLIB_ZCL_IDENTIFY_OPS_IDENTIFY,
116 on_zclidentify_control_identify_resp, resp_cb_data);
118 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
120 /* Free response callback data */
121 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
123 /* Send failure response */
124 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
132 static void on_zclidentify_control_query_resp(ZigBeeServiceInterface *service_interface,
133 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
135 ZigbeeServiceInterfaceRespCbData_t *cb_data =
136 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
138 ZigbeeZcl_identify *id_object = NULL;
139 GDBusMethodInvocation *invocation = NULL;
141 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
143 NOT_USED(service_interface);
144 NOT_USED(request_id);
146 if (NULL == resp_data || 0 == resp_data_len) {
147 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
152 id_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
153 zblib_check_null_free_and_ret("id_object", id_object, cb_data);
155 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
156 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
158 zigbee_zcl_identify_complete_query(id_object, invocation, payload->result);
163 static gboolean on_zclidentify_control_query(ZigbeeZcl_identify *zclidentify_control_object,
164 GDBusMethodInvocation *invocation,
169 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
170 ZigbeeZclIdentifyQuery_t req;
171 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
175 memset(&req, 0x0, sizeof(ZigbeeZclIdentifyQuery_t));
177 /* Update request structure */
178 req.node_id = node_id;
179 req.dest_ep = dest_ep;
181 /* Allocate response callback data */
183 zigbee_service_dbus_interface_create_resp_cb_data(zclidentify_control_object,
184 invocation, NULL, 0);
185 if (NULL == resp_cb_data) {
186 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
188 /* Send failure response */
189 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
194 /* Dispatch request */
195 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
196 ZBLIB_DRIVER_TYPE_ZCL_IDENTIFY,
197 ZBLIB_ZCL_IDENTIFY_OPS_QUERY,
199 on_zclidentify_control_query_resp, resp_cb_data);
201 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
203 /* Free response callback data */
204 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
206 /* Send failure response */
207 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
215 void zigbee_service_dbus_interface_zcl_identify_notification(ZigBeeServiceInterface *service_interface,
216 guint noti_id, gpointer noti_data, guint noti_data_len, gpointer noti_cb_data)
218 ZigbeeZcl_identify *id_object;
220 zblib_check_null_ret("service_interface", service_interface);
222 if (NULL == noti_data || 0 == noti_data_len) {
223 Z_LOGE("noti_data=%p or noti_data_len=%d is null", noti_data, noti_data_len);
227 id_object = _service_interface_ref_zigbee_zcl_identify(service_interface);
228 zblib_check_null_ret("id_object", id_object);
230 NOT_USED(noti_cb_data);
233 case ZBLIB_ZCL_IDENTIFY_NOTI_QUERY_RSP: {
234 ZigbeeZclIdentifyQueryNoti_t *rsp = (ZigbeeZclIdentifyQueryNoti_t*)noti_data;
236 Z_LOGD("query_rsp from : [0x%X]", rsp->node_id);
238 zigbee_zcl_identify_emit_query_rsp(id_object, rsp->node_id, rsp->identify_time);
242 Z_LOGE("Unexpected notification [%x]", noti_id);
246 /* ZigbeeZcl_identify should be dereferenced */
247 g_object_unref(id_object);
250 gboolean zigbee_service_dbus_interface_zcl_identify_init(ZigBeeServiceInterface *service_interface,
251 ZigbeeObjectSkeleton *zigbee_object)
253 ZigbeeZcl_identify *zclidentify_control_object;
255 if (NULL == service_interface) {
256 Z_LOGE("service_interface is NULL");
260 zclidentify_control_object = zigbee_zcl_identify_skeleton_new();
261 zigbee_object_skeleton_set_zcl_identify(zigbee_object, zclidentify_control_object);
262 g_object_unref(zclidentify_control_object);
264 Z_LOGI("zclidentify_control_object: [%p]", zclidentify_control_object);
267 * Register signal handlers for 'zclidentify_control' interface
269 g_signal_connect(zclidentify_control_object,
271 G_CALLBACK(on_zclidentify_control_identify), service_interface);
273 g_signal_connect(zclidentify_control_object,
275 G_CALLBACK(on_zclidentify_control_query), service_interface);