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; }
/* * 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); }
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; }
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(); }
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(); }
/* Dispose this object */ static void _xfdashboard_plugins_manager_dispose_remove_plugin(gpointer inData) { XfdashboardPlugin *plugin; g_return_if_fail(inData && XFDASHBOARD_IS_PLUGIN(inData)); plugin=XFDASHBOARD_PLUGIN(inData); /* Disable plugin */ xfdashboard_plugin_disable(plugin); /* Unload plugin */ g_type_module_unuse(G_TYPE_MODULE(plugin)); }
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; }
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)); }
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); }
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; }
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; }
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; }
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; }