Re: gobject, dynamic loading of classes



I am working with GTypeModule to load gobject types that register types
dynamically. These types derive from an abstract base class defined statically in the main code. It works fine, but one thing I notice is that any header files you distribute for the dynamic "plugin" types cannot define _get_type() in the
conventional way.

Normally, when you define a (static) gobject type, your .h header file would
have the standard macros and something like this:

--- foo.h ---
GType      foo_get_type   (void);

Any client code that wants to use this type to instantiate a foo object would

#include "foo.h"

and link to foo.o to bind the function foo_get_type().  But in my situation,
the client code cannot bind foo_get_type() since that function lives in a plugin
that isn't loaded until runtime.

The solution I am using at the moment is to use an alternate version of
foo_get_type():

static void    foo_get_type    (void)  { return g_type_from_name ("Foo"); }

where "Foo" is the Type Name used by the plugin at dynamic registration time. The salient point is that this get_type() does not register any type -- it only
returns the type if it has been register, or G_TYPE_INVALID if not.

I haven't found a better way to do this, given that the gobject headers contain structures and macros which must be seen by the client when the client compiles..

Phil





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