openshot-audio  0.1.6
juce_MessageManager.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_MESSAGEMANAGER_H_INCLUDED
26 #define JUCE_MESSAGEMANAGER_H_INCLUDED
27 
28 class MessageManagerLock;
29 class ThreadPoolJob;
30 class ActionListener;
31 class ActionBroadcaster;
32 
33 
34 //==============================================================================
37 typedef void* (MessageCallbackFunction) (void* userData);
38 
39 
40 //==============================================================================
47 {
48 public:
49  //==============================================================================
51  static MessageManager* getInstance();
52 
54  static MessageManager* getInstanceWithoutCreating() noexcept;
55 
59  static void deleteInstance();
60 
61  //==============================================================================
69  void runDispatchLoop();
70 
78  void stopDispatchLoop();
79 
82  bool hasStopMessageBeenSent() const noexcept { return quitMessagePosted; }
83 
84  #if JUCE_MODAL_LOOPS_PERMITTED || DOXYGEN
85 
90  bool runDispatchLoopUntil (int millisecondsToRunFor);
91  #endif
92 
93  //==============================================================================
94  #if JUCE_COMPILER_SUPPORTS_LAMBDAS
95 
98  static void callAsync (std::function<void(void)>);
99  #endif
100 
119  void* callFunctionOnMessageThread (MessageCallbackFunction* callback, void* userData);
120 
122  bool isThisTheMessageThread() const noexcept;
123 
129  void setCurrentThreadAsMessageThread();
130 
136  Thread::ThreadID getCurrentMessageThread() const noexcept { return messageThreadId; }
137 
145  bool currentThreadHasLockedMessageManager() const noexcept;
146 
147  //==============================================================================
154  static void broadcastMessage (const String& messageText);
155 
163  void registerBroadcastListener (ActionListener* listener);
164 
166  void deregisterBroadcastListener (ActionListener* listener);
167 
168  //==============================================================================
174  {
175  public:
176  MessageBase() noexcept {}
177  virtual ~MessageBase() {}
178 
179  virtual void messageCallback() = 0;
180  bool post();
181 
183 
185  };
186 
187  //==============================================================================
188  #ifndef DOXYGEN
189  // Internal methods - do not use!
190  void deliverBroadcastMessage (const String&);
191  ~MessageManager() noexcept;
192  #endif
193 
194 private:
195  //==============================================================================
196  MessageManager() noexcept;
197 
198  static MessageManager* instance;
199 
200  friend class MessageBase;
201  class QuitMessage;
202  friend class QuitMessage;
203  friend class MessageManagerLock;
204 
205  ScopedPointer <ActionBroadcaster> broadcaster;
206  bool quitMessagePosted, quitMessageReceived;
207  Thread::ThreadID messageThreadId;
208  Thread::ThreadID volatile threadWithLock;
209  CriticalSection lockingLock;
210 
211  static bool postMessageToSystemQueue (MessageBase*);
212  static void* exitModalLoopCallback (void*);
213  static void doPlatformSpecificInitialisation();
214  static void doPlatformSpecificShutdown();
215  static bool dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages);
216 
218 };
219 
220 
221 //==============================================================================
253 class JUCE_API MessageManagerLock
254 {
255 public:
256  //==============================================================================
298  MessageManagerLock (Thread* threadToCheckForExitSignal = nullptr);
299 
300  //==============================================================================
306  MessageManagerLock (ThreadPoolJob* jobToCheckForExitSignal);
307 
308 
309  //==============================================================================
315  ~MessageManagerLock() noexcept;
316 
317  //==============================================================================
321  bool lockWasGained() const noexcept { return locked; }
322 
323 private:
327  bool locked;
328 
329  bool attemptLock (Thread*, ThreadPoolJob*);
330 
331  JUCE_DECLARE_NON_COPYABLE (MessageManagerLock)
332 };
333 
334 
335 #endif // JUCE_MESSAGEMANAGER_H_INCLUDED
bool hasStopMessageBeenSent() const noexcept
Definition: juce_MessageManager.h:82
#define noexcept
Definition: juce_CompilerSupport.h:141
Definition: juce_MessageManager.h:173
virtual ~MessageBase()
Definition: juce_MessageManager.h:177
void *( MessageCallbackFunction)(void *userData)
Definition: juce_MessageManager.h:37
Definition: juce_String.h:43
#define JUCE_API
Definition: juce_StandardHeader.h:139
#define const
Definition: juce_ActionBroadcaster.h:37
Definition: juce_ReferenceCountedObject.h:65
Definition: juce_CriticalSection.h:47
Definition: juce_MessageManager.h:253
Definition: juce_ReferenceCountedObject.h:227
Definition: juce_MessageManager.cpp:108
Definition: juce_ScopedPointer.h:70
Definition: juce_ActionListener.h:35
Definition: juce_MessageManager.cpp:266
#define JUCE_DECLARE_NON_COPYABLE(className)
Definition: juce_PlatformDefs.h:191
Definition: juce_Thread.h:47
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
Definition: juce_PlatformDefs.h:198
Definition: juce_ThreadPool.h:50
message messageCallback()
MessageBase() noexcept
Definition: juce_MessageManager.h:176
ReferenceCountedObjectPtr< MessageBase > Ptr
Definition: juce_MessageManager.h:182
bool lockWasGained() const noexcept
Definition: juce_MessageManager.h:321
Definition: juce_MessageManager.h:46