dbus

package
v0.1.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 14 Imported by: 0 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 dbus is a small pure-Go client of the D-Bus message bus: the wire format (marshalling per the D-Bus specification), the EXTERNAL authentication, method calls, signal delivery and serving method calls. It is what the desktop notification backend (org.freedesktop.Notifications) is built on and is deliberately limited to the unix transports and to what that needs: no file descriptor passing, no introspection helpers.

Index

Constants

View Source
const (
	TypeMethodCall = 1
	TypeReply      = 2
	TypeError      = 3
	TypeSignal     = 4
)

Message types and header fields (D-Bus specification, "Message Format").

Variables

This section is empty.

Functions

func Decode

func Decode(order binary.ByteOrder, sig string, data []byte) ([]any, error)

Decode unmarshals a body of signature sig.

func Encode

func Encode(order byteOrder, sig string, vals ...any) ([]byte, error)

Encode marshals values according to signature sig, as a message body (or header field array) starting at an 8-aligned offset.

func SessionAddress

func SessionAddress() string

SessionAddress returns the session bus address from the environment.

Types

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

Conn is a connection to a message bus (or a direct peer).

func Dial

func Dial(address string) (*Conn, error)

Dial connects to the bus at address (a ";"-free list is tried in order: "unix:path=...", "unix:abstract=...", optionally with ",guid=...") and says Hello.

func NewConn

func NewConn(rwc io.ReadWriteCloser, opts ...Option) (*Conn, error)

NewConn authenticates over rwc and, unless Peer or ServerSide is given, says Hello to a bus daemon.

func (*Conn) AddMatch

func (c *Conn) AddMatch(ctx context.Context, rule string) error

AddMatch asks the bus to route signals matching rule to this connection.

func (*Conn) Call

func (c *Conn) Call(ctx context.Context, dest, path, iface, method, sig string, args ...any) (*Message, error)

Call invokes a method and waits for the reply. dest may be "" on a peer connection.

func (*Conn) Close

func (c *Conn) Close() error

Close ends the connection.

func (*Conn) Done

func (c *Conn) Done() <-chan struct{}

Done is closed when the connection ends.

func (*Conn) OnSignal

func (c *Conn) OnSignal(f func(*Message))

OnSignal sets the function that receives every signal (it must not block).

func (*Conn) Serve

func (c *Conn) Serve(f func(*Message) (sig string, body []any, err *Error))

Serve sets the function that answers method calls addressed to this connection. A nil error and a signature give a reply; an *Error gives an error reply.

func (*Conn) Signal

func (c *Conn) Signal(dest, path, iface, member, sig string, args ...any) error

Signal sends a signal (to dest when non-empty, else broadcast).

func (*Conn) UniqueName

func (c *Conn) UniqueName() string

UniqueName is the connection's name on the bus (":1.42"); empty for a peer connection.

type Error

type Error struct {
	Name string
	Msg  string
}

Error is a D-Bus error reply.

func (*Error) Error

func (e *Error) Error() string

type Message

type Message struct {
	Type        int
	Serial      uint32
	ReplySerial uint32
	Path        string
	Interface   string
	Member      string
	ErrorName   string
	Destination string
	Sender      string
	Signature   string
	Body        []any
}

Message is a decoded D-Bus message.

type ObjectPath

type ObjectPath string

ObjectPath is a value of type "o".

type Option

type Option func(*connConfig)

Option configures NewConn.

func Peer

func Peer() Option

Peer makes a connection that does not talk to a bus daemon (no Hello): a direct connection to one service.

func ServerSide

func ServerSide() Option

ServerSide runs the server half of the authentication handshake (for tests and in-process fakes).

type Signature

type Signature string

Signature is a value of type "g".

type Struct

type Struct []any

Struct is the decoded form of a "(...)" value.

type Variant

type Variant struct {
	Sig   string
	Value any
}

Variant is a value with a dynamic type (signature "v").

Jump to

Keyboard shortcuts

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