#include <Handler.h>
#include <Looper.h>
#include "MessageEvent.h"
\brief A special event that sends a message when executed.
The constructors set the "auto delete" flag to \c true by default. It can
be changed by SetAutoDelete(), but note, that the object's creator is
responsible for its destruction then.
*/
\brief Message to be sent.
*/
\brief Message target.
Valid only, if \a fHandler is \c NULL.
*/
\brief Message target.
May be \c NULL, then \a fMessenger specifies the message target.
*/
command.
\note The supplied BHandler must be valid the whole life time of the
MessageEvent.
\param time The time at which the message shall be sent.
\param handler The BHandler to which the message shall be delivered.
\param command The "what" field of the message to be sent.
*/
MessageEvent::MessageEvent(bigtime_t time, BHandler* handler, uint32 command)
: Event(time, true),
fMessage(command),
fMessenger(),
fHandler(handler)
{
}
The caller retains ownership of the supplied message. It can savely be
deleted after the constructor returns.
\note The supplied BHandler must be valid the whole life time of the
MessageEvent.
\param time The time at which the message shall be sent.
\param handler The BHandler to which the message shall be delivered.
\param message The message to be sent.
*/
MessageEvent::MessageEvent(bigtime_t time, BHandler* handler,
const BMessage *message)
: Event(time, true),
fMessage(*message),
fMessenger(),
fHandler(handler)
{
}
command.
\param time The time at which the message shall be sent.
\param messenger The BMessenger specifying the target to which the message
shall be delivered.
\param command The "what" field of the message to be sent.
*/
MessageEvent::MessageEvent(bigtime_t time, const BMessenger& messenger,
uint32 command)
: Event(time, true),
fMessage(command),
fMessenger(messenger),
fHandler(NULL)
{
}
The caller retains ownership of the supplied message. It can savely be
deleted after the constructor returns.
\param time The time at which the message shall be sent.
\param messenger The BMessenger specifying the target to which the message
shall be delivered.
\param message The message to be sent.
*/
MessageEvent::MessageEvent(bigtime_t time, const BMessenger& messenger,
const BMessage *message)
: Event(time, true),
fMessage(*message),
fMessenger(messenger),
fHandler(NULL)
{
}
*/
MessageEvent::~MessageEvent()
{
}
Implements Event. Delivers the message to the target.
\param queue The event queue executing the event.
\return \c true, if the object shall be deleted, \c false otherwise.
*/
bool
MessageEvent::Do(EventQueue *queue)
{
if (fHandler) {
if (BLooper* looper = fHandler->Looper())
looper->PostMessage(&fMessage, fHandler);
} else
fMessenger.SendMessage(&fMessage);
return false;
}