LMMS
Loading...
Searching...
No Matches
juce::MessageManager Class Referencefinal

#include <juce_MessageManager.h>

Classes

class  MessageBase
class  Lock
class  QuitMessage

Public Member Functions

void runDispatchLoop ()
void stopDispatchLoop ()
bool hasStopMessageBeenSent () const noexcept
voidcallFunctionOnMessageThread (MessageCallbackFunction *callback, void *userData)
bool isThisTheMessageThread () const noexcept
void setCurrentThreadAsMessageThread ()
Thread::ThreadID getCurrentMessageThread () const noexcept
bool currentThreadHasLockedMessageManager () const noexcept
void registerBroadcastListener (ActionListener *listener)
void deregisterBroadcastListener (ActionListener *listener)
void deliverBroadcastMessage (const String &)
 ~MessageManager () noexcept

Static Public Member Functions

static MessageManagergetInstance ()
static MessageManagergetInstanceWithoutCreating () noexcept
static void deleteInstance ()
static bool callAsync (std::function< void()> functionToCall)
static bool existsAndIsLockedByCurrentThread () noexcept
static bool existsAndIsCurrentThread () noexcept
static void broadcastMessage (const String &messageText)

Private Member Functions

 MessageManager () noexcept

Static Private Member Functions

static bool postMessageToSystemQueue (MessageBase *)
static voidexitModalLoopCallback (void *)
static void doPlatformSpecificInitialisation ()
static void doPlatformSpecificShutdown ()

Private Attributes

std::unique_ptr< ActionBroadcasterbroadcaster
Atomic< intquitMessagePosted { 0 }
Atomic< intquitMessageReceived { 0 }
Thread::ThreadID messageThreadId
Atomic< Thread::ThreadIDthreadWithLock

Static Private Attributes

static MessageManagerinstance = nullptr

Friends

class MessageBase
class QuitMessage
class MessageManagerLock

Detailed Description

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

See also
Message, CallbackMessage, MessageManagerLock, JUCEApplication, JUCEApplicationBase

@tags{Events}

Constructor & Destructor Documentation

◆ ~MessageManager()

juce::MessageManager::~MessageManager ( )
noexcept

◆ MessageManager()

juce::MessageManager::MessageManager ( )
privatenoexcept

Member Function Documentation

◆ broadcastMessage()

void juce::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()

bool juce::MessageManager::callAsync ( std::function< void()> functionToCall)
static

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

Returns
true if the message was successfully posted to the message queue, or false otherwise.

◆ callFunctionOnMessageThread()

void * juce::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 juce::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()

void juce::MessageManager::deleteInstance ( )
static

Deletes the global MessageManager instance. Does nothing if no instance had been created.

◆ deliverBroadcastMessage()

void juce::MessageManager::deliverBroadcastMessage ( const String & value)

◆ deregisterBroadcastListener()

void juce::MessageManager::deregisterBroadcastListener ( ActionListener * listener)

Deregisters a broadcast listener.

◆ doPlatformSpecificInitialisation()

void juce::MessageManager::doPlatformSpecificInitialisation ( )
staticprivate

◆ doPlatformSpecificShutdown()

void juce::MessageManager::doPlatformSpecificShutdown ( )
staticprivate

◆ existsAndIsCurrentThread()

bool juce::MessageManager::existsAndIsCurrentThread ( )
staticnoexcept

Returns true if there's an instance of the MessageManager, and if the current thread is running it.

◆ existsAndIsLockedByCurrentThread()

bool juce::MessageManager::existsAndIsLockedByCurrentThread ( )
staticnoexcept

Returns true if there's an instance of the MessageManager, and if the current thread has the lock on it.

◆ exitModalLoopCallback()

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

◆ getCurrentMessageThread()

Thread::ThreadID juce::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()

MessageManager * juce::MessageManager::getInstance ( )
static

Returns the global instance of the MessageManager.

◆ getInstanceWithoutCreating()

MessageManager * juce::MessageManager::getInstanceWithoutCreating ( )
staticnoexcept

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

◆ hasStopMessageBeenSent()

bool juce::MessageManager::hasStopMessageBeenSent ( ) const
inlinenoexcept

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

◆ isThisTheMessageThread()

bool juce::MessageManager::isThisTheMessageThread ( ) const
noexcept

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

◆ postMessageToSystemQueue()

bool juce::MessageManager::postMessageToSystemQueue ( MessageBase * message)
staticprivate

◆ registerBroadcastListener()

void juce::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 juce::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

◆ setCurrentThreadAsMessageThread()

void juce::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 juce::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

◆ MessageBase

friend class MessageBase
friend

◆ MessageManagerLock

friend class MessageManagerLock
friend

◆ QuitMessage

friend class QuitMessage
friend

Member Data Documentation

◆ broadcaster

std::unique_ptr<ActionBroadcaster> juce::MessageManager::broadcaster
private

◆ instance

MessageManager * juce::MessageManager::instance = nullptr
staticprivate

◆ messageThreadId

Thread::ThreadID juce::MessageManager::messageThreadId
private

◆ quitMessagePosted

Atomic<int> juce::MessageManager::quitMessagePosted { 0 }
private

◆ quitMessageReceived

Atomic<int> juce::MessageManager::quitMessageReceived { 0 }
private

◆ threadWithLock

Atomic<Thread::ThreadID> juce::MessageManager::threadWithLock
private

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