wip: migrate to mono-repo. SPN has already been moved to spn/
This commit is contained in:
46
spn/docks/cranehooks.go
Normal file
46
spn/docks/cranehooks.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package docks
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/safing/portbase/log"
|
||||
)
|
||||
|
||||
var (
|
||||
craneUpdateHook func(crane *Crane)
|
||||
craneUpdateHookLock sync.Mutex
|
||||
)
|
||||
|
||||
// RegisterCraneUpdateHook allows the captain to hook into receiving updates for cranes.
|
||||
func RegisterCraneUpdateHook(fn func(crane *Crane)) {
|
||||
craneUpdateHookLock.Lock()
|
||||
defer craneUpdateHookLock.Unlock()
|
||||
|
||||
if craneUpdateHook == nil {
|
||||
craneUpdateHook = fn
|
||||
} else {
|
||||
log.Error("spn/docks: crane update hook already registered")
|
||||
}
|
||||
}
|
||||
|
||||
// ResetCraneUpdateHook resets the hook for receiving updates for cranes.
|
||||
func ResetCraneUpdateHook() {
|
||||
craneUpdateHookLock.Lock()
|
||||
defer craneUpdateHookLock.Unlock()
|
||||
|
||||
craneUpdateHook = nil
|
||||
}
|
||||
|
||||
// NotifyUpdate calls the registers crane update hook function.
|
||||
func (crane *Crane) NotifyUpdate() {
|
||||
if crane == nil {
|
||||
return
|
||||
}
|
||||
|
||||
craneUpdateHookLock.Lock()
|
||||
defer craneUpdateHookLock.Unlock()
|
||||
|
||||
if craneUpdateHook != nil {
|
||||
craneUpdateHook(crane)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user