Creating a DBusInterface in Java
Urizev
urizev at gmail.com
Wed May 21 14:47:32 PDT 2008
Thank you very much. Tomorrow, in the morning I will try that and will
tell you about.
Thanks again.
On Wed, May 21, 2008 at 8:31 PM, Matthew Johnson <dbus at matthew.ath.cx> wrote:
> On Wed May 21 14:47, Urizev wrote:
>> As it is supposed, hal has not the GetAllDevices method. I know it is
>> possible to create the class with CreateInterface, but I do not know
>> how. Beside, I think that this process would can be automatic since it
>> is possible to request for the introspection data of the interface via
>> DBUS. I do not know if how can I use the API. If anybody has some
>> information, any reference or example, I would really appreciate it.
>
> Because Java is a statically typed language, the interfaces you are
> calling must be available at compile time. It is possible to create
> these from introspection data, this is what CreateInterface does.
> Alternatively, if you know the syntax of the methods you are calling,
> you can write the interface file by hand, it's generally very simple.
>
> All this should be documented here:
>
> http://dbus.freedesktop.org/doc/dbus-java/
>
> It _is_ possible to do it all dynamically, using reflection support
> in Java, but it's ugly, and since you will always know the name and
> types, still easier to just write the interface file itself.
>
> Either you write:
>
> (Manager.java)
> ...
> interface Manager extends DBusInterface
> {
> ...
> List<String> GetAllDevices();
> }
>
> ^^ this can be replaced with a call to CreateInterface
>
> (Test.java)
> ...
> Manager hal = conn.getRemoteObject("org.freedesktop.Hal", "/org/freedesktop/Hal/Manager", Manager.class);
> List<String> ds = hal.GetAllDevices();
>
> or:
> ...
> DBusInterface hal = conn.getRemoteObject("org.freedesktop.Hal", "/org/freedesktop/Hal/Manager");
> try {
> Method m = hal.getClass().getMethod("GetAllDevices", new Class[] {});
> List<String> ds = (List<String>) m.invoke(hal, new Object[] {});
> } (....)
>
> with lots of handling of possible reflection exceptions.
>
> Matt
> --
> www.matthew.ath.cx
> D-Bus Java
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (GNU/Linux)
>
> iD8DBQFINGp92XtckeYvo1gRAlZKAKC9TDIdVnipzfA4ShIw/DvpCygSuwCfXOus
> BDakyfhCqcVpHgEgm86KQ4g=
> =MZ5+
> -----END PGP SIGNATURE-----
>
>
--
Saludos
Juan Carlos
"¡¡Viva lo rancio!!"
More information about the dbus
mailing list