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_basic.h>
23 static void *_service_interface_ref_zigbee_zcl_basic(ZigBeeServiceInterface *service_interface)
25 ZigbeeObjectSkeleton *zigbee_object = NULL;
26 ZigbeeCustomData_t *custom_data = NULL;
27 ZigbeeZcl_basic *basic_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 basic_object = zigbee_object_get_zcl_basic(ZIGBEE_OBJECT(zigbee_object));
46 static void on_zclbasic_control_reset_factory_default_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_basic *zcl_basic_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 is null");
66 zcl_basic_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
67 zblib_check_null_free_and_ret("zcl_basic_object", zcl_basic_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_basic_complete_reset_factory_default(zcl_basic_object, invocation,
78 static gboolean on_zclbasic_control_reset_factory_default(ZigbeeZcl_basic *zclbasic_control_object,
79 GDBusMethodInvocation *invocation,
84 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
85 ZigbeeZclBasicResetFactoryDefault_t req;
86 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
90 memset(&req, 0x0, sizeof(ZigbeeZclBasicResetFactoryDefault_t));
92 /* Update request structure */
93 req.node_id = node_id;
94 req.dest_ep = dest_ep;
96 /* Allocate response callback data */
98 zigbee_service_dbus_interface_create_resp_cb_data(zclbasic_control_object,
100 if (NULL == resp_cb_data) {
101 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
103 /* Send failure response */
104 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
109 /* Dispatch request */
110 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
111 ZBLIB_DRIVER_TYPE_ZCL_BASIC,
112 ZBLIB_ZCL_BASIC_OPS_RESET_FACTORY_DEFAULT,
114 on_zclbasic_control_reset_factory_default_resp, resp_cb_data);
116 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
118 /* Free response callback data */
119 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
121 /* Send failure response */
122 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
130 void zigbee_service_dbus_interface_zcl_basic_notification(ZigBeeServiceInterface *service_interface,
131 guint noti_id, gpointer noti_data, guint noti_data_len, gpointer noti_cb_data)
133 ZigbeeZcl_basic *basic_object;
135 zblib_check_null_ret("service_interface", service_interface);
137 if (NULL == noti_data || 0 == noti_data_len) {
138 Z_LOGE("noti_data is NULL");
142 basic_object = _service_interface_ref_zigbee_zcl_basic(service_interface);
143 zblib_check_null_ret("basic_object", basic_object);
145 NOT_USED(noti_cb_data);
149 Z_LOGE("Unexpected notification [%x]", noti_id);
153 /* ZigbeeZcl_basic should be dereferenced */
154 g_object_unref(basic_object);
157 gboolean zigbee_service_dbus_interface_zcl_basic_init(ZigBeeServiceInterface *service_interface,
158 ZigbeeObjectSkeleton *zigbee_object)
160 ZigbeeZcl_basic *zclbasic_control_object;
162 if (NULL == service_interface) {
163 Z_LOGE("service_interface is NULL");
167 zclbasic_control_object = zigbee_zcl_basic_skeleton_new();
168 zigbee_object_skeleton_set_zcl_basic(zigbee_object, zclbasic_control_object);
169 g_object_unref(zclbasic_control_object);
171 Z_LOGI("zclbasic_control_object: [%p]", zclbasic_control_object);
174 * Register signal handlers for 'zclbasic_control' interface
176 g_signal_connect(zclbasic_control_object,
177 "handle-reset-factory-default",
178 G_CALLBACK(on_zclbasic_control_reset_factory_default), service_interface);