9f713bc727188d334a8fa980479ef40fadb142bb
[platform/core/connectivity/zigbee-manager.git] / zigbee-daemon / zigbee-lib / src / drivers / zblib_driver_zcl_color.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 <zblib.h>
20 #include <zblib_driver.h>
21 #include <zblib_request.h>
22
23 #include "zblib_driver_zcl_color.h"
24
25 /**< Private data */
26 typedef struct {
27         ZblibDriverZclColorOps_t *ops; /**< Operations */
28 } ZblibDriverZclColorPrivData_t;
29
30 static gboolean __zblib_driver_zcl_color_dispatcher(ZigBeeDriver *driver, guint request_id)
31 {
32         ZigBeeService *service = NULL;
33         guint request_type;
34         guint ops_id;
35
36         if (NULL == driver) {
37                 Z_LOGE("driver is NULL");
38                 return FALSE;
39         }
40
41         service = zblib_driver_ref_service(driver);
42         if (NULL == service) {
43                 Z_LOGE("service is NULL");
44                 return FALSE;
45         }
46
47         /* Fetch request_type using request_id */
48         request_type = zblib_request_ref_request_type_by_request_id(service, request_id);
49
50         /* Fetch ops ID */
51         ops_id = zblib_request_get_ops_id(request_type);
52         switch (ops_id) {
53         case ZBLIB_ZCL_COLOR_OPS_MOVE_TO_HUE: {
54         }
55         break;
56
57         case ZBLIB_ZCL_COLOR_OPS_MOVE_HUE: {
58         }
59         break;
60
61         case ZBLIB_ZCL_COLOR_OPS_STEP_HUE: {
62         }
63         break;
64
65         case ZBLIB_ZCL_COLOR_OPS_MOVE_TO_STAURATION: {
66         }
67         break;
68
69         case ZBLIB_ZCL_COLOR_OPS_MOVE_STAURATION: {
70         }
71         break;
72
73         case ZBLIB_ZCL_COLOR_OPS_STEP_STAURATION: {
74         }
75         break;
76
77         case ZBLIB_ZCL_COLOR_OPS_MOVE_TO_HUE_AND_SATURATION: {
78         }
79         break;
80
81         case ZBLIB_ZCL_COLOR_OPS_MOVE_TO_COLOR: {
82         }
83         break;
84
85         case ZBLIB_ZCL_COLOR_OPS_MOVE_COLOR: {
86         }
87         break;
88
89         case ZBLIB_ZCL_COLOR_OPS_STEP_COLOR: {
90         }
91         break;
92
93         case ZBLIB_ZCL_COLOR_OPS_MOVE_COLOR_TEMPERATURE: {
94         }
95         break;
96
97         default:
98         break;
99         }
100
101         return TRUE;
102 }
103
104 static void __zblib_driver_zcl_color_free_hook(ZigBeeDriver *driver)
105 {
106         ZblibDriverZclColorPrivData_t *priv_data = NULL;
107
108         if (NULL == driver) {
109                 Z_LOGE("driver is NULL");
110                 return;
111         }
112
113         /* Fetch private data */
114         priv_data = zblib_driver_ref_object(driver);
115         if (NULL == priv_data) {
116                 Z_LOGE("priv_data is NULL");
117                 return;
118         }
119
120         /* Free resources */
121         g_free(priv_data);
122 }
123
124 ZigBeeDriver *zblib_driver_zcl_color_new(ZigBeePlugin *plugin,
125         const gchar *driver_name,
126         ZblibDriverZclColorOps_t *ops)
127 {
128         ZigBeeDriver *driver = NULL;
129         ZblibDriverZclColorPrivData_t *priv_data = NULL;
130         gboolean ret;
131
132         if (NULL == plugin) {
133                 Z_LOGE("plugin is NULL");
134                 return NULL;
135         }
136
137         /* Create new driver */
138         driver = zblib_driver_new(plugin, driver_name, ZBLIB_DRIVER_TYPE_ZCL_COLOR);
139         if (NULL == driver) {
140                 Z_LOGE("driver is NULL");
141                 return NULL;
142         }
143
144         /* Allocate memory for private data */
145         priv_data = g_malloc0(sizeof(ZblibDriverZclColorPrivData_t));
146
147         /* Update private data */
148         priv_data->ops = ops;
149
150         /* Link private data to driver */
151         ret = zblib_driver_link_object(driver, priv_data);
152         if (FALSE == ret) {
153                 Z_LOGE("zblib_driver_link_object failed!");
154
155                 /* Free allocated resources */
156                 g_free(priv_data);
157                 g_free(driver);
158
159                 return NULL;
160         }
161
162         /* Set operations dispatcher function */
163         ret = zblib_driver_set_dispatcher(driver, __zblib_driver_zcl_color_dispatcher);
164         if (FALSE == ret) {
165                 Z_LOGE("zblib_driver_set_dispatcher failed!");
166
167                 /* Free allocated resources */
168                 g_free(priv_data);
169                 g_free(driver);
170
171                 return NULL;
172         }
173
174         /* Set free hook function */
175         ret = zblib_driver_set_free_hook(driver, __zblib_driver_zcl_color_free_hook);
176         if (FALSE == ret) {
177                 Z_LOGE("zblib_driver_set_free_hook failed!");
178
179                 /* Free allocated resources */
180                 g_free(priv_data);
181                 g_free(driver);
182
183                 return NULL;
184         }
185
186         return driver;
187 }
188
189 void zblib_driver_zcl_color_free(ZigBeeDriver *driver)
190 {
191         if (NULL == driver) {
192                 Z_LOGE("driver is NULL");
193                 return;
194         }
195
196         /* Free driver */
197         zblib_driver_free(driver);
198 }