2 * Copyright © 2010-2011 Intel Corporation
3 * Copyright © 2008-2011 Kristian Høgsberg
4 * Copyright © 2013-2014 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_private.h"
46 #include "ico_plugin_version.h"
48 /* Internal function to load one plugin. */
49 static void load_module(struct weston_compositor *ec, const char *path, const char *entry,
50 int *argc, char *argv[]);
52 /* Static valiables */
53 static int debug_level = 3; /* Debug Level */
56 /*--------------------------------------------------------------------------*/
58 * @brief ico_ivi_debuglevel: answer debug output level.
61 * @return debug output level
62 * @retval 0 No debug output
63 * @retval 1 Only error output
64 * @retval 2 Error and Warning output
65 * @retval 3 Error, Warning and information output
66 * @retval 4 All output with debug write
68 /*--------------------------------------------------------------------------*/
70 ico_ivi_debuglevel(void)
75 /*--------------------------------------------------------------------------*/
77 * @brief load_module: load one plugin module.
79 * @param[in] ec weston compositor. (from weston)
80 * @param[in] path file path of locading plugin module.
81 * @param[in] entry entry function name of locading plugin module.
82 * @param[in] argc number of arguments.
83 * @param[in] argv arguments list.
86 /*--------------------------------------------------------------------------*/
88 load_module(struct weston_compositor *ec, const char *path, const char *entry,
89 int *argc, char *argv[])
91 void *module; /* module informations (dlopen) */
92 int (*init)(struct weston_compositor *ec, int *argc, char *argv[]);
93 /* enter function of loaded plugin */
95 uifw_info("ico_plugin_loader: Load(path=%s entry=%s)", path, entry);
97 /* get module informations */
98 module = dlopen(path, RTLD_NOW | RTLD_NOLOAD);
101 /* plugin module already loaded */
103 uifw_error("ico_plugin_loader: Load Error(%s already loaded)", path);
107 /* load plugin module */
108 uifw_trace("ico_plugin_loader: %s loading", path);
110 module = dlopen(path, RTLD_NOW | RTLD_GLOBAL);
113 /* plugin module dose not exist */
114 uifw_error("ico_plugin_loader: Load Error(%s error<%s>)", path, dlerror());
118 /* find initialize function */
120 init = dlsym(module, entry);
122 uifw_error("ico_plugin_loader: Load Error(%s, function %s dose not exist(%s))",
123 path, entry, dlerror());
126 /* call initialize function */
127 uifw_trace("ico_plugin_loader: Call %s:%s(%08x)", path, entry, (int)init);
128 init(ec, argc, argv);
129 uifw_info("ico_plugin_loader: %s Loaded", path);
134 /*--------------------------------------------------------------------------*/
136 * @brief module_init: initialize function of ico_plugin_loader
137 * called from weston compositor.
139 * @param[in] ec weston compositor(from weston)
140 * @param[in] argc number of arguments(unused)
141 * @param[in] argv argument list(unused)
146 /*--------------------------------------------------------------------------*/
148 module_init(struct weston_compositor *ec, int *argc, char *argv[])
150 struct weston_config_section *section;
151 char *moddir = NULL; /* Answer back from configuration */
152 char *modules = NULL; /* Answer back from configuration */
157 weston_log("INF>ico-uxf-weston-plugin " ICO_PLUIGN_VERSION "\n");
159 uifw_info("ico_plugin_loader: Enter(module_init)");
161 /* get ivi debug level */
162 section = weston_config_get_section(ec->config, "ivi-option", NULL, NULL);
164 weston_config_section_get_int(section, "log", &debug_level, 3);
167 /* get plugin module name from config file(weston_ivi_plugin.ini) */
168 section = weston_config_get_section(ec->config, "ivi-plugin", NULL, NULL);
170 weston_config_section_get_string(section, "moddir", &moddir, NULL);
171 weston_config_section_get_string(section, "modules", &modules, NULL);
174 if (modules == NULL) {
175 uifw_error("ico_plugin_loader: Leave(No Plugin in config)");
179 p = getenv("WESTON_IVI_PLUGIN_DIR");
187 end = strchrnul(p, ',');
189 snprintf(buffer, sizeof(buffer), "%.*s", (int) (end - p), p);
192 snprintf(buffer, sizeof(buffer), "%s/%.*s", moddir, (int) (end - p), p);
195 snprintf(buffer, sizeof(buffer), "%s/%.*s", MODULEDIR, (int) (end - p), p);
197 load_module(ec, buffer, "module_init", argc, argv);
205 uifw_info("ico_plugin_loader: Leave(module_init)");