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
- func Decode(order binary.ByteOrder, sig string, data []byte) ([]any, error)
- func Encode(order byteOrder, sig string, vals ...any) ([]byte, error)
- func SessionAddress() string
- type Conn
- func (c *Conn) AddMatch(ctx context.Context, rule string) error
- func (c *Conn) Call(ctx context.Context, dest, path, iface, method, sig string, args ...any) (*Message, error)
- func (c *Conn) Close() error
- func (c *Conn) Done() <-chan struct{}
- func (c *Conn) OnSignal(f func(*Message))
- func (c *Conn) Serve(f func(*Message) (sig string, body []any, err *Error))
- func (c *Conn) Signal(dest, path, iface, member, sig string, args ...any) error
- func (c *Conn) UniqueName() string
- type Error
- type Message
- type ObjectPath
- type Option
- type Signature
- type Struct
- type Variant
Constants ¶
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 Encode ¶
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 ¶
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) 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) Serve ¶
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) UniqueName ¶
UniqueName is the connection's name on the bus (":1.42"); empty for a peer connection.
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 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).