plugins: check for plugin types before loading it
authorImran Zaman <imran.zaman@linux.intel.com>
Wed, 29 May 2013 14:41:05 +0000 (17:41 +0300)
committerImran Zaman <imran.zaman@linux.intel.com>
Wed, 29 May 2013 14:41:05 +0000 (17:41 +0300)
src/daemon/plugins/gsignond-plugin-proxy-factory.c
src/daemon/plugins/gsignond-plugin-remote.c
src/daemon/plugins/plugind/gsignond-plugin-daemon.c

index c61d1d4..2b3f43d 100644 (file)
@@ -251,12 +251,22 @@ gsignond_plugin_proxy_factory_get_plugin(GSignondPluginProxyFactory* factory,
 
     GSignondPluginProxy* proxy = NULL;
 
+    if (factory->methods == NULL) {
+        _enumerate_plugins (factory);
+    }
+
+    if (g_hash_table_lookup(factory->mechanisms, plugin_type) == NULL) {
+        DBG("Plugin not known %s", plugin_type);
+        return NULL;
+    }
+
     proxy = g_hash_table_lookup(factory->plugins, plugin_type);
     if (proxy != NULL) {
         DBG("get existing plugin %s -> %p", plugin_type, proxy);
         g_object_ref(proxy);
         return proxy;
     }
+
     proxy = gsignond_plugin_proxy_new(factory->config, plugin_type);
     if (proxy == NULL) {
         return NULL;
@@ -304,21 +314,9 @@ gsignond_plugin_proxy_factory_get_plugin_mechanisms(
 {
     g_return_val_if_fail(factory->mechanisms, NULL);
 
-    const gchar **mechanisms = NULL;
-    mechanisms = g_hash_table_lookup(factory->mechanisms, plugin_type);
-    if (mechanisms == NULL) {
-        GSignondPlugin* plugin = GSIGNOND_PLUGIN (gsignond_plugin_remote_new (
-                factory->config, plugin_type));
-        if (plugin != NULL) {
-            gchar **mechs = NULL;
-            g_object_get (plugin, "mechanisms", &mechs, NULL);
-            if (mechs != NULL) {
-                g_hash_table_insert(factory->mechanisms, g_strdup(plugin_type),
-                        mechs);
-                mechanisms = (const gchar **)mechs;
-            }
-            g_object_unref (plugin);
-        }
+    if (factory->methods == NULL) {
+        _enumerate_plugins (factory);
     }
-    return mechanisms;
+
+    return g_hash_table_lookup(factory->mechanisms, plugin_type);
 }
index ac99c6b..c513c7f 100644 (file)
@@ -555,7 +555,6 @@ gsignond_plugin_remote_new (
         GSignondConfig *config,
         const gchar *plugin_type)
 {
-    gchar *object_path = NULL;
     GError *error = NULL;
     GPid cpid = 0;
     gchar **argv;
@@ -593,9 +592,6 @@ gsignond_plugin_remote_new (
             (GChildWatchFunc)_child_watch_cb, plugin);
     plugin->priv->cpid = cpid;
 
-    object_path = g_strdup_printf ("%s_%s", GSIGNOND_PLUGIN_OBJECTPATH,
-            plugin_type);
-
     /* Create dbus connection */
     stream = gsignond_pipe_stream_new (cout_fd, cin_fd, TRUE);
     plugin->priv->connection = g_dbus_connection_new_sync (G_IO_STREAM (stream),
@@ -608,18 +604,16 @@ gsignond_plugin_remote_new (
                     plugin->priv->connection,
                     G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
                     NULL,
-                    object_path,
+                    GSIGNOND_PLUGIN_OBJECTPATH,
                     NULL,
                     &error);
     if (error) {
         DBG ("Failed to register object: %s", error->message);
         g_error_free (error);
-        g_free (object_path);
         g_object_unref (plugin);
         return NULL;
     }
-    DBG("'%s' object exported(%p)", object_path, plugin);
-    g_free (object_path);
+    DBG("'%s' object exported(%p)", GSIGNOND_PLUGIN_OBJECTPATH, plugin);
 
     plugin->priv->signal_response = g_signal_connect_swapped (
             plugin->priv->dbus_plugin_proxy, "response",
index bcb4925..6e8b375 100644 (file)
@@ -361,7 +361,6 @@ gsignond_plugin_daemon_new (
         const gchar* plugin_type)
 {
     GError *error = NULL;
-    gchar *object_path = NULL;
     GSignondPipeStream *stream = NULL;
 
     g_return_val_if_fail (filename != NULL && plugin_type != NULL, NULL);
@@ -391,21 +390,17 @@ gsignond_plugin_daemon_new (
     daemon->priv->dbus_remote_plugin =
             gsignond_dbus_remote_plugin_skeleton_new ();
 
-    object_path = g_strdup_printf ("%s_%s", GSIGNOND_PLUGIN_OBJECTPATH,
-            daemon->priv->plugin_type);
     g_dbus_interface_skeleton_export (
                 G_DBUS_INTERFACE_SKELETON(daemon->priv->dbus_remote_plugin),
-                daemon->priv->connection, object_path, &error);
+                daemon->priv->connection, GSIGNOND_PLUGIN_OBJECTPATH, &error);
     if (error) {
         DBG ("failed to register object: %s", error->message);
         g_error_free (error);
-        g_free (object_path);
         g_object_unref (daemon);
         return NULL;
     }
     DBG("Started plugin daemon '%p' at path '%s' on conneciton '%p'",
-            daemon, object_path, daemon->priv->connection);
-    g_free (object_path);
+            daemon, GSIGNOND_PLUGIN_OBJECTPATH, daemon->priv->connection);
 
     /* Connect dbus remote plugin signals to handlers */
     g_signal_connect_swapped (daemon->priv->dbus_remote_plugin,