Add notification handling framework
[platform/core/connectivity/zigbee-manager.git] / zigbee-daemon / zigbee-interface / src / zigbee_service_dbus_interface_zcl_ias_zone.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_ias_zone.h>
22
23 static void on_zclias_control_enroll_response_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_zclias_control_enroll_response(ZigbeeZcl_ias_zone *zclias_control_object,
37         GDBusMethodInvocation *invocation,
38         gshort node_id,
39         gchar dest_ep,
40         gchar enroll_code,
41         gchar zone_id,
42         gpointer user_data)
43 {
44         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
45         ZigbeeZclIasZoneEnrollResponse_t req;
46         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
47
48         gboolean ret;
49
50         memset(&req, 0x0, sizeof(ZigbeeZclIasZoneEnrollResponse_t));
51
52         /* Update request structure */
53         req.node_id = node_id;
54         req.dest_ep = dest_ep;
55         req.enroll_code = enroll_code;
56         req.zone_id = zone_id;
57
58         /* Allocate response callback data */
59         resp_cb_data =
60                 zigbee_service_dbus_interface_create_resp_cb_data(zclias_control_object,
61                         invocation, NULL, 0);
62         if (NULL == resp_cb_data) {
63                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
64
65                 /* Send failure response */
66                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
67
68                 return TRUE;
69         }
70
71         /* Dispatch request */
72         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
73                 ZBLIB_DRIVER_TYPE_ZCL_IAS_ZONE,
74                 ZBLIB_ZCL_IAS_ZONE_OPS_ENROLL_RESPONSE,
75                 &req, sizeof(req),
76                 on_zclias_control_enroll_response_resp, resp_cb_data);
77         if (FALSE == ret) {
78                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
79
80                 /* Free response callback data */
81                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
82
83                 /* Send failure response */
84                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
85
86                 return TRUE;
87         }
88
89         return TRUE;
90 }
91
92 void zigbee_service_dbus_interface_zcl_ias_zone_notification(ZigBeeServiceInterface *service_interface,
93         guint noti_id, gpointer noti_data, guint noti_data_len, gpointer noti_cb_data)
94 {
95         if (NULL == service_interface) {
96                 Z_LOGE("service_interface is NULL");
97                 return;
98         }
99
100         NOT_USED(noti_id);
101         NOT_USED(noti_data);
102         NOT_USED(noti_data_len);
103         NOT_USED(noti_cb_data);
104 }
105
106 gboolean zigbee_service_dbus_interface_zcl_ias_zone_init(ZigBeeServiceInterface *service_interface,
107         ZigbeeObjectSkeleton *zigbee_object)
108 {
109         ZigbeeZcl_ias_zone *zclias_control_object;
110
111         if (NULL == service_interface) {
112                 Z_LOGE("service_interface is NULL");
113                 return FALSE;
114         }
115
116         zclias_control_object = zigbee_zcl_ias_zone_skeleton_new();
117         zigbee_object_skeleton_set_zcl_ias_zone(zigbee_object, zclias_control_object);
118         g_object_unref(zclias_control_object);
119
120         Z_LOGI("zclias_control_object: [%p]", zclias_control_object);
121
122         /*
123          * Register signal handlers for 'zclias_control' interface
124          */
125         g_signal_connect(zclias_control_object,
126                 "handle-enroll-response",
127                 G_CALLBACK(on_zclias_control_enroll_response), service_interface);
128
129         return TRUE;
130 }