Updated Perl API for DBus

Andy Wingo wingo at pobox.com
Sun Nov 28 10:26:52 PST 2004


On Thu, 25 Nov 2004, Daniel P. Berrange wrote:

> If we used the Sv{N,I,P}OKp hinting, there'd be different behaviour between
> the following calls
> 
>   &some_api(123);
>   &some_api(123.0);
>   &some_api("123");

Yes. This is the way the guile bindings work (and python too, iiuc).

> Now while a mis-typed message would be eventually caught and error thrown
> at the server

A mis-typed message is a programming error, and will be caught at
runtime. Pretty clear, I think.

> I feel it is better to try and take advantage of Perl type
> coercion

You certainly do need a way to specify a type, and coercion is as good a
way as anything I guess. E.g. int32 vs uint32, etc. Dunno how you did
compound types, though, for example an array of strings (or dict of
arrays of int64, or..). Coercion would not work then.

Guile does (dbus-message-iter-append iter val [type]). If TYPE is not
there, there are some heuristics to determine what type to use. If it is
there, it's a type structure that mirrors the structure of the data. For
example:

   desired type                         typespec
   ============                         ========
   int64                                the symbol, 'int64
   string                               the symbol, 'string
   array of strings                     the one-element list, '(string)
   array of int64                       the one-element list, '(int64)
   dict with keys arg1 (an int64)       like this: '(dict (arg1 . int64)
    and arg2 (an array of bytes)                          (arg2 . (byte)))

The dict syntax might look a bit funny, but it mirrors how the data
would be passed in: '((arg1 . 23) (arg2 . (#xF0 #x00))).

> > On a deeper level, one should be able to query the signature of an
> > interface
> 
> That's an interesting idea - I'm guessing that'd require extra API
> support in DBus bindings for each language. That may not be worth the
> extra effort just to satisfy the few weakly typed languages like Perl.

I want it for scheme ;) I'd like to be able to query the interface of a
method at a listener.

For static languages, it could also be a useful tool to have when
generating method stubs. 

  dbus_connection_get_method_arg_spec (c, "org.freedesktop.DBus.Hello", &x, &e)

where c is the connection, e is the error, and x is a DBusMessage of
type "argspec" or so -- just a message without data.

Just an idea -- I don't need it now so no code from this side.

Cheers,

Wingo.


More information about the dbus mailing list