Commit 02a06ee7 authored by Sebastien Granjoux's avatar Sebastien Granjoux

Report detailled error message in case of plugin loading failure

	* libanjuta/interfaces/libanjuta.idl,
	libanjuta/anjuta-plugin-manager.c,
	libanjuta/anjuta-plugin-manager.h,
	libanjuta/anjuta-c-plugin-factory.c,
	libanjuta/anjuta-c-module.h,
	libanjuta/anjuta-c-module.c:
	Report detailled error message in case of plugin loading failure

svn path=/trunk/; revision=3249
parent 2a86789f
2007-10-24 Sébastien Granjoux <seb.sfo@free.fr>
* libanjuta/interfaces/libanjuta.idl,
libanjuta/anjuta-plugin-manager.c,
libanjuta/anjuta-plugin-manager.h,
libanjuta/anjuta-c-plugin-factory.c,
libanjuta/anjuta-c-module.h,
libanjuta/anjuta-c-module.c:
Report detailled error message in case of plugin loading failure
2007-10-24 Johannes Schmid <jhs@gnome.org>
* configure.in:
......
......@@ -68,8 +68,12 @@
#include "anjuta-c-module.h"
#include <libanjuta/interfaces/ianjuta-plugin-factory.h>
#include <gmodule.h>
#define ANJUTA_PLUGIN_REGISTRATION "anjuta_glue_register_components"
/* Types
*---------------------------------------------------------------------------*/
......@@ -84,6 +88,7 @@ struct _AnjutaCModule
GModule *library;
gchar *full_name;
IAnjutaPluginFactoryError error;
};
typedef void (*AnjutaRegisterFunc) (GTypeModule *);
......@@ -109,13 +114,20 @@ anjuta_c_module_load (GTypeModule *gmodule)
if (module->library == NULL)
{
g_warning ("could not load plugin: %s", g_module_error ());
if (!g_file_test (module->full_name, G_FILE_TEST_IS_REGULAR))
{
module->error = IANJUTA_PLUGIN_FACTORY_MISSING_MODULE;
}
else
{
module->error = IANJUTA_PLUGIN_FACTORY_INVALID_MODULE;
}
return FALSE;
}
if (!g_module_symbol (module->library, "anjuta_glue_register_components", (gpointer *)(gpointer)&func))
if (!g_module_symbol (module->library, ANJUTA_PLUGIN_REGISTRATION, (gpointer *)(gpointer)&func))
{
g_warning ("unable to find register function in %s", module->full_name);
module->error = IANJUTA_PLUGIN_FACTORY_MISSING_FUNCTION;
g_module_close (module->library);
return FALSE;
......@@ -123,6 +135,7 @@ anjuta_c_module_load (GTypeModule *gmodule)
/* Register all types */
(* func) (gmodule);
module->error = IANJUTA_PLUGIN_FACTORY_OK;
return TRUE;
}
......@@ -169,6 +182,43 @@ static void
anjuta_c_module_init (AnjutaCModule *module)
{
module->full_name = NULL;
module->error = IANJUTA_PLUGIN_FACTORY_OK;
}
/* Public functions
*---------------------------------------------------------------------------*/
gboolean
anjuta_c_module_get_last_error (AnjutaCModule *module, GError** err)
{
g_return_val_if_fail (module->full_name != NULL, FALSE);
switch (module->error)
{
case IANJUTA_PLUGIN_FACTORY_OK:
return FALSE;
case IANJUTA_PLUGIN_FACTORY_MISSING_MODULE:
g_set_error (err, IANJUTA_PLUGIN_FACTORY_ERROR,
module->error,
_("Unable to find plugin module %s"), module->full_name);
return TRUE;
case IANJUTA_PLUGIN_FACTORY_INVALID_MODULE:
g_set_error (err, IANJUTA_PLUGIN_FACTORY_ERROR,
module->error,
g_module_error());
return TRUE;
case IANJUTA_PLUGIN_FACTORY_MISSING_FUNCTION:
g_set_error (err, IANJUTA_PLUGIN_FACTORY_ERROR,
module->error,
_("Unable to find plugin registration function %s in module %s"),
ANJUTA_PLUGIN_REGISTRATION, module->full_name);
return TRUE;
default:
g_set_error (err, IANJUTA_PLUGIN_FACTORY_ERROR,
module->error,
_("Unknown error in module %s"), module->full_name);
return TRUE;
}
}
/* Creation and Destruction
......
......@@ -38,6 +38,7 @@ typedef struct _AnjutaCModuleClass AnjutaCModuleClass;
GType anjuta_c_module_get_type (void) G_GNUC_CONST;
AnjutaCModule *anjuta_c_module_new (const gchar *path, const char *name);
gboolean anjuta_c_module_get_last_error (AnjutaCModule *module, GError** err);
G_END_DECLS
......
......@@ -101,8 +101,11 @@ anjuta_c_plugin_factory_create_plugin (AnjutaCPluginFactory *factory,
}
pieces = g_strsplit (anjuta_plugin_handle_get_id (handle), ":", -1);
if (pieces == NULL)
if ((pieces == NULL) || (pieces[0] == NULL))
{
g_set_error (error, IANJUTA_PLUGIN_FACTORY_ERROR,
IANJUTA_PLUGIN_FACTORY_MISSING_LOCATION,
_("Missing location of plugin %s"), anjuta_plugin_handle_get_name (handle));
return NULL;
}
module = g_hash_table_lookup (plugin_in_path, pieces[0]);
......@@ -110,9 +113,18 @@ anjuta_c_plugin_factory_create_plugin (AnjutaCPluginFactory *factory,
{
/* Plugin is not loaded */
module = anjuta_c_module_new (path, pieces[0]);
if (module == NULL) return NULL;
g_return_val_if_fail (module != NULL, NULL);
/* Load module */
g_type_module_use (G_TYPE_MODULE (module));
if (anjuta_c_module_get_last_error (module, error))
{
/* Avoid memory leak in case of error*/
g_strfreev (pieces);
return NULL;
}
g_hash_table_insert (plugin_in_path, g_strdup (pieces[0]), module);
}
else
......@@ -123,9 +135,22 @@ anjuta_c_plugin_factory_create_plugin (AnjutaCPluginFactory *factory,
/* Find plugin type */
if (pieces[1] == NULL)
{
g_strfreev (pieces);
g_set_error (error, IANJUTA_PLUGIN_FACTORY_ERROR,
IANJUTA_PLUGIN_FACTORY_MISSING_TYPE,
_("Missing type defined by plugin %s"), anjuta_plugin_handle_get_name (handle));
return NULL;
}
type = g_type_from_name (pieces[1]);
if (type == G_TYPE_INVALID)
{
g_set_error (error, IANJUTA_PLUGIN_FACTORY_ERROR,
IANJUTA_PLUGIN_FACTORY_INVALID_TYPE,
_("plugin %s fails to register type %s"), anjuta_plugin_handle_get_name (handle), pieces[1]);
g_strfreev (pieces);
return NULL;
}
g_strfreev (pieces);
/* Create plugin */
......@@ -134,7 +159,7 @@ anjuta_c_plugin_factory_create_plugin (AnjutaCPluginFactory *factory,
if ((module != NULL) && (anjuta_plugin_handle_get_resident(handle) == FALSE))
{
/* This module can be unloaded when not needed */
g_type_module_use (G_TYPE_MODULE (module));
g_type_module_unuse (G_TYPE_MODULE (module));
}
return plugin;
......
......@@ -116,7 +116,7 @@ static GHashTable* plugin_set_update (AnjutaPluginManager *plugin_manager,
gboolean load);
static IAnjutaPluginFactory* get_plugin_factory (AnjutaPluginManager *plugin_manager,
const gchar *language);
const gchar *language, GError **error);
GQuark
anjuta_plugin_manager_error_quark (void)
......@@ -541,31 +541,19 @@ activate_plugin (AnjutaPluginManager *plugin_manager,
resident = anjuta_plugin_handle_get_resident (handle);
language = anjuta_plugin_handle_get_language (handle);
factory = get_plugin_factory (plugin_manager, language);
if (factory == NULL)
{
g_set_error (error, ANJUTA_PLUGIN_MANAGER_ERROR,
ANJUTA_PLUGIN_MANAGER_ERROR_INVALID_TYPE,
_("Invalid plugin: %s"), plugin_id);
return NULL;
}
factory = get_plugin_factory (plugin_manager, language, error);
if (factory == NULL) return NULL;
plugin = ianjuta_plugin_factory_new_plugin (factory, handle, ANJUTA_SHELL (priv->shell), error);
if (plugin == NULL)
{
g_set_error (error, ANJUTA_PLUGIN_MANAGER_ERROR,
ANJUTA_PLUGIN_MANAGER_ERROR_INVALID_TYPE,
_("Invalid plugin: %s"), plugin_id);
}
else
{
g_signal_connect (plugin, "activated",
G_CALLBACK (on_plugin_activated), handle);
g_signal_connect (plugin, "deactivated",
G_CALLBACK (on_plugin_deactivated), handle);
return NULL;
}
g_signal_connect (plugin, "activated",
G_CALLBACK (on_plugin_activated), handle);
g_signal_connect (plugin, "deactivated",
G_CALLBACK (on_plugin_deactivated), handle);
return plugin;
}
......@@ -1226,7 +1214,8 @@ property_to_list (const char *value)
static IAnjutaPluginFactory*
get_plugin_factory (AnjutaPluginManager *plugin_manager,
const gchar *language)
const gchar *language,
GError **error)
{
AnjutaPluginManagerPriv *priv;
AnjutaPluginHandle *plugin;
......@@ -1340,7 +1329,9 @@ get_plugin_factory (AnjutaPluginManager *plugin_manager,
}
/* No plugin implementing this interface found */
g_warning ("No plugin found to load a %s plugin.", language);
g_set_error (error, ANJUTA_PLUGIN_MANAGER_ERROR,
ANJUTA_PLUGIN_MANAGER_MISSING_FACTORY,
_("No plugin able to load other plugins in %s"), language);
return NULL;
}
......
......@@ -37,7 +37,7 @@ G_BEGIN_DECLS
typedef enum
{
ANJUTA_PLUGIN_MANAGER_ERROR_INVALID_TYPE,
ANJUTA_PLUGIN_MANAGER_MISSING_FACTORY,
ANJUTA_PLUGIN_MANAGER_ERROR_UNKNOWN
} AnjutaPluginManagerError;
......
......@@ -4252,6 +4252,39 @@ interface IAnjutaPluginFactory
#include <libanjuta/anjuta-plugin.h>
#include <libanjuta/anjuta-shell.h>
#include <libanjuta/anjuta-plugin-handle.h>
/**
* IAnjutaPluginFactoryError:
* @IANJUTA_PLUGIN_FACTORY_MISSING_LOCATION: Module file location is
* missing in .plugin file
* @IANJUTA_PLUGIN_FACTORY_MISSING_TYPE: Plugin type (just after
* double colon following location) is missing in .plugin file
* @IANJUTA_PLUGIN_FACTORY_MISSING_MODULE: Module file name not found,
* plugin module is probably not installed
* @IANJUTA_PLUGIN_FACTORY_UNLOADABLE_MODULE: Module file cannot be
* loaded, not a shared library perhaps
* @IANJUTA_PLUGIN_FACTORY_MISSING_FUNCTION: Module does not contain
* registration function, library is not an anjuta plugin or
* is not for the right version
* @IANJUTA_PLUGIN_FACTORY_INVALID_TYPE: Module has not registered
* plugin type, library is not an anjuta plugin or not for
* the right version
* @IANJUTA_PLUGIN_FACTORY_UNKNOWN_ERROR: Another error
*
* These enumeration is used to specify errors.
*/
enum Error
{
OK = 0,
MISSING_LOCATION,
MISSING_TYPE,
MISSING_MODULE,
INVALID_MODULE,
MISSING_FUNCTION,
INVALID_TYPE,
UNKNOWN_ERROR,
}
/**
* ianjuta_plugin_factory_new_plugin:
* @obj: Self
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment