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