aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/conf/storewatcher.go
diff options
context:
space:
mode:
Diffstat (limited to 'conf/storewatcher.go')
-rw-r--r--conf/storewatcher.go38
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
+}