Request ID (skeleton)
[platform/core/connectivity/zigbee-manager.git] / zigbee-daemon / zigbee-lib / src / drivers / zblib_driver_zclbasic_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 <zblib.h>
20 #include <zblib_driver.h>
21 #include <zblib_request.h>
22
23 #include "zblib_driver_zclbasic_control.h"
24
25 /**< Private data */
26 typedef struct {
27         ZblibDriverZclbasicControlOps_t *ops; /**< Operations */
28 } ZblibDriverZclbasicControlPrivData_t;
29
30 static gboolean __zblib_driver_zclbasic_control_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_ZCLBASIC_CONTROL_OPS_RESET_FACTORY_DEFAULT: {
54         }
55         break;
56
57         default:
58         break;
59         }
60
61         return TRUE;
62 }
63
64 static void __zblib_driver_zclbasic_control_free_hook(ZigBeeDriver *driver)
65 {
66         ZblibDriverZclbasicControlPrivData_t *priv_data = NULL;
67
68         if (NULL == driver) {
69                 Z_LOGE("driver is NULL");
70                 return;
71         }
72
73         /* Fetch private data */
74         priv_data = zblib_driver_ref_object(driver);
75         if (NULL == priv_data) {
76                 Z_LOGE("priv_data is NULL");
77                 return;
78         }
79
80         /* Free resources */
81         g_free(priv_data);
82 }
83
84 ZigBeeDriver *zblib_driver_zclbasic_control_new(ZigBeePlugin *plugin,
85         const gchar *driver_name,
86         ZblibDriverZclbasicControlOps_t *ops)
87 {
88         ZigBeeDriver *driver = NULL;
89         ZblibDriverZclbasicControlPrivData_t *priv_data = NULL;
90         gboolean ret;
91
92         if (NULL == plugin) {
93                 Z_LOGE("plugin is NULL");
94                 return NULL;
95         }
96
97         /* Create new driver */
98         driver = zblib_driver_new(plugin, driver_name, ZBLIB_DRIVER_TYPE_ZCLBASIC_CONTROL);
99         if (NULL == driver) {
100                 Z_LOGE("driver is NULL");
101                 return NULL;
102         }
103
104         /* Allocate memory for private data */
105         priv_data = g_malloc0(sizeof(ZblibDriverZclbasicControlPrivData_t));
106
107         /* Update private data */
108         priv_data->ops = ops;
109
110         /* Link private data to driver */
111         ret = zblib_driver_link_object(driver, priv_data);
112         if (FALSE == ret) {
113                 Z_LOGE("zblib_driver_link_object failed!");
114
115                 /* Free allocated resources */
116                 g_free(priv_data);
117                 g_free(driver);
118
119                 return NULL;
120         }
121
122         /* Set operations dispatcher function */
123         ret = zblib_driver_set_dispatcher(driver, __zblib_driver_zclbasic_control_dispatcher);
124         if (FALSE == ret) {
125                 Z_LOGE("zblib_driver_set_dispatcher failed!");
126
127                 /* Free allocated resources */
128                 g_free(priv_data);
129                 g_free(driver);
130
131                 return NULL;
132         }
133
134         /* Set free hook function */
135         ret = zblib_driver_set_free_hook(driver, __zblib_driver_zclbasic_control_free_hook);
136         if (FALSE == ret) {
137                 Z_LOGE("zblib_driver_set_free_hook failed!");
138
139                 /* Free allocated resources */
140                 g_free(priv_data);
141                 g_free(driver);
142
143                 return NULL;
144         }
145
146         return driver;
147 }
148
149 void zblib_driver_zclbasic_control_free(ZigBeeDriver *driver)
150 {
151         if (NULL == driver) {
152                 Z_LOGE("driver is NULL");
153                 return;
154         }
155
156         /* Free driver */
157         zblib_driver_free(driver);
158 }