module dbussource
A D-Bus client (PLAN.md, F6c): a connection to a bus over a
Unix socket, authenticated as the process's user (SASL EXTERNAL), which
sends method calls, replies, errors and signals and receives them, for
the accessibility bus and the desktop portal and any program using the
session or system bus. Calls can wait for their reply; everything else
arrives through receive, which never blocks, the connection's socket
polled beside a program's own (fd).
import pkg::alloy::dbus;
fn main() -> i32 {
var bus = if (Connection::session() is ::Some |move c|) move c else {
return 1;
};
var names = Vector<Value>::empty();
if (bus.call(&"org.freedesktop.DBus", &"/org/freedesktop/DBus", &"org.freedesktop.DBus",
&"ListNames", &"", Vector<Value>::empty()) is ::Some |&reply|) {
...
}
bus.dispose();
return 0;
}
## How it was built
Notes kept from each stage as it was finished, the sizes and numbers of their day; what changed since is in REVIEW.md and the history.
Built in F6c, for AT-SPI and the desktop portal: see pkg::alloy::window's notes.
ValueValue::textValue::pathValue::variantValue::entryas_textas_integeritemslookupMessageKindMessageMessage::emptyMessage::callMessage::signalreplyerroris_errorConnectiondisposeConnection::sessionConnection::openfdsendcallcall_messagereceivehas_receivedwaitadd_matchrequest_nameget_property
type Valuesource
exp type Value = enum
A value D-Bus carries. A dict is an array of two-field structs.
Variants
Byte: u8Boolean: boolInt16: i16Uint16: u16Int32: i32Uint32: u32Int64: i64Uint64: u64Double: f64Text: StringObjectPath: StringSignature: StringArray: Vector<Value>Struct: Vector<Value>Variant: *Value
Functions
exp fn Value::text(text: &[u8]) -> Valueexp fn Value::path(text: &[u8]) -> Valueexp fn Value::variant(value: Value) -> Valueexp fn Value::entry(key: Value, value: Value) -> Valueexp fn as_text(self v: &Value) -> &[u8]exp fn as_integer(self v: &Value) -> i64exp fn items(self v: &Value) -> &[Value]exp fn lookup(self v: &Value, key: &[u8]) -> Option<&Value>
fn Value::textsource
exp fn Value::text(text: &[u8]) -> Value
fn Value::pathsource
exp fn Value::path(text: &[u8]) -> Value
fn Value::variantsource
exp fn Value::variant(value: Value) -> Value
fn Value::entrysource
exp fn Value::entry(key: Value, value: Value) -> Value
A dict entry, as a two-field struct.
fn as_textsource
exp fn as_text(self v: &Value) -> &[u8]
The text a string, object path or signature holds, or empty.
fn as_integersource
exp fn as_integer(self v: &Value) -> i64
The number an integer holds, or 0.
fn itemssource
exp fn items(self v: &Value) -> &[Value]
The items of an array, or none.
fn lookupsource
exp fn lookup(self v: &Value, key: &[u8]) -> Option<&Value>
The value under the key in a dict (a{sv}), a variant's own value.
type MessageKindsource
exp type MessageKind = enum : u8
A message's kind, by its number in the header.
Variants
Call = 1Return = 2Error = 3Signal = 4
type Messagesource
exp type Message = struct
Fields
exp kind: MessageKindexp flags: u81: no reply expected
exp serial: u32exp path: Stringexp interface_name: Stringexp member: Stringexp error_name: Stringexp reply_serial: u32exp destination: Stringexp sender: Stringexp signature: Stringexp body: Vector<Value>
Functions
exp fn Message::empty() -> Messageexp fn Message::call( destination: &[u8], path: &[u8], interface_name: &[u8], member: &[u8], signature: &[u8], body: Vector<Value> ) -> Messageexp fn Message::signal( path: &[u8], interface_name: &[u8], member: &[u8], signature: &[u8], body: Vector<Value> ) -> Messageexp fn reply(self call: &Message, signature: &[u8], body: Vector<Value>) -> Messageexp fn error(self call: &Message, name: &[u8], text: &[u8]) -> Messageexp fn is_error(self m: &Message) -> bool
fn Message::emptysource
exp fn Message::empty() -> Message
fn Message::callsource
exp fn Message::call(
destination: &[u8],
path: &[u8],
interface_name: &[u8],
member: &[u8],
signature: &[u8],
body: Vector<Value>
) -> Message
A method call.
fn Message::signalsource
exp fn Message::signal(
path: &[u8],
interface_name: &[u8],
member: &[u8],
signature: &[u8],
body: Vector<Value>
) -> Message
A signal from the object.
fn replysource
exp fn reply(self call: &Message, signature: &[u8], body: Vector<Value>) -> Message
The reply to a call.
fn errorsource
exp fn error(self call: &Message, name: &[u8], text: &[u8]) -> Message
An error answering a call.
fn is_errorsource
exp fn is_error(self m: &Message) -> bool
type Connectionsource
exp type Connection : Disposable = struct
A connection to a bus.
Fields
exp unique_name: Stringthe name the bus gave it
Functions
exp fn dispose(self c: &var Connection)exp fn Connection::session() -> Option<Connection>exp fn Connection::open(address: &[u8]) -> Option<Connection>exp fn fd(self c: &Connection) -> i32exp fn send(self c: &var Connection, message: Message) -> Option<u32>exp fn call( self c: &var Connection, destination: &[u8], path: &[u8], interface_name: &[u8], member: &[u8], signature: &[u8], body: Vector<Value> ) -> Option<Message>exp fn call_message(self c: &var Connection, message: Message, timeout: i32) -> Option<Message>exp fn receive(self c: &var Connection) -> Option<Message>exp fn has_received(self c: &Connection) -> boolexp fn wait(self c: &var Connection, timeout: i32) -> Option<Message>exp fn add_match(self c: &var Connection, rule: &[u8]) -> boolexp fn request_name(self c: &var Connection, name: &[u8]) -> boolexp fn get_property( self c: &var Connection, destination: &[u8], path: &[u8], interface_name: &[u8], name: &[u8] ) -> Option<Value>
fn disposesource
exp fn dispose(self c: &var Connection)
fn Connection::sessionsource
exp fn Connection::session() -> Option<Connection>
The session bus, from DBUS_SESSION_BUS_ADDRESS; none without one.
fn Connection::opensource
exp fn Connection::open(address: &[u8]) -> Option<Connection>
The bus at the address (unix:path=... or unix:abstract=..., the
first of several that connects), authenticated and greeted.
fn fdsource
exp fn fd(self c: &Connection) -> i32
The socket, for a loop to poll beside its own: when it is readable,
receive takes what came.
fn sendsource
exp fn send(self c: &var Connection, message: Message) -> Option<u32>
Sends the message, numbering it; its serial, none when it could not.
fn callsource
exp fn call(
self c: &var Connection,
destination: &[u8],
path: &[u8],
interface_name: &[u8],
member: &[u8],
signature: &[u8],
body: Vector<Value>
) -> Option<Message>
Calls the method and waits up to 5 seconds for its reply (or error);
what else arrives meanwhile waits for receive.
fn call_messagesource
exp fn call_message(self c: &var Connection, message: Message, timeout: i32) -> Option<Message>
fn receivesource
exp fn receive(self c: &var Connection) -> Option<Message>
The next message received, never waiting; none when none came.
fn has_receivedsource
exp fn has_received(self c: &Connection) -> bool
Whether messages wait to be taken, read already while waiting for a reply: a loop polling the socket would not see them.
fn waitsource
exp fn wait(self c: &var Connection, timeout: i32) -> Option<Message>
Waits up to the milliseconds for a message.
fn add_matchsource
exp fn add_match(self c: &var Connection, rule: &[u8]) -> bool
Asks the bus for the messages the match rule selects, as
type='signal',interface='org.freedesktop.portal.Request'.
fn request_namesource
exp fn request_name(self c: &var Connection, name: &[u8]) -> bool
Asks the bus for the well-known name; whether this connection owns it.
fn get_propertysource
exp fn get_property(
self c: &var Connection,
destination: &[u8],
path: &[u8],
interface_name: &[u8],
name: &[u8]
) -> Option<Value>
A property of an object, through org.freedesktop.DBus.Properties.