Re: [Vala] DBus services in shared modules implementing interfaces defined in a shared library



Hi Michael,

The types of internally used libraries are not registered if ModuleInit
is used. 

I solved the same issue recently, in a rather convoluted way.

A noinst convenient library libcore.la
Another noinst convenient library libmain.la
Each is built with one call to valac. They are then compiled with gcc,
and linked via libtool into libfoo.la which is an installed shared
library.

In libcore, there is a public static method:

[ModuleInit]
core_init() {}

PluginManager class and PluginModule class are defined in libmain.la,
class PluginManager {
  void query(string filename);
  void query_static(PluginModule.ModuleInitFunc init_func) {
    push new PluginModule.static(init_func) to a owned list.
  }
}
class PluginModule: TypeModule {
 PluginModule.from_file(string file);
 PluginModule.static(ModuleInitFunc init_func);
 private ModuleInitFunc init_func;
 public override use() {
    init_func(this);
 }
}

libmain.la implements a public init function (NOT a ModuleInit)

namespace Foo {
   public void init() {
      manager = new PluginModuleManager();
      manager.query_static(core_init);
   }
}

In this way I was able to ensure all types added in libcore.la are
automatically initialized, without manifestly peeking them one by one.

The two library scheme is mandatory. If all classes are in the same la
[ModuleInit] will also floats PluginModule, which makes it
uninstantiatable. Then it will be impossible to bootstrap the entire
type system.

Regards,

Yu

On Wed, 2009-03-18 at 21:33 +0100, Michael 'Mickey' Lauer wrote:
On Monday 16 March 2009 22:31:13 Feng Yu wrote:
You have to subclass GTypeModule, and manifestly call the annotated
method(declared in the plugin) within the plugin manager code.

Yes, that's clear and I'm doing that, and these types get registered, but 
obviously not some of their bases, which are contained in the shared library 
(not the plugin). How am I supposed to init these? If I add a [ModuleInit] to 
the shared library, then I get the following:

void register_types (GTypeModule* module) {
        g_return_if_fail (module != NULL);
        fso_framework_device_led_register_type (module);
        fso_framework_abstract_logger_register_type (module);
        fso_framework_file_logger_register_type (module);
        fso_framework_syslog_logger_register_type (module);
        fso_framework_base_plugin_register_type (module);
        fso_framework_smart_key_file_register_type (module);
        fso_framework_abstract_subsystem_register_type (module);
        fso_framework_base_subsystem_register_type (module);
        fso_framework_dbus_subsystem_register_type (module);
        g_debug ("zzz.vala:6: init all types ");
}

where "fso_framework_device_led_register_type" is exactly the dbus interface 
which doesn't work.

So -- although the shared library which contains these types is not loaded via 
dlopen (but rather linked to the main executable), I need to create a 
TypeModule for it?

Cheers,





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