Fix the coverity issues
[platform/core/connectivity/zigbee-manager.git] / zigbee-daemon / zigbee-interface / src / zigbee_service_dbus_interface_zcl_color_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_color_control.h>
22
23 /* LCOV_EXCL_START */
24 static void *_service_interface_ref_zigbee_zcl_color_control(
25         ZigBeeServiceInterface *service_interface)
26 {
27         ZigbeeObjectSkeleton *zigbee_object = NULL;
28         ZigbeeCustomData_t *custom_data = NULL;
29         ZigbeeZcl_color_control *color_object = NULL;
30
31         custom_data = (ZigbeeCustomData_t *)zblib_service_interface_ref_user_data(service_interface);
32         if (NULL == custom_data) {
33                 Z_LOGE("D-BUS service interface custom_data is NULL!");
34                 return NULL;
35         }
36
37         /* Get zigbee object */
38         zigbee_object = g_hash_table_lookup(custom_data->objects, ZIGBEE_SERVICE_PATH);
39         if (NULL == zigbee_object) {
40                 Z_LOGW("Cannot find ZigBee D-BUS interface object!");
41                 return NULL;
42         }
43
44         color_object = zigbee_object_get_zcl_color_control(ZIGBEE_OBJECT(zigbee_object));
45         return color_object;
46 }
47
48 static void on_zcl_color_move_to_hue_resp(ZigBeeServiceInterface *service_interface,
49         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
50 {
51         ZigbeeServiceInterfaceRespCbData_t *cb_data =
52                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
53
54         ZigbeeZcl_color_control *zcl_color_object = NULL;
55         GDBusMethodInvocation *invocation = NULL;
56
57         ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
58
59         NOT_USED(service_interface);
60         NOT_USED(request_id);
61
62         if (NULL == resp_data || 0 == resp_data_len) {
63                 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
64                 g_free(cb_data);
65                 return;
66         }
67
68         zcl_color_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
69         zblib_check_null_free_and_ret("zcl_color_object", zcl_color_object, cb_data);
70
71         invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
72         zblib_check_null_free_and_ret("invocation", invocation, cb_data);
73
74         zigbee_zcl_color_control_complete_move_to_hue(zcl_color_object, invocation,
75                 payload->result);
76
77         g_free(cb_data);
78 }
79
80 static gboolean on_zcl_color_move_to_hue(ZigbeeZcl_color_control *zcl_color_object,
81         GDBusMethodInvocation *invocation,
82         gshort node_id,
83         gchar endpoint,
84         gchar hue,
85         gchar direction,
86         gshort transition_time,
87         gpointer user_data)
88 {
89         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
90         ZigbeeZclColorControlMoveToHue_t req;
91         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
92
93         gboolean ret;
94
95         memset(&req, 0x0, sizeof(ZigbeeZclColorControlMoveToHue_t));
96
97         /* Update request structure */
98         req.node_id = node_id;
99         req.dest_ep = endpoint;
100         req.hue = hue;
101         req.direction = direction;
102         req.transition_time = transition_time;
103
104         /* Allocate response callback data */
105         resp_cb_data =
106                 zigbee_service_dbus_interface_create_resp_cb_data(zcl_color_object,
107                         invocation, NULL, 0);
108         if (NULL == resp_cb_data) {
109                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
110
111                 /* Send failure response */
112                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
113
114                 return TRUE;
115         }
116
117         /* Dispatch request */
118         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
119                 ZBLIB_DRIVER_TYPE_ZCL_COLOR_CONTROL,
120                 ZBLIB_ZCL_COLOR_CONTROL_OPS_MOVE_TO_HUE,
121                 &req, sizeof(req),
122                 on_zcl_color_move_to_hue_resp, resp_cb_data);
123         if (FALSE == ret) {
124                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
125
126                 /* Free response callback data */
127                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
128
129                 /* Send failure response */
130                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
131
132                 return TRUE;
133         }
134
135         return TRUE;
136 }
137
138 static void on_zcl_color_move_hue_resp(ZigBeeServiceInterface *service_interface,
139         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
140 {
141         ZigbeeServiceInterfaceRespCbData_t *cb_data =
142                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
143
144         ZigbeeZcl_color_control *zcl_color_object = NULL;
145         GDBusMethodInvocation *invocation = NULL;
146
147         ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
148
149         NOT_USED(service_interface);
150         NOT_USED(request_id);
151
152         if (NULL == resp_data || 0 == resp_data_len) {
153                 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
154                 g_free(cb_data);
155                 return;
156         }
157
158         zcl_color_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
159         zblib_check_null_free_and_ret("zcl_color_object", zcl_color_object, cb_data);
160
161         invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
162         zblib_check_null_free_and_ret("invocation", invocation, cb_data);
163
164         zigbee_zcl_color_control_complete_move_hue(zcl_color_object, invocation,
165                 payload->result);
166
167         g_free(cb_data);
168 }
169
170 static gboolean on_zcl_color_move_hue(ZigbeeZcl_color_control *zcl_color_object,
171         GDBusMethodInvocation *invocation,
172         gshort node_id,
173         gchar endpoint,
174         gchar move_mode,
175         gchar rate,
176         gpointer user_data)
177 {
178         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
179         ZigbeeZclColorControlMoveHue_t req;
180         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
181
182         gboolean ret;
183
184         memset(&req, 0x0, sizeof(ZigbeeZclColorControlMoveHue_t));
185
186         /* Update request structure */
187         req.node_id = node_id;
188         req.dest_ep = endpoint;
189         req.move_mode = move_mode;
190         req.rate = rate;
191
192         /* Allocate response callback data */
193         resp_cb_data =
194                 zigbee_service_dbus_interface_create_resp_cb_data(zcl_color_object,
195                         invocation, NULL, 0);
196         if (NULL == resp_cb_data) {
197                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
198
199                 /* Send failure response */
200                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
201
202                 return TRUE;
203         }
204
205         /* Dispatch request */
206         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
207                 ZBLIB_DRIVER_TYPE_ZCL_COLOR_CONTROL,
208                 ZBLIB_ZCL_COLOR_CONTROL_OPS_MOVE_HUE,
209                 &req, sizeof(req),
210                 on_zcl_color_move_hue_resp, resp_cb_data);
211         if (FALSE == ret) {
212                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
213
214                 /* Free response callback data */
215                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
216
217                 /* Send failure response */
218                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
219
220                 return TRUE;
221         }
222
223         return TRUE;
224 }
225
226 static void on_zcl_color_step_hue_resp(ZigBeeServiceInterface *service_interface,
227         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
228 {
229         ZigbeeServiceInterfaceRespCbData_t *cb_data =
230                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
231
232         ZigbeeZcl_color_control *zcl_color_object = NULL;
233         GDBusMethodInvocation *invocation = NULL;
234
235         ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
236
237         NOT_USED(service_interface);
238         NOT_USED(request_id);
239
240         if (NULL == resp_data || 0 == resp_data_len) {
241                 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
242                 g_free(cb_data);
243                 return;
244         }
245
246         zcl_color_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
247         zblib_check_null_free_and_ret("zcl_color_object", zcl_color_object, cb_data);
248
249         invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
250         zblib_check_null_free_and_ret("invocation", invocation, cb_data);
251
252         zigbee_zcl_color_control_complete_step_hue(zcl_color_object, invocation,
253                 payload->result);
254
255         g_free(cb_data);
256 }
257
258 static gboolean on_zcl_color_step_hue(ZigbeeZcl_color_control *zcl_color_object,
259         GDBusMethodInvocation *invocation,
260         gshort node_id,
261         gchar endpoint,
262         gchar step_mode,
263         gchar step_size,
264         gchar transition_time,
265         gpointer user_data)
266 {
267         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
268         ZigbeeZclColorControlStepHue_t req;
269         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
270
271         gboolean ret;
272
273         memset(&req, 0x0, sizeof(ZigbeeZclColorControlStepHue_t));
274
275         /* Update request structure */
276         req.node_id = node_id;
277         req.dest_ep = endpoint;
278         req.step_mode = step_mode;
279         req.step_size = step_size;
280         req.transition_time = transition_time;
281
282         /* Allocate response callback data */
283         resp_cb_data =
284                 zigbee_service_dbus_interface_create_resp_cb_data(zcl_color_object,
285                         invocation, NULL, 0);
286         if (NULL == resp_cb_data) {
287                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
288
289                 /* Send failure response */
290                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
291
292                 return TRUE;
293         }
294
295         /* Dispatch request */
296         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
297                 ZBLIB_DRIVER_TYPE_ZCL_COLOR_CONTROL,
298                 ZBLIB_ZCL_COLOR_CONTROL_OPS_STEP_HUE,
299                 &req, sizeof(req),
300                 on_zcl_color_step_hue_resp, resp_cb_data);
301         if (FALSE == ret) {
302                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
303
304                 /* Free response callback data */
305                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
306
307                 /* Send failure response */
308                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
309
310                 return TRUE;
311         }
312
313         return TRUE;
314 }
315
316 static void on_zcl_color_move_to_saturation_resp(ZigBeeServiceInterface *service_interface,
317         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
318 {
319         ZigbeeServiceInterfaceRespCbData_t *cb_data =
320                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
321
322         ZigbeeZcl_color_control *zcl_color_object = NULL;
323         GDBusMethodInvocation *invocation = NULL;
324
325         ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
326
327         NOT_USED(service_interface);
328         NOT_USED(request_id);
329
330         if (NULL == resp_data || 0 == resp_data_len) {
331                 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
332                 g_free(cb_data);
333                 return;
334         }
335
336         zcl_color_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
337         zblib_check_null_free_and_ret("zcl_color_object", zcl_color_object, cb_data);
338
339         invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
340         zblib_check_null_free_and_ret("invocation", invocation, cb_data);
341
342         zigbee_zcl_color_control_complete_move_to_saturation(zcl_color_object, invocation,
343                 payload->result);
344
345         g_free(cb_data);
346 }
347
348 static gboolean on_zcl_color_move_to_saturation(ZigbeeZcl_color_control *zcl_color_object,
349         GDBusMethodInvocation *invocation,
350         gshort node_id,
351         gchar endpoint,
352         gchar saturation,
353         gshort transition_time,
354         gpointer user_data)
355 {
356         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
357         ZigbeeZclColorControlMoveToSaturation_t req;
358         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
359
360         gboolean ret;
361
362         memset(&req, 0x0, sizeof(ZigbeeZclColorControlMoveToSaturation_t));
363
364         /* Update request structure */
365         req.node_id = node_id;
366         req.dest_ep = endpoint;
367         req.saturation = saturation;
368         req.transition_time = transition_time;
369
370         /* Allocate response callback data */
371         resp_cb_data =
372                 zigbee_service_dbus_interface_create_resp_cb_data(zcl_color_object,
373                         invocation, NULL, 0);
374         if (NULL == resp_cb_data) {
375                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
376
377                 /* Send failure response */
378                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
379
380                 return TRUE;
381         }
382
383         /* Dispatch request */
384         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
385                 ZBLIB_DRIVER_TYPE_ZCL_COLOR_CONTROL,
386                 ZBLIB_ZCL_COLOR_CONTROL_OPS_MOVE_TO_STAURATION,
387                 &req, sizeof(req),
388                 on_zcl_color_move_to_saturation_resp, resp_cb_data);
389         if (FALSE == ret) {
390                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
391
392                 /* Free response callback data */
393                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
394
395                 /* Send failure response */
396                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
397
398                 return TRUE;
399         }
400
401         return TRUE;
402 }
403
404 static void on_zcl_color_move_saturation_resp(ZigBeeServiceInterface *service_interface,
405         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
406 {
407         ZigbeeServiceInterfaceRespCbData_t *cb_data =
408                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
409
410         ZigbeeZcl_color_control *zcl_color_object = NULL;
411         GDBusMethodInvocation *invocation = NULL;
412
413         ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
414
415         NOT_USED(service_interface);
416         NOT_USED(request_id);
417
418         if (NULL == resp_data || 0 == resp_data_len) {
419                 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
420                 g_free(cb_data);
421                 return;
422         }
423
424         zcl_color_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
425         zblib_check_null_free_and_ret("zcl_color_object", zcl_color_object, cb_data);
426
427         invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
428         zblib_check_null_free_and_ret("invocation", invocation, cb_data);
429
430         zigbee_zcl_color_control_complete_move_saturation(zcl_color_object, invocation,
431                 payload->result);
432
433         g_free(cb_data);
434 }
435
436 static gboolean on_zcl_color_move_saturation(ZigbeeZcl_color_control *zcl_color_object,
437         GDBusMethodInvocation *invocation,
438         gshort node_id,
439         gchar endpoint,
440         gchar move_mode,
441         gchar rate,
442         gpointer user_data)
443 {
444         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
445         ZigbeeZclColorControlMoveSaturation_t req;
446         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
447
448         gboolean ret;
449
450         memset(&req, 0x0, sizeof(ZigbeeZclColorControlMoveSaturation_t));
451
452         /* Update request structure */
453         req.node_id = node_id;
454         req.dest_ep = endpoint;
455         req.move_mode = move_mode;
456         req.rate = rate;
457
458         /* Allocate response callback data */
459         resp_cb_data =
460                 zigbee_service_dbus_interface_create_resp_cb_data(zcl_color_object,
461                         invocation, NULL, 0);
462         if (NULL == resp_cb_data) {
463                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
464
465                 /* Send failure response */
466                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
467
468                 return TRUE;
469         }
470
471         /* Dispatch request */
472         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
473                 ZBLIB_DRIVER_TYPE_ZCL_COLOR_CONTROL,
474                 ZBLIB_ZCL_COLOR_CONTROL_OPS_MOVE_STAURATION,
475                 &req, sizeof(req),
476                 on_zcl_color_move_saturation_resp, resp_cb_data);
477         if (FALSE == ret) {
478                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
479
480                 /* Free response callback data */
481                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
482
483                 /* Send failure response */
484                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
485
486                 return TRUE;
487         }
488
489         return TRUE;
490 }
491
492 static void on_zcl_color_step_saturation_resp(ZigBeeServiceInterface *service_interface,
493         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
494 {
495         ZigbeeServiceInterfaceRespCbData_t *cb_data =
496                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
497
498         ZigbeeZcl_color_control *zcl_color_object = NULL;
499         GDBusMethodInvocation *invocation = NULL;
500
501         ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
502
503         NOT_USED(service_interface);
504         NOT_USED(request_id);
505
506         if (NULL == resp_data || 0 == resp_data_len) {
507                 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
508                 g_free(cb_data);
509                 return;
510         }
511
512         zcl_color_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
513         zblib_check_null_free_and_ret("zcl_color_object", zcl_color_object, cb_data);
514
515         invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
516         zblib_check_null_free_and_ret("invocation", invocation, cb_data);
517
518         zigbee_zcl_color_control_complete_step_saturation(zcl_color_object, invocation,
519                 payload->result);
520
521         g_free(cb_data);
522 }
523
524 static gboolean on_zcl_color_step_saturation(ZigbeeZcl_color_control *zcl_color_object,
525         GDBusMethodInvocation *invocation,
526         gshort node_id,
527         gchar endpoint,
528         gchar step_mode,
529         gchar step_size,
530         gchar transition_time,
531         gpointer user_data)
532 {
533         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
534         ZigbeeZclColorControlStepSaturation_t req;
535         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
536
537         gboolean ret;
538
539         memset(&req, 0x0, sizeof(ZigbeeZclColorControlStepSaturation_t));
540
541         /* Update request structure */
542         req.node_id = node_id;
543         req.dest_ep = endpoint;
544         req.step_mode = step_mode;
545         req.step_size = step_size;
546         req.transition_time = transition_time;
547
548         /* Allocate response callback data */
549         resp_cb_data =
550                 zigbee_service_dbus_interface_create_resp_cb_data(zcl_color_object,
551                         invocation, NULL, 0);
552         if (NULL == resp_cb_data) {
553                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
554
555                 /* Send failure response */
556                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
557
558                 return TRUE;
559         }
560
561         /* Dispatch request */
562         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
563                 ZBLIB_DRIVER_TYPE_ZCL_COLOR_CONTROL,
564                 ZBLIB_ZCL_COLOR_CONTROL_OPS_STEP_STAURATION,
565                 &req, sizeof(req),
566                 on_zcl_color_step_saturation_resp, resp_cb_data);
567         if (FALSE == ret) {
568                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
569
570                 /* Free response callback data */
571                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
572
573                 /* Send failure response */
574                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
575
576                 return TRUE;
577         }
578
579         return TRUE;
580 }
581
582 static void on_zcl_color_move_to_hue_and_saturation_resp(ZigBeeServiceInterface *service_interface,
583         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
584 {
585         ZigbeeServiceInterfaceRespCbData_t *cb_data =
586                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
587
588         ZigbeeZcl_color_control *zcl_color_object = NULL;
589         GDBusMethodInvocation *invocation = NULL;
590
591         ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
592
593         NOT_USED(service_interface);
594         NOT_USED(request_id);
595
596         if (NULL == resp_data || 0 == resp_data_len) {
597                 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
598                 g_free(cb_data);
599                 return;
600         }
601
602         zcl_color_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
603         zblib_check_null_free_and_ret("zcl_color_object", zcl_color_object, cb_data);
604
605         invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
606         zblib_check_null_free_and_ret("invocation", invocation, cb_data);
607
608         zigbee_zcl_color_control_complete_move_to_hue_and_saturation(zcl_color_object,
609                 invocation, payload->result);
610
611         g_free(cb_data);
612 }
613
614 static gboolean on_zcl_color_move_to_hue_and_saturation(ZigbeeZcl_color_control *zcl_color_object,
615         GDBusMethodInvocation *invocation,
616         gshort node_id,
617         gchar endpoint,
618         gchar hue,
619         gchar saturation,
620         gshort transition_time,
621         gpointer user_data)
622 {
623         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
624         ZigbeeZclColorControlMoveToHueAndSaturation_t req;
625         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
626
627         gboolean ret;
628
629         memset(&req, 0x0, sizeof(ZigbeeZclColorControlMoveToHueAndSaturation_t));
630
631         /* Update request structure */
632         req.node_id = node_id;
633         req.dest_ep = endpoint;
634         req.hue = hue;
635         req.saturation = saturation;
636         req.transition_time = transition_time;
637
638         /* Allocate response callback data */
639         resp_cb_data =
640                 zigbee_service_dbus_interface_create_resp_cb_data(zcl_color_object,
641                         invocation, NULL, 0);
642         if (NULL == resp_cb_data) {
643                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
644
645                 /* Send failure response */
646                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
647
648                 return TRUE;
649         }
650
651         /* Dispatch request */
652         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
653                 ZBLIB_DRIVER_TYPE_ZCL_COLOR_CONTROL,
654                 ZBLIB_ZCL_COLOR_CONTROL_OPS_MOVE_TO_HUE_AND_SATURATION,
655                 &req, sizeof(req),
656                 on_zcl_color_move_to_hue_and_saturation_resp, resp_cb_data);
657         if (FALSE == ret) {
658                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
659
660                 /* Free response callback data */
661                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
662
663                 /* Send failure response */
664                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
665
666                 return TRUE;
667         }
668
669         return TRUE;
670 }
671
672 static void on_zcl_color_move_to_color_resp(ZigBeeServiceInterface *service_interface,
673         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
674 {
675         ZigbeeServiceInterfaceRespCbData_t *cb_data =
676                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
677
678         ZigbeeZcl_color_control *zcl_color_object = NULL;
679         GDBusMethodInvocation *invocation = NULL;
680
681         ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
682
683         NOT_USED(service_interface);
684         NOT_USED(request_id);
685
686         if (NULL == resp_data || 0 == resp_data_len) {
687                 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
688                 g_free(cb_data);
689                 return;
690         }
691
692         zcl_color_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
693         zblib_check_null_free_and_ret("zcl_color_object", zcl_color_object, cb_data);
694
695         invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
696         zblib_check_null_free_and_ret("invocation", invocation, cb_data);
697
698         zigbee_zcl_color_control_complete_move_to_color(zcl_color_object, invocation,
699                 payload->result);
700
701         g_free(cb_data);
702 }
703
704 static gboolean on_zcl_color_move_to_color(ZigbeeZcl_color_control *zcl_color_object,
705         GDBusMethodInvocation *invocation,
706         gshort node_id,
707         gchar endpoint,
708         gshort start_x,
709         gshort start_y,
710         gshort transition_time,
711         gpointer user_data)
712 {
713         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
714         ZigbeeZclColorControlMoveToColor_t req;
715         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
716
717         gboolean ret;
718
719         memset(&req, 0x0, sizeof(ZigbeeZclColorControlMoveToColor_t));
720
721         /* Update request structure */
722         req.node_id = node_id;
723         req.dest_ep = endpoint;
724         req.color_x = start_x;
725         req.color_y = start_y;
726         req.transition_time = transition_time;
727
728         /* Allocate response callback data */
729         resp_cb_data =
730                 zigbee_service_dbus_interface_create_resp_cb_data(zcl_color_object,
731                         invocation, NULL, 0);
732         if (NULL == resp_cb_data) {
733                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
734
735                 /* Send failure response */
736                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
737
738                 return TRUE;
739         }
740
741         /* Dispatch request */
742         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
743                 ZBLIB_DRIVER_TYPE_ZCL_COLOR_CONTROL,
744                 ZBLIB_ZCL_COLOR_CONTROL_OPS_MOVE_TO_COLOR,
745                 &req, sizeof(req),
746                 on_zcl_color_move_to_color_resp, resp_cb_data);
747         if (FALSE == ret) {
748                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
749
750                 /* Free response callback data */
751                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
752
753                 /* Send failure response */
754                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
755
756                 return TRUE;
757         }
758
759         return TRUE;
760 }
761
762 static void on_zcl_color_move_color_resp(ZigBeeServiceInterface *service_interface,
763         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
764 {
765         ZigbeeServiceInterfaceRespCbData_t *cb_data =
766                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
767
768         ZigbeeZcl_color_control *zcl_color_object = NULL;
769         GDBusMethodInvocation *invocation = NULL;
770
771         ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
772
773         NOT_USED(service_interface);
774         NOT_USED(request_id);
775
776         if (NULL == resp_data || 0 == resp_data_len) {
777                 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
778                 g_free(cb_data);
779                 return;
780         }
781
782         zcl_color_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
783         zblib_check_null_free_and_ret("zcl_color_object", zcl_color_object, cb_data);
784
785         invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
786         zblib_check_null_free_and_ret("invocation", invocation, cb_data);
787
788         zigbee_zcl_color_control_complete_move_color(zcl_color_object, invocation,
789                 payload->result);
790
791         g_free(cb_data);
792 }
793
794 static gboolean on_zcl_color_move_color(ZigbeeZcl_color_control *zcl_color_object,
795         GDBusMethodInvocation *invocation,
796         gshort node_id,
797         gchar endpoint,
798         gshort rate_x,
799         gshort rate_y,
800         gpointer user_data)
801 {
802         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
803         ZigbeeZclColorControlMoveColor_t req;
804         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
805
806         gboolean ret;
807
808         memset(&req, 0x0, sizeof(ZigbeeZclColorControlMoveColor_t));
809
810         /* Update request structure */
811         req.node_id = node_id;
812         req.dest_ep = endpoint;
813         req.rate_x = rate_x;
814         req.rate_y = rate_y;
815
816         /* Allocate response callback data */
817         resp_cb_data =
818                 zigbee_service_dbus_interface_create_resp_cb_data(zcl_color_object,
819                         invocation, NULL, 0);
820         if (NULL == resp_cb_data) {
821                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
822
823                 /* Send failure response */
824                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
825
826                 return TRUE;
827         }
828
829         /* Dispatch request */
830         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
831                 ZBLIB_DRIVER_TYPE_ZCL_COLOR_CONTROL,
832                 ZBLIB_ZCL_COLOR_CONTROL_OPS_MOVE_COLOR,
833                 &req, sizeof(req),
834                 on_zcl_color_move_color_resp, resp_cb_data);
835         if (FALSE == ret) {
836                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
837
838                 /* Free response callback data */
839                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
840
841                 /* Send failure response */
842                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
843
844                 return TRUE;
845         }
846
847         return TRUE;
848 }
849
850 static void on_zcl_color_step_color_resp(ZigBeeServiceInterface *service_interface,
851         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
852 {
853         ZigbeeServiceInterfaceRespCbData_t *cb_data =
854                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
855
856         ZigbeeZcl_color_control *zcl_color_object = NULL;
857         GDBusMethodInvocation *invocation = NULL;
858
859         ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
860
861         NOT_USED(service_interface);
862         NOT_USED(request_id);
863
864         if (NULL == resp_data || 0 == resp_data_len) {
865                 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
866                 g_free(cb_data);
867                 return;
868         }
869
870         zcl_color_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
871         zblib_check_null_free_and_ret("zcl_color_object", zcl_color_object, cb_data);
872
873         invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
874         zblib_check_null_free_and_ret("invocation", invocation, cb_data);
875
876         zigbee_zcl_color_control_complete_step_color(zcl_color_object, invocation,
877                 payload->result);
878
879         g_free(cb_data);
880 }
881
882 static gboolean on_zcl_color_step_color(ZigbeeZcl_color_control *zcl_color_object,
883         GDBusMethodInvocation *invocation,
884         gshort node_id,
885         gchar endpoint,
886         gshort step_x,
887         gshort step_y,
888         gshort transition_time,
889         gpointer user_data)
890 {
891         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
892         ZigbeeZclColorControlStepColor_t req;
893         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
894
895         gboolean ret;
896
897         memset(&req, 0x0, sizeof(ZigbeeZclColorControlStepColor_t));
898
899         /* Update request structure */
900         req.node_id = node_id;
901         req.dest_ep = endpoint;
902         req.step_x = step_x;
903         req.step_y = step_y;
904         req.transition_time = transition_time;
905
906         /* Allocate response callback data */
907         resp_cb_data =
908                 zigbee_service_dbus_interface_create_resp_cb_data(zcl_color_object,
909                         invocation, NULL, 0);
910         if (NULL == resp_cb_data) {
911                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
912
913                 /* Send failure response */
914                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
915
916                 return TRUE;
917         }
918
919         /* Dispatch request */
920         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
921                 ZBLIB_DRIVER_TYPE_ZCL_COLOR_CONTROL,
922                 ZBLIB_ZCL_COLOR_CONTROL_OPS_STEP_COLOR,
923                 &req, sizeof(req),
924                 on_zcl_color_step_color_resp, resp_cb_data);
925         if (FALSE == ret) {
926                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
927
928                 /* Free response callback data */
929                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
930
931                 /* Send failure response */
932                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
933
934                 return TRUE;
935         }
936
937         return TRUE;
938 }
939
940 static void on_zcl_color_move_color_temperature_resp(ZigBeeServiceInterface *service_interface,
941         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
942 {
943         ZigbeeServiceInterfaceRespCbData_t *cb_data =
944                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
945
946         ZigbeeZcl_color_control *zcl_color_object = NULL;
947         GDBusMethodInvocation *invocation = NULL;
948
949         ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
950
951         NOT_USED(service_interface);
952         NOT_USED(request_id);
953
954         if (NULL == resp_data || 0 == resp_data_len) {
955                 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
956                 g_free(cb_data);
957                 return;
958         }
959
960         zcl_color_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
961         zblib_check_null_free_and_ret("zcl_color_object", zcl_color_object, cb_data);
962
963         invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
964         zblib_check_null_free_and_ret("invocation", invocation, cb_data);
965
966         zigbee_zcl_color_control_complete_move_color_temperature(zcl_color_object, invocation,
967                 payload->result);
968
969         g_free(cb_data);
970 }
971
972 static gboolean on_zcl_color_move_color_temperature(ZigbeeZcl_color_control *zcl_color_object,
973         GDBusMethodInvocation *invocation,
974         gshort node_id,
975         gchar endpoint,
976         gshort color_temperature,
977         gshort transition_time,
978         gpointer user_data)
979 {
980         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
981         ZigbeeZclColorControlMoveColorTemperature_t req;
982         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
983
984         gboolean ret;
985
986         memset(&req, 0x0, sizeof(ZigbeeZclColorControlMoveColorTemperature_t));
987
988         /* Update request structure */
989         req.node_id = node_id;
990         req.dest_ep = endpoint;
991         req.color_temperature = color_temperature;
992         req.transition_time = transition_time;
993
994         /* Allocate response callback data */
995         resp_cb_data =
996                 zigbee_service_dbus_interface_create_resp_cb_data(zcl_color_object,
997                         invocation, NULL, 0);
998         if (NULL == resp_cb_data) {
999                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
1000
1001                 /* Send failure response */
1002                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1003
1004                 return TRUE;
1005         }
1006
1007         /* Dispatch request */
1008         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
1009                 ZBLIB_DRIVER_TYPE_ZCL_COLOR_CONTROL,
1010                 ZBLIB_ZCL_COLOR_CONTROL_OPS_MOVE_COLOR_TEMPERATURE,
1011                 &req, sizeof(req),
1012                 on_zcl_color_move_color_temperature_resp, resp_cb_data);
1013         if (FALSE == ret) {
1014                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
1015
1016                 /* Free response callback data */
1017                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
1018
1019                 /* Send failure response */
1020                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
1021
1022                 return TRUE;
1023         }
1024
1025         return TRUE;
1026 }
1027
1028 void zigbee_service_dbus_interface_zcl_color_control_notification(ZigBeeServiceInterface *service_interface,
1029         guint noti_id, gpointer noti_data, guint noti_data_len, gpointer noti_cb_data)
1030 {
1031         ZigbeeZcl_color_control *color_object;
1032
1033         zblib_check_null_ret("service_interface", service_interface);
1034
1035         if (NULL == noti_data || 0 == noti_data_len) {
1036                 Z_LOGE("noti_data is NULL");
1037                 return;
1038         }
1039
1040         color_object = _service_interface_ref_zigbee_zcl_color_control(service_interface);
1041         zblib_check_null_ret("color_object", color_object);
1042
1043         NOT_USED(noti_cb_data);
1044
1045         switch (noti_id) {
1046         default:
1047                 Z_LOGE("Unexpected notification [%x]", noti_id);
1048         break;
1049         }
1050
1051         /* ZigbeeZcl_color_control should be dereferenced */
1052         g_object_unref(color_object);
1053 }
1054 /* LCOV_EXCL_STOP */
1055
1056 gboolean zigbee_service_dbus_interface_zcl_color_control_init(ZigBeeServiceInterface *service_interface,
1057         ZigbeeObjectSkeleton *zigbee_object)
1058 {
1059         ZigbeeZcl_color_control *zcl_color_object;
1060
1061         if (NULL == service_interface) {
1062                 /* LCOV_EXCL_START */
1063                 Z_LOGE("service_interface is NULL");
1064                 return FALSE;
1065                 /* LCOV_EXCL_STOP */
1066         }
1067
1068         zcl_color_object = zigbee_zcl_color_control_skeleton_new();
1069         zigbee_object_skeleton_set_zcl_color_control(zigbee_object, zcl_color_object);
1070         g_object_unref(zcl_color_object);
1071
1072         Z_LOGI("zcl_color_object: [%p]", zcl_color_object);
1073
1074         /*
1075          * Register signal handlers for 'zcl_color' interface
1076          */
1077         g_signal_connect(zcl_color_object,
1078                 "handle-move-to-hue",
1079                 G_CALLBACK(on_zcl_color_move_to_hue), service_interface);
1080
1081         g_signal_connect(zcl_color_object,
1082                 "handle-move-hue",
1083                 G_CALLBACK(on_zcl_color_move_hue), service_interface);
1084
1085         g_signal_connect(zcl_color_object,
1086                 "handle-step-hue",
1087                 G_CALLBACK(on_zcl_color_step_hue), service_interface);
1088
1089         g_signal_connect(zcl_color_object,
1090                 "handle-move-to-saturation",
1091                 G_CALLBACK(on_zcl_color_move_to_saturation), service_interface);
1092
1093         g_signal_connect(zcl_color_object,
1094                 "handle-move-saturation",
1095                 G_CALLBACK(on_zcl_color_move_saturation), service_interface);
1096
1097         g_signal_connect(zcl_color_object,
1098                 "handle-step-saturation",
1099                 G_CALLBACK(on_zcl_color_step_saturation), service_interface);
1100
1101         g_signal_connect(zcl_color_object,
1102                 "handle-move-to-hue-and-saturation",
1103                 G_CALLBACK(on_zcl_color_move_to_hue_and_saturation), service_interface);
1104
1105         g_signal_connect(zcl_color_object,
1106                 "handle-move-to-color",
1107                 G_CALLBACK(on_zcl_color_move_to_color), service_interface);
1108
1109         g_signal_connect(zcl_color_object,
1110                 "handle-move-color",
1111                 G_CALLBACK(on_zcl_color_move_color), service_interface);
1112
1113         g_signal_connect(zcl_color_object,
1114                 "handle-step-color",
1115                 G_CALLBACK(on_zcl_color_step_color), service_interface);
1116
1117         g_signal_connect(zcl_color_object,
1118                 "handle-move-color-temperature",
1119                 G_CALLBACK(on_zcl_color_move_color_temperature), service_interface);
1120
1121         return TRUE;
1122 }