Support Tizen 3.0
[profile/ivi/ico-uxf-weston-plugin.git] / src / ico_plugin_loader.c
index 5f3ac61..e9ce14f 100644 (file)
@@ -26,7 +26,7 @@
  * @brief   Load the Weston plugins, because plugin loader of main body of Weston
  * @brief   cannot use other plugin functions by a other plugin.
  *
- * @date    Feb-08-2013
+ * @date    Jul-26-2013
  */
 
 #define _GNU_SOURCE
 #include <time.h>
 
 #include <weston/compositor.h>
+#include <weston/config-parser.h>
 #include "ico_ivi_common.h"
 
-/* This function is called from the main body of Weston and initializes this module.*/
-int module_init(struct weston_compositor *ec);
-
 /* Internal function to load one plugin.    */
-static void load_module(struct weston_compositor *ec, const char *path, const char *entry);
+static void load_module(struct weston_compositor *ec, const char *path, const char *entry,
+                        int *argc, char *argv[]);
 
 /* Static valiables                         */
-static char *moddir = NULL;                 /* Answer back from configuration       */
-static char *modules = NULL;                /* Answer back from configuration       */
 static int  debug_level = 3;                /* Debug Level                          */
 
-/* Configuration key                        */
-static const struct config_key plugin_config_keys[] = {
-        { "moddir", CONFIG_KEY_STRING, &moddir },
-        { "modules", CONFIG_KEY_STRING, &modules },
-    };
-
-static const struct config_section conf_plugin[] = {
-        { "plugin", plugin_config_keys, ARRAY_LENGTH(plugin_config_keys) },
-    };
-
-static const struct config_key debug_config_keys[] = {
-        { "ivi_debug", CONFIG_KEY_INTEGER, &debug_level },
-    };
-
-static const struct config_section conf_debug[] = {
-        { "debug", debug_config_keys, ARRAY_LENGTH(debug_config_keys) },
-    };
-
 
 /*--------------------------------------------------------------------------*/
 /**
@@ -81,8 +60,9 @@ static const struct config_section conf_debug[] = {
  * @return      debug output level
  * @retval      0       No debug output
  * @retval      1       Only error output
- * @retval      2       Error and information output
- * @retval      3       All output with debug write
+ * @retval      2       Error and Warning output
+ * @retval      3       Error, Warning and information output
+ * @retval      4       All output with debug write
  */
 /*--------------------------------------------------------------------------*/
 int
@@ -96,16 +76,19 @@ ico_ivi_debuglevel(void)
  * @brief   load_module: load one plugin module.
  *
  * @param[in]   ec          weston compositor. (from weston)
- * @param[in]   path        file path of plugin module.
- * @param[in]   entry       entry function name of plugin module.
+ * @param[in]   path        file path of locading plugin module.
+ * @param[in]   entry       entry function name of locading plugin module.
+ * @param[in]   argc        number of arguments.
+ * @param[in]   argv        arguments list.
  * @return      none
  */
 /*--------------------------------------------------------------------------*/
 static void
-load_module(struct weston_compositor *ec, const char *path, const char *entry)
+load_module(struct weston_compositor *ec, const char *path, const char *entry,
+            int *argc, char *argv[])
 {
     void    *module;                    /* module informations (dlopen)             */
-    int (*init)(struct weston_compositor *ec);
+    int (*init)(struct weston_compositor *ec, int *argc, char *argv[]);
                                         /* enter function of loaded plugin          */
 
     uifw_info("ico_plugin_loader: Load(path=%s entry=%s)", path, entry);
@@ -141,7 +124,7 @@ load_module(struct weston_compositor *ec, const char *path, const char *entry)
         else    {
             /* call initialize function             */
             uifw_trace("ico_plugin_loader: Call %s:%s(%08x)", path, entry, (int)init);
-            init(ec);
+            init(ec, argc, argv);
             uifw_info("ico_plugin_loader: %s Loaded", path);
         }
     }
@@ -153,32 +136,48 @@ load_module(struct weston_compositor *ec, const char *path, const char *entry)
  *                       called from weston compositor.
  *
  * @param[in]   ec          weston compositor(from weston)
+ * @param[in]   argc        number of arguments(unused)
+ * @param[in]   argv        argument list(unused)
  * @return      result
  * @retval      0           sccess
  * @retval      -1          error
  */
 /*--------------------------------------------------------------------------*/
 WL_EXPORT int
-module_init(struct weston_compositor *ec)
+module_init(struct weston_compositor *ec, int *argc, char *argv[])
 {
-    int     config_fd;
+    struct weston_config_section *section;
+    char    *moddir = NULL;                 /* Answer back from configuration       */
+    char    *modules = NULL;                /* Answer back from configuration       */
     char    *p;
     char    *end;
     char    buffer[256];
 
     uifw_info("ico_plugin_loader: Enter(module_init)");
 
+    /* get ivi debug level          */
+    section = weston_config_get_section(ec->config, "ivi-debug", NULL, NULL);
+    if (section)    {
+        weston_config_section_get_int(section, "log", &debug_level, 3);
+    }
+    
     /* get plugin module name from config file(weston_ivi_plugin.ini)   */
-    config_fd = open_config_file(ICO_IVI_PLUGIN_CONFIG);
-    parse_config_file(config_fd, conf_plugin, ARRAY_LENGTH(conf_plugin), NULL);
-    parse_config_file(config_fd, conf_debug, ARRAY_LENGTH(conf_debug), NULL);
-    close(config_fd);
+    section = weston_config_get_section(ec->config, "ivi-plugin", NULL, NULL);
+    if (section)    {
+        weston_config_section_get_string(section, "moddir", &moddir, NULL);
+        weston_config_section_get_string(section, "modules", &modules, NULL);
+    }
 
     if (modules == NULL)    {
         uifw_error("ico_plugin_loader: Leave(No Plugin in config)");
+        if (moddir) free(moddir);
         return -1;
     }
-    moddir = getenv("WESTON_IVI_PLUGIN_DIR");
+    p = getenv("WESTON_IVI_PLUGIN_DIR");
+    if (p)  {
+        if (moddir) free(moddir);
+        moddir = strdup(p);
+    }
 
     p = modules;
     while (*p) {
@@ -192,13 +191,14 @@ module_init(struct weston_compositor *ec)
         else    {
             snprintf(buffer, sizeof(buffer), "%s/%.*s", MODULEDIR, (int) (end - p), p);
         }
-        load_module(ec, buffer, "module_init");
+        load_module(ec, buffer, "module_init", argc, argv);
         p = end;
         while (*p == ',')   {
             p++;
         }
     }
-
+    if (moddir) free(moddir);
+    free(modules);
     uifw_info("ico_plugin_loader: Leave(module_init)");
 
     return 0;