UTMessageDestination.h

Go to the documentation of this file.
00001 //==================================================================================================
00002 // Copyright (C) 2010  Brian Tietz    sdbtietz at yahoo dot com
00003 //
00004 // This program is free software; you can redistribute it and/or modify it under the terms of the
00005 // GNU General Public License as published by the Free Software Foundation, version 2.0 of the
00006 // License.
00007 //
00008 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
00009 // even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00010 // General Public License for more details.
00011 //
00012 // You should have received a copy of the GNU General Public License along with this program; if
00013 // not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00014 // 02110-1301, USA.
00015 //
00016 // For commercial software, the copyright holder (Brian Tietz, email sdbtietz at yahoo dot com)
00017 // reserves the right and is willing to waive the proprietary source code disclosure aspects of that
00018 // license as applied to the UT library in exchange for either substantial contributions to the
00019 // development of the UT library or other forms of compensation.  Any such waiver must be
00020 // established in writing between the copyright holder and the commercial entity obtaining such a
00021 // waiver.
00022 //==================================================================================================
00023 
00024 
00025 #ifndef _UT_MESSAGE_DESTINATION_H_
00026 #define _UT_MESSAGE_DESTINATION_H_
00027 
00028 
00029 //==================================================================================================
00030 //=== Project headers
00031 //==================================================================================================
00032 #include "UTMessageReceiver.h"
00033 #include "UTLists.h"
00034 
00035 
00036 //==================================================================================================
00037 //=== Forward name declarations
00038 //==================================================================================================
00039 class MessageLoop_t;
00040 
00041 
00042 // \cond DOXYGEN_DOCUMENT_NEVER
00043 //==================================================================================================
00044 class UT_EXPORT AbstractMessageDestination_t
00045 //==================================================================================================
00046 : public LinkedListNode_t<AbstractMessageDestination_t>
00047 {
00048     //----------------------------------------------------------------------------------------------
00049     public:
00050     //----------------------------------------------------------------------------------------------
00051     inline                      AbstractMessageDestination_t();
00052                                 AbstractMessageDestination_t(
00053                                                             MessageLoop_t* message_loop,
00054                                                             Task_t* task,
00055                                                             AbstractMessageReceiver_t* receiver );
00056     inline void                 Set(const AbstractMessageDestination_t& copy);
00057     inline const AbstractMessageDestination_t&
00058                                 operator=(const AbstractMessageDestination_t& copy);
00059     inline bool                 IsValid() const;
00060     inline void                 Invalidate();
00061     inline MessageLoop_t*       MessageLoop() const;
00062 
00063     void                        SendMessage(    const Message_t& message,
00064                                                 const MessageLoop_t* sent_from_context ) const;
00065     void                        SendMessageAsync(takes Message_t* message) const;
00066 
00067     //----------------------------------------------------------------------------------------------
00068     private:
00069     //----------------------------------------------------------------------------------------------
00070     MessageLoop_t*              m_message_loop;
00071     int32                       m_message_loop_token;
00072     Task_t*                     m_task;
00073     int32                       m_task_token;
00074     AbstractMessageReceiver_t*  m_receiver;
00075 
00076     friend class Message_t;
00077     friend class MessageLoop_t;
00078 };
00079 // \endcond
00080 
00083 
00084 
00085 //==================================================================================================
00086 template <class MESSAGE_TYPE>
00087 class MessageDestination_t
00088 //==================================================================================================
00089 : public AbstractMessageDestination_t
00096 {
00097     //----------------------------------------------------------------------------------------------
00098     public:
00099     //----------------------------------------------------------------------------------------------
00100     inline                  MessageDestination_t();
00102 
00103     inline                  MessageDestination_t(   MessageLoop_t* message_loop,
00104                                                     Task_t* task,
00105                                                     MessageTypeReceiver_t<MESSAGE_TYPE>* receiver );
00111 
00112     inline const            MessageDestination_t<MESSAGE_TYPE>&
00113                                         operator =(const MessageDestination_t<MESSAGE_TYPE>& copy);
00115 
00116     inline bool             IsValid() const;
00123 
00124     inline void             Invalidate();
00126 
00127     inline MessageLoop_t*   MessageLoop() const;
00133 
00134     inline void             SendMessage(    const MESSAGE_TYPE& message,
00135                                             const MessageLoop_t* sent_from_context )  const;
00143 
00144     inline void             SendMessageAsync(takes MESSAGE_TYPE* message) const;
00149 
00150     inline void             SendMessageAsync(const MESSAGE_TYPE& message) const;
00153 };
00154 
00155 
00156 
00157 
00158 //==================================================================================================
00159 //==================================================================================================
00160 //===
00161 //=== Inline function implementations: class AbstractMessageDestination_t
00162 //===
00163 //==================================================================================================
00164 //==================================================================================================
00165 
00166 
00167 // \cond DOXYGEN_DOCUMENT_NEVER
00168 
00169 
00170 inline
00171 AbstractMessageDestination_t::AbstractMessageDestination_t()
00172 {
00173     m_message_loop = NULL;
00174     // Don't care about the other info...none of it matters without a message loop.
00175 }
00176 
00177 
00178 inline void
00179 AbstractMessageDestination_t::Set(const AbstractMessageDestination_t& copy)
00180 {
00181     m_message_loop = copy.m_message_loop;
00182     m_message_loop_token = copy.m_message_loop_token;
00183     m_task = copy.m_task;
00184     m_task_token = copy.m_task_token;
00185     m_receiver = copy.m_receiver;
00186 }
00187 
00188 
00189 inline const AbstractMessageDestination_t&
00190 AbstractMessageDestination_t::operator=(const AbstractMessageDestination_t& copy)
00191 {
00192     m_message_loop = copy.m_message_loop;
00193     m_message_loop_token = copy.m_message_loop_token;
00194     m_task = copy.m_task;
00195     m_task_token = copy.m_task_token;
00196     m_receiver = copy.m_receiver;
00197     return *this;
00198 }
00199 
00200 
00201 inline bool
00202 AbstractMessageDestination_t::IsValid() const
00203 {
00204     return (m_message_loop != NULL);
00205     // Don't care about the other info...none of it matters without a message loop.
00206 }
00207 
00208 
00209 inline void
00210 AbstractMessageDestination_t::Invalidate()
00211 {
00212     m_message_loop = NULL;
00213     // Don't care about the other info...none of it matters without a message loop.
00214 }
00215 
00216 
00217 inline MessageLoop_t*
00218 AbstractMessageDestination_t::MessageLoop() const
00219 {
00220     return m_message_loop;
00221 }
00222 
00223 
00224 // \endcond
00225 
00226 
00227 
00228 
00229 //==================================================================================================
00230 //==================================================================================================
00231 //===
00232 //=== Template function implementations: class MessageDestination_t
00233 //===
00234 //==================================================================================================
00235 //==================================================================================================
00236 template <class MESSAGE_TYPE>
00237 inline
00238 MessageDestination_t<MESSAGE_TYPE>::MessageDestination_t()
00239 : AbstractMessageDestination_t()
00240 { }
00241 
00242 
00243 template <class MESSAGE_TYPE>
00244 inline
00245 MessageDestination_t<MESSAGE_TYPE>::MessageDestination_t(
00246                                                     MessageLoop_t* message_loop,
00247                                                     Task_t* task,
00248                                                     MessageTypeReceiver_t<MESSAGE_TYPE>* receiver )
00249 : AbstractMessageDestination_t( message_loop, task, receiver )
00250 { }
00251 
00252 
00253 template <class MESSAGE_TYPE>
00254 inline const MessageDestination_t<MESSAGE_TYPE>&
00255 MessageDestination_t<MESSAGE_TYPE>::operator =(const MessageDestination_t<MESSAGE_TYPE>& copy)
00256 {
00257     Set(copy);
00258     return *this;
00259 }
00260 
00261 
00262 template <class MESSAGE_TYPE>
00263 inline bool
00264 MessageDestination_t<MESSAGE_TYPE>::IsValid() const
00265 {
00266     return AbstractMessageDestination_t::IsValid();
00267 }
00268 
00269 
00270 template <class MESSAGE_TYPE>
00271 inline void
00272 MessageDestination_t<MESSAGE_TYPE>::Invalidate()
00273 {
00274     AbstractMessageDestination_t::Invalidate();
00275 }
00276 
00277 
00278 template <class MESSAGE_TYPE>
00279 inline MessageLoop_t*
00280 MessageDestination_t<MESSAGE_TYPE>::MessageLoop() const
00281 {
00282     return AbstractMessageDestination_t::MessageLoop();
00283 }
00284 
00285 
00286 template <class MESSAGE_TYPE>
00287 inline void
00288 MessageDestination_t<MESSAGE_TYPE>::SendMessage(    const MESSAGE_TYPE& message,
00289                                                     const MessageLoop_t* sent_from_context ) const
00290 {
00291     AbstractMessageDestination_t::SendMessage( message, sent_from_context );
00292 }
00293 
00294 
00295 template <class MESSAGE_TYPE>
00296 inline void
00297 MessageDestination_t<MESSAGE_TYPE>::SendMessageAsync(takes MESSAGE_TYPE* message) const
00298 {
00299     AbstractMessageDestination_t::SendMessageAsync(message);
00300 }
00301 
00302 
00303 template <class MESSAGE_TYPE>
00304 inline void
00305 MessageDestination_t<MESSAGE_TYPE>::SendMessageAsync(const MESSAGE_TYPE& message) const
00306 {
00307     AbstractMessageDestination_t::SendMessageAsync( message.Clone() );
00308 }
00309 
00310 
00311 #endif // _UT_MESSAGE_DESTINATION_H_

Generated on Tue Dec 14 22:35:05 2010 for UT library by  doxygen 1.6.1