JUCE  v5.1.1-3-g1a0b28c73
JUCE API
MessageManager Class Reference

This class is in charge of the application's event-dispatch loop. More...

#include <juce_MessageManager.h>

Collaboration diagram for MessageManager:

Classes

struct  AsyncCallInvoker
 
class  MessageBase
 Internal class used as the base class for all message objects. More...
 

Public Member Functions

void * callFunctionOnMessageThread (MessageCallbackFunction *callback, void *userData)
 Calls a function using the message-thread. More...
 
bool currentThreadHasLockedMessageManager () const noexcept
 Returns true if the caller thread has currently got the message manager locked. More...
 
void deregisterBroadcastListener (ActionListener *listener)
 Deregisters a broadcast listener. More...
 
Thread::ThreadID getCurrentMessageThread () const noexcept
 Returns the ID of the current message thread, as set by setCurrentThreadAsMessageThread(). More...
 
bool hasStopMessageBeenSent () const noexcept
 Returns true if the stopDispatchLoop() method has been called. More...
 
bool isThisTheMessageThread () const noexcept
 Returns true if the caller-thread is the message thread. More...
 
void registerBroadcastListener (ActionListener *listener)
 Registers a listener to get told about broadcast messages. More...
 
void runDispatchLoop ()
 Runs the event dispatch loop until a stop message is posted. More...
 
bool runDispatchLoopUntil (int millisecondsToRunFor)
 Synchronously dispatches messages until a given time has elapsed. More...
 
void setCurrentThreadAsMessageThread ()
 Called to tell the manager that the current thread is the one that's running the dispatch loop. More...
 
void stopDispatchLoop ()
 Sends a signal that the dispatch loop should terminate. More...
 

Static Public Member Functions

static void broadcastMessage (const String &messageText)
 Sends a message to all other JUCE applications that are running. More...
 
template<typename FunctionType >
static void callAsync (FunctionType functionToCall)
 Asynchronously invokes a function or C++11 lambda on the message thread. More...
 
static void deleteInstance ()
 Deletes the global MessageManager instance. More...
 
static MessageManagergetInstance ()
 Returns the global instance of the MessageManager. More...
 
static MessageManagergetInstanceWithoutCreating () noexcept
 Returns the global instance of the MessageManager, or nullptr if it doesn't exist. More...
 

Private Member Functions

 MessageManager () noexcept
 

Static Private Member Functions

static bool dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages)
 
static void doPlatformSpecificInitialisation ()
 
static void doPlatformSpecificShutdown ()
 
static void * exitModalLoopCallback (void *)
 
static bool postMessageToSystemQueue (MessageBase *)
 

Private Attributes

ScopedPointer< ActionBroadcasterbroadcaster
 
CriticalSection lockingLock
 
Thread::ThreadID messageThreadId
 
bool quitMessagePosted = false
 
bool quitMessageReceived = false
 
Thread::ThreadID volatile threadWithLock = {}
 

Static Private Attributes

static MessageManagerinstance
 

Friends

class MessageBase
 
class MessageManagerLock
 
class QuitMessage
 

Detailed Description

This class is in charge of the application's event-dispatch loop.

See also
Message, CallbackMessage, MessageManagerLock, JUCEApplication, JUCEApplicationBase

Constructor & Destructor Documentation

◆ MessageManager()

MessageManager::MessageManager ( )
privatenoexcept

Member Function Documentation

◆ broadcastMessage()

static void MessageManager::broadcastMessage ( const String messageText)
static

Sends a message to all other JUCE applications that are running.

Parameters
messageTextthe string that will be passed to the actionListenerCallback() method of the broadcast listeners in the other app.
See also
registerBroadcastListener, ActionListener

◆ callAsync()

template<typename FunctionType >
static void MessageManager::callAsync ( FunctionType  functionToCall)
inlinestatic

Asynchronously invokes a function or C++11 lambda on the message thread.

◆ callFunctionOnMessageThread()

void* MessageManager::callFunctionOnMessageThread ( MessageCallbackFunction callback,
void *  userData 
)

Calls a function using the message-thread.

This can be used by any thread to cause this function to be called-back by the message thread. If it's the message-thread that's calling this method, then the function will just be called; if another thread is calling, a message will be posted to the queue, and this method will block until that message is delivered, the function is called, and the result is returned.

Be careful not to cause any deadlocks with this! It's easy to do - e.g. if the caller thread has a critical section locked, which an unrelated message callback then tries to lock before the message thread gets round to processing this callback.

Parameters
callbackthe function to call - its signature must be
void* myCallbackFunction (void*)
userDataa user-defined pointer that will be passed to the function that gets called
Returns
the value that the callback function returns.
See also
MessageManagerLock

◆ currentThreadHasLockedMessageManager()

bool MessageManager::currentThreadHasLockedMessageManager ( ) const
noexcept

Returns true if the caller thread has currently got the message manager locked.

see the MessageManagerLock class for more info about this.

This will be true if the caller is the message thread, because that automatically gains a lock while a message is being dispatched.

◆ deleteInstance()

static void MessageManager::deleteInstance ( )
static

Deletes the global MessageManager instance.

Does nothing if no instance had been created.

◆ deregisterBroadcastListener()

void MessageManager::deregisterBroadcastListener ( ActionListener listener)

Deregisters a broadcast listener.

◆ dispatchNextMessageOnSystemQueue()

static bool MessageManager::dispatchNextMessageOnSystemQueue ( bool  returnIfNoPendingMessages)
staticprivate

◆ doPlatformSpecificInitialisation()

static void MessageManager::doPlatformSpecificInitialisation ( )
staticprivate

◆ doPlatformSpecificShutdown()

static void MessageManager::doPlatformSpecificShutdown ( )
staticprivate

◆ exitModalLoopCallback()

static void* MessageManager::exitModalLoopCallback ( void *  )
staticprivate

◆ getCurrentMessageThread()

Thread::ThreadID MessageManager::getCurrentMessageThread ( ) const
inlinenoexcept

Returns the ID of the current message thread, as set by setCurrentThreadAsMessageThread().

(Best to ignore this method unless you really know what you're doing..)

See also
setCurrentThreadAsMessageThread

◆ getInstance()

static MessageManager* MessageManager::getInstance ( )
static

Returns the global instance of the MessageManager.

Referenced by VideoComponent::Pimpl::DirectShowContext::loadFile().

◆ getInstanceWithoutCreating()

static MessageManager* MessageManager::getInstanceWithoutCreating ( )
staticnoexcept

Returns the global instance of the MessageManager, or nullptr if it doesn't exist.

◆ hasStopMessageBeenSent()

bool MessageManager::hasStopMessageBeenSent ( ) const
inlinenoexcept

Returns true if the stopDispatchLoop() method has been called.

◆ isThisTheMessageThread()

bool MessageManager::isThisTheMessageThread ( ) const
noexcept

Returns true if the caller-thread is the message thread.

◆ postMessageToSystemQueue()

static bool MessageManager::postMessageToSystemQueue ( MessageBase )
staticprivate

◆ registerBroadcastListener()

void MessageManager::registerBroadcastListener ( ActionListener listener)

Registers a listener to get told about broadcast messages.

The actionListenerCallback() callback's string parameter is the message passed into broadcastMessage().

See also
broadcastMessage

◆ runDispatchLoop()

void MessageManager::runDispatchLoop ( )

Runs the event dispatch loop until a stop message is posted.

This method is only intended to be run by the application's startup routine, as it blocks, and will only return after the stopDispatchLoop() method has been used.

See also
stopDispatchLoop

◆ runDispatchLoopUntil()

bool MessageManager::runDispatchLoopUntil ( int  millisecondsToRunFor)

Synchronously dispatches messages until a given time has elapsed.

Returns false if a quit message has been posted by a call to stopDispatchLoop(), otherwise returns true.

Referenced by VideoComponent::Pimpl::DirectShowContext::loadFile().

◆ setCurrentThreadAsMessageThread()

void MessageManager::setCurrentThreadAsMessageThread ( )

Called to tell the manager that the current thread is the one that's running the dispatch loop.

(Best to ignore this method unless you really know what you're doing..)

See also
getCurrentMessageThread

◆ stopDispatchLoop()

void MessageManager::stopDispatchLoop ( )

Sends a signal that the dispatch loop should terminate.

After this is called, the runDispatchLoop() or runDispatchLoopUntil() methods will be interrupted and will return.

See also
runDispatchLoop

Friends And Related Function Documentation

◆ MessageBase

friend class MessageBase
friend

◆ MessageManagerLock

friend class MessageManagerLock
friend

◆ QuitMessage

friend class QuitMessage
friend

Member Data Documentation

◆ broadcaster

ScopedPointer<ActionBroadcaster> MessageManager::broadcaster
private

◆ instance

MessageManager* MessageManager::instance
staticprivate

◆ lockingLock

CriticalSection MessageManager::lockingLock
private

◆ messageThreadId

Thread::ThreadID MessageManager::messageThreadId
private

◆ quitMessagePosted

bool MessageManager::quitMessagePosted = false
private

◆ quitMessageReceived

bool MessageManager::quitMessageReceived = false
private

◆ threadWithLock

Thread::ThreadID volatile MessageManager::threadWithLock = {}
private

The documentation for this class was generated from the following file: