ui_app

module pkg::alloy::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.

type Valuesource

exp type Value = enum

A value D-Bus carries. A dict is an array of two-field structs.

Variants

Byte: u8
Boolean: bool
Int16: i16
Uint16: u16
Int32: i32
Uint32: u32
Int64: i64
Uint64: u64
Double: f64
Text: String
ObjectPath: String
Signature: String
Array: Vector<Value>
Struct: Vector<Value>
Variant: *Value

Functions

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 = 1
Return = 2
Error = 3
Signal = 4

type Messagesource

exp type Message = struct

Fields

exp kind: MessageKind
exp flags: u8

1: no reply expected

exp serial: u32
exp path: String
exp interface_name: String
exp member: String
exp error_name: String
exp reply_serial: u32
exp destination: String
exp sender: String
exp signature: String
exp body: Vector<Value>

Functions

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: String

the name the bus gave it

Functions

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.