LMMS
Loading...
Searching...
No Matches
juce_osx_MessageQueue.h
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25
26//==============================================================================
27/* An internal message pump class used in OSX and iOS. */
29{
30public:
32 {
33 #if JUCE_IOS
34 runLoop = CFRunLoopGetCurrent();
35 #else
36 runLoop = CFRunLoopGetMain();
37 #endif
38
39 CFRunLoopSourceContext sourceContext;
40 zerostruct (sourceContext); // (can't use "= { 0 }" on this object because it's typedef'ed as a C struct)
41 sourceContext.info = this;
42 sourceContext.perform = runLoopSourceCallback;
43 runLoopSource.reset (CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext));
44 CFRunLoopAddSource (runLoop, runLoopSource.get(), kCFRunLoopCommonModes);
45 }
46
48 {
49 CFRunLoopRemoveSource (runLoop, runLoopSource.get(), kCFRunLoopCommonModes);
50 CFRunLoopSourceInvalidate (runLoopSource.get());
51 }
52
54 {
55 messages.add (message);
56 wakeUp();
57 }
58
59private:
61 CFRunLoopRef runLoop;
63
65 {
66 CFRunLoopSourceSignal (runLoopSource.get());
67 CFRunLoopWakeUp (runLoop);
68 }
69
71 {
72 const MessageManager::MessageBase::Ptr nextMessage (messages.removeAndReturn (0));
73
74 if (nextMessage == nullptr)
75 return false;
76
78 {
80 {
81 nextMessage->messageCallback();
82 }
84 }
85
86 return true;
87 }
88
90 {
91 for (int i = 4; --i >= 0;)
92 if (! deliverNextMessage())
93 return;
94
95 wakeUp();
96 }
97
98 static void runLoopSourceCallback (void* info) noexcept
99 {
100 static_cast<MessageQueue*> (info)->runLoopCallback();
101 }
102};
103
104} // namespace juce
#define noexcept
Definition DistrhoDefines.h:72
static void message(int level, const char *fmt,...)
Definition adplugdb.cpp:120
Definition juce_MessageManager.h:182
ReferenceCountedObjectPtr< MessageBase > Ptr
Definition juce_MessageManager.h:190
CFUniquePtr< CFRunLoopSourceRef > runLoopSource
Definition juce_osx_MessageQueue.h:62
ReferenceCountedArray< MessageManager::MessageBase, CriticalSection > messages
Definition juce_osx_MessageQueue.h:60
~MessageQueue() noexcept
Definition juce_osx_MessageQueue.h:47
void post(MessageManager::MessageBase *const message)
Definition juce_osx_MessageQueue.h:53
bool deliverNextMessage()
Definition juce_osx_MessageQueue.h:70
static void runLoopSourceCallback(void *info) noexcept
Definition juce_osx_MessageQueue.h:98
CFRunLoopRef runLoop
Definition juce_osx_MessageQueue.h:61
MessageQueue()
Definition juce_osx_MessageQueue.h:31
void wakeUp() noexcept
Definition juce_osx_MessageQueue.h:64
void runLoopCallback() noexcept
Definition juce_osx_MessageQueue.h:89
Definition juce_ReferenceCountedArray.h:51
register unsigned i
Definition inflate.c:1575
struct backing_store_struct * info
Definition jmemsys.h:183
#define JUCE_TRY
Definition juce_ApplicationBase.h:329
#define JUCE_CATCH_EXCEPTION
Definition juce_ApplicationBase.h:330
#define JUCE_AUTORELEASEPOOL
Definition juce_Memory.h:158
Definition carla_juce.cpp:31
void zerostruct(Type &structure) noexcept
Definition juce_Memory.h:32
std::unique_ptr< typename std::remove_pointer< CFType >::type, CFObjectDeleter< CFType > > CFUniquePtr
Definition juce_mac_CFHelpers.h:40