Documentation
¶
Overview ¶
Package dbusx holds the D-Bus plumbing every lys process shares, on lys-lib's patched godbus: exporting interfaces at a path and under a well-known name the way zbus's object_server().at + request_name does, serving zbus-style #[zbus(property)] getters (computed on every read) and setters over org.freedesktop.DBus.Properties, introspection built on demand, and watching a name for its owner.
Index ¶
- Constants
- Variables
- func Export(conn *dbus.Conn, path dbus.ObjectPath, ifaces ...Interface) (unexport func(), err error)
- func Failed(msg string) *dbus.Error
- func File(fd dbus.UnixFD, name string) (*os.File, error)
- func InvalidArgs(msg string) *dbus.Error
- func NameOwner(ctx context.Context, conn *dbus.Conn, name string) (string, error)
- func NameOwnerChange(sig *dbus.Signal, name string) (oldOwner, newOwner string, ok bool)
- func Own(conn *dbus.Conn, name string) (func(), error)
- func OwnerMatch(name string) []dbus.MatchOption
- func Serve(conn *dbus.Conn, s Service) (func(), error)
- func WatchOwner(ctx context.Context, conn *dbus.Conn, name string, appeared func()) error
- type Getters
- type Interface
- type Service
- type Setters
- type Signal
- type SignalDecl
Constants ¶
const ( ErrFailed = "org.freedesktop.DBus.Error.Failed" ErrInvalidArgs = "org.freedesktop.DBus.Error.InvalidArgs" ErrUnknownProperty = "org.freedesktop.DBus.Error.UnknownProperty" ErrUnknownIface = "org.freedesktop.DBus.Error.UnknownInterface" ErrPropertyRO = "org.freedesktop.DBus.Error.PropertyReadOnly" )
Error names of the standard org.freedesktop.DBus errors (zbus's fdo::Error variants).
Variables ¶
var ErrNameTaken = errors.New("name already owned")
ErrNameTaken is what Own and Serve wrap when another connection already owns the well-known name, so a caller can tell a taken name from a bus failure.
Functions ¶
func Export ¶
func Export(conn *dbus.Conn, path dbus.ObjectPath, ifaces ...Interface) (unexport func(), err error)
Export puts ifaces at path on conn, with one Properties object serving all of their properties and introspection listing them all, as zbus's object_server().at does for each interface it mounts at a path. The returned unexport removes them again (a Request or Session object ending). Export is all or nothing: every interface is checked before any is exported, and a failure leaves none of them at path.
func InvalidArgs ¶
InvalidArgs is fdo::Error::InvalidArgs(msg).
func NameOwner ¶
NameOwner returns the unique name of name's current owner; a name nobody owns is an error.
func NameOwnerChange ¶
NameOwnerChange reads a NameOwnerChanged signal the bus sent about name: the old and new owners ("" for none), and whether the signal is that one. Another peer sending NameOwnerChanged is not the bus, so its signal is not that one.
func Own ¶
Own takes a well-known name; the returned release drops it. A name already owned is ErrNameTaken, as zbus's request_name with DoNotQueue.
func OwnerMatch ¶
func OwnerMatch(name string) []dbus.MatchOption
OwnerMatch matches the NameOwnerChanged signals the bus sends about name.
Types ¶
type Getters ¶
Getters maps property names to their read functions. Each returns a value godbus can marshal; the D-Bus signature is taken from it.
type Interface ¶
type Interface struct {
Name string
Methods any
Properties Getters
Setters Setters
Signals []SignalDecl
// Ordered are the methods whose calls run one at a time in arrival
// order (dbus.Conn.DispatchInOrder), for a caller that does not wait
// for each reply.
Ordered []string
}
Interface is one D-Bus interface of an object: its methods (an object whose exported methods each end in a *dbus.Error result), its properties, the writers of those that are writable, and the signals it emits.
type Service ¶
type Service struct {
// Name is the well-known bus name and Path the object path.
Name string
Path dbus.ObjectPath
// Interface is the D-Bus interface the methods are exported as.
Interface string
// Methods is the object whose exported methods (each ending in a
// *dbus.Error result) form the interface.
Methods any
// Properties are the read-only properties.
Properties Getters
// Signals are the signals the interface emits.
Signals []SignalDecl
}
Service is one exported interface.
type Setters ¶
Setters maps writable property names to their write functions, which decode the variant themselves and refuse a wrong type.
type Signal ¶
type Signal[T any] struct { // contains filtered or unexported fields }
Signal is one signal of a D-Bus interface, carrying a T: a struct whose exported fields, except those tagged `dbus:"-"`, are the signal's arguments in order. A field's dbus tag names its argument in the introspection data; an untagged field's argument is unnamed. The same Signal declares it on an Interface, emits it and decodes it, so its name and signature exist once.
func NewSignal ¶
NewSignal declares the signal member of iface carrying a T. It panics when T is not a struct or a field has no D-Bus type, as a declaration that cannot exist.
func (Signal[T]) Decode ¶
Decode reads a received signal as this one, refusing another signal and a body that does not carry exactly its arguments. Arguments holding a struct arrive untyped, so within them it accepts what dbus.Store converts.
type SignalDecl ¶
type SignalDecl interface {
// contains filtered or unexported methods
}
SignalDecl is a Signal as an Interface declares it, whatever it carries.