Swift library for D-Bus
// momentum
// why it's here
- Active: last commit today
- Built almost entirely by one person
- Health 91/100 with only 12 stars
- Around since 2016 and still shipping
// how to help
// readme
DBus
Pure Swift library for D-Bus. No libdbus, no C implementation β the wire format, the SASL
handshake and the transport are all implemented in Swift.
Requirements
- Swift 6.4+
- Linux (or any platform with a D-Bus daemon reachable over a Unix socket)
Depends on PureSwift/Socket for async sockets.
Usage
import DBus
let connection = try await DBusConnection.connect(to: .session)
let reply = try await connection.send(
DBusMessage(methodCall: DBusMessage.MethodCall(
destination: DBusBusName(rawValue: "org.freedesktop.DBus")!,
path: DBusObjectPath(rawValue: "/org/freedesktop/DBus")!,
interface: DBusInterface(rawValue: "org.freedesktop.DBus")!,
method: DBusMember(rawValue: "ListNames")!
))
)
if case let .array(names)? = reply.arguments.first {
for name in names.compactMap({ $0.stringValue }) {
print(name)
}
}
await connection.close()
An error reply is thrown as a DBusError carrying its org.freedesktop.DBus.Error.* name;
framing and marshalling failures are thrown as DBusProtocolError.