Add iOS-related code to signals.c #37

This commit is contained in:
Victor Farazdagi 2016-10-17 15:29:00 +03:00 committed by Roman Volosovskyi
parent 7c08869ad8
commit 95fc7706a8
2 changed files with 47 additions and 2 deletions

12
geth/ios.go Normal file
View File

@ -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"

View File

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