OWLNext 7.0
Borland's Object Windows Library for the modern age
|
TMsgThread implements basic behavior for threads that own message queues, including mutex locking for the queue. More...
#include <owl/msgthred.h>
Public Types | |
enum | TCurrent { Current } |
Public Member Functions | |
TMsgThread (TCurrent) | |
Attaches to the current running thread. | |
virtual int | MessageLoop () |
Retrieves and processes messages from the thread's message queue using PumpWaitingMessages() until BreakMessageLoop becomes true. | |
virtual bool | IdleAction (long idleCount) |
Called each time there are no messages in the queue. | |
virtual bool | ProcessMsg (MSG &msg) |
Called for each message that is pulled from the queue, to perform all translation and dispatching. | |
bool | PumpWaitingMessages () |
The inner message loop. | |
void | FlushQueue () |
Flushes all real messages from the message queue. | |
bool | IsRunning () const |
Is this queue thread running its message loop? | |
Protected Member Functions | |
virtual int | Run () |
Runs this message thread, returns when the message queue quits. | |
virtual void | InitInstance () |
Handles initialization for each executing instance of the message thread. | |
virtual int | TermInstance (int status) |
Handles termination for each executing instance of the message thread. | |
Protected Attributes | |
bool | BreakMessageLoop |
Message loop is broken via WM_QUIT. | |
int | MessageLoopResult |
Return value from message loop. | |
bool | LoopRunning |
Track if the loop is running. | |
TMsgThread implements basic behavior for threads that own message queues, including mutex locking for the queue.
This class provides message queue oriented thread class support. TMsgThread degenerates to a simple message queue owner under non-threaded environments.
Definition at line 44 of file msgthred.h.
Enumerator | |
---|---|
Current |
Definition at line 47 of file msgthred.h.
owl::TMsgThread::TMsgThread | ( | TCurrent | ) |
Attaches to the current running thread.
This is often the initial process thread, or even the only thread for non-threaded systems.
Definition at line 28 of file msgthred.cpp.
void owl::TMsgThread::FlushQueue | ( | ) |
Flushes all real messages from the message queue.
Definition at line 147 of file msgthred.cpp.
Called each time there are no messages in the queue.
Idle count is incremented each time, and zeroed when messages are pumped. Returns whether or not more processing needs to be done.
Reimplemented in owl::TApplication.
Definition at line 91 of file msgthred.cpp.
References TRACEX.
|
protectedvirtual |
Handles initialization for each executing instance of the message thread.
Derived classes can override this to perform initialization for each instance.
Reimplemented in owl::TApplication.
Definition at line 189 of file msgthred.cpp.
References TRACEX.
|
inline |
Is this queue thread running its message loop?
Returns true if this queue thread is running its message loop.
Definition at line 139 of file msgthred.h.
|
virtual |
Retrieves and processes messages from the thread's message queue using PumpWaitingMessages() until BreakMessageLoop becomes true.
Catches exceptions to post a quit message and cleanup before resuming.
Calls IdleAction() when there are no messages
Reimplemented in owl::TApplication.
Definition at line 61 of file msgthred.cpp.
References BreakMessageLoop, IdleAction(), MessageLoopResult, and PumpWaitingMessages().
Called for each message that is pulled from the queue, to perform all translation and dispatching.
Returns true to drop out of the pump.
Reimplemented in owl::TApplication.
Definition at line 106 of file msgthred.cpp.
bool owl::TMsgThread::PumpWaitingMessages | ( | ) |
The inner message loop.
Retrieves and processes messages from the OWL application's message queue until it is empty. Sets BreakMessageLoop if a WM_QUIT passes through. Calls ProcessAppMsg for each message to allow special pre-handling.
Definition at line 123 of file msgthred.cpp.
References BreakMessageLoop, MessageLoopResult, and ProcessMsg().
|
protectedvirtual |
Runs this message thread, returns when the message queue quits.
Initializes instances. Runs the thread's message loop. Each of the virtual functions called are expected to throw an exception if there is an error. Exceptions that are not handled, that is, where the status remains non-zero, are propagated out of this function. The message queue is still flushed and TermInstance called.
Reimplemented in owl::TApplication.
Definition at line 164 of file msgthred.cpp.
References FlushQueue(), InitInstance(), LoopRunning, MessageLoop(), and TermInstance().
Handles termination for each executing instance of the message thread.
Called at the end of a Run() with the final return status.
Reimplemented in owl::TApplication.
Definition at line 202 of file msgthred.cpp.
References TRACEX.
|
protected |
Message loop is broken via WM_QUIT.
Definition at line 106 of file msgthred.h.
|
protected |
Track if the loop is running.
Definition at line 110 of file msgthred.h.
|
protected |
Return value from message loop.
Definition at line 107 of file msgthred.h.