diff options
Diffstat (limited to 'Swiften/EventLoop/Cocoa/CocoaEventLoop.mm')
-rw-r--r-- | Swiften/EventLoop/Cocoa/CocoaEventLoop.mm | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/Swiften/EventLoop/Cocoa/CocoaEventLoop.mm b/Swiften/EventLoop/Cocoa/CocoaEventLoop.mm index ba73884..88da262 100644 --- a/Swiften/EventLoop/Cocoa/CocoaEventLoop.mm +++ b/Swiften/EventLoop/Cocoa/CocoaEventLoop.mm @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + #include <Swiften/EventLoop/Cocoa/CocoaEventLoop.h> #include <Swiften/EventLoop/Cocoa/CocoaEvent.h> @@ -5,17 +11,33 @@ namespace Swift { -CocoaEventLoop::CocoaEventLoop() { +CocoaEventLoop::CocoaEventLoop() : isEventInCocoaEventLoop_(false) { +} + +CocoaEventLoop::~CocoaEventLoop() { + +} + +void CocoaEventLoop::handleNextCocoaEvent() { + { + boost::recursive_mutex::scoped_lock lock(isEventInCocoaEventLoopMutex_); + isEventInCocoaEventLoop_ = false; + } + handleNextEvent(); } -void CocoaEventLoop::post(const Event& event) { - Event* eventCopy = new Event(event); - CocoaEvent* cocoaEvent = [[CocoaEvent alloc] initWithEvent: eventCopy eventLoop: this]; - [cocoaEvent +void CocoaEventLoop::eventPosted() { + boost::recursive_mutex::scoped_lock lock(isEventInCocoaEventLoopMutex_); + if (!isEventInCocoaEventLoop_) { + isEventInCocoaEventLoop_ = true; + + CocoaEvent* cocoaEvent = [[CocoaEvent alloc] init: this]; + [cocoaEvent performSelectorOnMainThread:@selector(process) withObject: nil waitUntilDone: NO]; - [cocoaEvent release]; + [cocoaEvent release]; + } } } |