aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental/iOSSampleApp/SkIOSNotifier.mm
diff options
context:
space:
mode:
Diffstat (limited to 'experimental/iOSSampleApp/SkIOSNotifier.mm')
-rw-r--r--experimental/iOSSampleApp/SkIOSNotifier.mm55
1 files changed, 55 insertions, 0 deletions
diff --git a/experimental/iOSSampleApp/SkIOSNotifier.mm b/experimental/iOSSampleApp/SkIOSNotifier.mm
new file mode 100644
index 0000000000..92c89d2760
--- /dev/null
+++ b/experimental/iOSSampleApp/SkIOSNotifier.mm
@@ -0,0 +1,55 @@
+#import "SkIOSNotifier.h"
+#import "SkEvent.h"
+#define SkEventClass @"SkEvenClass"
+@implementation SkIOSNotifier
+- (id)init {
+ self = [super init];
+ if (self) {
+ //Register as an observer for SkEventClass events and call
+ //receiveSkEvent: upon receiving the event
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(receiveSkEvent:)
+ name:SkEventClass object:nil];
+
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
+ [super dealloc];
+}
+
+-(BOOL) acceptsFirstResponder {
+ return YES;
+}
+
+-(void) receiveSkEvent:(NSNotification *)notification {
+ if(SkEvent::ProcessEvent())
+ SkEvent::SignalNonEmptyQueue();
+}
+
++(void) postTimedEvent:(NSTimeInterval)ti {
+ [NSTimer scheduledTimerWithTimeInterval:ti target:self
+ selector:@selector(timerFireMethod:)
+ userInfo:nil repeats:NO];
+}
+
++(void) timerFireMethod:(NSTimer*)theTimer {
+ SkEvent::ServiceQueueTimer();
+}
+@end
+////////////////////////////////////////////////////////////////////////////////
+void SkEvent::SignalNonEmptyQueue() {
+ //post a SkEventClass event to the default notification center
+ [[NSNotificationCenter defaultCenter] postNotificationName:SkEventClass
+ object:nil];
+}
+
+void SkEvent::SignalQueueTimer(SkMSec delay) {
+ if (delay) {
+ //Convert to seconds
+ NSTimeInterval ti = delay/(float)SK_MSec1;
+ [SkIOSNotifier postTimedEvent:ti];
+ }
+} \ No newline at end of file