policy.go RawHistoryFolder
1package ports
2
3import "time"
4
5type Generation uint64
6type Action uint8
7
8const (
9 Lock Action = iota
10 Fade
11 OutputOff
12 Sleep
13)
14
15// Input contains no credentials. LockReleased is an authoritative visual-owner
16// lifecycle result, never an activity/reload request to unlock.
17type PolicyEvent interface{ policyEvent() }
18type IdleDue struct {
19 Generation Generation
20 // Notification identifies an existing proxy across unrelated reloads.
21 Notification uint64
22 After time.Duration
23}
24type Activity struct{}
25type Reload struct{ Config Config }
26type LockConfirmed struct{ Generation Generation }
27type LockReleased struct{ Generation Generation }
28type BeforeSleep struct{}
29
30func (IdleDue) policyEvent() {}
31func (Activity) policyEvent() {}
32func (Reload) policyEvent() {}
33func (LockConfirmed) policyEvent() {}
34func (LockReleased) policyEvent() {}
35func (BeforeSleep) policyEvent() {}
36
37// One notification per distinct timeout and registration origin; After is
38// relative to registration. Equal timeout values after a reload may have
39// different IDs: retaining an old origin must not rebase unchanged deadlines.
40// Actions sharing one notification dispatch in Lock/Fade/OutputOff/Sleep order.
41// Replacement destroys old proxies. Generation fences their queued events.
42type IdleNotification struct {
43 // ID is stable while this pending deadline is unchanged by reload.
44 // Adapters retain that proxy (and its old admitting Generation), avoiding
45 // recreation that would invent an exact current idle age.
46 ID uint64
47 After time.Duration
48}
49type PolicyEffect interface{ policyEffect() }
50type ArmIdle struct {
51 Generation Generation
52 Notifications []IdleNotification
53}
54type AcquireLock struct{ Generation Generation }
55type SetFade struct {
56 Black bool
57 Duration time.Duration
58}
59type SetOutputPower struct{ On bool }
60type Suspend struct{}
61
62// SleepReady lets the system adapter release its delay inhibitor. No sleep is
63// induced by this response; it acknowledges a BeforeSleep already in progress.
64type SleepReady struct{}
65
66func (ArmIdle) policyEffect() {}
67func (AcquireLock) policyEffect() {}
68func (SetFade) policyEffect() {}
69func (SetOutputPower) policyEffect() {}
70func (Suspend) policyEffect() {}
71func (SleepReady) policyEffect() {}
72
73// LockRequested asks policy to acquire the session lock now (logind Lock
74// signal or the private control socket). It is idempotent while a lock is
75// being acquired or held and never orders/forces any other action.
76type LockRequested struct{}
77
78func (LockRequested) policyEvent() {}