Add iOS-related code to signals.c #37
This commit is contained in:
parent
7c08869ad8
commit
95fc7706a8
|
@ -0,0 +1,12 @@
|
|||
// +build darwin,cgo
|
||||
|
||||
package geth
|
||||
|
||||
/*
|
||||
#cgo CFLAGS: -x objective-c
|
||||
#cgo LDFLAGS: -framework Foundation
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
extern bool StatusServiceSignalEvent( const char *jsonEvent );
|
||||
*/
|
||||
import "C"
|
|
@ -5,9 +5,42 @@
|
|||
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <objc/objc.h>
|
||||
#include <objc/runtime.h>
|
||||
#include <objc/message.h>
|
||||
|
||||
static id statusServiceClassRef = nil;
|
||||
static SEL statusServiceSelector = nil;
|
||||
|
||||
static bool initLibrary() {
|
||||
if (statusServiceClassRef == nil) {
|
||||
statusServiceClassRef = objc_getClass("Status");
|
||||
if (statusServiceClassRef == nil) return false;
|
||||
}
|
||||
|
||||
if (statusServiceSelector == nil) {
|
||||
statusServiceSelector = sel_getUid("signalEvent:");
|
||||
if (statusServiceSelector == nil) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* @brief Calls static method signalEvent of class GethService.
|
||||
*
|
||||
* @param jsonEvent - UTF8 string
|
||||
*
|
||||
* @note Definition of signalEvent method.
|
||||
* + (void)signalEvent:(const char *)json
|
||||
*/
|
||||
bool StatusServiceSignalEvent(const char *jsonEvent) {
|
||||
// code for sending JSON notification up to iOS app
|
||||
if (!initLibrary()) return false;
|
||||
|
||||
objc_msgSend(statusServiceClassRef, statusServiceSelector, jsonEvent);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue