From 95fc7706a8cf866b6ca53ada15e33dea241a2613 Mon Sep 17 00:00:00 2001 From: Victor Farazdagi Date: Mon, 17 Oct 2016 15:29:00 +0300 Subject: [PATCH] Add iOS-related code to signals.c #37 --- geth/ios.go | 12 ++++++++++++ geth/signals.c | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 geth/ios.go diff --git a/geth/ios.go b/geth/ios.go new file mode 100644 index 00000000000..c8bd4f5e68e --- /dev/null +++ b/geth/ios.go @@ -0,0 +1,12 @@ +// +build darwin,cgo + +package geth + +/* +#cgo CFLAGS: -x objective-c +#cgo LDFLAGS: -framework Foundation +#include +#include +extern bool StatusServiceSignalEvent( const char *jsonEvent ); +*/ +import "C" diff --git a/geth/signals.c b/geth/signals.c index cb9a7c7e9c5..c06ccb54ced 100644 --- a/geth/signals.c +++ b/geth/signals.c @@ -5,10 +5,43 @@ #include #include +#include +#include +#include +#include + +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 - return true; + if (!initLibrary()) return false; + + objc_msgSend(statusServiceClassRef, statusServiceSelector, jsonEvent); + + return true; } #elif defined(ANDROID_DEPLOYMENT)