diff --git a/lib/library.go b/lib/library.go index 5c02584f3..0aa8b88c0 100644 --- a/lib/library.go +++ b/lib/library.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "os" + "unsafe" "github.com/NaySoftware/go-fcm" "github.com/ethereum/go-ethereum/log" @@ -14,6 +15,7 @@ import ( "github.com/status-im/status-go/profiling" "github.com/status-im/status-go/sign" "gopkg.in/go-playground/validator.v9" + "github.com/status-im/status-go/signal" ) // All general log messages in this package should be routed through this logger. @@ -484,3 +486,9 @@ func ConnectionChange(typ *C.char, expensive C.int) { func AppStateChange(state *C.char) { statusBackend.AppStateChange(C.GoString(state)) } + +// SetSignalEventCallback setup geth callback to notify about new jail signal +//export SetSignalEventCallback +func SetSignalEventCallback(cb unsafe.Pointer) { + signal.SetSignalEventCallback(cb) +} diff --git a/signal/signals.c b/signal/signals.c index 123a427a4..788fb3645 100644 --- a/signal/signals.c +++ b/signal/signals.c @@ -198,7 +198,7 @@ bool StatusServiceSignalEvent(const char *jsonEvent) { #else // ====================================================================================== -// cgo compilation (for local tests) +// cgo compilation (for desktop platforms and local tests) // ====================================================================================== #include @@ -206,10 +206,21 @@ bool StatusServiceSignalEvent(const char *jsonEvent) { #include #include "_cgo_export.h" +typedef void (*callback)(const char *jsonEvent); +callback gCallback = 0; + bool StatusServiceSignalEvent(const char *jsonEvent) { - NotifyNode((char *)jsonEvent); // re-send notification back to status node + if (gCallback) { + gCallback(jsonEvent); + } else { + NotifyNode((char *)jsonEvent); // re-send notification back to status node + } return true; } +void SetEventCallback(void *cb) { + gCallback = (callback)cb; +} + #endif diff --git a/signal/signals.go b/signal/signals.go index 4135274a2..a8fdf79b0 100644 --- a/signal/signals.go +++ b/signal/signals.go @@ -4,11 +4,14 @@ package signal #include #include extern bool StatusServiceSignalEvent(const char *jsonEvent); +extern void SetEventCallback(void *cb); */ import "C" import ( "encoding/json" + "unsafe" + "sync" "github.com/ethereum/go-ethereum/log" @@ -82,3 +85,8 @@ func NotifyNode(jsonEvent *C.char) { func TriggerTestSignal() { C.StatusServiceSignalEvent(C.CString(`{"answer": 42}`)) } + +// SetSignalEventCallback set callback +func SetSignalEventCallback(cb unsafe.Pointer) { + C.SetEventCallback(cb) +}