GtkModules



hi all!

i finally got dynamic linking in gtk working, and feel like i should 
share the news and informational bits with the rest of the developers.

GLE, besides being an ordinary shared library that programs can
link against, is now a gtk module and can be loaded by gtk at runtime.
this looks like

$ testgtk --gtk-with-module=gle

and suddenly that <alt>+<ctrl>+TAB (GLE's init sequence) combination is
available in testgtk which has not been linked against GLE.

i'm currently making a shared library a gtk module by defining two functions
in one of GLE's .c files:

/* --- GLE Module stuff --- */
G_MODULE_EXPORT const gchar* g_module_check_init (GModule *module);
const gchar*
g_module_check_init (GModule *module)
{
  GModule *main;
  guint *version;

  main = g_module_open (NULL, 0);
  if (!main)
    return "no main handle";
  if (!g_module_symbol (main, "gtk_major_version", &version) && version)
    return "no gtk library?";
  if (*version != GTK_MAJOR_VERSION)
    return "version mismatch (major)";
  if (!g_module_symbol (main, "gtk_minor_version", &version) && version)
    return "no gtk library?";
  if (*version != GTK_MINOR_VERSION)
    return "version mismatch (minor)";
  if (!g_module_symbol (main, "gtk_micro_version", &version) && version)
    return "no gtk library?";
  if (*version != GTK_MICRO_VERSION)
    return "version mismatch (micro)";

  return NULL;
}

G_MODULE_EXPORT void gtk_module_init (gint *argc, gchar ***argv);
void
gtk_module_init (int            *argc,
                 char           ***argv)
{
  gle_init (argc, argv);
}

the function names are mandatory, g_module_check_init() is optionally featured
by the GModule stuff and gets invoked upon g_module_open(). if a value != NULL
is returned, the loading is considered errernerous and is aborted.
gtk_module_init() is a mandatory function, that is required for a gtk module
and will be called at the end of gtk_init() to initialize the module.

i'm curious towards hearing people's comments, especially with regards to the
module API.


---
ciaoTJ



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