Chagne DBus object name following Zigbee Specification
[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 on_zcl_color_move_to_hue_resp(ZigBeeServiceInterface *service_interface,
24         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
25 {
26         ZigbeeServiceInterfaceRespCbData_t *cb_data =
27                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
28
29         NOT_USED(cb_data);
30         NOT_USED(service_interface);
31         NOT_USED(request_id);
32         NOT_USED(resp_data);
33         NOT_USED(resp_data_len);
34 }
35
36 static gboolean on_zcl_color_move_to_hue(ZigbeeZcl_color_control *zcl_color_object,
37         GDBusMethodInvocation *invocation,
38         gshort node_id,
39         gchar endpoint,
40         gchar hue,
41         gchar direction,
42         gshort transition_time,
43         gpointer user_data)
44 {
45         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
46         ZigbeeZclColorMoveToHue_t req;
47         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
48
49         gboolean ret;
50
51         memset(&req, 0x0, sizeof(ZigbeeZclColorMoveToHue_t));
52
53         /* Update request structure */
54         req.node_id = node_id;
55         req.dest_ep = endpoint;
56         req.hue = hue;
57         req.direction = direction;
58         req.transition_time = transition_time;
59
60         /* Allocate response callback data */
61         resp_cb_data =
62                 zigbee_service_dbus_interface_create_resp_cb_data(zcl_color_object,
63                         invocation, NULL, 0);
64         if (NULL == resp_cb_data) {
65                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
66
67                 /* Send failure response */
68                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
69
70                 return TRUE;
71         }
72
73         /* Dispatch request */
74         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
75                 ZBLIB_DRIVER_TYPE_ZCL_COLOR,
76                 ZBLIB_ZCL_COLOR_OPS_MOVE_TO_HUE,
77                 &req, sizeof(req),
78                 on_zcl_color_move_to_hue_resp, resp_cb_data);
79         if (FALSE == ret) {
80                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
81
82                 /* Free response callback data */
83                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
84
85                 /* Send failure response */
86                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
87
88                 return TRUE;
89         }
90
91         return TRUE;
92 }
93
94 static void on_zcl_color_move_hue_resp(ZigBeeServiceInterface *service_interface,
95         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
96 {
97         ZigbeeServiceInterfaceRespCbData_t *cb_data =
98                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
99
100         NOT_USED(cb_data);
101         NOT_USED(service_interface);
102         NOT_USED(request_id);
103         NOT_USED(resp_data);
104         NOT_USED(resp_data_len);
105 }
106
107 static gboolean on_zcl_color_move_hue(ZigbeeZcl_color_control *zcl_color_object,
108         GDBusMethodInvocation *invocation,
109         gshort node_id,
110         gchar endpoint,
111         gchar move_mode,
112         gchar rate,
113         gpointer user_data)
114 {
115         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
116         ZigbeeZclColorMoveHue_t req;
117         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
118
119         gboolean ret;
120
121         memset(&req, 0x0, sizeof(ZigbeeZclColorMoveHue_t));
122
123         /* Update request structure */
124         req.node_id = node_id;
125         req.dest_ep = endpoint;
126         req.move_mode = move_mode;
127         req.rate = rate;
128
129         /* Allocate response callback data */
130         resp_cb_data =
131                 zigbee_service_dbus_interface_create_resp_cb_data(zcl_color_object,
132                         invocation, NULL, 0);
133         if (NULL == resp_cb_data) {
134                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
135
136                 /* Send failure response */
137                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
138
139                 return TRUE;
140         }
141
142         /* Dispatch request */
143         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
144                 ZBLIB_DRIVER_TYPE_ZCL_COLOR,
145                 ZBLIB_ZCL_COLOR_OPS_MOVE_HUE,
146                 &req, sizeof(req),
147                 on_zcl_color_move_hue_resp, resp_cb_data);
148         if (FALSE == ret) {
149                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
150
151                 /* Free response callback data */
152                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
153
154                 /* Send failure response */
155                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
156
157                 return TRUE;
158         }
159
160         return TRUE;
161 }
162
163 static void on_zcl_color_step_hue_resp(ZigBeeServiceInterface *service_interface,
164         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
165 {
166         ZigbeeServiceInterfaceRespCbData_t *cb_data =
167                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
168
169         NOT_USED(cb_data);
170         NOT_USED(service_interface);
171         NOT_USED(request_id);
172         NOT_USED(resp_data);
173         NOT_USED(resp_data_len);
174 }
175
176 static gboolean on_zcl_color_step_hue(ZigbeeZcl_color_control *zcl_color_object,
177         GDBusMethodInvocation *invocation,
178         gshort node_id,
179         gchar endpoint,
180         gchar step_mode,
181         gchar step_size,
182         gchar transition_time,
183         gpointer user_data)
184 {
185         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
186         ZigbeeZclColorStepHue_t req;
187         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
188
189         gboolean ret;
190
191         memset(&req, 0x0, sizeof(ZigbeeZclColorStepHue_t));
192
193         /* Update request structure */
194         req.node_id = node_id;
195         req.dest_ep = endpoint;
196         req.step_mode = step_mode;
197         req.step_size = step_size;
198         req.transition_time = transition_time;
199
200         /* Allocate response callback data */
201         resp_cb_data =
202                 zigbee_service_dbus_interface_create_resp_cb_data(zcl_color_object,
203                         invocation, NULL, 0);
204         if (NULL == resp_cb_data) {
205                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
206
207                 /* Send failure response */
208                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
209
210                 return TRUE;
211         }
212
213         /* Dispatch request */
214         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
215                 ZBLIB_DRIVER_TYPE_ZCL_COLOR,
216                 ZBLIB_ZCL_COLOR_OPS_STEP_HUE,
217                 &req, sizeof(req),
218                 on_zcl_color_step_hue_resp, resp_cb_data);
219         if (FALSE == ret) {
220                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
221
222                 /* Free response callback data */
223                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
224
225                 /* Send failure response */
226                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
227
228                 return TRUE;
229         }
230
231         return TRUE;
232 }
233
234 static void on_zcl_color_move_to_saturation_resp(ZigBeeServiceInterface *service_interface,
235         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
236 {
237         ZigbeeServiceInterfaceRespCbData_t *cb_data =
238                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
239
240         NOT_USED(cb_data);
241         NOT_USED(service_interface);
242         NOT_USED(request_id);
243         NOT_USED(resp_data);
244         NOT_USED(resp_data_len);
245 }
246
247 static gboolean on_zcl_color_move_to_saturation(ZigbeeZcl_color_control *zcl_color_object,
248         GDBusMethodInvocation *invocation,
249         gshort node_id,
250         gchar endpoint,
251         gchar saturation,
252         gshort transition_time,
253         gpointer user_data)
254 {
255         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
256         ZigbeeZclColorMoveToSaturation_t req;
257         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
258
259         gboolean ret;
260
261         memset(&req, 0x0, sizeof(ZigbeeZclColorMoveToSaturation_t));
262
263         /* Update request structure */
264         req.node_id = node_id;
265         req.dest_ep = endpoint;
266         req.saturation = saturation;
267         req.transition_time = transition_time;
268
269         /* Allocate response callback data */
270         resp_cb_data =
271                 zigbee_service_dbus_interface_create_resp_cb_data(zcl_color_object,
272                         invocation, NULL, 0);
273         if (NULL == resp_cb_data) {
274                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
275
276                 /* Send failure response */
277                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
278
279                 return TRUE;
280         }
281
282         /* Dispatch request */
283         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
284                 ZBLIB_DRIVER_TYPE_ZCL_COLOR,
285                 ZBLIB_ZCL_COLOR_OPS_MOVE_TO_STAURATION,
286                 &req, sizeof(req),
287                 on_zcl_color_move_to_saturation_resp, resp_cb_data);
288         if (FALSE == ret) {
289                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
290
291                 /* Free response callback data */
292                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
293
294                 /* Send failure response */
295                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
296
297                 return TRUE;
298         }
299
300         return TRUE;
301 }
302
303 static void on_zcl_color_move_saturation_resp(ZigBeeServiceInterface *service_interface,
304         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
305 {
306         ZigbeeServiceInterfaceRespCbData_t *cb_data =
307                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
308
309         NOT_USED(cb_data);
310         NOT_USED(service_interface);
311         NOT_USED(request_id);
312         NOT_USED(resp_data);
313         NOT_USED(resp_data_len);
314 }
315
316 static gboolean on_zcl_color_move_saturation(ZigbeeZcl_color_control *zcl_color_object,
317         GDBusMethodInvocation *invocation,
318         gshort node_id,
319         gchar endpoint,
320         gchar move_mode,
321         gchar rate,
322         gpointer user_data)
323 {
324         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
325         ZigbeeZclColorMoveSaturation_t req;
326         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
327
328         gboolean ret;
329
330         memset(&req, 0x0, sizeof(ZigbeeZclColorMoveSaturation_t));
331
332         /* Update request structure */
333         req.node_id = node_id;
334         req.dest_ep = endpoint;
335         req.move_mode = move_mode;
336         req.rate = rate;
337
338         /* Allocate response callback data */
339         resp_cb_data =
340                 zigbee_service_dbus_interface_create_resp_cb_data(zcl_color_object,
341                         invocation, NULL, 0);
342         if (NULL == resp_cb_data) {
343                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
344
345                 /* Send failure response */
346                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
347
348                 return TRUE;
349         }
350
351         /* Dispatch request */
352         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
353                 ZBLIB_DRIVER_TYPE_ZCL_COLOR,
354                 ZBLIB_ZCL_COLOR_OPS_MOVE_STAURATION,
355                 &req, sizeof(req),
356                 on_zcl_color_move_saturation_resp, resp_cb_data);
357         if (FALSE == ret) {
358                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
359
360                 /* Free response callback data */
361                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
362
363                 /* Send failure response */
364                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
365
366                 return TRUE;
367         }
368
369         return TRUE;
370 }
371
372 static void on_zcl_color_step_saturation_resp(ZigBeeServiceInterface *service_interface,
373         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
374 {
375         ZigbeeServiceInterfaceRespCbData_t *cb_data =
376                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
377
378         NOT_USED(cb_data);
379         NOT_USED(service_interface);
380         NOT_USED(request_id);
381         NOT_USED(resp_data);
382         NOT_USED(resp_data_len);
383 }
384
385 static gboolean on_zcl_color_step_saturation(ZigbeeZcl_color_control *zcl_color_object,
386         GDBusMethodInvocation *invocation,
387         gshort node_id,
388         gchar endpoint,
389         gchar step_mode,
390         gchar step_size,
391         gchar transition_time,
392         gpointer user_data)
393 {
394         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
395         ZigbeeZclColorStepSaturation_t req;
396         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
397
398         gboolean ret;
399
400         memset(&req, 0x0, sizeof(ZigbeeZclColorStepSaturation_t));
401
402         /* Update request structure */
403         req.node_id = node_id;
404         req.dest_ep = endpoint;
405         req.step_mode = step_mode;
406         req.step_size = step_size;
407         req.transition_time = transition_time;
408
409         /* Allocate response callback data */
410         resp_cb_data =
411                 zigbee_service_dbus_interface_create_resp_cb_data(zcl_color_object,
412                         invocation, NULL, 0);
413         if (NULL == resp_cb_data) {
414                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
415
416                 /* Send failure response */
417                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
418
419                 return TRUE;
420         }
421
422         /* Dispatch request */
423         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
424                 ZBLIB_DRIVER_TYPE_ZCL_COLOR,
425                 ZBLIB_ZCL_COLOR_OPS_STEP_STAURATION,
426                 &req, sizeof(req),
427                 on_zcl_color_step_saturation_resp, resp_cb_data);
428         if (FALSE == ret) {
429                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
430
431                 /* Free response callback data */
432                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
433
434                 /* Send failure response */
435                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
436
437                 return TRUE;
438         }
439
440         return TRUE;
441 }
442
443 static void on_zcl_color_move_to_hue_and_saturation_resp(ZigBeeServiceInterface *service_interface,
444         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
445 {
446         ZigbeeServiceInterfaceRespCbData_t *cb_data =
447                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
448
449         NOT_USED(cb_data);
450         NOT_USED(service_interface);
451         NOT_USED(request_id);
452         NOT_USED(resp_data);
453         NOT_USED(resp_data_len);
454 }
455
456 static gboolean on_zcl_color_move_to_hue_and_saturation(ZigbeeZcl_color_control *zcl_color_object,
457         GDBusMethodInvocation *invocation,
458         gshort node_id,
459         gchar endpoint,
460         gchar hue,
461         gchar saturation,
462         gshort transition_time,
463         gpointer user_data)
464 {
465         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
466         ZigbeeZclColorMoveToHueAndSaturation_t req;
467         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
468
469         gboolean ret;
470
471         memset(&req, 0x0, sizeof(ZigbeeZclColorMoveToHueAndSaturation_t));
472
473         /* Update request structure */
474         req.node_id = node_id;
475         req.dest_ep = endpoint;
476         req.hue = hue;
477         req.saturation = saturation;
478         req.transition_time = transition_time;
479
480         /* Allocate response callback data */
481         resp_cb_data =
482                 zigbee_service_dbus_interface_create_resp_cb_data(zcl_color_object,
483                         invocation, NULL, 0);
484         if (NULL == resp_cb_data) {
485                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
486
487                 /* Send failure response */
488                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
489
490                 return TRUE;
491         }
492
493         /* Dispatch request */
494         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
495                 ZBLIB_DRIVER_TYPE_ZCL_COLOR,
496                 ZBLIB_ZCL_COLOR_OPS_MOVE_TO_HUE_AND_SATURATION,
497                 &req, sizeof(req),
498                 on_zcl_color_move_to_hue_and_saturation_resp, resp_cb_data);
499         if (FALSE == ret) {
500                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
501
502                 /* Free response callback data */
503                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
504
505                 /* Send failure response */
506                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
507
508                 return TRUE;
509         }
510
511         return TRUE;
512 }
513
514 static void on_zcl_color_move_to_color_resp(ZigBeeServiceInterface *service_interface,
515         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
516 {
517         ZigbeeServiceInterfaceRespCbData_t *cb_data =
518                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
519
520         NOT_USED(cb_data);
521         NOT_USED(service_interface);
522         NOT_USED(request_id);
523         NOT_USED(resp_data);
524         NOT_USED(resp_data_len);
525 }
526
527 static gboolean on_zcl_color_move_to_color(ZigbeeZcl_color_control *zcl_color_object,
528         GDBusMethodInvocation *invocation,
529         gshort node_id,
530         gchar endpoint,
531         gshort start_x,
532         gshort start_y,
533         gshort transition_time,
534         gpointer user_data)
535 {
536         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
537         ZigbeeZclColorMoveToColor_t req;
538         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
539
540         gboolean ret;
541
542         memset(&req, 0x0, sizeof(ZigbeeZclColorMoveToColor_t));
543
544         /* Update request structure */
545         req.node_id = node_id;
546         req.dest_ep = endpoint;
547         req.color_x = start_x;
548         req.color_y = start_y;
549         req.transition_time = transition_time;
550
551         /* Allocate response callback data */
552         resp_cb_data =
553                 zigbee_service_dbus_interface_create_resp_cb_data(zcl_color_object,
554                         invocation, NULL, 0);
555         if (NULL == resp_cb_data) {
556                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
557
558                 /* Send failure response */
559                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
560
561                 return TRUE;
562         }
563
564         /* Dispatch request */
565         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
566                 ZBLIB_DRIVER_TYPE_ZCL_COLOR,
567                 ZBLIB_ZCL_COLOR_OPS_MOVE_TO_COLOR,
568                 &req, sizeof(req),
569                 on_zcl_color_move_to_color_resp, resp_cb_data);
570         if (FALSE == ret) {
571                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
572
573                 /* Free response callback data */
574                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
575
576                 /* Send failure response */
577                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
578
579                 return TRUE;
580         }
581
582         return TRUE;
583 }
584
585 static void on_zcl_color_move_color_resp(ZigBeeServiceInterface *service_interface,
586         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
587 {
588         ZigbeeServiceInterfaceRespCbData_t *cb_data =
589                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
590
591         NOT_USED(cb_data);
592         NOT_USED(service_interface);
593         NOT_USED(request_id);
594         NOT_USED(resp_data);
595         NOT_USED(resp_data_len);
596 }
597
598 static gboolean on_zcl_color_move_color(ZigbeeZcl_color_control *zcl_color_object,
599         GDBusMethodInvocation *invocation,
600         gshort node_id,
601         gchar endpoint,
602         gshort rate_x,
603         gshort rate_y,
604         gpointer user_data)
605 {
606         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
607         ZigbeeZclColorMoveColor_t req;
608         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
609
610         gboolean ret;
611
612         memset(&req, 0x0, sizeof(ZigbeeZclColorMoveColor_t));
613
614         /* Update request structure */
615         req.node_id = node_id;
616         req.dest_ep = endpoint;
617         req.rate_x = rate_x;
618         req.rate_y = rate_y;
619
620         /* Allocate response callback data */
621         resp_cb_data =
622                 zigbee_service_dbus_interface_create_resp_cb_data(zcl_color_object,
623                         invocation, NULL, 0);
624         if (NULL == resp_cb_data) {
625                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
626
627                 /* Send failure response */
628                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
629
630                 return TRUE;
631         }
632
633         /* Dispatch request */
634         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
635                 ZBLIB_DRIVER_TYPE_ZCL_COLOR,
636                 ZBLIB_ZCL_COLOR_OPS_MOVE_COLOR,
637                 &req, sizeof(req),
638                 on_zcl_color_move_color_resp, resp_cb_data);
639         if (FALSE == ret) {
640                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
641
642                 /* Free response callback data */
643                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
644
645                 /* Send failure response */
646                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
647
648                 return TRUE;
649         }
650
651         return TRUE;
652 }
653
654 static void on_zcl_color_step_color_resp(ZigBeeServiceInterface *service_interface,
655         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
656 {
657         ZigbeeServiceInterfaceRespCbData_t *cb_data =
658                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
659
660         NOT_USED(cb_data);
661         NOT_USED(service_interface);
662         NOT_USED(request_id);
663         NOT_USED(resp_data);
664         NOT_USED(resp_data_len);
665 }
666
667 static gboolean on_zcl_color_step_color(ZigbeeZcl_color_control *zcl_color_object,
668         GDBusMethodInvocation *invocation,
669         gshort node_id,
670         gchar endpoint,
671         gshort rate_x,
672         gshort rate_y,
673         gshort transition_time,
674         gpointer user_data)
675 {
676         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
677         ZigbeeZclColorStepColor_t req;
678         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
679
680         gboolean ret;
681
682         memset(&req, 0x0, sizeof(ZigbeeZclColorStepColor_t));
683
684         /* Update request structure */
685         req.node_id = node_id;
686         req.dest_ep = endpoint;
687         req.rate_x = rate_x;
688         req.rate_y = rate_y;
689         req.transition_time = transition_time;
690
691         /* Allocate response callback data */
692         resp_cb_data =
693                 zigbee_service_dbus_interface_create_resp_cb_data(zcl_color_object,
694                         invocation, NULL, 0);
695         if (NULL == resp_cb_data) {
696                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
697
698                 /* Send failure response */
699                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
700
701                 return TRUE;
702         }
703
704         /* Dispatch request */
705         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
706                 ZBLIB_DRIVER_TYPE_ZCL_COLOR,
707                 ZBLIB_ZCL_COLOR_OPS_STEP_COLOR,
708                 &req, sizeof(req),
709                 on_zcl_color_step_color_resp, resp_cb_data);
710         if (FALSE == ret) {
711                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
712
713                 /* Free response callback data */
714                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
715
716                 /* Send failure response */
717                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
718
719                 return TRUE;
720         }
721
722         return TRUE;
723 }
724
725 static void on_zcl_color_move_color_temperature_resp(ZigBeeServiceInterface *service_interface,
726         guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
727 {
728         ZigbeeServiceInterfaceRespCbData_t *cb_data =
729                 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
730
731         NOT_USED(cb_data);
732         NOT_USED(service_interface);
733         NOT_USED(request_id);
734         NOT_USED(resp_data);
735         NOT_USED(resp_data_len);
736 }
737
738 static gboolean on_zcl_color_move_color_temperature(ZigbeeZcl_color_control *zcl_color_object,
739         GDBusMethodInvocation *invocation,
740         gshort node_id,
741         gchar endpoint,
742         gshort color_temperature,
743         gshort transition_time,
744         gpointer user_data)
745 {
746         ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
747         ZigbeeZclColorMoveColorTemperature_t req;
748         ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
749
750         gboolean ret;
751
752         memset(&req, 0x0, sizeof(ZigbeeZclColorMoveColorTemperature_t));
753
754         /* Update request structure */
755         req.node_id = node_id;
756         req.dest_ep = endpoint;
757         req.color_temperature = color_temperature;
758         req.transition_time = transition_time;
759
760         /* Allocate response callback data */
761         resp_cb_data =
762                 zigbee_service_dbus_interface_create_resp_cb_data(zcl_color_object,
763                         invocation, NULL, 0);
764         if (NULL == resp_cb_data) {
765                 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
766
767                 /* Send failure response */
768                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
769
770                 return TRUE;
771         }
772
773         /* Dispatch request */
774         ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
775                 ZBLIB_DRIVER_TYPE_ZCL_COLOR,
776                 ZBLIB_ZCL_COLOR_OPS_MOVE_COLOR_TEMPERATURE,
777                 &req, sizeof(req),
778                 on_zcl_color_move_color_temperature_resp, resp_cb_data);
779         if (FALSE == ret) {
780                 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
781
782                 /* Free response callback data */
783                 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
784
785                 /* Send failure response */
786                 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
787
788                 return TRUE;
789         }
790
791         return TRUE;
792 }
793
794 gboolean zigbee_service_dbus_interface_zcl_color_control_init(ZigBeeServiceInterface *service_interface,
795         ZigbeeObjectSkeleton *zigbee_object)
796 {
797         ZigbeeZcl_color_control *zcl_color_object;
798
799         if (NULL == service_interface) {
800                 Z_LOGE("service_interface is NULL");
801                 return FALSE;
802         }
803
804         zcl_color_object = zigbee_zcl_color_control_skeleton_new();
805         zigbee_object_skeleton_set_zcl_color_control(zigbee_object, zcl_color_object);
806         g_object_unref(zcl_color_object);
807
808         Z_LOGI("zcl_color_object: [%p]", zcl_color_object);
809
810         /*
811          * Register signal handlers for 'zcl_color' interface
812          */
813         g_signal_connect(zcl_color_object,
814                 "handle-move-to-hue",
815                 G_CALLBACK(on_zcl_color_move_to_hue), service_interface);
816
817         g_signal_connect(zcl_color_object,
818                 "handle-move-hue",
819                 G_CALLBACK(on_zcl_color_move_hue), service_interface);
820
821         g_signal_connect(zcl_color_object,
822                 "handle-step-hue",
823                 G_CALLBACK(on_zcl_color_step_hue), service_interface);
824
825         g_signal_connect(zcl_color_object,
826                 "handle-move-to-saturation",
827                 G_CALLBACK(on_zcl_color_move_to_saturation), service_interface);
828
829         g_signal_connect(zcl_color_object,
830                 "handle-move-saturation",
831                 G_CALLBACK(on_zcl_color_move_saturation), service_interface);
832
833         g_signal_connect(zcl_color_object,
834                 "handle-step-saturation",
835                 G_CALLBACK(on_zcl_color_step_saturation), service_interface);
836
837         g_signal_connect(zcl_color_object,
838                 "handle-move-to-hue-and-saturation",
839                 G_CALLBACK(on_zcl_color_move_to_hue_and_saturation), service_interface);
840
841         g_signal_connect(zcl_color_object,
842                 "handle-move-to-color",
843                 G_CALLBACK(on_zcl_color_move_to_color), service_interface);
844
845         g_signal_connect(zcl_color_object,
846                 "handle-move-color",
847                 G_CALLBACK(on_zcl_color_move_color), service_interface);
848
849         g_signal_connect(zcl_color_object,
850                 "handle-step-color",
851                 G_CALLBACK(on_zcl_color_step_color), service_interface);
852
853         g_signal_connect(zcl_color_object,
854                 "handle-move-color-temperature",
855                 G_CALLBACK(on_zcl_color_move_color_temperature), service_interface);
856
857         return TRUE;
858 }