Adding service interface layer logic for request processing
[platform/core/connectivity/zigbee-manager.git] / zigbee-daemon / zigbee-interface / src / zigbee_service_dbus_interface_zcl_poll_control.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_poll_control.h>
22
23 static void on_zcl_poll_control_check_in_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_zcl_poll_control_check_in_response(ZigbeeZcl_poll_control *zcl_poll_control_object,
37         GDBusMethodInvocation *invocation,
38         gshort node_id,
39         gchar dest_ep,
40         gchar start_fast_polling,
41         gshort fast_poll_timeout,
42         gpointer user_data)
43 {
44         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
45         ZigbeeZclPollControlCheckInResponse_t req;
46         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
47
48         gboolean ret;
49
50         memset(&req, 0x0, sizeof(ZigbeeZclPollControlCheckInResponse_t));
51
52         /* Update request structure */
53         req.node_id = node_id;
54         req.dest_ep = dest_ep;
55         req.start_fast_polling = start_fast_polling;
56         req.fast_poll_timeout = fast_poll_timeout;
57
58         /* Allocate response callback data */
59         resp_cb_data =
60                 zigbee_service_dbus_interface_create_resp_cb_data(zcl_poll_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_POLL_CONTROL,
74                 ZBLIB_ZCL_POLL_CONTROL_OPS_CHECK_IN_RESPONSE,
75                 &req, sizeof(req),
76                 on_zcl_poll_control_check_in_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 static void on_zcl_poll_control_fast_poll_stop_resp(ZigBeeServiceInterface *service_interface,
93         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
94 {
95         ZigbeeServiceInterfaceRespCbData_t *cb_data =
96                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
97
98         NOT_USED(cb_data);
99         NOT_USED(service_interface);
100         NOT_USED(request_id);
101         NOT_USED(resp_data);
102         NOT_USED(resp_data_len);
103 }
104
105 static gboolean on_zcl_poll_control_fast_poll_stop(ZigbeeZcl_poll_control *zcl_poll_control_object,
106         GDBusMethodInvocation *invocation,
107         gshort node_id,
108         gchar dest_ep,
109         gpointer user_data)
110 {
111         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
112         ZigbeeZclPollControlFastPollStop_t req;
113         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
114
115         gboolean ret;
116
117         memset(&req, 0x0, sizeof(ZigbeeZclPollControlFastPollStop_t));
118
119         /* Update request structure */
120         req.node_id = node_id;
121         req.dest_ep = dest_ep;
122
123         /* Allocate response callback data */
124         resp_cb_data =
125                 zigbee_service_dbus_interface_create_resp_cb_data(zcl_poll_control_object,
126                         invocation, NULL, 0);
127         if (NULL == resp_cb_data) {
128                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
129
130                 /* Send failure response */
131                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
132
133                 return TRUE;
134         }
135
136         /* Dispatch request */
137         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
138                 ZBLIB_DRIVER_TYPE_ZCL_POLL_CONTROL,
139                 ZBLIB_ZCL_POLL_CONTROL_OPS_FAST_POLL_STOP,
140                 &req, sizeof(req),
141                 on_zcl_poll_control_fast_poll_stop_resp, resp_cb_data);
142         if (FALSE == ret) {
143                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
144
145                 /* Free response callback data */
146                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
147
148                 /* Send failure response */
149                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
150
151                 return TRUE;
152         }
153
154         return TRUE;
155 }
156
157 static void on_zcl_poll_control_set_long_poll_interval_resp(ZigBeeServiceInterface *service_interface,
158         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
159 {
160         ZigbeeServiceInterfaceRespCbData_t *cb_data =
161                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
162
163         NOT_USED(cb_data);
164         NOT_USED(service_interface);
165         NOT_USED(request_id);
166         NOT_USED(resp_data);
167         NOT_USED(resp_data_len);
168 }
169
170 static gboolean on_zcl_poll_control_set_long_poll_interval(ZigbeeZcl_poll_control *zcl_poll_control_object,
171         GDBusMethodInvocation *invocation,
172         gshort node_id,
173         gchar dest_ep,
174         guint new_long_poll_interval,
175         gpointer user_data)
176 {
177         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
178         ZigbeeZclPollControlSetLongPollInterval_t req;
179         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
180
181         gboolean ret;
182
183         memset(&req, 0x0, sizeof(ZigbeeZclPollControlSetLongPollInterval_t));
184
185         /* Update request structure */
186         req.node_id = node_id;
187         req.dest_ep = dest_ep;
188         req.new_long_poll_interval = new_long_poll_interval;
189
190         /* Allocate response callback data */
191         resp_cb_data =
192                 zigbee_service_dbus_interface_create_resp_cb_data(zcl_poll_control_object,
193                         invocation, NULL, 0);
194         if (NULL == resp_cb_data) {
195                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
196
197                 /* Send failure response */
198                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
199
200                 return TRUE;
201         }
202
203         /* Dispatch request */
204         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
205                 ZBLIB_DRIVER_TYPE_ZCL_POLL_CONTROL,
206                 ZBLIB_ZCL_POLL_CONTROL_OPS_SET_LONG_POLL_INTERVAL,
207                 &req, sizeof(req),
208                 on_zcl_poll_control_set_long_poll_interval_resp, resp_cb_data);
209         if (FALSE == ret) {
210                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
211
212                 /* Free response callback data */
213                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
214
215                 /* Send failure response */
216                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
217
218                 return TRUE;
219         }
220
221         return TRUE;
222 }
223
224 static void on_zcl_poll_control_set_short_poll_interval_resp(ZigBeeServiceInterface *service_interface,
225         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
226 {
227         ZigbeeServiceInterfaceRespCbData_t *cb_data =
228                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
229
230         NOT_USED(cb_data);
231         NOT_USED(service_interface);
232         NOT_USED(request_id);
233         NOT_USED(resp_data);
234         NOT_USED(resp_data_len);
235 }
236
237 static gboolean on_zcl_poll_control_set_short_poll_interval(ZigbeeZcl_poll_control *zcl_poll_control_object,
238         GDBusMethodInvocation *invocation,
239         gshort node_id,
240         gchar dest_ep,
241         guint new_short_poll_interval,
242         gpointer user_data)
243 {
244         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
245         ZigbeeZclPollControlSetShortPollInterval_t req;
246         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
247
248         gboolean ret;
249
250         memset(&req, 0x0, sizeof(ZigbeeZclPollControlSetShortPollInterval_t));
251
252         /* Update request structure */
253         req.node_id = node_id;
254         req.dest_ep = dest_ep;
255         req.new_short_poll_interval = new_short_poll_interval;
256
257         /* Allocate response callback data */
258         resp_cb_data =
259                 zigbee_service_dbus_interface_create_resp_cb_data(zcl_poll_control_object,
260                         invocation, NULL, 0);
261         if (NULL == resp_cb_data) {
262                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
263
264                 /* Send failure response */
265                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
266
267                 return TRUE;
268         }
269
270         /* Dispatch request */
271         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
272                 ZBLIB_DRIVER_TYPE_ZCL_POLL_CONTROL,
273                 ZBLIB_ZCL_POLL_CONTROL_OPS_SET_SHORT_POLL_INTERVAL,
274                 &req, sizeof(req),
275                 on_zcl_poll_control_set_short_poll_interval_resp, resp_cb_data);
276         if (FALSE == ret) {
277                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
278
279                 /* Free response callback data */
280                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
281
282                 /* Send failure response */
283                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
284
285                 return TRUE;
286         }
287
288         return TRUE;
289 }
290
291 gboolean zigbee_service_dbus_interface_zcl_poll_control_init(ZigBeeServiceInterface *service_interface,
292         ZigbeeObjectSkeleton *zigbee_object)
293 {
294         ZigbeeZcl_poll_control *zcl_poll_control_object;
295
296         if (NULL == service_interface) {
297                 Z_LOGE("service_interface is NULL");
298                 return FALSE;
299         }
300
301         zcl_poll_control_object = zigbee_zcl_poll_control_skeleton_new();
302         zigbee_object_skeleton_set_zcl_poll_control(zigbee_object, zcl_poll_control_object);
303         g_object_unref(zcl_poll_control_object);
304
305         Z_LOGI("zcl_poll_control_object: [%p]", zcl_poll_control_object);
306
307         /*
308          * Register signal handlers for 'zcl_poll_control' interface
309          */
310         g_signal_connect(zcl_poll_control_object,
311                 "handle-check-in-response",
312                 G_CALLBACK(on_zcl_poll_control_check_in_response), service_interface);
313
314         g_signal_connect(zcl_poll_control_object,
315                 "handle-fast-poll-stop",
316                 G_CALLBACK(on_zcl_poll_control_fast_poll_stop), service_interface);
317
318         g_signal_connect(zcl_poll_control_object,
319                 "handle-set-long-poll-interval",
320                 G_CALLBACK(on_zcl_poll_control_set_long_poll_interval), service_interface);
321
322         g_signal_connect(zcl_poll_control_object,
323                 "handle-set-short-poll-interval",
324                 G_CALLBACK(on_zcl_poll_control_set_short_poll_interval), service_interface);
325
326         return TRUE;
327 }