1package logind
2
3import (
4 "context"
5 "github.com/godbus/dbus/v5"
6)
7
8// bus is an adapter-local godbus seam. newAdapter consumes its connection.
9type bus interface {
10 call(context.Context, string, dbus.ObjectPath, string, ...any) ([]any, error)
11 suspend(context.Context, string) <-chan *dbus.Call
12 match(context.Context, string) error
13 signals(chan<- *dbus.Signal)
14 removeSignals(chan<- *dbus.Signal)
15 unixFDs() bool
16 close() error
17}
18type connection struct{ conn *dbus.Conn }
19
20func (c connection) call(ctx context.Context, destination string, path dbus.ObjectPath, method string, args ...any) ([]any, error) {
21 call := c.conn.Object(destination, path).CallWithContext(ctx, method, 0, args...)
22 return call.Body, call.Err
23}
24func (c connection) suspend(ctx context.Context, owner string) <-chan *dbus.Call {
25 call := c.conn.Object(owner, managerPath).GoWithContext(ctx, managerInterface+".Suspend", 0, make(chan *dbus.Call, 1), false)
26 return call.Done
27}
28func (c connection) match(ctx context.Context, rule string) error {
29 return c.conn.BusObject().CallWithContext(ctx, "org.freedesktop.DBus.AddMatch", 0, rule).Err
30}
31func (c connection) signals(ch chan<- *dbus.Signal) { c.conn.Signal(ch) }
32func (c connection) removeSignals(ch chan<- *dbus.Signal) { c.conn.RemoveSignal(ch) }
33func (c connection) unixFDs() bool { return c.conn.SupportsUnixFDs() }
34func (c connection) close() error { return c.conn.Close() }