D-Bus
Jan Dvorak <mordae@anilinux.org>
Native D-Bus Client For Racket.
(require dbus) | package: dbus |
1 Connecting
procedure
(dbus-connection? v) → boolean?
v : any/c
procedure
(dbus-connect-session-bus [auth-method]) → dbus-connection?
auth-method : (-> input-port? output-port? void?) = dbus-auth-external
procedure
(dbus-connect-system-bus [auth-method]) → dbus-connection?
auth-method : (-> input-port? output-port? void?) = dbus-auth-external
procedure
(dbus-connect/address address [auth-method]) → dbus-connection?
address : string?
auth-method : (-> input-port? output-port? void?) = dbus-auth-external
procedure
(dbus-connect/socket [path auth-method]) → dbus-connection?
path : unix-socket-path? = "/var/run/dbus/system_bus_socket"
auth-method : (-> input-port? output-port? void?) = dbus-auth-external
procedure
(dbus-connect/tcp host port [auth-method]) → dbus-connection?
host : string? port : (integer-in 1 65535)
auth-method : (-> input-port? output-port? void?) = dbus-auth-anonymous
procedure
(dbus-auth-external in out) → void?
in : input-port? out : output-port?
procedure
(dbus-auth-anonymous in out) → void?
in : input-port? out : output-port?
So, in order to connect to the system bus on a typical Linux system:
(current-dbus-connection (dbus-connect/socket "/var/run/dbus/system_bus_socket"))
Or, to connect to a remote bus without authentication:
(current-dbus-connection (dbus-connect/tcp "localhost" 1234))
procedure
(dbus-listen-evt [connection])
→
(evt/c (list/c dbus-object-path? dbus-interface-name? dbus-member-name? any/c)) connection : dbus-connection? = (current-dbus-connection)
2 Proxy Objects
In order to operate on remote objects, you first need to describe their interfaces and create proxy object instances that will map remote objects to regular ones.
|
superclass: object% |
constructor
(new dbus-object% [path path] [ [endpoint endpoint] [connection connection]]) → (is-a?/c dbus-object%) path : dbus-object-path? endpoint : dbus-endpoint-name? = (current-dbus-endpoint) connection : dbus-connection? = (current-dbus-connection) Every dbus-object% instance need to know these three things in order to communicate with the actual remote object. It can be advantageous to define current-dbus-connection or even current-dbus-endpoint beforehand.
value
Objects without any methods are not very useful. In order to create proxies that can actually call anything, you need to make use of define-dbus-interface macro that will create a mixin with proxy calls to defined methods.
syntax
(define-dbus-interface interface-name (method-name args-type) ...)
(define-dbus-interface dbus-interface<%> "org.freedesktop.DBus" (Hello "") (ListNames "")) (define dbus% (dbus-interface<%> dbus-object%)) (define dbus (new dbus% (object-path "/org/freedesktop/DBus") (endpoint "org.freedesktop.DBus"))) (send dbus ListNames)
2.1 Parameters
parameter
(current-dbus-connection) → (or/c #f dbus-connection?)
(current-dbus-connection connection) → void? connection : (or/c #f dbus-connection?)
parameter
(current-dbus-endpoint) → (or/c #f dbus-endpoint-name?)
(current-dbus-endpoint endpoint) → void? endpoint : (or/c #f dbus-endpoint-name?)
3 Other
3.1 Exceptions
procedure
(exn:fail:dbus? v) → boolean?
v : any/c
procedure
v : any/c
procedure
v : any/c
3.2 Bus Names
D-Bus uses a whole lot of specially formatted strings. You can use these predicates to check your data early.
procedure
(dbus-signature? v) → boolean?
v : any/c
procedure
v : any/c
procedure
(dbus-object-path? v) → boolean?
v : any/c
procedure
(dbus-interface-name? v) → boolean?
v : any/c
procedure
(dbus-error-name? v) → boolean?
v : any/c
procedure
(dbus-member-name? v) → boolean?
v : any/c
procedure
(dbus-endpoint-name? v) → boolean?
v : any/c
4 Interfaces
(require dbus/interface) | package: dbus |
| ||
| ||
|
method
(send a-dbus-introspectable Introspect) → string?
Retrieve the introspection XML document.
| ||
| ||
|
method
(send a-dbus-properties Get interface-name property-name) → (cons/c dbus-single-signature? any/c) interface-name : dbus-interface-name? property-name : dbus-member-name? Get property value.
method
(send a-dbus-properties Set interface-name property-name value) → void? interface-name : dbus-interface-name? property-name : dbus-member-name? value : (cons/c dbus-single-signature? any/c) Set property to specified value.
method
interface-name : dbus-interface-name? Get values of all properties for given interface.
value
| ||
| ||
|
First method to call when communicating using a message bus. Returns your connection name.Get list of names claimed on the bus.
method
(send a-dbus RequestName name flags)
→ exact-nonnegative-integer? name : string? flags : exact-nonnegative-integer? Ask bus to assign you given name. See Message Bus Names section in the D-Bus specification for details.
method
(send a-dbus ReleaseName name) → exact-nonnegative-integer?
name : string? Release owned bus name.Ask bus to route some messages your way. Used mainly for signal subscription. See Match Rules section in the D-Bus specification for details.
method
(send a-dbus RemoveMatch rule) → void?
rule : string? Cancel specified message matching rule.
value
procedure
(dbus-manager [connection]) → object?
connection : dbus-connection? = (current-dbus-connection)