2 * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
4 * Contact: Suresh Kumar N (suresh.n@samsung.com)
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <zblib_plugin.h>
23 #include <zblib_driver.h>
25 /**< ZigBee plug-in object */
26 struct zblib_plugin_type {
27 gchar *plugin_name; /**< ZigBee plug-in name */
28 const struct zblib_plugin_descriptor *descriptor; /**< ZigBee plug-in descriptor */
29 void *plugin_handle; /**< ZigBee Plug-in .so handle */
31 GSList *driver_list; /**< List of ZigBee drivers */
33 ZigBeeService *service; /**< ZigBee Service */
36 ZigBeePlugin *zblib_plugin_new(ZigBeeService *service,
37 const gchar *plugin_name,
38 const struct zblib_plugin_descriptor *descriptor,
41 ZigBeePlugin *plugin = NULL;
44 plugin = g_malloc0(sizeof(ZigBeePlugin));
47 plugin->plugin_name = g_strdup(plugin_name);
48 plugin->descriptor = descriptor;
49 plugin->plugin_handle = plugin_handle;
50 plugin->service = service;
52 Z_LOGI("Vendor plug-in created - Name [%s]", descriptor->name);
57 void zblib_plugin_free(ZigBeePlugin *plugin)
60 Z_LOGE("ZigBee vendor plug-in is NULL");
64 Z_LOGI("Freeing Vendor plug-in - Name [%s]", plugin->descriptor->name);
66 if (plugin->driver_list) {
70 for (list = plugin->driver_list; list; list = list->next) {
75 zblib_driver_free(driver);
79 g_slist_free(plugin->driver_list);
80 plugin->driver_list = NULL;
83 if (plugin->plugin_name) {
84 g_free(plugin->plugin_name);
85 plugin->plugin_name = NULL;
88 plugin->descriptor = NULL;
90 if (plugin->plugin_handle) {
91 dlclose(plugin->plugin_handle);
92 plugin->plugin_handle = NULL;
98 const struct zblib_plugin_descriptor *zblib_plugin_get_descriptor(ZigBeePlugin *plugin)
100 if (NULL == plugin) {
101 Z_LOGE("ZigBee vendor plug-in is NULL");
105 return plugin->descriptor;
108 char *zblib_plugin_get_plugin_name(ZigBeePlugin *plugin)
110 if (NULL == plugin) {
111 Z_LOGE("ZigBee vendor plug-in is NULL");
115 return g_strdup(plugin->plugin_name);
118 ZigBeeDriver *zblib_plugin_ref_driver(ZigBeePlugin *plugin, ZblibDriverType_e driver_type)
120 ZigBeeDriver *driver = NULL;
121 ZblibDriverType_e _driver_type;
124 if (NULL == plugin) {
125 Z_LOGE("ZigBee vendor plug-in is NULL");
129 list = plugin->driver_list;
131 /* Fetch driver type of driver */
132 _driver_type = zblib_driver_ref_driver_type((ZigBeeDriver *)(list->data));
133 if (_driver_type == driver_type) {
135 driver = (ZigBeeDriver *)(list->data);
139 /* Move to next driver */
140 list = g_slist_next(list);