1 //------------------------------------------------------------------------------
2 // Copyright (c) 2001-2002, OpenBeOS
4 // Permission is hereby granted, free of charge, to any person obtaining a
5 // copy of this software and associated documentation files (the "Software"),
6 // to deal in the Software without restriction, including without limitation
7 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 // and/or sell copies of the Software, and to permit persons to whom the
9 // Software is furnished to do so, subject to the following conditions:
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 // DEALINGS IN THE SOFTWARE.
22 // File Name: MessageEvent.cpp
23 // Author: Ingo Weinhold (bonefish@users.sf.net)
24 // YellowBites (http://www.yellowbites.com)
25 // Description: A special event that sends a message when executed.
26 //------------------------------------------------------------------------------
31 #include "MessageEvent.h"
33 /*! \class MessageEvent
34 \brief A special event that sends a message when executed.
36 The constructors set the "auto delete" flag to \c true by default. It can
37 be changed by SetAutoDelete(), but note, that the object's creator is
38 responsible for its destruction then.
41 /*! \var BMessage MessageEvent::fMessage
42 \brief Message to be sent.
45 /*! \var BMessenger MessageEvent::fMessenger
46 \brief Message target.
48 Valid only, if \a fHandler is \c NULL.
51 /*! \var BHandler *MessageEvent::fHandler
52 \brief Message target.
54 May be \c NULL, then \a fMessenger specifies the message target.
59 /*! \brief Creates a new MessageEvent with a target BHandler and a message
62 \note The supplied BHandler must be valid the whole life time of the
65 \param time The time at which the message shall be sent.
66 \param handler The BHandler to which the message shall be delivered.
67 \param command The "what" field of the message to be sent.
69 MessageEvent::MessageEvent(bigtime_t time
, BHandler
* handler
, uint32 command
)
78 /*! \brief Creates a new MessageEvent with a target BHandler and a message.
80 The caller retains ownership of the supplied message. It can savely be
81 deleted after the constructor returns.
83 \note The supplied BHandler must be valid the whole life time of the
86 \param time The time at which the message shall be sent.
87 \param handler The BHandler to which the message shall be delivered.
88 \param message The message to be sent.
90 MessageEvent::MessageEvent(bigtime_t time
, BHandler
* handler
,
91 const BMessage
*message
)
100 /*! \brief Creates a new MessageEvent with a target BMessenger and a message
102 \param time The time at which the message shall be sent.
103 \param messenger The BMessenger specifying the target to which the message
105 \param command The "what" field of the message to be sent.
107 MessageEvent::MessageEvent(bigtime_t time
, const BMessenger
& messenger
,
111 fMessenger(messenger
),
117 /*! \brief Creates a new MessageEvent with a target BMessenger and a message.
119 The caller retains ownership of the supplied message. It can savely be
120 deleted after the constructor returns.
122 \param time The time at which the message shall be sent.
123 \param messenger The BMessenger specifying the target to which the message
125 \param message The message to be sent.
127 MessageEvent::MessageEvent(bigtime_t time
, const BMessenger
& messenger
,
128 const BMessage
*message
)
131 fMessenger(messenger
),
137 /*! \brief Frees all resources associated with the object.
139 MessageEvent::~MessageEvent()
144 /*! \brief Hook method invoked when the event is executed.
146 Implements Event. Delivers the message to the target.
148 \param queue The event queue executing the event.
149 \return \c true, if the object shall be deleted, \c false otherwise.
152 MessageEvent::Do(EventQueue
*queue
)
155 if (BLooper
* looper
= fHandler
->Looper())
156 looper
->PostMessage(&fMessage
, fHandler
);
158 fMessenger
.SendMessage(&fMessage
);