Add a way to fetch the plugin API version on building a plugin
authorJose Dapena Paz <jdapena@igalia.com>
Fri, 20 Mar 2009 14:57:47 +0000 (14:57 +0000)
committerJose Dapena Paz <jdapena@igalia.com>
Fri, 20 Mar 2009 14:57:47 +0000 (14:57 +0000)
pmo-trunk-r8274

configure.ac
src/modest-plugin-factory.c
src/modest-plugin.c
src/modest-plugin.h

index 468f0af..8fc7f51 100644 (file)
 AC_INIT([modest],[1.0],[http://maemo.org])
 AC_CONFIG_HEADERS([config.h])
 
+m4_define([modest_api_major_version], [1])
+m4_define([modest_api_minor_version], [0])
+m4_define([modest_api_micro_version], [0])
+m4_define([modest_api_version], [modest_api_major_version.modest_api_minor_version.modest_api_micro_version])
+
+
 AC_CONFIG_SRCDIR(src/modest-main.c)
 AM_INIT_AUTOMAKE([dist-bzip2])
 
+MODEST_API_MAJOR_VERSION=modest_api_major_version
+MODEST_API_MINOR_VERSION=modest_api_minor_version
+MODEST_API_MICRO_VERSION=modest_api_micro_version
+MODEST_API_VERSION=modest_api_version
+AC_SUBST(MODEST_API_MAJOR_VERSION)
+AC_SUBST(MODEST_API_MINOR_VERSION)
+AC_SUBST(MODEST_API_MICRO_VERSION)
+AC_SUBST(MODEST_API_VERSION)
+
 ALL_LINGUAS="en_GB"
 
 MODEST_LOCALE_DIR='$prefix/${DATADIRNAME}/locale'
@@ -148,9 +163,9 @@ if test "$MODEST_PLATFORM" = "detect"; then
 fi
 
 if test "$with_platform" = "maemo"; then
-       MODEST_PLUGIN_DEFINES=" -DMODEST_PLATFORM_MAEMO"
+       MODEST_PLUGIN_DEFINES=" -DMODEST_PLATFORM_MAEMO -DMODEST_API_VERSION=${MODEST_API_VERSION}"
 elif test "$with_platform" = "gnome"; then
-       MODEST_PLUGIN_DEFINES=" -DMODEST_PLATFORM_GNOME"
+       MODEST_PLUGIN_DEFINES=" -DMODEST_PLATFORM_GNOME -DMODEST_API_VERSION=${MODEST_API_VERSION}"
 fi
 AC_SUBST(MODEST_PLUGIN_DEFINES)
 
index 185a02e..dd10213 100644 (file)
@@ -222,11 +222,12 @@ modest_plugin_factory_load (const gchar *file)
        g_free (dir);
 
        /* plugin = g_module_open (path, G_MODULE_BIND_LAZY); */
-       g_message ("PLUGIN TYPE IS %d", (gint) modest_plugin_get_type ());
        type_module = G_TYPE_MODULE (modest_module_new (path));
        if (type_module) {
                g_type_module_use (type_module);
                plugin = MODEST_PLUGIN (modest_module_new_object (MODEST_MODULE (type_module)));
+               if (plugin)
+                       g_message ("Plugin %s API version %s", plugin_name, modest_plugin_get_api_version (plugin));
        }
        g_free (path);
 
index 81543f7..a6f47e7 100644 (file)
@@ -91,3 +91,15 @@ modest_plugin_get_protocol_registry (void)
        /* This is for avoiding including modest runtime itself */
        return modest_runtime_get_protocol_registry ();
 }
+
+const gchar *
+modest_plugin_get_api_version (ModestPlugin *plugin)
+{
+       ModestPluginClass *plugin_class;
+
+       plugin_class = MODEST_PLUGIN_GET_CLASS (plugin);
+       if (plugin_class->get_version)
+               return plugin_class->get_version ();
+       else
+               return NULL;
+}
index 4f9cc78..54c5f8c 100644 (file)
 #include <modest-account-mgr.h>
 #include <modest-protocol-registry.h>
 
+#define MODEST_API_VERSION_STR2_HELPER(x) #x
+#define MODEST_API_VERSION_STR_HELPER(x) MODEST_API_VERSION_STR2_HELPER(x)
+#define MODEST_API_VERSION_STR MODEST_API_VERSION_STR_HELPER(MODEST_API_VERSION)
+
 G_BEGIN_DECLS
 
 /* convenience macros */
@@ -53,6 +57,7 @@ struct _ModestPlugin {
 
 struct _ModestPluginClass {
        GObjectClass parent_class;
+       const gchar * (*get_version) (void);
 };
 
 /**
@@ -75,10 +80,15 @@ plugin_name##_get_type (void)                                                       \
 static void     plugin_name##_init              (PluginName        *self);     \
 static void     plugin_name##_class_init        (PluginName##Class *klass);    \
 static gpointer plugin_name##_parent_class = NULL;                             \
+static const gchar *plugin_name##_internal_get_version (void)                  \
+{                                                                               \
+        return MODEST_API_VERSION_STR;                                         \
+}                                                                               \
 static void     plugin_name##_class_intern_init (gpointer klass)               \
 {                                                                              \
        plugin_name##_parent_class = g_type_class_peek_parent (klass);          \
        plugin_name##_class_init ((PluginName##Class *) klass);                 \
+       ((ModestPluginClass *)klass)->get_version = plugin_name##_internal_get_version; \
 }                                                                              \
                                                                                \
 G_MODULE_EXPORT GType                                                          \
@@ -110,6 +120,7 @@ register_modest_plugin (GTypeModule *module)                                        \
 /* Global methods providing access to singletons without using modest runtime */
 ModestAccountMgr *modest_plugin_get_account_mgr (void);
 ModestProtocolRegistry *modest_plugin_get_protocol_registry (void);
+const gchar *modest_plugin_get_api_version (ModestPlugin *plugin);
 
 G_END_DECLS