diff options
author | kali kaneko (leap communications) <kali@leap.se> | 2020-06-22 22:00:23 +0200 |
---|---|---|
committer | kali kaneko (leap communications) <kali@leap.se> | 2020-06-26 12:13:44 +0200 |
commit | 06a7453984adca0b34e62421a1baa8fe54b0d7bb (patch) | |
tree | 4eb7d0f31d540c33d2d6f53ed44257c06a4d8220 /pkg/backend/callbacks.go | |
parent | 20266b063c1be8818d4582bff7b59486551ee447 (diff) |
[refactor] several simplifications after review
- simplify notification routine (we dont need no rejected action). we
just check every hour, as in the original code.
- open links directly from Qt
- rename some global variables to make them less cryptic
- move cleanup function to the same module that created them
Diffstat (limited to 'pkg/backend/callbacks.go')
-rw-r--r-- | pkg/backend/callbacks.go | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/pkg/backend/callbacks.go b/pkg/backend/callbacks.go index f3bb39f..5fb8642 100644 --- a/pkg/backend/callbacks.go +++ b/pkg/backend/callbacks.go @@ -19,11 +19,11 @@ import ( // } import "C" -/* callbacks into C-land */ +/* callbacks into C-land. We keep a registry, and protect its updates with a mutex. */ + +var callbacks = make(map[string](*[0]byte)) +var callbackMutex sync.Mutex -var mut sync.Mutex -var stmut sync.Mutex -var cbs = make(map[string](*[0]byte)) var initOnce sync.Once // Events are just a enumeration of all the posible events that C functions can @@ -38,23 +38,23 @@ const OnStatusChanged string = "OnStatusChanged" // subscribe registers a callback from C-land. // This callback needs to be passed as a void* C function pointer. func subscribe(event string, fp unsafe.Pointer) { - mut.Lock() - defer mut.Unlock() + callbackMutex.Lock() + defer callbackMutex.Unlock() e := &Events{} v := reflect.Indirect(reflect.ValueOf(&e)) hf := v.Elem().FieldByName(event) if reflect.ValueOf(hf).IsZero() { fmt.Println("ERROR: not a valid event:", event) } else { - cbs[event] = (*[0]byte)(fp) + callbacks[event] = (*[0]byte)(fp) } } // trigger fires a callback from C-land. func trigger(event string) { - mut.Lock() - defer mut.Unlock() - cb := cbs[event] + callbackMutex.Lock() + defer callbackMutex.Unlock() + cb := callbacks[event] if cb != nil { C._do_callback(cb) } else { |