dbusx

package
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 11 Imported by: 6 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

View Source
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 Failed

func Failed(msg string) *dbus.Error

Failed is fdo::Error::Failed(msg).

func File

func File(fd dbus.UnixFD, name string) (*os.File, error)

File wraps a descriptor received over D-Bus; a negative one is an error, not a file.

func InvalidArgs

func InvalidArgs(msg string) *dbus.Error

InvalidArgs is fdo::Error::InvalidArgs(msg).

func NameOwner

func NameOwner(ctx context.Context, conn *dbus.Conn, name string) (string, error)

NameOwner returns the unique name of name's current owner; a name nobody owns is an error.

func NameOwnerChange

func NameOwnerChange(sig *dbus.Signal, name string) (oldOwner, newOwner string, ok bool)

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

func Own(conn *dbus.Conn, name string) (func(), error)

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.

func Serve

func Serve(conn *dbus.Conn, s Service) (func(), error)

Serve exports s on conn and takes its well-known name; the returned release drops the name and unexports s. A name already owned is ErrNameTaken, as zbus's request_name with DoNotQueue, and leaves nothing exported.

func WatchOwner

func WatchOwner(ctx context.Context, conn *dbus.Conn, name string, appeared func()) error

WatchOwner runs appeared, on a goroutine of its own, each time name gains an owner on conn, until ctx ends: a service that starts (or restarts) after its client did.

Types

type Getters

type Getters map[string]func() any

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

type Setters map[string]func(dbus.Variant) *dbus.Error

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

func NewSignal[T any](iface, member string) Signal[T]

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

func (s Signal[T]) Decode(sig *dbus.Signal) (T, error)

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.

func (Signal[T]) Emit

func (s Signal[T]) Emit(conn *dbus.Conn, path dbus.ObjectPath, v T) error

Emit sends the signal from the object at path on conn, carrying v.

func (Signal[T]) Name

func (s Signal[T]) Name() string

Name is the signal's full name, interface and member, as a received dbus.Signal carries it.

type SignalDecl

type SignalDecl interface {
	// contains filtered or unexported methods
}

SignalDecl is a Signal as an Interface declares it, whatever it carries.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL