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_door_lock.h>
23 static void on_door_lock_subscribe_lock_event_resp(ZigBeeServiceInterface *service_interface,
24 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
26 ZigbeeServiceInterfaceRespCbData_t *cb_data =
27 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
30 NOT_USED(service_interface);
33 NOT_USED(resp_data_len);
36 static gboolean on_door_lock_subscribe_lock_event(ZigbeeZcl_door_lock *door_lock_object,
37 GDBusMethodInvocation *invocation,
42 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
43 ZigbeeDoorLockSubscriberLockEvent_t req;
44 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
46 GVariantIter *iter = NULL;
51 memset(&req, 0x0, sizeof(ZigbeeDoorLockSubscriberLockEvent_t));
53 /* Update request structure */
54 g_variant_get(eui64, "ay", &iter);
55 while (g_variant_iter_loop(iter, "y", req.eui64[i])) {
57 if (i >= ZIGBEE_EUI64_SIZE)
60 req.endpoint = endpoint;
62 /* Allocate response callback data */
64 zigbee_service_dbus_interface_create_resp_cb_data(door_lock_object,
66 if (NULL == resp_cb_data) {
67 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
69 /* Send failure response */
70 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
75 /* Dispatch request */
76 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
77 ZBLIB_DRIVER_TYPE_DOOR_LOCK,
78 ZBLIB_DOOR_LOCK_OPS_SUBSCRIBE_LOCK_EVENT,
80 on_door_lock_subscribe_lock_event_resp, resp_cb_data);
82 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
84 /* Free response callback data */
85 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
87 /* Send failure response */
88 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
96 static void on_door_lock_set_door_lock_pin_resp(ZigBeeServiceInterface *service_interface,
97 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
99 ZigbeeServiceInterfaceRespCbData_t *cb_data =
100 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
103 NOT_USED(service_interface);
104 NOT_USED(request_id);
106 NOT_USED(resp_data_len);
109 static gboolean on_door_lock_set_door_lock_pin(ZigbeeZcl_door_lock *door_lock_object,
110 GDBusMethodInvocation *invocation,
119 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
120 ZigbeeDoorLockSetDoorLockPin_t req;
121 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
123 GVariantIter *iter = NULL;
128 memset(&req, 0x0, sizeof(ZigbeeDoorLockSetDoorLockPin_t));
130 /* Update request structure */
132 req.ustatus = ustatus;
134 g_variant_get(eui64, "ay", &iter);
135 while (g_variant_iter_loop(iter, "y", req.eui64[i])) {
137 if (i >= ZIGBEE_EUI64_SIZE)
140 req.endpoint = endpoint;
141 g_strlcpy(req.pin, pin, ZIGBEE_DOOR_LOCK_MAX_PIN_LEN + 1);
143 /* Allocate response callback data */
145 zigbee_service_dbus_interface_create_resp_cb_data(door_lock_object,
146 invocation, NULL, 0);
147 if (NULL == resp_cb_data) {
148 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
150 /* Send failure response */
151 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
156 /* Dispatch request */
157 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
158 ZBLIB_DRIVER_TYPE_DOOR_LOCK,
159 ZBLIB_DOOR_LOCK_OPS_SET_DOOR_LOCK_PIN,
161 on_door_lock_set_door_lock_pin_resp, resp_cb_data);
163 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
165 /* Free response callback data */
166 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
168 /* Send failure response */
169 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
177 static void on_door_lock_set_door_lock_resp(ZigBeeServiceInterface *service_interface,
178 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
180 ZigbeeServiceInterfaceRespCbData_t *cb_data =
181 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
184 NOT_USED(service_interface);
185 NOT_USED(request_id);
187 NOT_USED(resp_data_len);
190 static gboolean on_door_lock_set_door_lock(ZigbeeZcl_door_lock *door_lock_object,
191 GDBusMethodInvocation *invocation,
195 gint lock_unlock_type,
198 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
199 ZigbeeDoorLockSetDoorLock_t req;
200 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
202 GVariantIter *iter = NULL;
207 memset(&req, 0x0, sizeof(ZigbeeDoorLockSetDoorLock_t));
209 /* Update request structure */
210 g_variant_get(eui64, "ay", &iter);
211 while (g_variant_iter_loop(iter, "y", req.eui64[i])) {
213 if (i >= ZIGBEE_EUI64_SIZE)
216 req.endpoint = endpoint;
217 g_strlcpy(req.pin, pin, ZIGBEE_DOOR_LOCK_MAX_PIN_LEN + 1);
218 req.lock_unlock_type = lock_unlock_type;
220 /* Allocate response callback data */
222 zigbee_service_dbus_interface_create_resp_cb_data(door_lock_object,
223 invocation, NULL, 0);
224 if (NULL == resp_cb_data) {
225 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
227 /* Send failure response */
228 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
233 /* Dispatch request */
234 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
235 ZBLIB_DRIVER_TYPE_DOOR_LOCK,
236 ZBLIB_DOOR_LOCK_OPS_SET_DOOR_LOCK,
238 on_door_lock_set_door_lock_resp, resp_cb_data);
240 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
242 /* Free response callback data */
243 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
245 /* Send failure response */
246 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
254 static void on_door_lock_get_lock_state_resp(ZigBeeServiceInterface *service_interface,
255 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
257 ZigbeeServiceInterfaceRespCbData_t *cb_data =
258 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
261 NOT_USED(service_interface);
262 NOT_USED(request_id);
264 NOT_USED(resp_data_len);
267 static gboolean on_door_lock_get_lock_state(ZigbeeZcl_door_lock *door_lock_object,
268 GDBusMethodInvocation *invocation,
273 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
274 ZigbeeDoorLockGetDoorLock_t req;
275 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
277 GVariantIter *iter = NULL;
282 memset(&req, 0x0, sizeof(ZigbeeDoorLockGetDoorLock_t));
284 /* Update request structure */
285 g_variant_get(eui64, "ay", &iter);
286 while (g_variant_iter_loop(iter, "y", req.eui64[i])) {
288 if (i >= ZIGBEE_EUI64_SIZE)
291 req.endpoint = endpoint;
293 /* Allocate response callback data */
295 zigbee_service_dbus_interface_create_resp_cb_data(door_lock_object,
296 invocation, NULL, 0);
297 if (NULL == resp_cb_data) {
298 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
300 /* Send failure response */
301 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
306 /* Dispatch request */
307 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
308 ZBLIB_DRIVER_TYPE_DOOR_LOCK,
309 ZBLIB_DOOR_LOCK_OPS_GET_LOCK_STATE,
311 on_door_lock_get_lock_state_resp, resp_cb_data);
313 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
315 /* Free response callback data */
316 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
318 /* Send failure response */
319 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
327 gboolean zigbee_service_dbus_interface_zcl_door_lock_init(ZigBeeServiceInterface *service_interface,
328 ZigbeeObjectSkeleton *zigbee_object)
330 ZigbeeZcl_door_lock *door_lock_object;
332 if (NULL == service_interface) {
333 Z_LOGE("service_interface is NULL");
337 door_lock_object = zigbee_zcl_door_lock_skeleton_new();
338 zigbee_object_skeleton_set_zcl_door_lock(zigbee_object, door_lock_object);
339 g_object_unref(door_lock_object);
341 Z_LOGI("door_lock_object: [%p]", door_lock_object);
344 * Register signal handlers for 'door_lock' interface
346 g_signal_connect(door_lock_object,
347 "handle-subscribe-lock-event",
348 G_CALLBACK(on_door_lock_subscribe_lock_event), service_interface);
350 g_signal_connect(door_lock_object,
351 "handle-set-door-lock-pin",
352 G_CALLBACK(on_door_lock_set_door_lock_pin), service_interface);
354 g_signal_connect(door_lock_object,
355 "handle-set-door-lock",
356 G_CALLBACK(on_door_lock_set_door_lock), service_interface);
358 g_signal_connect(door_lock_object,
359 "handle-get-lock-state",
360 G_CALLBACK(on_door_lock_get_lock_state), service_interface);