Desktop platform jail signal callback support
This commit is contained in:
parent
29d90b651d
commit
327299ddec
|
@ -5,6 +5,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
"github.com/NaySoftware/go-fcm"
|
"github.com/NaySoftware/go-fcm"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
|
@ -14,6 +15,7 @@ import (
|
||||||
"github.com/status-im/status-go/profiling"
|
"github.com/status-im/status-go/profiling"
|
||||||
"github.com/status-im/status-go/sign"
|
"github.com/status-im/status-go/sign"
|
||||||
"gopkg.in/go-playground/validator.v9"
|
"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.
|
// 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) {
|
func AppStateChange(state *C.char) {
|
||||||
statusBackend.AppStateChange(C.GoString(state))
|
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)
|
||||||
|
}
|
||||||
|
|
|
@ -198,7 +198,7 @@ bool StatusServiceSignalEvent(const char *jsonEvent) {
|
||||||
|
|
||||||
#else
|
#else
|
||||||
// ======================================================================================
|
// ======================================================================================
|
||||||
// cgo compilation (for local tests)
|
// cgo compilation (for desktop platforms and local tests)
|
||||||
// ======================================================================================
|
// ======================================================================================
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -206,10 +206,21 @@ bool StatusServiceSignalEvent(const char *jsonEvent) {
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "_cgo_export.h"
|
#include "_cgo_export.h"
|
||||||
|
|
||||||
|
typedef void (*callback)(const char *jsonEvent);
|
||||||
|
callback gCallback = 0;
|
||||||
|
|
||||||
bool StatusServiceSignalEvent(const char *jsonEvent) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetEventCallback(void *cb) {
|
||||||
|
gCallback = (callback)cb;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -4,11 +4,14 @@ package signal
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
extern bool StatusServiceSignalEvent(const char *jsonEvent);
|
extern bool StatusServiceSignalEvent(const char *jsonEvent);
|
||||||
|
extern void SetEventCallback(void *cb);
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
|
@ -82,3 +85,8 @@ func NotifyNode(jsonEvent *C.char) {
|
||||||
func TriggerTestSignal() {
|
func TriggerTestSignal() {
|
||||||
C.StatusServiceSignalEvent(C.CString(`{"answer": 42}`))
|
C.StatusServiceSignalEvent(C.CString(`{"answer": 42}`))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetSignalEventCallback set callback
|
||||||
|
func SetSignalEventCallback(cb unsafe.Pointer) {
|
||||||
|
C.SetEventCallback(cb)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue