aboutsummaryrefslogtreecommitdiffhomepage
path: root/system/dispatcher.go
blob: c896de57723347ea58ccf5c2a8fb9b652029f0e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package system

import (
	"hakurei.app/system/acl"
	"hakurei.app/system/dbus"
)

// syscallDispatcher provides methods that make state-dependent system calls as part of their behaviour.
// syscallDispatcher is embedded in [I], so all methods must be unexported.
type syscallDispatcher interface {
	// new starts a goroutine with a new instance of syscallDispatcher.
	// A syscallDispatcher must never be used in any goroutine other than the one owning it,
	// just synchronising access is not enough, as this is for test instrumentation.
	new(f func(k syscallDispatcher))

	// aclUpdate provides [acl.Update].
	aclUpdate(name string, uid int, perms ...acl.Perm) error

	// dbusAddress provides [dbus.Address].
	dbusAddress() (session, system string)
	// dbusFinalise provides [dbus.Finalise].
	dbusFinalise(sessionBus, systemBus dbus.ProxyPair, session, system *dbus.Config) (final *dbus.Final, err error)
	// dbusProxyStart provides the Start method of [dbus.Proxy].
	dbusProxyStart(proxy *dbus.Proxy) error
	// dbusProxyClose provides the Close method of [dbus.Proxy].
	dbusProxyClose(proxy *dbus.Proxy)
	// dbusProxyWait provides the Wait method of [dbus.Proxy].
	dbusProxyWait(proxy *dbus.Proxy) error

	isVerbose() bool
	verbose(v ...any)
	verbosef(format string, v ...any)
}

// direct implements syscallDispatcher on the current kernel.
type direct struct{}

func (k direct) new(f func(k syscallDispatcher)) { go f(k) }

func (k direct) aclUpdate(name string, uid int, perms ...acl.Perm) error {
	return acl.Update(name, uid, perms...)
}

func (k direct) dbusAddress() (session, system string) {
	return dbus.Address()
}

func (k direct) dbusFinalise(sessionBus, systemBus dbus.ProxyPair, session, system *dbus.Config) (final *dbus.Final, err error) {
	return dbus.Finalise(sessionBus, systemBus, session, system)
}

func (k direct) dbusProxyStart(proxy *dbus.Proxy) error { return proxy.Start() }
func (k direct) dbusProxyClose(proxy *dbus.Proxy)       { proxy.Close() }
func (k direct) dbusProxyWait(proxy *dbus.Proxy) error  { return proxy.Wait() }

func (k direct) isVerbose() bool                { return msg.IsVerbose() }
func (direct) verbose(v ...any)                 { msg.Verbose(v...) }
func (direct) verbosef(format string, v ...any) { msg.Verbosef(format, v...) }