diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-02-25 18:45:32 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-02-28 08:05:02 +0100 |
commit | 019ce9f2815cd21756be4f11702fcb02b5453fdc (patch) | |
tree | 43070181e30db403dfad69f3e67a566ba589df4e /conf/storewatcher.go | |
parent | Initial scaffolding (diff) | |
download | wireguard-windows-019ce9f2815cd21756be4f11702fcb02b5453fdc.tar.xz wireguard-windows-019ce9f2815cd21756be4f11702fcb02b5453fdc.zip |
conf: introduce configuration management
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'conf/storewatcher.go')
-rw-r--r-- | conf/storewatcher.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/conf/storewatcher.go b/conf/storewatcher.go new file mode 100644 index 00000000..4f9c2ef7 --- /dev/null +++ b/conf/storewatcher.go @@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (C) 2019 WireGuard LLC. All Rights Reserved. + */ + +package conf + +import "reflect" + +type StoreCallback func() + +var storeCallbacks []StoreCallback + +func RegisterStoreChangeCallback(cb StoreCallback) { + startWatchingConfigDir() + cb() + storeCallbacks = append(storeCallbacks, cb) +} + +func UnregisterStoreChangeCallback(cb StoreCallback) { + //TODO: this function is ridiculous, doing slow iteration like this and reflection too. + + index := -1 + for i, e := range storeCallbacks { + if reflect.ValueOf(e).Pointer() == reflect.ValueOf(cb).Pointer() { + index = i + break + } + } + if index == -1 { + return + } + newList := storeCallbacks[0:index] + if index < len(storeCallbacks)-1 { + newList = append(newList, storeCallbacks[index+1:]...) + } + storeCallbacks = newList +} |