[libpeas/proxys: 8/22] Do not make plugin_loader_load return a special object.



commit fa233cd4c08b72471c51f957dbdd22bc99d9ef87
Author: Steve Frécinaux <code istique net>
Date:   Wed May 19 01:07:45 2010 +0200

    Do not make plugin_loader_load return a special object.
    
    The existing PeasPlugin should really be converted into a GInterface
    to use through PeasExtension.

 libpeas/peas-engine.c            |  154 +-------------------------------------
 libpeas/peas-engine.h            |   17 ----
 libpeas/peas-plugin-info-priv.h  |    2 +-
 libpeas/peas-plugin-info.c       |    5 +-
 libpeas/peas-plugin-loader.c     |    6 +-
 libpeas/peas-plugin-loader.h     |    4 +-
 loaders/c/peas-plugin-loader-c.c |   40 +++++------
 7 files changed, 29 insertions(+), 199 deletions(-)
---
diff --git a/libpeas/peas-engine.c b/libpeas/peas-engine.c
index d44e916..69eefef 100644
--- a/libpeas/peas-engine.c
+++ b/libpeas/peas-engine.c
@@ -366,22 +366,6 @@ peas_engine_finalize (GObject *object)
 }
 
 static void
-peas_engine_activate_plugin_on_object (PeasEngine     *engine,
-                                       PeasPluginInfo *info,
-                                       GObject        *object)
-{
-  peas_plugin_activate (info->plugin, object);
-}
-
-static void
-peas_engine_deactivate_plugin_on_object (PeasEngine     *engine,
-                                         PeasPluginInfo *info,
-                                         GObject        *object)
-{
-  peas_plugin_deactivate (info->plugin, object);
-}
-
-static void
 peas_engine_class_init (PeasEngineClass *klass)
 {
   GType the_type = G_TYPE_FROM_CLASS (klass);
@@ -393,8 +377,6 @@ peas_engine_class_init (PeasEngineClass *klass)
   object_class->finalize = peas_engine_finalize;
   klass->activate_plugin = peas_engine_activate_plugin_real;
   klass->deactivate_plugin = peas_engine_deactivate_plugin_real;
-  klass->activate_plugin_on_object = peas_engine_activate_plugin_on_object;
-  klass->deactivate_plugin_on_object = peas_engine_deactivate_plugin_on_object;
 
   /**
    * PeasEngine:app-name:
@@ -657,9 +639,9 @@ load_plugin (PeasEngine     *engine,
       return FALSE;
     }
 
-  info->plugin = peas_plugin_loader_load (loader, info);
+  info->active = peas_plugin_loader_load (loader, info);
 
-  if (info->plugin == NULL)
+  if (info->active == FALSE)
     {
       g_warning ("Error loading plugin '%s'", info->name);
       info->available = FALSE;
@@ -673,14 +655,7 @@ static void
 peas_engine_activate_plugin_real (PeasEngine     *engine,
                                   PeasPluginInfo *info)
 {
-  PeasEngineClass *engine_class = PEAS_ENGINE_GET_CLASS (engine);
-  const GList *item;
-
-  if (!load_plugin (engine, info))
-    return;
-
-  for (item = engine->priv->object_list; item != NULL; item = item->next)
-    engine_class->activate_plugin_on_object (engine, info, G_OBJECT (item->data));
+  load_plugin (engine, info);
 }
 
 /**
@@ -714,27 +689,19 @@ static void
 peas_engine_deactivate_plugin_real (PeasEngine     *engine,
                                     PeasPluginInfo *info)
 {
-  PeasEngineClass *engine_class = PEAS_ENGINE_GET_CLASS (engine);
-  const GList *item;
   PeasPluginLoader *loader;
 
   if (!peas_plugin_info_is_active (info) ||
       !peas_plugin_info_is_available (info))
     return;
 
-  for (item = engine->priv->object_list; item != NULL; item = item->next)
-    engine_class->deactivate_plugin_on_object (engine, info, G_OBJECT (item->data));
-
-  /* first unref the plugin (the loader still has one) */
-  g_object_unref (info->plugin);
-
   /* find the loader and tell it to gc and unload the plugin */
   loader = get_plugin_loader (engine, info);
 
   peas_plugin_loader_garbage_collect (loader);
   peas_plugin_loader_unload (loader, info);
 
-  info->plugin = NULL;
+  info->active = FALSE;
 }
 
 /**
@@ -762,35 +729,6 @@ peas_engine_deactivate_plugin (PeasEngine     *engine,
   return !peas_plugin_info_is_active (info);
 }
 
-/**
- * peas_engine_update_plugins_ui:
- * @engine: A #PeasEngine.
- * @object: A registered #GObject.
- *
- * Triggers an update of all the plugins user interfaces to take into
- * account state changes due to a plugin or an user action.
- */
-void
-peas_engine_update_plugins_ui (PeasEngine *engine,
-                               GObject    *object)
-{
-  GList *pl;
-
-  g_return_if_fail (PEAS_IS_ENGINE (engine));
-  g_return_if_fail (G_IS_OBJECT (object));
-
-  /* call update_ui for all active plugins */
-  for (pl = engine->priv->plugin_list; pl; pl = pl->next)
-    {
-      PeasPluginInfo *info = (PeasPluginInfo *) pl->data;
-
-      if (!peas_plugin_info_is_active (info))
-        continue;
-
-      peas_plugin_update_ui (info->plugin, object);
-    }
-}
-
 gboolean
 peas_engine_provides_extension (PeasEngine *engine,
                                 PeasPluginInfo *info,
@@ -899,90 +837,6 @@ peas_engine_set_active_plugins (PeasEngine   *engine,
 }
 
 /**
- * peas_engine_add_object:
- * @engine: A #PeasEngine.
- * @object: A #GObject to register.
- *
- * Register an object against the #PeasEngine. The activate() method of all
- * the active plugins will be called on every registered object.
- */
-void
-peas_engine_add_object (PeasEngine *engine,
-                        GObject    *object)
-{
-  PeasEngineClass *engine_class;
-  GList *pl;
-
-  g_return_if_fail (PEAS_IS_ENGINE (engine));
-  g_return_if_fail (G_IS_OBJECT (object));
-
-  engine_class = PEAS_ENGINE_GET_CLASS (engine);
-
-  /* Ensure we don't insert the same object twice... */
-  if (g_list_find (engine->priv->object_list, object))
-    return;
-
-  /* Activate the plugin on object, and add it to the list of managed objects */
-  for (pl = engine->priv->plugin_list; pl; pl = pl->next)
-    {
-      PeasPluginInfo *info = (PeasPluginInfo *) pl->data;
-
-      /* check if the plugin is actually active */
-      if (!peas_plugin_info_is_active (info))
-        continue;
-
-      engine_class->activate_plugin_on_object (engine, info, object);
-    }
-
-  engine->priv->object_list = g_list_prepend (engine->priv->object_list, object);
-
-  /* also call update_ui after activation */
-  peas_engine_update_plugins_ui (engine, object);
-
-}
-
-/**
- * peas_engine_remove_object:
- * @engine: A #PeasEngine.
- * @object: A #GObject to unregister.
- *
- * Unregister an object against the #PeasEngine. The deactivate() method of
- * all the active plugins will be called on the object while he is being
- * unregistered.
- */
-void
-peas_engine_remove_object (PeasEngine *engine,
-                           GObject    *object)
-{
-  PeasEngineClass *engine_class;
-  GList *pl;
-
-  g_return_if_fail (PEAS_IS_ENGINE (engine));
-  g_return_if_fail (G_IS_OBJECT (object));
-
-  engine_class = PEAS_ENGINE_GET_CLASS (engine);
-
-  GList *item = g_list_find (engine->priv->object_list, object);
-  if (item == NULL)
-    return;
-
-  /* Remove the object to the list of managed objects, and deactivate the plugin on it */
-  engine->priv->object_list = g_list_delete_link (engine->priv->object_list, item);
-
-  for (pl = engine->priv->plugin_list; pl; pl = pl->next)
-    {
-      PeasPluginInfo *info = (PeasPluginInfo *) pl->data;
-
-      /* check if the plugin is actually active */
-      if (!peas_plugin_info_is_active (info))
-        continue;
-
-      /* call deactivate for the plugin for this window */
-      engine_class->deactivate_plugin_on_object (engine, info, object);
-    }
-}
-
-/**
  * peas_engine_new:
  * @app_name: The name of the app
  * @base_module_dir: The base directory for language modules
diff --git a/libpeas/peas-engine.h b/libpeas/peas-engine.h
index 37b638c..ed9bc0f 100644
--- a/libpeas/peas-engine.h
+++ b/libpeas/peas-engine.h
@@ -61,14 +61,6 @@ struct _PeasEngineClass {
 
   void     (*deactivate_plugin)           (PeasEngine     *engine,
                                            PeasPluginInfo *info);
-
-  void     (*activate_plugin_on_object)   (PeasEngine     *engine,
-                                           PeasPluginInfo *info,
-                                           GObject        *object);
-
-  void     (*deactivate_plugin_on_object) (PeasEngine     *engine,
-                                           PeasPluginInfo *info,
-                                           GObject        *object);
 };
 
 GType             peas_engine_get_type            (void) G_GNUC_CONST;
@@ -99,15 +91,6 @@ PeasExtension    *peas_engine_get_extension       (PeasEngine      *engine,
                                                    PeasPluginInfo  *info,
                                                    GType            ext_type);
 
-/* plugin activation/deactivation per target_object */
-void              peas_engine_update_plugins_ui   (PeasEngine      *engine,
-                                                   GObject         *object);
-
-/* object management */
-void              peas_engine_add_object          (PeasEngine      *engine,
-                                                   GObject         *object);
-void              peas_engine_remove_object       (PeasEngine      *engine,
-                                                   GObject         *object);
 
 G_END_DECLS
 
diff --git a/libpeas/peas-plugin-info-priv.h b/libpeas/peas-plugin-info-priv.h
index 6b3d84c..7401a96 100644
--- a/libpeas/peas-plugin-info-priv.h
+++ b/libpeas/peas-plugin-info-priv.h
@@ -30,7 +30,6 @@ struct _PeasPluginInfo {
   /*< private >*/
   gint refcount;
 
-  PeasPlugin *plugin;
   gchar *file;
   gchar *module_dir;
   gchar *data_dir;
@@ -50,6 +49,7 @@ struct _PeasPluginInfo {
   gboolean visible;
   GHashTable *keys;
 
+  gint active : 1;
   /* A plugin is unavailable if it is not possible to activate it
      due to an error loading the plugin module (e.g. for Python plugins
      when the interpreter has not been correctly initializated) */
diff --git a/libpeas/peas-plugin-info.c b/libpeas/peas-plugin-info.c
index e5293a5..7e4df25 100644
--- a/libpeas/peas-plugin-info.c
+++ b/libpeas/peas-plugin-info.c
@@ -51,9 +51,6 @@ _peas_plugin_info_unref (PeasPluginInfo *info)
   if (!g_atomic_int_dec_and_test (&info->refcount))
     return;
 
-  if (info->plugin != NULL)
-    g_object_unref (info->plugin);
-
   if (info->keys != NULL)
     g_hash_table_destroy (info->keys);
   g_free (info->file);
@@ -337,7 +334,7 @@ peas_plugin_info_is_active (PeasPluginInfo *info)
 {
   g_return_val_if_fail (info != NULL, FALSE);
 
-  return info->available && info->plugin != NULL;
+  return info->available && info->active;
 }
 
 /**
diff --git a/libpeas/peas-plugin-loader.c b/libpeas/peas-plugin-loader.c
index 157036e..a723222 100644
--- a/libpeas/peas-plugin-loader.c
+++ b/libpeas/peas-plugin-loader.c
@@ -47,16 +47,16 @@ peas_plugin_loader_add_module_directory (PeasPluginLoader *loader,
   klass->add_module_directory (loader, module_dir);
 }
 
-PeasPlugin *
+gboolean
 peas_plugin_loader_load (PeasPluginLoader *loader,
                          PeasPluginInfo   *info)
 {
   PeasPluginLoaderClass *klass;
 
-  g_return_val_if_fail (PEAS_IS_PLUGIN_LOADER (loader), NULL);
+  g_return_val_if_fail (PEAS_IS_PLUGIN_LOADER (loader), FALSE);
 
   klass = PEAS_PLUGIN_LOADER_GET_CLASS (loader);
-  g_return_val_if_fail (klass->load != NULL, NULL);
+  g_return_val_if_fail (klass->load != NULL, FALSE);
 
   return klass->load (loader, info);
 }
diff --git a/libpeas/peas-plugin-loader.h b/libpeas/peas-plugin-loader.h
index d7c1e01..5d58086 100644
--- a/libpeas/peas-plugin-loader.h
+++ b/libpeas/peas-plugin-loader.h
@@ -50,7 +50,7 @@ struct _PeasPluginLoaderClass {
   void          (*add_module_directory)   (PeasPluginLoader *loader,
                                            const gchar      *module_dir);
 
-  PeasPlugin   *(*load)                   (PeasPluginLoader *loader,
+  gboolean      (*load)                   (PeasPluginLoader *loader,
                                            PeasPluginInfo   *info);
   void          (*unload)                 (PeasPluginLoader *loader,
                                            PeasPluginInfo   *info);
@@ -69,7 +69,7 @@ GType         peas_plugin_loader_get_type             (void);
 void          peas_plugin_loader_add_module_directory (PeasPluginLoader *loader,
                                                        const gchar      *module_dir);
 
-PeasPlugin   *peas_plugin_loader_load                 (PeasPluginLoader *loader,
+gboolean      peas_plugin_loader_load                 (PeasPluginLoader *loader,
                                                        PeasPluginInfo   *info);
 void          peas_plugin_loader_unload               (PeasPluginLoader *loader,
                                                        PeasPluginInfo   *info);
diff --git a/loaders/c/peas-plugin-loader-c.c b/loaders/c/peas-plugin-loader-c.c
index e9c31c8..00654b2 100644
--- a/loaders/c/peas-plugin-loader-c.c
+++ b/loaders/c/peas-plugin-loader-c.c
@@ -31,7 +31,6 @@ struct _PeasPluginLoaderCPrivate
   GHashTable *loaded_plugins;
 };
 
-/*PEAS_PLUGIN_LOADER_REGISTER_TYPE (PeasPluginLoaderC, peas_plugin_loader_c);*/
 G_DEFINE_DYNAMIC_TYPE (PeasPluginLoaderC, peas_plugin_loader_c, PEAS_TYPE_PLUGIN_LOADER);
 
 G_MODULE_EXPORT GObject *
@@ -49,14 +48,13 @@ peas_plugin_loader_c_add_module_directory (PeasPluginLoader *loader,
   /* This is a no-op for C modules... */
 }
 
-static PeasPlugin *
+static gboolean
 peas_plugin_loader_c_load (PeasPluginLoader * loader,
                            PeasPluginInfo   *info)
 {
   PeasPluginLoaderC *cloader = PEAS_PLUGIN_LOADER_C (loader);
   PeasObjectModule *module;
   const gchar *module_name;
-  PeasPlugin *result;
 
   module = (PeasObjectModule *) g_hash_table_lookup (cloader->priv->loaded_plugins,
                                                      info);
@@ -74,6 +72,7 @@ peas_plugin_loader_c_load (PeasPluginLoader * loader,
        * If this changes, we should use weak refs or something */
 
       g_hash_table_insert (cloader->priv->loaded_plugins, info, module);
+      g_debug ("Insert module %s into C module set", module_name);
     }
 
   if (!g_type_module_use (G_TYPE_MODULE (module)))
@@ -81,25 +80,16 @@ peas_plugin_loader_c_load (PeasPluginLoader * loader,
       g_warning ("Could not load plugin module: %s",
                  peas_plugin_info_get_name (info));
 
-      return NULL;
+      return FALSE;
     }
 
-  result = (PeasPlugin *) peas_object_module_new_object (module);
-
-  if (!result)
-    {
-      g_warning ("Could not create plugin object: %s",
-                 peas_plugin_info_get_name (info));
-      g_type_module_unuse (G_TYPE_MODULE (module));
-
-      return NULL;
-    }
-
-  g_object_set (result, "plugin-info", info, NULL);
-
-  g_type_module_unuse (G_TYPE_MODULE (module));
+  {
+    /* FIXME: This weird hack is currently necessary but ought to be removed. */
+    PeasPlugin *result = (PeasPlugin *) peas_object_module_new_object (module);
+    g_object_unref (result);
+  }
 
-  return result;
+  return TRUE;
 }
 
 static CreateFunc
@@ -114,9 +104,11 @@ get_create_function (PeasPluginLoaderC *cloader,
 
   module = (PeasObjectModule *) g_hash_table_lookup (cloader->priv->loaded_plugins,
                                                      info);
+
   g_return_val_if_fail (module != NULL, NULL);
 
   symbol_name = g_strdup_printf ("create_%s", g_type_name (exten_type));
+  g_debug ("Resolving symbol %s", symbol_name);
   ret = g_module_symbol (peas_object_module_get_library (module), symbol_name, &symbol);
   g_free (symbol_name);
 
@@ -161,9 +153,13 @@ static void
 peas_plugin_loader_c_unload (PeasPluginLoader *loader,
                              PeasPluginInfo   *info)
 {
-  /* this is a no-op, since the type module will be properly unused as
-     the last reference to the plugin dies. When the plugin is activated
-     again, the library will be reloaded */
+  PeasPluginLoaderC *cloader = PEAS_PLUGIN_LOADER_C (loader);
+  PeasObjectModule *module;
+
+  module = (PeasObjectModule *) g_hash_table_lookup (cloader->priv->loaded_plugins,
+                                                     info);
+
+  g_type_module_unuse (G_TYPE_MODULE (module));
 }
 
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]