25c8998c1bd5a55c52f7fb49af4a901293188baf
[platform/core/connectivity/zigbee-manager.git] / zigbee-daemon / zigbee-interface / src / zigbee_service_dbus_interface_zcl_basic.c
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
3  *
4  * Contact: Suresh Kumar N (suresh.n@samsung.com)
5  *
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  */
18
19 #include "zigbee_service_interface_common.h"
20
21 #include <zblib_driver_zcl_basic.h>
22
23 static void on_zclbasic_control_reset_factory_default_resp(ZigBeeServiceInterface *service_interface,
24         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
25 {
26         ZigbeeServiceInterfaceRespCbData_t *cb_data =
27                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
28
29         NOT_USED(cb_data);
30         NOT_USED(service_interface);
31         NOT_USED(request_id);
32         NOT_USED(resp_data);
33         NOT_USED(resp_data_len);
34 }
35
36 static gboolean on_zclbasic_control_reset_factory_default(ZigbeeZcl_basic *zclbasic_control_object,
37         GDBusMethodInvocation *invocation,
38         gshort node_id,
39         gchar dest_ep,
40         gpointer user_data)
41 {
42         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
43         ZigbeeZclBasicResetFactoryDefault_t req;
44         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
45
46         gboolean ret;
47
48         memset(&req, 0x0, sizeof(ZigbeeZclBasicResetFactoryDefault_t));
49
50         /* Update request structure */
51         req.node_id = node_id;
52         req.dest_ep = dest_ep;
53
54         /* Allocate response callback data */
55         resp_cb_data =
56                 zigbee_service_dbus_interface_create_resp_cb_data(zclbasic_control_object,
57                         invocation, NULL, 0);
58         if (NULL == resp_cb_data) {
59                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
60
61                 /* Send failure response */
62                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
63
64                 return TRUE;
65         }
66
67         /* Dispatch request */
68         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
69                 ZBLIB_DRIVER_TYPE_ZCL_BASIC,
70                 ZBLIB_ZCL_BASIC_OPS_RESET_FACTORY_DEFAULT,
71                 &req, sizeof(req),
72                 on_zclbasic_control_reset_factory_default_resp, resp_cb_data);
73         if (FALSE == ret) {
74                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
75
76                 /* Free response callback data */
77                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
78
79                 /* Send failure response */
80                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
81
82                 return TRUE;
83         }
84
85         return TRUE;
86 }
87
88 void zigbee_service_dbus_interface_zcl_basic_notification(ZigBeeServiceInterface *service_interface,
89         guint noti_id, gpointer noti_data, guint noti_data_len, gpointer noti_cb_data)
90 {
91         if (NULL == service_interface) {
92                 Z_LOGE("service_interface is NULL");
93                 return;
94         }
95
96         NOT_USED(noti_id);
97         NOT_USED(noti_data);
98         NOT_USED(noti_data_len);
99         NOT_USED(noti_cb_data);
100 }
101
102 gboolean zigbee_service_dbus_interface_zcl_basic_init(ZigBeeServiceInterface *service_interface,
103         ZigbeeObjectSkeleton *zigbee_object)
104 {
105         ZigbeeZcl_basic *zclbasic_control_object;
106
107         if (NULL == service_interface) {
108                 Z_LOGE("service_interface is NULL");
109                 return FALSE;
110         }
111
112         zclbasic_control_object = zigbee_zcl_basic_skeleton_new();
113         zigbee_object_skeleton_set_zcl_basic(zigbee_object, zclbasic_control_object);
114         g_object_unref(zclbasic_control_object);
115
116         Z_LOGI("zclbasic_control_object: [%p]", zclbasic_control_object);
117
118         /*
119          * Register signal handlers for 'zclbasic_control' interface
120          */
121         g_signal_connect(zclbasic_control_object,
122                 "handle-reset-factory-default",
123                 G_CALLBACK(on_zclbasic_control_reset_factory_default), service_interface);
124
125         return TRUE;
126 }