Implement ZCL Global control
[platform/core/connectivity/zigbee-manager.git] / zigbee-daemon / zigbee-interface / src / zigbee_service_dbus_interface_zcl_group.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_group.h>
22
23 static void *_service_interface_ref_zigbee_zcl_group(ZigBeeServiceInterface *service_interface)
24 {
25         ZigbeeObjectSkeleton *zigbee_object = NULL;
26         ZigbeeCustomData_t *custom_data = NULL;
27         ZigbeeZcl_group *group_object = NULL;
28
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!");
32                 return NULL;
33         }
34
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);
39                 return NULL;
40         }
41
42         group_object = zigbee_object_get_zcl_group(ZIGBEE_OBJECT(zigbee_object));
43         return group_object;
44 }
45
46 static void on_zcl_group_add_group_resp(ZigBeeServiceInterface *service_interface,
47         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
48 {
49         ZigbeeServiceInterfaceRespCbData_t *cb_data =
50                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
51
52         ZigbeeZcl_group *group_object = NULL;
53         GDBusMethodInvocation *invocation = NULL;
54
55         ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
56
57         NOT_USED(service_interface);
58         NOT_USED(request_id);
59
60         if (NULL == resp_data || 0 == resp_data_len) {
61                 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
62                 g_free(cb_data);
63                 return;
64         }
65
66         group_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
67         zblib_check_null_free_and_ret("group_object", group_object, cb_data);
68
69         invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
70         zblib_check_null_free_and_ret("invocation", invocation, cb_data);
71
72         zigbee_zcl_group_complete_add_group(group_object, invocation, payload->result);
73
74         g_free(cb_data);
75 }
76
77 static gboolean on_zcl_group_add_group(ZigbeeZcl_group *zcl_group_object,
78         GDBusMethodInvocation *invocation,
79         gshort node_id,
80         gchar dest_ep,
81         gshort group_id,
82         GVariant *group_name,
83         gpointer user_data)
84 {
85         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
86         ZigbeeZclGroupAddGroup_t req;
87         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
88
89         GVariantIter *iter = NULL;
90         gint i = 0;
91
92         gboolean ret;
93
94         memset(&req, 0x0, sizeof(ZigbeeZclGroupAddGroup_t));
95
96         /* Update request structure */
97         req.node_id = node_id;
98         req.dest_ep = dest_ep;
99         req.group_id = group_id;
100
101
102         g_variant_get(group_name, "a(y)", &iter);
103         while (g_variant_iter_loop(iter, "(y)", &req.group_name[i])) {
104                 i++;
105                 if (i >= ZIGBEE_ZCL_GROUP_NAME_MAX_LEN + 1)
106                         break;
107         }
108
109         /* Allocate response callback data */
110         resp_cb_data =
111                 zigbee_service_dbus_interface_create_resp_cb_data(zcl_group_object,
112                         invocation, NULL, 0);
113         if (NULL == resp_cb_data) {
114                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
115
116                 /* Send failure response */
117                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
118
119                 return TRUE;
120         }
121
122         /* Dispatch request */
123         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
124                 ZBLIB_DRIVER_TYPE_ZCL_GROUP,
125                 ZBLIB_ZCL_GROUP_OPS_ADD_GROUP,
126                 &req, sizeof(req),
127                 on_zcl_group_add_group_resp, resp_cb_data);
128         if (FALSE == ret) {
129                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
130
131                 /* Free response callback data */
132                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
133
134                 /* Send failure response */
135                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
136
137                 return TRUE;
138         }
139
140         return TRUE;
141 }
142
143 static void on_zcl_group_view_group_resp(ZigBeeServiceInterface *service_interface,
144         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
145 {
146         ZigbeeServiceInterfaceRespCbData_t *cb_data =
147                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
148
149         ZigbeeZcl_group *group_object = NULL;
150         GDBusMethodInvocation *invocation = NULL;
151
152         ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
153
154         NOT_USED(service_interface);
155         NOT_USED(request_id);
156
157         if (NULL == resp_data || 0 == resp_data_len) {
158                 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
159                 g_free(cb_data);
160                 return;
161         }
162
163         group_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
164         zblib_check_null_free_and_ret("group_object", group_object, cb_data);
165
166         invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
167         zblib_check_null_free_and_ret("invocation", invocation, cb_data);
168
169         zigbee_zcl_group_complete_view_group(group_object, invocation, payload->result);
170
171         g_free(cb_data);
172 }
173
174 static gboolean on_zcl_group_view_group(ZigbeeZcl_group *zcl_group_object,
175         GDBusMethodInvocation *invocation,
176         gshort node_id,
177         gchar dest_ep,
178         gshort group_id,
179         gpointer user_data)
180 {
181         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
182         ZigbeeZclGroupViewGroup_t req;
183         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
184
185         gboolean ret;
186
187         memset(&req, 0x0, sizeof(ZigbeeZclGroupViewGroup_t));
188
189         /* Update request structure */
190         req.node_id = node_id;
191         req.dest_ep = dest_ep;
192         req.group_id = group_id;
193
194         /* Allocate response callback data */
195         resp_cb_data =
196                 zigbee_service_dbus_interface_create_resp_cb_data(zcl_group_object,
197                         invocation, NULL, 0);
198         if (NULL == resp_cb_data) {
199                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
200
201                 /* Send failure response */
202                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
203
204                 return TRUE;
205         }
206
207         /* Dispatch request */
208         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
209                 ZBLIB_DRIVER_TYPE_ZCL_GROUP,
210                 ZBLIB_ZCL_GROUP_OPS_VIEW_GROUP,
211                 &req, sizeof(req),
212                 on_zcl_group_view_group_resp, resp_cb_data);
213         if (FALSE == ret) {
214                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
215
216                 /* Free response callback data */
217                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
218
219                 /* Send failure response */
220                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
221
222                 return TRUE;
223         }
224
225         return TRUE;
226 }
227
228 static void on_zcl_group_get_group_membership_resp(ZigBeeServiceInterface *service_interface,
229         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
230 {
231         ZigbeeServiceInterfaceRespCbData_t *cb_data =
232                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
233
234         ZigbeeZcl_group *group_object = NULL;
235         GDBusMethodInvocation *invocation = NULL;
236
237         ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
238
239         NOT_USED(service_interface);
240         NOT_USED(request_id);
241
242         if (NULL == resp_data || 0 == resp_data_len) {
243                 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
244                 g_free(cb_data);
245                 return;
246         }
247
248         group_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
249         zblib_check_null_free_and_ret("group_object", group_object, cb_data);
250
251         invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
252         zblib_check_null_free_and_ret("invocation", invocation, cb_data);
253
254         zigbee_zcl_group_complete_get_group_membership(group_object, invocation, payload->result);
255
256         g_free(cb_data);
257 }
258
259 static gboolean on_zcl_group_get_group_membership(ZigbeeZcl_group *zcl_group_object,
260         GDBusMethodInvocation *invocation,
261         gshort node_id,
262         gchar dest_ep,
263         gchar group_count,
264         GVariant *group_list,
265         gpointer user_data)
266 {
267         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
268         ZigbeeZclGroupGetGroupMembership_t req;
269         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
270
271         GVariantIter *iter = NULL;
272         gint i = 0;
273
274         gboolean ret;
275
276         memset(&req, 0x0, sizeof(ZigbeeZclGroupGetGroupMembership_t));
277
278         /* Update request structure */
279         req.node_id = node_id;
280         req.dest_ep = dest_ep;
281         req.group_count = group_count;
282         req.group_list = g_malloc0(sizeof(gshort) * group_count);
283         g_variant_get(group_list, "aq", &iter);
284         while (g_variant_iter_loop(iter, "q", req.group_list[i])) {
285                 i++;
286                 if (i >= group_count)
287                         break;
288         }
289
290         /* Allocate response callback data */
291         resp_cb_data =
292                 zigbee_service_dbus_interface_create_resp_cb_data(zcl_group_object,
293                         invocation, NULL, 0);
294         if (NULL == resp_cb_data) {
295                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
296
297                 /* Send failure response */
298                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
299
300                 return TRUE;
301         }
302
303         /* Dispatch request */
304         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
305                 ZBLIB_DRIVER_TYPE_ZCL_GROUP,
306                 ZBLIB_ZCL_GROUP_OPS_GET_GROUP_MEMBERSHIP,
307                 &req, sizeof(req),
308                 on_zcl_group_get_group_membership_resp, resp_cb_data);
309
310         /* Free resource */
311         g_free(req.group_list);
312
313         if (FALSE == ret) {
314                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
315
316                 /* Free response callback data */
317                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
318
319                 /* Send failure response */
320                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
321
322                 return TRUE;
323         }
324
325         return TRUE;
326 }
327
328 static void on_zcl_group_remove_group_resp(ZigBeeServiceInterface *service_interface,
329         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
330 {
331         ZigbeeServiceInterfaceRespCbData_t *cb_data =
332                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
333
334         ZigbeeZcl_group *group_object = NULL;
335         GDBusMethodInvocation *invocation = NULL;
336
337         ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
338
339         NOT_USED(service_interface);
340         NOT_USED(request_id);
341
342         if (NULL == resp_data || 0 == resp_data_len) {
343                 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
344                 g_free(cb_data);
345                 return;
346         }
347
348         group_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
349         zblib_check_null_free_and_ret("group_object", group_object, cb_data);
350
351         invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
352         zblib_check_null_free_and_ret("invocation", invocation, cb_data);
353
354         zigbee_zcl_group_complete_remove_group(group_object, invocation, payload->result);
355
356         g_free(cb_data);
357 }
358
359 static gboolean on_zcl_group_remove_group(ZigbeeZcl_group *zcl_group_object,
360         GDBusMethodInvocation *invocation,
361         gshort node_id,
362         gchar dest_ep,
363         gshort group_id,
364         gpointer user_data)
365 {
366         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
367         ZigbeeZclGroupRemoveGroup_t req;
368         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
369
370         gboolean ret;
371
372         memset(&req, 0x0, sizeof(ZigbeeZclGroupRemoveGroup_t));
373
374         /* Update request structure */
375         req.node_id = node_id;
376         req.dest_ep = dest_ep;
377         req.group_id = group_id;
378
379         /* Allocate response callback data */
380         resp_cb_data =
381                 zigbee_service_dbus_interface_create_resp_cb_data(zcl_group_object,
382                         invocation, NULL, 0);
383         if (NULL == resp_cb_data) {
384                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
385
386                 /* Send failure response */
387                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
388
389                 return TRUE;
390         }
391
392         /* Dispatch request */
393         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
394                 ZBLIB_DRIVER_TYPE_ZCL_GROUP,
395                 ZBLIB_ZCL_GROUP_OPS_REMOVE_GROUP,
396                 &req, sizeof(req),
397                 on_zcl_group_remove_group_resp, resp_cb_data);
398         if (FALSE == ret) {
399                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
400
401                 /* Free response callback data */
402                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
403
404                 /* Send failure response */
405                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
406
407                 return TRUE;
408         }
409
410         return TRUE;
411 }
412
413 static void on_zcl_group_remove_all_group_resp(ZigBeeServiceInterface *service_interface,
414         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
415 {
416         ZigbeeServiceInterfaceRespCbData_t *cb_data =
417                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
418
419         ZigbeeZcl_group *group_object = NULL;
420         GDBusMethodInvocation *invocation = NULL;
421
422         ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
423
424         NOT_USED(service_interface);
425         NOT_USED(request_id);
426
427         if (NULL == resp_data || 0 == resp_data_len) {
428                 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
429                 g_free(cb_data);
430                 return;
431         }
432
433         group_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
434         zblib_check_null_free_and_ret("group_object", group_object, cb_data);
435
436         invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
437         zblib_check_null_free_and_ret("invocation", invocation, cb_data);
438
439         zigbee_zcl_group_complete_remove_all_group(group_object, invocation, payload->result);
440
441         g_free(cb_data);
442 }
443
444 static gboolean on_zcl_group_remove_all_group(ZigbeeZcl_group *zcl_group_object,
445         GDBusMethodInvocation *invocation,
446         gshort node_id,
447         gchar dest_ep,
448         gpointer user_data)
449 {
450         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
451         ZigbeeZclGroupRemoveAllGroup_t req;
452         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
453
454         gboolean ret;
455
456         memset(&req, 0x0, sizeof(ZigbeeZclGroupRemoveAllGroup_t));
457
458         /* Update request structure */
459         req.node_id = node_id;
460         req.dest_ep = dest_ep;
461
462         /* Allocate response callback data */
463         resp_cb_data =
464                 zigbee_service_dbus_interface_create_resp_cb_data(zcl_group_object,
465                         invocation, NULL, 0);
466         if (NULL == resp_cb_data) {
467                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
468
469                 /* Send failure response */
470                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
471
472                 return TRUE;
473         }
474
475         /* Dispatch request */
476         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
477                 ZBLIB_DRIVER_TYPE_ZCL_GROUP,
478                 ZBLIB_ZCL_GROUP_OPS_REMOVE_ALL_GROUP,
479                 &req, sizeof(req),
480                 on_zcl_group_remove_all_group_resp, resp_cb_data);
481         if (FALSE == ret) {
482                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
483
484                 /* Free response callback data */
485                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
486
487                 /* Send failure response */
488                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
489
490                 return TRUE;
491         }
492
493         return TRUE;
494 }
495
496 static void on_zcl_group_add_group_if_identifying_resp(ZigBeeServiceInterface *service_interface,
497         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
498 {
499         ZigbeeServiceInterfaceRespCbData_t *cb_data =
500                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
501
502         ZigbeeZcl_group *group_object = NULL;
503         GDBusMethodInvocation *invocation = NULL;
504
505         ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
506
507         NOT_USED(service_interface);
508         NOT_USED(request_id);
509
510         if (NULL == resp_data || 0 == resp_data_len) {
511                 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
512                 g_free(cb_data);
513                 return;
514         }
515
516         group_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
517         zblib_check_null_free_and_ret("group_object", group_object, cb_data);
518
519         invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
520         zblib_check_null_free_and_ret("invocation", invocation, cb_data);
521
522         zigbee_zcl_group_complete_add_group_if_identifying(group_object, invocation, payload->result);
523
524         g_free(cb_data);
525 }
526
527 static gboolean on_zcl_group_add_group_if_identifying(ZigbeeZcl_group *zcl_group_object,
528         GDBusMethodInvocation *invocation,
529         gshort node_id,
530         gchar dest_ep,
531         gshort group_id,
532         GVariant *group_name,
533         gpointer user_data)
534 {
535         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
536         ZigbeeZclGroupAddGroupIfIdentifying_t req;
537         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
538
539         GVariantIter *iter = NULL;
540         gint i = 0;
541
542         gboolean ret;
543
544         memset(&req, 0x0, sizeof(ZigbeeZclGroupAddGroupIfIdentifying_t));
545
546         /* Update request structure */
547         req.node_id = node_id;
548         req.dest_ep = dest_ep;
549         req.group_id = group_id;
550         g_variant_get(group_name, "a(y)", &iter);
551         while (g_variant_iter_loop(iter, "(y)", &req.group_name[i])) {
552                 i++;
553                 if (i >= ZIGBEE_ZCL_GROUP_NAME_MAX_LEN + 1)
554                         break;
555         }
556
557         /* Allocate response callback data */
558         resp_cb_data =
559                 zigbee_service_dbus_interface_create_resp_cb_data(zcl_group_object,
560                         invocation, NULL, 0);
561         if (NULL == resp_cb_data) {
562                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
563
564                 /* Send failure response */
565                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
566
567                 return TRUE;
568         }
569
570         /* Dispatch request */
571         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
572                 ZBLIB_DRIVER_TYPE_ZCL_GROUP,
573                 ZBLIB_ZCL_GROUP_OPS_ADD_GROUP_IF_IDENTIFYING,
574                 &req, sizeof(req),
575                 on_zcl_group_add_group_if_identifying_resp, resp_cb_data);
576         if (FALSE == ret) {
577                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
578
579                 /* Free response callback data */
580                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
581
582                 /* Send failure response */
583                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
584
585                 return TRUE;
586         }
587
588         return TRUE;
589 }
590
591 void zigbee_service_dbus_interface_zcl_group_notification(ZigBeeServiceInterface *service_interface,
592         guint noti_id, gpointer noti_data, guint noti_data_len, gpointer noti_cb_data)
593 {
594         ZigbeeZcl_group *group_object;
595
596         zblib_check_null_ret("service_interface", service_interface);
597
598         if (NULL == noti_data || 0 == noti_data_len) {
599                 Z_LOGE("noti_data=%p or noti_data_len=%d is null", noti_data, noti_data_len);
600                 return;
601         }
602
603         group_object = _service_interface_ref_zigbee_zcl_group(service_interface);
604         zblib_check_null_ret("group_object", group_object);
605
606         NOT_USED(noti_cb_data);
607
608         switch(noti_id) {
609         case ZBLIB_SERVICE_NOTI_ADD_GROUP_RSP: {
610                 ZigbeeZclGroupAddGroupNoti_t *rsp =
611                         (ZigbeeZclGroupAddGroupNoti_t*)noti_data;
612
613                 Z_LOGD("add_group_rsp from : [0x%X]", rsp->node_id);
614
615                 zigbee_zcl_group_emit_add_group_rsp(group_object, rsp->node_id, rsp->src_ep,
616                         rsp->status, rsp->group_id);
617         }
618         break;
619         case ZBLIB_SERVICE_NOTI_VIEW_GROUP_RSP: {
620                 ZigbeeZclGroupViewGroupNoti_t *rsp =
621                         (ZigbeeZclGroupViewGroupNoti_t*)noti_data;
622
623                 Z_LOGD("view_group_rsp from : [0x%X]", rsp->node_id);
624
625                 zigbee_zcl_group_emit_view_group_rsp(group_object, rsp->node_id, rsp->src_ep,
626                         rsp->status, rsp->group_id, rsp->group_name);
627         }
628         break;
629         case ZBLIB_SERVICE_NOTI_GET_GROUP_MEMBERSHIP_RSP: {
630                 int i;
631                 GVariant* group_list = NULL;
632                 GVariantBuilder *attr_builder = NULL;
633
634                 ZigbeeZclGroupGetGroupMembershipNoti_t *rsp =
635                         (ZigbeeZclGroupGetGroupMembershipNoti_t*)noti_data;
636
637                 Z_LOGD("get_group_membership_rsp from : [0x%X]", rsp->node_id);
638
639                 attr_builder = g_variant_builder_new(G_VARIANT_TYPE("aq"));
640
641                 for (i = 0; i < rsp->group_count; i++)
642                         g_variant_builder_add(attr_builder, "q", rsp->group_list[i]);
643                 group_list = g_variant_builder_end(attr_builder);
644                 g_variant_builder_unref(attr_builder);
645
646                 zigbee_zcl_group_emit_get_group_membership_rsp(group_object, rsp->node_id,
647                         rsp->src_ep, rsp->capacity, rsp->group_count, group_list);
648         }
649         break;
650         case ZBLIB_SERVICE_NOTI_REMOVE_GROUP_RSP: {
651                 ZigbeeZclGroupRemoveGroupNoti_t *rsp =
652                         (ZigbeeZclGroupRemoveGroupNoti_t*)noti_data;
653
654                 Z_LOGD("remove_group_rsp from : [0x%X]", rsp->node_id);
655
656                 zigbee_zcl_group_emit_remove_group_rsp(group_object, rsp->node_id, rsp->src_ep,
657                         rsp->status, rsp->group_id);
658         }
659         break;
660         default:
661                 Z_LOGE("Unexpected notification [%x]", noti_id);
662         break;
663         }
664
665         /* ZigbeeZcl_group should be dereferenced */
666         g_object_unref(group_object);
667 }
668
669 gboolean zigbee_service_dbus_interface_zcl_group_init(ZigBeeServiceInterface *service_interface,
670         ZigbeeObjectSkeleton *zigbee_object)
671 {
672         ZigbeeZcl_group *zcl_group_object;
673
674         if (NULL == service_interface) {
675                 Z_LOGE("service_interface is NULL");
676                 return FALSE;
677         }
678
679         zcl_group_object = zigbee_zcl_group_skeleton_new();
680         zigbee_object_skeleton_set_zcl_group(zigbee_object, zcl_group_object);
681         g_object_unref(zcl_group_object);
682
683         Z_LOGI("zcl_group_object: [%p]", zcl_group_object);
684
685         /*
686          * Register signal handlers for 'zcl_group' interface
687          */
688         g_signal_connect(zcl_group_object,
689                 "handle-add-group",
690                 G_CALLBACK(on_zcl_group_add_group), service_interface);
691
692         g_signal_connect(zcl_group_object,
693                 "handle-view-group",
694                 G_CALLBACK(on_zcl_group_view_group), service_interface);
695
696         g_signal_connect(zcl_group_object,
697                 "handle-get-group-membership",
698                 G_CALLBACK(on_zcl_group_get_group_membership), service_interface);
699
700         g_signal_connect(zcl_group_object,
701                 "handle-remove-group",
702                 G_CALLBACK(on_zcl_group_remove_group), service_interface);
703
704         g_signal_connect(zcl_group_object,
705                 "handle-remove-all-group",
706                 G_CALLBACK(on_zcl_group_remove_all_group), service_interface);
707
708         g_signal_connect(zcl_group_object,
709                 "handle-add-group-if-identifying",
710                 G_CALLBACK(on_zcl_group_add_group_if_identifying), service_interface);
711
712         return TRUE;
713 }