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 <weston/config-parser.h>
45 #include "ico_ivi_common.h"
47 /* Internal function to load one plugin. */
48 static void load_module(struct weston_compositor *ec, const char *path, const char *entry,
49 int *argc, char *argv[]);
51 /* Static valiables */
52 static int debug_level = 3; /* Debug Level */
55 /*--------------------------------------------------------------------------*/
57 * @brief ico_ivi_debuglevel: answer debug output level.
60 * @return debug output level
61 * @retval 0 No debug output
62 * @retval 1 Only error output
63 * @retval 2 Error and Warning output
64 * @retval 3 Error, Warning and information output
65 * @retval 4 All output with debug write
67 /*--------------------------------------------------------------------------*/
69 ico_ivi_debuglevel(void)
74 /*--------------------------------------------------------------------------*/
76 * @brief load_module: load one plugin module.
78 * @param[in] ec weston compositor. (from weston)
79 * @param[in] path file path of locading plugin module.
80 * @param[in] entry entry function name of locading plugin module.
81 * @param[in] argc number of arguments.
82 * @param[in] argv arguments list.
85 /*--------------------------------------------------------------------------*/
87 load_module(struct weston_compositor *ec, const char *path, const char *entry,
88 int *argc, char *argv[])
90 void *module; /* module informations (dlopen) */
91 int (*init)(struct weston_compositor *ec, int *argc, char *argv[]);
92 /* enter function of loaded plugin */
94 uifw_info("ico_plugin_loader: Load(path=%s entry=%s)", path, entry);
96 /* get module informations */
97 module = dlopen(path, RTLD_NOW | RTLD_NOLOAD);
100 /* plugin module already loaded */
102 uifw_error("ico_plugin_loader: Load Error(%s already loaded)", path);
106 /* load plugin module */
107 uifw_trace("ico_plugin_loader: %s loading", path);
109 module = dlopen(path, RTLD_NOW | RTLD_GLOBAL);
112 /* plugin module dose not exist */
113 uifw_error("ico_plugin_loader: Load Error(%s error<%s>)", path, dlerror());
117 /* find initialize function */
119 init = dlsym(module, entry);
121 uifw_error("ico_plugin_loader: Load Error(%s, function %s dose not exist(%s))",
122 path, entry, dlerror());
125 /* call initialize function */
126 uifw_trace("ico_plugin_loader: Call %s:%s(%08x)", path, entry, (int)init);
127 init(ec, argc, argv);
128 uifw_info("ico_plugin_loader: %s Loaded", path);
133 /*--------------------------------------------------------------------------*/
135 * @brief module_init: initialize function of ico_plugin_loader
136 * called from weston compositor.
138 * @param[in] ec weston compositor(from weston)
139 * @param[in] argc number of arguments(unused)
140 * @param[in] argv argument list(unused)
145 /*--------------------------------------------------------------------------*/
147 module_init(struct weston_compositor *ec, int *argc, char *argv[])
149 struct weston_config_section *section;
150 char *moddir = NULL; /* Answer back from configuration */
151 char *modules = NULL; /* Answer back from configuration */
156 uifw_info("ico_plugin_loader: Enter(module_init)");
158 /* get ivi debug level */
159 section = weston_config_get_section(ec->config, "ivi-debug", NULL, NULL);
161 weston_config_section_get_int(section, "log", &debug_level, 3);
164 /* get plugin module name from config file(weston_ivi_plugin.ini) */
165 section = weston_config_get_section(ec->config, "ivi-plugin", NULL, NULL);
167 weston_config_section_get_string(section, "moddir", &moddir, NULL);
168 weston_config_section_get_string(section, "modules", &modules, NULL);
171 if (modules == NULL) {
172 uifw_error("ico_plugin_loader: Leave(No Plugin in config)");
173 if (moddir) free(moddir);
176 p = getenv("WESTON_IVI_PLUGIN_DIR");
178 if (moddir) free(moddir);
184 end = strchrnul(p, ',');
186 snprintf(buffer, sizeof(buffer), "%.*s", (int) (end - p), p);
189 snprintf(buffer, sizeof(buffer), "%s/%.*s", moddir, (int) (end - p), p);
192 snprintf(buffer, sizeof(buffer), "%s/%.*s", MODULEDIR, (int) (end - p), p);
194 load_module(ec, buffer, "module_init", argc, argv);
200 if (moddir) free(moddir);
202 uifw_info("ico_plugin_loader: Leave(module_init)");