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

## Detailed Description

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

See also
  Message, CallbackMessage, MessageManagerLock, JUCEApplication, JUCEApplicationBase

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

- juce_events/messages/juce_MessageManager.h

## Classes

class | MessageBase
| Internal class used as the base class for all message objects. More...
class | Lock
| A lock you can use to lock the message manager. More...

## Public Member Functions

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

## Static Public Member Functions

static MessageManager * | getInstance ()
| Returns the global instance of the MessageManager.
static MessageManager * | getInstanceWithoutCreating () noexcept
| Returns the global instance of the MessageManager, or nullptr if it doesn't exist.
static void | deleteInstance ()
| Deletes the global MessageManager instance.
template<typename Function>
static bool | callAsync (Function &&function)
| Asynchronously invokes a function or C++11 lambda on the message thread.
template<typename Function>
static auto | callSync (Function &&function) -> CallSyncResult< decltype(function())>
| Similar to callFunctionOnMessageThread(), calls a function on the message thread, blocking the current thread until a result is available.
static bool | existsAndIsLockedByCurrentThread () noexcept
| Returns true if there's an instance of the MessageManager, and if the current thread has the lock on it.
static bool | existsAndIsCurrentThread () noexcept
| Returns true if there's an instance of the MessageManager, and if the current thread is running it.
static void | broadcastMessage (const String &messageText)
| Sends a message to all other JUCE applications that are running.

## Member Functions

## getInstance()

MessageManager * juce::MessageManager::getInstance | ( |  | ) |

static

Returns the global instance of the MessageManager.

Referenced by callSync().

## getInstanceWithoutCreating()

MessageManager * juce::MessageManager::getInstanceWithoutCreating | ( |  | ) |

static noexcept

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

## deleteInstance()

void juce::MessageManager::deleteInstance | ( |  | ) |

static

Deletes the global MessageManager instance.

Does nothing if no instance had been created.

References deleteInstance().

Referenced by deleteInstance().

## 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

References runDispatchLoop().

Referenced by runDispatchLoop().

## 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

References stopDispatchLoop().

Referenced by stopDispatchLoop().

## hasStopMessageBeenSent()

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

inline noexcept

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

References hasStopMessageBeenSent().

Referenced by hasStopMessageBeenSent().

## runDispatchLoopUntil()

bool juce::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.

## callAsync()

template<typename Function>

bool juce::MessageManager::callAsync | ( | Function && | function | ) |

inline static

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

Parameters

  function | the function to call, which should have no arguments

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

Referenced by callSync().

## 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

  callback | the function to call - its signature must be void* myCallbackFunction (void*)
  userData | a user-defined pointer that will be passed to the function that gets called

Returns
  the value that the callback function returns.

See also
  MessageManagerLock

## callSync()

template<typename Function>

auto juce::MessageManager::callSync | ( | Function && | function | ) | ->CallSyncResult< decltype(function())>

inline static

Similar to callFunctionOnMessageThread(), calls a function on the message thread, blocking the current thread until a result is available.

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

  function | the function to call, which should have no parameters

Returns
  if function() returns void, then callSync returns a boolean where 'true' indicates that the function was called successfully, and 'false' indicates that the message could not be posted. if function() returns any other type 'T', then callSync returns std::optional<T>, where the optional value will be valid if the function was called successfully, or nullopt otherwise.

References callAsync(), getInstance(), isThisTheMessageThread(), and jassertfalse.

## isThisTheMessageThread()

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

noexcept

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

Referenced by callSync().

## 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

References setCurrentThreadAsMessageThread().

Referenced by setCurrentThreadAsMessageThread().

## getCurrentMessageThread()

Thread::ThreadID juce::MessageManager::getCurrentMessageThread | ( |  | ) | const

inline noexcept

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

References getCurrentMessageThread().

Referenced by getCurrentMessageThread().

## 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.

## existsAndIsLockedByCurrentThread()

bool juce::MessageManager::existsAndIsLockedByCurrentThread | ( |  | ) |

static noexcept

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

References existsAndIsLockedByCurrentThread().

Referenced by existsAndIsLockedByCurrentThread().

## existsAndIsCurrentThread()

bool juce::MessageManager::existsAndIsCurrentThread | ( |  | ) |

static noexcept

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

References existsAndIsCurrentThread().

Referenced by existsAndIsCurrentThread().

## broadcastMessage()

void juce::MessageManager::broadcastMessage | ( | const String & | messageText | ) |

static

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

Parameters

  messageText | the string that will be passed to the actionListenerCallback() method of the broadcast listeners in the other app.

See also
  registerBroadcastListener, ActionListener

References broadcastMessage().

Referenced by broadcastMessage().

## 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

References registerBroadcastListener().

Referenced by registerBroadcastListener().

## deregisterBroadcastListener()

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

Deregisters a broadcast listener.

References deregisterBroadcastListener().

Referenced by deregisterBroadcastListener().

### Purchase

Get JUCE

### Discover

What's New in JUCE Features

### Learn

Documentaion Tutorials Made with JUCE Resources

### Support

JUCE Forum Newsletter Archive

### About

Contact Us JUCE Legal JUCE Licensing FAQ

### Events

Audio Developer Conference
© Raw Material Software Limited