2 * Copyright © 2010-2011 Intel Corporation
3 * Copyright © 2008-2011 Kristian Høgsberg
4 * Copyright © 2013 TOYOTA MOTOR CORPORATION.
6 * Permission to use, copy, modify, distribute, and sell this software and
7 * its documentation for any purpose is hereby granted without fee, provided
8 * that the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of the copyright holders not be used in
11 * advertising or publicity pertaining to distribution of the software
12 * without specific, written prior permission. The copyright holders make
13 * no representations about the suitability of this software for any
14 * purpose. It is provided "as is" without express or implied warranty.
16 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
17 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
18 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
20 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
21 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
22 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 * @brief Weston(Wayland) Plugin Loader
26 * @brief Load the Weston plugins, because plugin loader of main body of Weston
27 * @brief cannot use other plugin functions by a other plugin.
43 #include <weston/compositor.h>
44 #include "ico_ivi_common.h"
46 /* This function is called from the main body of Weston and initializes this module.*/
47 int module_init(struct weston_compositor *ec);
49 /* Internal function to load one plugin. */
50 static void load_module(struct weston_compositor *ec, const char *path, const char *entry);
52 /* Static valiables */
53 static char *moddir = NULL; /* Answer back from configuration */
54 static char *modules = NULL; /* Answer back from configuration */
55 static int debug_level = 3; /* Debug Level */
57 /* Configuration key */
58 static const struct config_key plugin_config_keys[] = {
59 { "moddir", CONFIG_KEY_STRING, &moddir },
60 { "modules", CONFIG_KEY_STRING, &modules },
63 static const struct config_section conf_plugin[] = {
64 { "plugin", plugin_config_keys, ARRAY_LENGTH(plugin_config_keys) },
67 static const struct config_key debug_config_keys[] = {
68 { "ivi_debug", CONFIG_KEY_INTEGER, &debug_level },
71 static const struct config_section conf_debug[] = {
72 { "debug", debug_config_keys, ARRAY_LENGTH(debug_config_keys) },
76 /*--------------------------------------------------------------------------*/
78 * @brief ico_ivi_debuglevel: answer debug output level.
81 * @return debug output level
82 * @retval 0 No debug output
83 * @retval 1 Only error output
84 * @retval 2 Error and information output
85 * @retval 3 All output with debug write
87 /*--------------------------------------------------------------------------*/
89 ico_ivi_debuglevel(void)
94 /*--------------------------------------------------------------------------*/
96 * @brief load_module: load one plugin module.
98 * @param[in] ec weston compositor. (from weston)
99 * @param[in] path file path of plugin module.
100 * @param[in] entry entry function name of plugin module.
103 /*--------------------------------------------------------------------------*/
105 load_module(struct weston_compositor *ec, const char *path, const char *entry)
107 void *module; /* module informations (dlopen) */
108 int (*init)(struct weston_compositor *ec);
109 /* enter function of loaded plugin */
111 uifw_info("ico_plugin_loader: Load(path=%s entry=%s)", path, entry);
113 /* get module informations */
114 module = dlopen(path, RTLD_NOW | RTLD_NOLOAD);
117 /* plugin module already loaded */
119 uifw_error("ico_plugin_loader: Load Error(%s already loaded)", path);
123 /* load plugin module */
124 uifw_trace("ico_plugin_loader: %s loading", path);
126 module = dlopen(path, RTLD_NOW | RTLD_GLOBAL);
129 /* plugin module dose not exist */
130 uifw_error("ico_plugin_loader: Load Error(%s error<%s>)", path, dlerror());
134 /* find initialize function */
136 init = dlsym(module, entry);
138 uifw_error("ico_plugin_loader: Load Error(%s, function %s dose not exist(%s))",
139 path, entry, dlerror());
142 /* call initialize function */
143 uifw_trace("ico_plugin_loader: Call %s:%s(%08x)", path, entry, (int)init);
145 uifw_info("ico_plugin_loader: %s Loaded", path);
150 /*--------------------------------------------------------------------------*/
152 * @brief module_init: initialize function of ico_plugin_loader
153 * called from weston compositor.
155 * @param[in] ec weston compositor(from weston)
160 /*--------------------------------------------------------------------------*/
162 module_init(struct weston_compositor *ec)
169 uifw_info("ico_plugin_loader: Enter(module_init)");
171 /* get plugin module name from config file(weston_ivi_plugin.ini) */
172 config_fd = open_config_file(ICO_IVI_PLUGIN_CONFIG);
173 parse_config_file(config_fd, conf_plugin, ARRAY_LENGTH(conf_plugin), NULL);
174 parse_config_file(config_fd, conf_debug, ARRAY_LENGTH(conf_debug), NULL);
177 if (modules == NULL) {
178 uifw_error("ico_plugin_loader: Leave(No Plugin in config)");
181 moddir = getenv("WESTON_IVI_PLUGIN_DIR");
185 end = strchrnul(p, ',');
187 snprintf(buffer, sizeof(buffer), "%.*s", (int) (end - p), p);
190 snprintf(buffer, sizeof(buffer), "%s/%.*s", moddir, (int) (end - p), p);
193 snprintf(buffer, sizeof(buffer), "%s/%.*s", MODULEDIR, (int) (end - p), p);
195 load_module(ec, buffer, "module_init");
202 uifw_info("ico_plugin_loader: Leave(module_init)");