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_on_off.h>
23 static void on_on_off_set_on_off_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_on_off_set_on_off(ZigbeeZcl_on_off *on_off_object,
37 GDBusMethodInvocation *invocation,
43 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
44 ZigbeeZclOnOffSetOnOff_t req;
45 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
49 memset(&req, 0x0, sizeof(ZigbeeZclOnOffSetOnOff_t));
51 /* Update request structure */
52 req.node_id = node_id;
53 req.endpoint = endpoint;
54 req.on_off_type = on_off_type;
56 /* Allocate response callback data */
58 zigbee_service_dbus_interface_create_resp_cb_data(on_off_object,
60 if (NULL == resp_cb_data) {
61 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
63 /* Send failure response */
64 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
69 /* Dispatch request */
70 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
71 ZBLIB_DRIVER_TYPE_ZCL_ON_OFF,
72 ZBLIB_ZCL_ON_OFF_OPS_SET_ON_OFF,
74 on_on_off_set_on_off_resp, resp_cb_data);
76 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
78 /* Free response callback data */
79 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
81 /* Send failure response */
82 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
90 static void on_on_off_get_on_off_state_resp(ZigBeeServiceInterface *service_interface,
91 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
93 ZigbeeServiceInterfaceRespCbData_t *cb_data =
94 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
97 NOT_USED(service_interface);
100 NOT_USED(resp_data_len);
103 static gboolean on_on_off_get_on_off_state(ZigbeeZcl_on_off *on_off_object,
104 GDBusMethodInvocation *invocation,
109 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
110 ZigbeeZclOnOffGetOnOffState_t req;
111 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
115 memset(&req, 0x0, sizeof(ZigbeeZclOnOffGetOnOffState_t));
117 /* Update request structure */
118 req.node_id = node_id;
119 req.endpoint = endpoint;
121 /* Allocate response callback data */
123 zigbee_service_dbus_interface_create_resp_cb_data(on_off_object,
124 invocation, NULL, 0);
125 if (NULL == resp_cb_data) {
126 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
128 /* Send failure response */
129 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
134 /* Dispatch request */
135 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
136 ZBLIB_DRIVER_TYPE_ZCL_ON_OFF,
137 ZBLIB_ZCL_ON_OFF_OPS_GET_ON_OFF_STATE,
139 on_on_off_get_on_off_state_resp, resp_cb_data);
141 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
143 /* Free response callback data */
144 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
146 /* Send failure response */
147 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
155 gboolean zigbee_service_dbus_interface_zcl_on_off_init(ZigBeeServiceInterface *service_interface,
156 ZigbeeObjectSkeleton *zigbee_object)
158 ZigbeeZcl_on_off *on_off_object;
160 if (NULL == service_interface) {
161 Z_LOGE("service_interface is NULL");
165 on_off_object = zigbee_zcl_on_off_skeleton_new();
166 zigbee_object_skeleton_set_zcl_on_off(zigbee_object, on_off_object);
167 g_object_unref(on_off_object);
169 Z_LOGI("on_off_object: [%p]", on_off_object);
172 * Register signal handlers for 'on_off' interface
174 g_signal_connect(on_off_object,
176 G_CALLBACK(on_on_off_set_on_off), service_interface);
178 g_signal_connect(on_off_object,
179 "handle-get-on-off-state",
180 G_CALLBACK(on_on_off_get_on_off_state), service_interface);