openshot-audio  0.1.2
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) 2015 - ROLI Ltd.
6 
7  Permission is granted to use this software under the terms of either:
8  a) the GPL v2 (or any later version)
9  b) the Affero GPL v3
10 
11  Details of these licenses can be found at: www.gnu.org/licenses
12 
13  JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
14  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15  A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 
17  ------------------------------------------------------------------------------
18 
19  To release a closed-source product which uses JUCE, commercial licenses are
20  available: visit www.juce.com for more information.
21 
22  ==============================================================================
23 */
24 
25 #ifndef JUCE_OSX_MESSAGEQUEUE_H_INCLUDED
26 #define JUCE_OSX_MESSAGEQUEUE_H_INCLUDED
27 
28 //==============================================================================
29 /* An internal message pump class used in OSX and iOS. */
31 {
32 public:
34  {
35  #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4 && ! JUCE_IOS
36  runLoop = CFRunLoopGetMain();
37  #else
38  runLoop = CFRunLoopGetCurrent();
39  #endif
40 
41  CFRunLoopSourceContext sourceContext;
42  zerostruct (sourceContext); // (can't use "= { 0 }" on this object because it's typedef'ed as a C struct)
43  sourceContext.info = this;
44  sourceContext.perform = runLoopSourceCallback;
45  runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
46  CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
47  }
48 
50  {
51  CFRunLoopRemoveSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
52  CFRunLoopSourceInvalidate (runLoopSource);
53  CFRelease (runLoopSource);
54  }
55 
56  void post (MessageManager::MessageBase* const message)
57  {
58  messages.add (message);
59  CFRunLoopSourceSignal (runLoopSource);
60  CFRunLoopWakeUp (runLoop);
61  }
62 
63 private:
65  CFRunLoopRef runLoop;
66  CFRunLoopSourceRef runLoopSource;
67 
68  bool deliverNextMessage()
69  {
70  const MessageManager::MessageBase::Ptr nextMessage (messages.removeAndReturn (0));
71 
72  if (nextMessage == nullptr)
73  return false;
74 
76  {
77  JUCE_TRY
78  {
79  nextMessage->messageCallback();
80  }
82  }
83 
84  return true;
85  }
86 
87  void runLoopCallback()
88  {
89  for (int i = 4; --i >= 0;)
90  if (! deliverNextMessage())
91  return;
92 
93  CFRunLoopSourceSignal (runLoopSource);
94  CFRunLoopWakeUp (runLoop);
95  }
96 
97  static void runLoopSourceCallback (void* info)
98  {
99  static_cast <MessageQueue*> (info)->runLoopCallback();
100  }
101 };
102 
103 #endif // JUCE_OSX_MESSAGEQUEUE_H_INCLUDED
Definition: juce_osx_MessageQueue.h:30
void post(MessageManager::MessageBase *const message)
Definition: juce_osx_MessageQueue.h:56
#define JUCE_CATCH_EXCEPTION
Definition: juce_PlatformDefs.h:276
MessageQueue()
Definition: juce_osx_MessageQueue.h:33
#define JUCE_TRY
Definition: juce_PlatformDefs.h:275
Definition: juce_MessageManager.h:173
void zerostruct(Type &structure) noexcept
Definition: juce_Memory.h:38
~MessageQueue()
Definition: juce_osx_MessageQueue.h:49
Definition: juce_ReferenceCountedObject.h:227
#define JUCE_AUTORELEASEPOOL
ObjectClassPtr removeAndReturn(const int indexToRemove)
Definition: juce_ReferenceCountedArray.h:588
added some headers to allow you to turn off FLAC and commented out a couple of unused bits of and which applies just to the files I ve included in this directory For more info
Definition: Flac Licence.txt:12
ObjectClass * add(ObjectClass *const newObject) noexcept
Definition: juce_ReferenceCountedArray.h:321