summaryrefslogtreecommitdiffstats
blob: b8ab621fc5cf7a9926093e7140baf2d70e6d4a50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
 * Copyright (c) 2015-2016 Isode Limited.
 * All rights reserved.
 * See the COPYING file for more information.
 */

#include <Swiften/EventLoop/Cocoa/CocoaEventLoop.h>
#include <Swiften/EventLoop/Cocoa/CocoaEvent.h>

#pragma GCC diagnostic ignored "-Wold-style-cast"

namespace Swift {

CocoaEventLoop::CocoaEventLoop() : isEventInCocoaEventLoop_(false) {
}

CocoaEventLoop::~CocoaEventLoop() {

}

void CocoaEventLoop::handleNextCocoaEvent() {
    {
        std::unique_lock<std::recursive_mutex> lock(isEventInCocoaEventLoopMutex_);
        isEventInCocoaEventLoop_ = false;
    }
    handleNextEvents();
}

void CocoaEventLoop::eventPosted() {
    std::unique_lock<std::recursive_mutex> lock(isEventInCocoaEventLoopMutex_);
    if (!isEventInCocoaEventLoop_) {
        isEventInCocoaEventLoop_ = true;

        CocoaEvent* cocoaEvent = [[CocoaEvent alloc] init: this];
        [cocoaEvent
            performSelectorOnMainThread:@selector(process)
            withObject: nil
            waitUntilDone: NO];
        [cocoaEvent release];
    }
}

}