#include <looper.h>
Inheritance diagram for os::Looper:
Public Types | |
typedef std::map<int,Handler*> | handler_map |
Public Methods | |
Looper (const std::string &cName, int nPriority=NORMAL_PRIORITY, int nPortSize=DEFAULT_PORT_SIZE) | |
The looper constructor. More... | |
virtual | ~Looper () |
Looper destructor. More... | |
port_id | GetMsgPort () const |
Obtain the low-level message port used by this looper. More... | |
thread_id | GetThread () const |
Obtain the thread id of the looper thread. More... | |
proc_id | GetProcess () const |
Obtain the process ID of the loopers thread. More... | |
status_t | Lock () |
Lock the looper object. More... | |
status_t | Unlock () |
Unlock the looper. More... | |
int | GetLockCount (void) const |
Obtain the number of locks held on the looper. More... | |
thread_id | GetLockingThread (void) const |
Obtaing the owner of the looper lock. More... | |
bool | IsLocked () const |
Check if the looper lock is owned by the calling thread. More... | |
virtual thread_id | Run () |
Start and unlock the looper. More... | |
int | Wait () const |
status_t | PostMessage (uint32 nCode) |
Deliver a message to the looper. More... | |
status_t | PostMessage (Message *pcMsg) |
Deliver a message to the looper. More... | |
status_t | PostMessage (uint32 cCode, Handler *pcHandler, Handler *pcReplyTo=NULL) |
Deliver a message to the looper. More... | |
status_t | PostMessage (Message *pcMsg, Handler *pcHandler, Handler *pcReplyTo=NULL) |
Deliver a message to the looper. More... | |
void | SpoolMessages () |
Drain the low-level message port. More... | |
Message* | GetCurrentMessage () const |
Obtaine the message currently being processed. More... | |
Message* | DetachCurrentMessage () |
Steal the current message. More... | |
virtual void | DispatchMessage (Message *pcMessage, Handler *pcHandler) |
The loopers message handling callback. More... | |
virtual void | Started () |
Called by the looper thread before entering the message loop. More... | |
virtual bool | Idle () |
Hook called each time the message queue is drained. More... | |
MessageQueue* | GetMessageQueue () const |
Obtain the internal message queue used by the looper. More... | |
virtual bool | OkToQuit () |
Check if it is ok to break the loop. More... | |
virtual void | Quit () |
Unconditionally terminate the looper. More... | |
void | AddTimer (Handler *pcTarget, int nID, bigtime_t nTimeout, bool bOneShot=true) |
Add a timer to the looper. More... | |
bool | RemoveTimer (Handler *pcTarget, int nID) |
Delete a timer. More... | |
const handler_map& | GetHandlerMap () const |
Get the internal handler list. More... | |
void | AddHandler (Handler *pcHandler) |
Add a handler to the looper. More... | |
bool | RemoveHandler (Handler *pcHandler) |
Remove a handler previously added by AddHandler(). More... | |
Handler* | FindHandler (const std::string &cName) const |
Search the looper for a named handler. More... | |
int | GetHandlerCount () const |
Obtain the count of handlers added to this looper. More... | |
void | SetDefaultHandler (Handler *pcHandler) |
Set the default target for incomming messages. More... | |
Handler* | GetDefaultHandler () const |
Obtain the default handler for the looper. More... | |
Friends | |
class | Application |
class | Messenger |
class | NodeMonitor |
|
|
|
The looper constructor. This is the only Looper constructor. It initiates the looper and create the needed message port and message queue, but it does not spawn a new thread. To actually start the message loop you must call Run(). Before the constructor returns it will lock the looper by calling Lock(). This means that before any other threads are able to access it you must call Unlock().
|
|
Looper destructor.
|
|
Add a handler to the looper.
|
|
Add a timer to the looper.
|
|
Steal the current message.
|
|
The loopers message handling callback.
If the message destination however is not fully qualified DispatchMessage() attempts to pass the message on to the Default handler (as set through the Looper::SetDefaultHandler()). If there is no final destination and no default handler, the Looper will handle the message itself by calling its own version of HandleMessage() (The looper is itself a Handler) Not all messages are passed on to a handler. If the message code is M_QUIT the Looper::OkToQuit() member is called instead, and if it return true Looper::Quit() will be called, and the message loop terminated. If you would like to handle certain messages directly by the looper, bypassing the normal scheduling you can overload DispatchMessage() to process messages before they are passed on to any handler. If you do so, you should call the loopers version of DispatchMessage() for each message you don't know how to handle.
Reimplemented in os::Window. |
|
Search the looper for a named handler.
|
|
Obtaine the message currently being processed.
|
|
Obtain the default handler for the looper.
|
|
Obtain the count of handlers added to this looper.
|
|
Get the internal handler list.
|
|
Obtain the number of locks held on the looper.
|
|
Obtaing the owner of the looper lock.
|
|
Obtain the internal message queue used by the looper.
|
|
Obtain the low-level message port used by this looper.
|
|
Obtain the process ID of the loopers thread.
|
|
Obtain the thread id of the looper thread.
|
|
Hook called each time the message queue is drained.
Reimplemented in os_priv::DirKeeper. |
|
Check if the looper lock is owned by the calling thread.
|
|
Lock the looper object.
|
|
Check if it is ok to break the loop.
|
|
Deliver a message to the looper.
|
|
Deliver a message to the looper.
|
|
Deliver a message to the looper.
|
|
Deliver a message to the looper.
|
|
Unconditionally terminate the looper.
|
|
Remove a handler previously added by AddHandler().
|
|
Delete a timer. When creating a timer in repeate mode, you will propably at some time want to get rid of it. This is the way to go.
|
|
Start and unlock the looper.
Reimplemented in os::Application. |
|
Set the default target for incomming messages.
|
|
Drain the low-level message port.
|
|
Called by the looper thread before entering the message loop.
|
|
Unlock the looper.
|
|
|
|
|
|
Reimplemented from os::Handler. |
|
Reimplemented from os::Handler. |