示例#1
0
EvDocument *
ev_backends_manager_get_document (const gchar *mime_type)
{
	EvDocument    *document;
	EvBackendInfo *info;

	info = ev_backends_manager_get_backend_info (mime_type);
	if (!info)
		return NULL;

	if (!info->module) {
		gchar *path;
		
		path = g_module_build_path (backends_dir(), info->module_name);
		info->module = G_TYPE_MODULE (ev_module_new (path, info->resident));
		g_free (path);
	}
	
	if (!g_type_module_use (info->module)) {
		g_warning ("Cannot load backend '%s' since file '%s' cannot be read.",
			   info->module_name,
			   ev_module_get_path (EV_MODULE (info->module)));
		g_object_unref (G_OBJECT (info->module));
		info->module = NULL;

		return NULL;
	}

	document = EV_DOCUMENT (ev_module_new_object (EV_MODULE (info->module)));
	g_type_module_unuse (info->module);

	return document;
}
void
g_io_module_load (GIOModule *module)
{
    /* see gvfsproxyvolumemonitor.c:g_vfs_proxy_volume_monitor_daemon_init() */
    if (g_getenv ("GVFS_REMOTE_VOLUME_MONITOR_IGNORE") != NULL)
        goto out;

    /* We make this module resident since we *may* hold on to an instance
     * of the union monitor in the static method get_mount_for_mount_path()
     * on GNativeVolumeMonitor. And it doesn't make much sense to unload
     * the module *anyway*.
     *
     * See the comment gproxyvolumemonitor.c:get_mount_for_mount_path().
     */
    g_type_module_use (G_TYPE_MODULE (module));

    bindtextdomain (GETTEXT_PACKAGE, GVFS_LOCALEDIR);
    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");

    g_proxy_drive_register (module);
    g_proxy_mount_register (module);
    g_proxy_shadow_mount_register (module);
    g_proxy_volume_register (module);
    g_proxy_volume_monitor_register (module);
out:
    ;
}
示例#3
0
/*
 * Loads the given plugin.
 */
void
meta_plugin_manager_load (const gchar       *plugin_name)
{
  const gchar *dpath = MUTTER_PLUGIN_DIR "/";
  gchar       *path;
  MetaModule  *module;

  if (g_path_is_absolute (plugin_name))
    path = g_strdup (plugin_name);
  else
    path = g_strconcat (dpath, plugin_name, ".so", NULL);

  module = g_object_new (META_TYPE_MODULE, "path", path, NULL);
  if (!module || !g_type_module_use (G_TYPE_MODULE (module)))
    {
      /* This is fatal under the assumption that a monitoring
       * process like gnome-session will take over and handle
       * our untimely exit.
       */
      g_printerr ("Unable to load plugin module [%s]: %s",
                  path, g_module_error());
      exit (1);
    }

  meta_plugin_manager_set_plugin_type (meta_module_get_plugin_type (module));

  g_type_module_unuse (G_TYPE_MODULE (module));
  g_free (path);
}
示例#4
0
文件: ibusim.c 项目: colorant/ibus
G_MODULE_EXPORT void
im_module_init (GTypeModule *type_module)
{
    /* make module resident */
    g_type_module_use (type_module);

    ibus_im_context_register_type (type_module);
}
示例#5
0
void im_module_init(GTypeModule *module)
{
    if (g_getenv("QIMSYS_DEBUG")) {
        qimsys_debug_on();
    }
    qimsys_debug_in();
    g_type_module_use(module);
    qimsys_im_context_register_type(module);
    qimsys_debug_out();
}
示例#6
0
int
main(int argc, char *argv[])
{
	g_test_init(&argc, &argv, NULL);
#if !GLIB_CHECK_VERSION(2, 36, 0)
	g_type_init();
#endif
	GTypeModule *module =
		log4g_module_new("modules/layouts/liblog4g-layouts.la");
	g_assert(module);
	g_assert(g_type_module_use(module));
	g_type_module_unuse(module);
	module = log4g_module_new("modules/appenders/liblog4g-appenders.la");
	g_assert(module);
	g_assert(g_type_module_use(module));
	g_type_module_unuse(module);
	g_test_add(CLASS"/001", gpointer, NULL, NULL, test_001, NULL);
	return g_test_run();
}
示例#7
0
static CeditPlugin *
cedit_plugin_loader_iface_load (CeditPluginLoader *loader,
				CeditPluginInfo   *info,
				const gchar       *path)
{
	CeditPluginLoaderC *cloader = CEDIT_PLUGIN_LOADER_C (loader);
	CeditObjectModule *module;
	const gchar *module_name;
	CeditPlugin *result;

	module = (CeditObjectModule *)g_hash_table_lookup (cloader->priv->loaded_plugins, info);
	module_name = cedit_plugin_info_get_module_name (info);

	if (module == NULL)
	{
		/* For now we force all modules to be resident */
		module = cedit_object_module_new (module_name,
						  path,
						  "register_cedit_plugin",
						  TRUE);

		/* Infos are available for all the lifetime of the loader.
		 * If this changes, we should use weak refs or something */

		g_hash_table_insert (cloader->priv->loaded_plugins, info, module);
	}

	if (!g_type_module_use (G_TYPE_MODULE (module)))
	{
		g_warning ("Could not load plugin module: %s", cedit_plugin_info_get_name (info));

		return NULL;
	}

	/* TODO: for now we force data-dir-name = module-name... if needed we can
	 * add a datadir field to the plugin descriptor file.
	 */
	result = (CeditPlugin *)cedit_object_module_new_object (module,
								"install-dir", path,
								"data-dir-name", module_name,
								NULL);

	if (!result)
	{
		g_warning ("Could not create plugin object: %s", cedit_plugin_info_get_name (info));
		g_type_module_unuse (G_TYPE_MODULE (module));
		
		return NULL;
	}

	g_type_module_unuse (G_TYPE_MODULE (module));
	
	return result;
}
示例#8
0
文件: gsf-utils.c 项目: arcean/libgsf
/**
 * gsf_init :
 *
 * Initializes the GSF library
 **/
void
gsf_init (void)
{
	static gboolean libgsf_initialized = FALSE;
	if (libgsf_initialized)
		return;

#ifdef ENABLE_NLS
#ifdef G_OS_WIN32
	{
		char *pkg_dir	  = g_win32_get_package_installation_directory_of_module (gsf_dll_hmodule);
		gchar *locale_dir = g_build_filename (pkg_dir, "lib/locale", NULL);
		bindtextdomain (GETTEXT_PACKAGE, locale_dir);
		g_free (locale_dir);
		g_free (pkg_dir);
	}
#else
	bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
#endif
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
#endif

	g_type_init ();
#ifndef HAVE_G_BASE64_ENCODE
	base64_init ();
#endif

#ifdef _GSF_GTYPE_THREADING_FIXED
	if (NULL == static_type_module) {
		static_type_module = g_object_new (gsf_dummy_type_module_get_type(), NULL);
		g_assert (static_type_module != NULL);
		g_type_module_use (static_type_module);
		g_type_module_set_name (static_type_module, "libgsf-builtin");
	}
#else
	gsf_init_dynamic (NULL);
#endif

	{
		/* Little-endian representation of M_PI.  */
		static guint8 pibytes[8] = {
			0x18, 0x2d, 0x44, 0x54, 0xfb, 0x21, 0x09, 0x40
		};

		/*
		 * If this fails, see
		 *   http://bugzilla.gnome.org/show_bug.cgi?id=350973
		 */
		double pi = gsf_le_get_double (pibytes);
		if (!(pi > 3.14 && pi < 3.15))
			g_error ("Compilation trouble with endianess.");
	}
}
示例#9
0
文件: util.c 项目: wangd/dmapd
GObject *
object_from_module (GType type, const gchar *module_dir, const gchar *module_name, const gchar *first_property_name, ...)
{
	va_list ap;
	GType *filters = NULL;
	GType child_type = G_TYPE_INVALID;
	guint n_filters;
	const gchar *fmt;
	gchar *module_filename;
        gchar *module_path;
	GObject *fnval = NULL;
	DmapdModule *module;

	va_start (ap, first_property_name);

	if (! (fmt = find_plugin_template (type))) {
		g_error ("Could not find plugin template");
	}

	/* dmapd-dmap-db-ghashtable is built in because it is used by DmapdDMAPContainerRecord: */
	if (! strcmp (module_name, "ghashtable")) {
		g_debug ("Not loading built in %s.", g_type_name (TYPE_DMAPD_DMAP_DB_GHASHTABLE));
		child_type = TYPE_DMAPD_DMAP_DB_GHASHTABLE;
		fnval = g_object_new_valist (child_type, first_property_name, ap);
	} else {
		module_filename = g_strdup_printf (fmt, module_name);
		module_path = g_module_build_path (module_dir, module_filename);

		module = dmapd_module_new (module_path);
		if (module == NULL || ! g_type_module_use (G_TYPE_MODULE (module))) {
			g_warning ("Error opening %s", module_path);
		} else {
			/* FIXME: free filters */
			filters = g_type_children (type, &n_filters);
			g_assert (n_filters == 1);
			g_assert (g_type_is_a (filters[0], type));

			child_type = filters[0];
			fnval = g_object_new_valist (child_type, first_property_name, ap);
		}

		if (filters)
			g_free (filters);

		g_free (module_filename);
		g_free (module_path);
	}

	va_end (ap);

	return fnval;
}
示例#10
0
int
main(int argc, char *argv[])
{
	g_test_init(&argc, &argv, NULL);
	g_type_init();
#ifndef G_THREADS_IMPL_NONE
	if (!g_thread_supported()) {
		g_thread_init(NULL);
	}
#endif
	GTypeModule *module =
		log4g_module_new("../modules/layouts/liblog4g-layouts.la");
	g_assert(module);
	g_assert(g_type_module_use(module));
	g_type_module_unuse(module);
	module = log4g_module_new("../modules/appenders/liblog4g-appenders.la");
	g_assert(module);
	g_assert(g_type_module_use(module));
	g_type_module_unuse(module);
	g_test_add(CLASS"/001", gpointer, NULL, NULL, test_001, NULL);
	return g_test_run();
}
示例#11
0
int
main(int argc, char *argv[])
{
	g_test_init(&argc, &argv, NULL);
#if !GLIB_CHECK_VERSION(2, 36, 0)
	g_type_init();
#endif
	GTypeModule *module =
		log4g_module_new("modules/filters/liblog4g-filters.la");
	g_assert(module);
	g_assert(g_type_module_use(module));
	g_type_module_unuse(module);
	g_test_add(CLASS"/001", Fixture, NULL, setup, test_001, teardown);
	return g_test_run();
}
static gboolean
load_loader (PlumaPluginsEngine *engine,
	     const gchar        *filename,
	     gpointer		 data)
{
	PlumaObjectModule *module;
	gchar *base;
	gchar *path;
	const gchar *id;
	GType type;

	/* try to load in the module */
	path = g_path_get_dirname (filename);
	base = g_path_get_basename (filename);

	/* for now they are all resident */
	module = pluma_object_module_new (base,
					  path,
					  "register_pluma_plugin_loader",
					  TRUE);

	g_free (base);
	g_free (path);

	/* make sure to load the type definition */
	if (!g_type_module_use (G_TYPE_MODULE (module)))
	{
		g_object_unref (module);
		g_warning ("Plugin loader module `%s' could not be loaded", filename);

		return TRUE;
	}

	/* get the exported type and check the name as exported by the
	 * loader interface */
	type = pluma_object_module_get_object_type (module);
	id = pluma_plugin_loader_type_get_id (type);

	add_loader (engine, id, module);
	g_type_module_unuse (G_TYPE_MODULE (module));

	return TRUE;
}
示例#13
0
static void
aim_module_manager_load_module (AimModuleManager *manager,
                                const gchar      *path)
{
  g_debug (G_STRLOC ": %s", G_STRFUNC);

  AimModule *module;

  module = aim_module_new (path);

  if (!g_type_module_use (G_TYPE_MODULE (module)))
  {
    g_warning (G_STRLOC ":" "Failed to load module: %s", path);
    g_object_unref (module);
    return;
  }

  g_hash_table_insert (manager->modules, g_strdup (path), module);

  g_type_module_unuse (G_TYPE_MODULE (module));
}
示例#14
0
文件: main.c 项目: lcp/bisho
static void
load_modules (void)
{
  GError *error = NULL;
  const char *name;
  GDir *dir;

  dir = g_dir_open (PKGLIBDIR, 0, &error);

  if (!dir) {
    if (error->domain != G_FILE_ERROR || error->code != G_FILE_ERROR_NOENT)
      g_printerr ("Cannot open module directory: %s\n", error->message);
    g_error_free (error);
    return;
  }

  while ((name = g_dir_read_name (dir))) {
    if (g_str_has_suffix (name, ".so")) {
      BishoModule *module;
      char *path;

      path = g_build_filename (PKGLIBDIR, name, NULL);
      module = bisho_module_new (path);

      if (!g_type_module_use (G_TYPE_MODULE (module))) {
        g_printerr ("Cannot load module %s\n", path);
        g_object_unref (module);
        g_free (path);
        continue;
      }

      g_free (path);

      g_type_module_unuse (G_TYPE_MODULE (module));
    }
  }

  g_dir_close (dir);
}
示例#15
0
G_MODULE_EXPORT void theme_init(GTypeModule *module)
{
   /* prevent unloading of this theme: */
   g_type_module_use(module);

   metatheme_toolkit_init(&metatheme_toolkit);

   metatheme_rc_style_register_type (module);
   metatheme_style_register_type (module);

   gdk_event_handler_set(_event_handler, 0, NULL);

   mt_default_engine = NULL;
   mt_first_engine = mt_get_engine();

   /* create window for retrieving messages: */

   comm_window = gtk_window_new(GTK_WINDOW_POPUP);
   gtk_window_set_default_size(GTK_WINDOW(comm_window), 0, 0);
   gtk_widget_set_uposition(comm_window, 32000, 32000);
   gtk_widget_show(comm_window);
}
示例#16
0
static void load_plugin (PhidiasLoader *loader, const gchar *plug_path)
{
	GObject *obj;
	PhidiasModule *module;

	module = phidias_module_new (plug_path);

	if (g_type_module_use (G_TYPE_MODULE (module)) == FALSE) {
		g_warning ("Unable to load module at %s.", plug_path);
		return;
	}

	obj = phidias_module_new_object (module);
	if (obj == NULL) {
		g_warning ("Unable to load module at %s.", plug_path);
	}
	else {
		loader->priv->loaded_plugins = g_list_prepend (loader->priv->loaded_plugins, obj);
		g_object_set_data_full (obj, "path", g_strdup (plug_path), g_free);
		g_signal_emit (loader, signals [PLUGIN_FOUND], 0, obj, NULL);
	}
}
static gboolean
load_plugin_module (MateSettingsPluginInfo *info)
{
        char    *path;
        char    *dirname;
        gboolean ret;

        ret = FALSE;

        g_return_val_if_fail (MATE_IS_SETTINGS_PLUGIN_INFO (info), FALSE);
        g_return_val_if_fail (info->priv->file != NULL, FALSE);
        g_return_val_if_fail (info->priv->location != NULL, FALSE);
        g_return_val_if_fail (info->priv->plugin == NULL, FALSE);
        g_return_val_if_fail (info->priv->available, FALSE);

        mate_settings_profile_start ("%s", info->priv->location);

        switch (info->priv->loader) {
                case MATE_SETTINGS_PLUGIN_LOADER_C:
                        dirname = g_path_get_dirname (info->priv->file);
                        g_return_val_if_fail (dirname != NULL, FALSE);

                        path = g_module_build_path (dirname, info->priv->location);
                        g_free (dirname);
                        g_return_val_if_fail (path != NULL, FALSE);

                        info->priv->module = G_TYPE_MODULE (mate_settings_module_new (path));
                        g_free (path);

                        break;

#ifdef ENABLE_PYTHON
                case MATE_SETTINGS_PLUGIN_LOADER_PY:
                {
                        char *dir;

                        if (!mate_settings_python_init ()) {
                                /* Mark plugin as unavailable and fails */
                                info->priv->available = FALSE;

                                g_warning ("Cannot load Python plugin '%s' since mate_settings "
                                           "was not able to initialize the Python interpreter.",
                                           info->priv->name);

                                goto out;
                        }

                        dir = g_path_get_dirname (info->priv->file);

                        g_return_val_if_fail ((info->priv->location != NULL) &&
                                              (info->priv->location[0] != '\0'),
                                              FALSE);

                        info->priv->module = G_TYPE_MODULE (
                                        mate_settings_python_module_new (dir, info->priv->location));

                        g_free (dir);
                        break;
                }
#endif
                default:
                        g_return_val_if_reached (FALSE);
        }

        if (!g_type_module_use (info->priv->module)) {
                switch (info->priv->loader) {
                        case MATE_SETTINGS_PLUGIN_LOADER_C:
                                g_warning ("Cannot load plugin '%s' since file '%s' cannot be read.",
                                           info->priv->name,
                                           mate_settings_module_get_path (MATE_SETTINGS_MODULE (info->priv->module)));
                                break;

                        case MATE_SETTINGS_PLUGIN_LOADER_PY:
                                g_warning ("Cannot load Python plugin '%s' since file '%s' cannot be read.",
                                           info->priv->name,
                                           info->priv->location);
                                break;

                        default:
                                g_return_val_if_reached (FALSE);
                }

                g_object_unref (G_OBJECT (info->priv->module));
                info->priv->module = NULL;

                /* Mark plugin as unavailable and fails */
                info->priv->available = FALSE;

                goto out;
        }

        switch (info->priv->loader) {
                case MATE_SETTINGS_PLUGIN_LOADER_C:
                        info->priv->plugin =
                                MATE_SETTINGS_PLUGIN (mate_settings_module_new_object (MATE_SETTINGS_MODULE (info->priv->module)));
                        break;

#ifdef ENABLE_PYTHON
                case MATE_SETTINGS_PLUGIN_LOADER_PY:
                        info->priv->plugin =
                                MATE_SETTINGS_PLUGIN (mate_settings_python_module_new_object (MATE_SETTINGS_PYTHON_MODULE (info->priv->module)));
                        break;
#endif

                default:
                        g_return_val_if_reached (FALSE);
        }

        g_type_module_unuse (info->priv->module);
        ret = TRUE;
 out:
        mate_settings_profile_end ("%s", info->priv->location);
        return ret;
}
示例#18
0
static GObject *
impl_get_object (EphyLoader *eloader,
		 GKeyFile *keyfile)
{
	EphyShlibLoader *loader = EPHY_SHLIB_LOADER (eloader);
	GSList *l;
	LoaderData *data = NULL;
	char *library;
	gboolean resident;

	g_return_val_if_fail (keyfile != NULL, NULL);

	library = g_key_file_get_string (keyfile, "Loader", "Library", NULL);
	if (library == NULL)
	{
		g_warning ("NULL library name!\n");
		return NULL;
	}

	resident = g_key_file_get_boolean (keyfile, "Loader", "Resident", NULL);

	l = g_slist_find_custom (loader->priv->data, library,
				(GCompareFunc) find_library);

	if (l != NULL)
	{
		data = l->data;
		g_return_val_if_fail (data != NULL, NULL);

		if (data->object != NULL)
		{
			g_free (library);
			return g_object_ref (data->object);
		}
	}
	else
	{
		data = g_new0 (LoaderData, 1);
		loader->priv->data = g_slist_prepend (loader->priv->data, data);
	}

	if (data->module == NULL)
	{
		data->module = ephy_module_new (library, resident);
	}

	g_return_val_if_fail (data->object == NULL, data->object);

	if (g_type_module_use (G_TYPE_MODULE (data->module)) == FALSE)
	{
		g_free (library);
		g_warning ("Could not load extension file at %s\n",
			   ephy_module_get_path (data->module));
		return NULL;
	}

	data->object = ephy_module_new_object (data->module);

	g_type_module_unuse (G_TYPE_MODULE (data->module));

	if (data->object != NULL)
	{
		g_object_set_data (G_OBJECT (data->object), DATA_KEY, data);
	}

	g_free (library);

	return data->object;
}
示例#19
0
CCMExtension *
ccm_extension_new (gchar * filename)
{
    g_return_val_if_fail (filename != NULL, NULL);

    CCMExtension *self = g_object_new (CCM_TYPE_EXTENSION, NULL);
    GKeyFile *plugin_file = g_key_file_new ();
    gint cpt;
    gchar *dirname = NULL;

    /* Load plugin configuration file */
    if (!g_key_file_load_from_file (plugin_file, filename, 
                                    G_KEY_FILE_NONE, NULL))
    {
        g_warning ("Error on load %s", filename);
        g_object_unref (self);
        return NULL;
    }

    /* Get plugin name */
    if ((self->priv->name = g_key_file_get_string (plugin_file, 
                                                   PLUGIN_SECTION, 
                                                   "Plugin",  NULL)) == NULL)
    {
        g_warning ("Error on get plugin name in %s", filename);
        g_object_unref (self);
        return NULL;
    }
    for (cpt = 0; self->priv->name[cpt]; ++cpt)
    {
        if (self->priv->name[cpt] == '-')
            self->priv->name[cpt] = '_';
    }
    g_type_module_set_name (G_TYPE_MODULE (self), self->priv->name);

    /* Get Label */
    self->priv->label =
        g_key_file_get_locale_string (plugin_file, PLUGIN_SECTION, "Name", NULL,
                                      NULL);

    /* Get description */
    self->priv->description =
        g_key_file_get_locale_string (plugin_file, PLUGIN_SECTION,
                                      "Description", NULL, NULL);

    /* Get version */
    self->priv->version =
        g_key_file_get_locale_string (plugin_file, PLUGIN_SECTION, "Version",
                                      NULL, NULL);

    /* Get backends */
    self->priv->backends =
        g_key_file_get_string_list (plugin_file, PLUGIN_SECTION, "Backends",
                                    NULL, NULL);

    /* Get plugin depends */
    self->priv->depends =
        g_key_file_get_string_list (plugin_file, PLUGIN_SECTION, "Depends",
                                    NULL, NULL);

    g_key_file_free (plugin_file);

    dirname = g_path_get_dirname (filename);
    self->priv->filename =
        g_module_build_path (dirname, G_TYPE_MODULE (self)->name);
    g_free (dirname);

    g_type_module_use (G_TYPE_MODULE (self));

    return self;
}
示例#20
0
static EvDocument *
ev_document_factory_new_document_for_mime_type (const gchar *mime_type,
                                                GError **error)
{
        EvDocument    *document;
        EvBackendInfo *info;
        GTypeModule *module = NULL;

        g_return_val_if_fail (mime_type != NULL, NULL);

        info = get_backend_info_for_mime_type (mime_type);
        if (info == NULL) {
                char *content_type, *mime_desc = NULL;

                content_type = g_content_type_from_mime_type (mime_type);
                if (content_type)
                        mime_desc = g_content_type_get_description (content_type);

                g_set_error (error,
                             EV_DOCUMENT_ERROR,
                             EV_DOCUMENT_ERROR_INVALID,
                             _("File type %s (%s) is not supported"),
                             mime_desc ? mime_desc : "(unknown)", mime_type);
                g_free (mime_desc);
                g_free (content_type);

                return NULL;
        }

        if (ev_module_hash != NULL) {
                module = g_hash_table_lookup (ev_module_hash, info->module_name);
        }
        if (module == NULL) {
                gchar *path;

                path = g_module_build_path (ev_backends_dir, info->module_name);
                module = G_TYPE_MODULE (_ev_module_new (path, info->resident));
                g_free (path);

                if (ev_module_hash == NULL) {
                        ev_module_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
                                                                g_free,
                                                                NULL /* leaked on purpose */);
                }
                g_hash_table_insert (ev_module_hash, g_strdup (info->module_name), module);
        }

        if (!g_type_module_use (module)) {
                const char *err;

                err = g_module_error ();
                g_set_error (error, EV_DOCUMENT_ERROR, EV_DOCUMENT_ERROR_INVALID,
                             "Failed to load backend for '%s': %s",
                             mime_type, err ? err : "unknown error");
                return NULL;
        }

        document = EV_DOCUMENT (_ev_module_new_object (EV_MODULE (module)));
        g_type_module_unuse (module);

        g_object_set_data_full (G_OBJECT (document), BACKEND_DATA_KEY,
                                _ev_backend_info_ref (info),
                                (GDestroyNotify) _ev_backend_info_unref);

        return document;
}
示例#21
0
static gboolean
load_plugin_module (RBPluginInfo *info)
{
	gchar *path;
	gchar *dirname;

	g_return_val_if_fail (info != NULL, FALSE);
	g_return_val_if_fail (info->file != NULL, FALSE);
	g_return_val_if_fail (info->location != NULL, FALSE);
	g_return_val_if_fail (info->plugin == NULL, FALSE);

	switch (info->lang) {
		case RB_PLUGIN_LOADER_C:
			dirname = g_path_get_dirname (info->file);
			g_return_val_if_fail (dirname != NULL, FALSE);

			path = g_module_build_path (dirname, info->location);
#ifdef USE_UNINSTALLED_DIRS
			if (!g_file_test (path, G_FILE_TEST_EXISTS)) {
				char *temp;

				g_free (path);
				temp = g_build_filename (dirname, ".libs", NULL);

				path = g_module_build_path (temp, info->location);
				g_free (temp);
			}
#endif

			g_free (dirname);
			g_return_val_if_fail (path != NULL, FALSE);

			info->module = G_TYPE_MODULE (rb_module_new (path, info->location));
			g_free (path);
			break;
		case RB_PLUGIN_LOADER_PY:
#ifdef ENABLE_PYTHON
			info->module = G_TYPE_MODULE (rb_python_module_new (info->file, info->location));
#else
			rb_debug ("cannot load plugin %s, python plugin support is disabled", info->location);
#endif
			break;
	}

	if (g_type_module_use (info->module) == FALSE) {
		g_warning ("Could not load plugin %s\n", info->location);

		g_object_unref (G_OBJECT (info->module));
		info->module = NULL;

		return FALSE;
	}

	switch (info->lang) {
		case RB_PLUGIN_LOADER_C:
			info->plugin = RB_PLUGIN (rb_module_new_object (RB_MODULE (info->module)));
			break;
		case RB_PLUGIN_LOADER_PY:
#ifdef ENABLE_PYTHON
			info->plugin = RB_PLUGIN (rb_python_module_new_object (RB_PYTHON_MODULE (info->module)));
#endif
			break;
	}

	return TRUE;
}
示例#22
0
static gboolean
load_plugin_module (EomPluginInfo *info)
{
	gchar *path;
	gchar *dirname;

	eom_debug (DEBUG_PLUGINS);

	g_return_val_if_fail (info != NULL, FALSE);
	g_return_val_if_fail (info->file != NULL, FALSE);
	g_return_val_if_fail (info->location != NULL, FALSE);
	g_return_val_if_fail (info->plugin == NULL, FALSE);
	g_return_val_if_fail (info->available, FALSE);

	switch (info->loader) {
	case EOM_PLUGIN_LOADER_C:
		dirname = g_path_get_dirname (info->file);
		g_return_val_if_fail (dirname != NULL, FALSE);

		path = g_module_build_path (dirname, info->location);

		g_free (dirname);

		g_return_val_if_fail (path != NULL, FALSE);

		info->module = G_TYPE_MODULE (eom_module_new (path));

		g_free (path);

		break;

#ifdef ENABLE_PYTHON
	case EOM_PLUGIN_LOADER_PY:
	{
		gchar *dir;

		if (!eom_python_init ()) {
			/* Mark plugin as unavailable and fails */
			info->available = FALSE;

			g_warning ("Cannot load Python plugin '%s' since eom "
			           "was not able to initialize the Python interpreter.",
			           info->name);

			return FALSE;
		}

		g_return_val_if_fail ((info->location != NULL) &&
		                      (info->location[0] != '\0'),
		                      FALSE);

		dir = g_path_get_dirname (info->file);

		info->module = G_TYPE_MODULE (
				eom_python_module_new (dir, info->location));

		g_free (dir);

		break;
	}
#endif
	default:
		g_return_val_if_reached (FALSE);
	}

	if (!g_type_module_use (info->module)) {
		switch (info->loader) {
		case EOM_PLUGIN_LOADER_C:
			g_warning ("Cannot load plugin '%s' since file '%s' cannot be read.",
				   info->name,
				   eom_module_get_path (EOM_MODULE (info->module)));
			break;

		case EOM_PLUGIN_LOADER_PY:
			g_warning ("Cannot load Python plugin '%s' since file '%s' cannot be read.",
				   info->name,
				   info->location);
			break;

		default:
			g_return_val_if_reached (FALSE);
		}

		g_object_unref (G_OBJECT (info->module));

		info->module = NULL;

		/* Mark plugin as unavailable and fails */
		info->available = FALSE;

		return FALSE;
	}

	switch (info->loader) {
	case EOM_PLUGIN_LOADER_C:
		info->plugin =
			EOM_PLUGIN (eom_module_new_object (EOM_MODULE (info->module)));
		break;

#ifdef ENABLE_PYTHON
	case EOM_PLUGIN_LOADER_PY:
		info->plugin =
			EOM_PLUGIN (eom_python_module_new_object (EOM_PYTHON_MODULE (info->module)));
		break;
#endif

	default:
		g_return_val_if_reached (FALSE);
	}

	g_type_module_unuse (info->module);

	eom_debug_message (DEBUG_PLUGINS, "End");

	return TRUE;
}