![]() |
Murl Engine API
Version 2025.1
|
The MessageThread class implements a thread with a ready to use MessageQueue and MessageDispatch class. More...
#include <murl_util_message_thread.h>
The MessageThread class implements a thread with a ready to use MessageQueue and MessageDispatch class.
Example for sending data to different methods:
Public Member Functions | |
| MessageThread () | |
| The default constructor. | |
| MessageThread (const String &name) | |
| Constructor taking a thread name. More... | |
| ~MessageThread () override | |
| The destructor. More... | |
| Bool | Start () override |
| Create and start the thread. More... | |
| virtual Bool | Start (const System::Time &timeout) |
| Create and start the thread, run the message loop with timeout. More... | |
| void | Stop () override |
| Stop the thread. More... | |
| void | SetTimeout (const System::Time &timeout) |
| Set the message loop timeout. More... | |
| const System::Time & | GetTimeout () const |
| Get the message loop timeout. More... | |
| MessageQueue & | GetMessageQueue () |
| Get the thread's message queue object. More... | |
| MessageDispatch & | GetMessageDispatch () |
| Get the thread's message dispatch object. More... | |
| virtual Bool | SendQuit () |
| Send the ID_QUIT message to the thread. More... | |
| virtual Bool | SendId (UInt32 messageId) |
| Send the Message object to the thread. More... | |
| virtual Bool | SendMessage (Message::AutoPtr message) |
| Send a message object to the thread. More... | |
| virtual Bool | SendSyncMessage (Message::AutoPtr message) |
| Send a message object to the thread and wait until the message is delivered and processed. More... | |
Public Member Functions inherited from Murl::System::Thread | |
| virtual | ~Thread () |
| The destructor. | |
| virtual void | Join () |
| Join and destroy the thread. More... | |
| virtual void | Flush () |
| Flush the autorelease memory pool. More... | |
| virtual UInt64 | GetId () |
| Get the thread identifier. More... | |
Protected Member Functions | |
| virtual MessageQueue::Result | WaitMessage (Message::AutoPtr &message) |
| Wait for a message (using Message::ID_ANY). More... | |
| virtual MessageQueue::Result | WaitMessage (Message::AutoPtr &message, const System::Time &timeout) |
| Wait for a message with timeout (using Message::ID_ANY). More... | |
| virtual MessageQueue::Result | GetMessage (Message::AutoPtr &message) |
| Get a message from the message queue (using Message::ID_ANY). More... | |
| virtual MessageQueue::Result | PeekMessage (const Message *&message) |
| Peek a message from the message queue (using Message::ID_ANY). More... | |
| Bool | Run () override |
| The System::Thread::Run() method implementation. More... | |
| virtual MessageQueue::Result | DispatchMessage (Message::AutoPtr &message) |
| Wait for a message and dispatch the message. More... | |
| virtual MessageQueue::Result | DispatchMessage (Message::AutoPtr &message, const System::Time &timeout) |
| Wait for a message and dispatch the message with timeout. More... | |
Protected Member Functions inherited from Murl::System::Thread | |
| Thread (const String &name) | |
| Constructor taking a thread name. More... | |
Protected Attributes | |
| MessageQueue | mMessageQueue |
| The message queue instance. | |
| MessageDispatch | mMessageDispatch |
| The message dispatch instance. | |
| System::Time | mTimeout |
| The message loop timeout. | |
Protected Attributes inherited from Murl::System::Thread | |
| Bool | mIsRunning |
| The running state of the thread. | |
| String | mName |
| The name of the thread. | |
| UInt64 | mThreadId |
| The identifier of the thread. | |
| ThreadHandle * | mHandle |
| The anonymous thread handle for internal use only. | |
Additional Inherited Members | |
Public Types inherited from Murl::System::Thread | |
| enum | SchedulingPriority { SCHEDULING_PRIORITY_LOWEST, SCHEDULING_PRIORITY_NORMAL, SCHEDULING_PRIORITY_HIGHEST } |
| Thread scheduling priority enumeration. More... | |
| enum | SchedulingPolicy { SCHEDULING_POLICY_OTHER, SCHEDULING_POLICY_FIFO, SCHEDULING_POLICY_ROUND_ROBIN } |
| Thread scheduling policy enumeration. More... | |
Static Public Member Functions inherited from Murl::System::Thread | |
| static Bool | SetCurrentPriority (SchedulingPriority priority, SchedulingPolicy policy=SCHEDULING_POLICY_OTHER) |
| Set the current thread's priority and scheduling policy. More... | |
| static Bool | SetCurrentAffinityMask (UInt32 mask) |
| Set the current thread's CPU affinity mask. More... | |
| static UInt64 | GetCurrentId () |
| Get the current thread identifier. More... | |
| Murl::Util::MessageThread::MessageThread | ( | const String & | name | ) |
Constructor taking a thread name.
| name | The thread name. |
|
override |
The destructor.
Calls Stop() and System::Thread::Join().
|
overridevirtual |
Create and start the thread.
Reimplemented from Murl::System::Thread.
|
virtual |
Create and start the thread, run the message loop with timeout.
If a timeout occurs the message dispatcher timeout method is called which executes the MessageDispatch::RegisterTimeout() callback object.
| timeout | The maximum time to wait for messages. |
|
overridevirtual |
Stop the thread.
Calls SendQuit() and System::Thread::Stop().
Reimplemented from Murl::System::Thread.
| void Murl::Util::MessageThread::SetTimeout | ( | const System::Time & | timeout | ) |
Set the message loop timeout.
| timeout | The maximum time to wait for messages. |
| const System::Time& Murl::Util::MessageThread::GetTimeout | ( | ) | const |
Get the message loop timeout.
| MessageQueue& Murl::Util::MessageThread::GetMessageQueue | ( | ) |
Get the thread's message queue object.
| MessageDispatch& Murl::Util::MessageThread::GetMessageDispatch | ( | ) |
Get the thread's message dispatch object.
|
virtual |
Send the ID_QUIT message to the thread.
Send the Message object to the thread.
| messageId | The message identifier to send. |
|
virtual |
Send a message object to the thread.
| message | The message object to send. |
|
virtual |
Send a message object to the thread and wait until the message is delivered and processed.
If this method is called from it's own thread context the message is dispatched immediately.
| message | The message object to send. |
|
protectedvirtual |
Wait for a message (using Message::ID_ANY).
| message | The message return value. The message returned is removed from the message queue. |
|
protectedvirtual |
Wait for a message with timeout (using Message::ID_ANY).
| message | The message return value. The message returned is removed from the message queue. |
| timeout | The maximum time to wait. |
|
protectedvirtual |
Get a message from the message queue (using Message::ID_ANY).
| message | The message return value. The message returned is removed from the message queue. |
|
protectedvirtual |
Peek a message from the message queue (using Message::ID_ANY).
Checks if a message is in the message queue but does not remove the message from the message queue.
| message | The message return value. |
|
overrideprotectedvirtual |
The System::Thread::Run() method implementation.
Implements the message loop:
Implements Murl::System::Thread.
|
protectedvirtual |
Wait for a message and dispatch the message.
| message | The message return value. |
|
protectedvirtual |
Wait for a message and dispatch the message with timeout.
| message | The message return value. |
| timeout | The maximum time to wait. |