Desktop platform jail signal callback support

This commit is contained in:
Max Risuhin 2018-06-28 02:16:27 +03:00
parent 29d90b651d
commit 327299ddec
No known key found for this signature in database
GPG Key ID: BF733F5ACA0B4448
3 changed files with 29 additions and 2 deletions

View File

@ -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)
}

View File

@ -198,7 +198,7 @@ bool StatusServiceSignalEvent(const char *jsonEvent) {
#else
// ======================================================================================
// cgo compilation (for local tests)
// cgo compilation (for desktop platforms and local tests)
// ======================================================================================
#include <stdio.h>
@ -206,10 +206,21 @@ bool StatusServiceSignalEvent(const char *jsonEvent) {
#include <stdbool.h>
#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

View File

@ -4,11 +4,14 @@ package signal
#include <stddef.h>
#include <stdbool.h>
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)
}