UTMessage.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_H_
00026 #define _UT_MESSAGE_H_
00027 
00028 
00029 //==================================================================================================
00030 //=== Project headers
00031 //==================================================================================================
00032 #include "UTMessageDestination.h"
00033 #include "UTPoolAllocator.h"
00034 
00035 
00036 //==================================================================================================
00037 //=== Forward name declarations
00038 //==================================================================================================
00039 class Buffer_t;
00040 
00041 
00042 //==================================================================================================
00043 class UT_EXPORT Message_t
00044 //==================================================================================================
00049 {
00050     //----------------------------------------------------------------------------------------------
00051     public:
00052     //----------------------------------------------------------------------------------------------
00053                                     Message_t();
00055 
00056     virtual                         ~Message_t();
00058 
00059     virtual gives Message_t*        Clone() const;
00061 
00062     void                            Flatten(out Buffer_t* buffer) const;
00064 
00065     virtual int                     FlattenContents(out byte* buffer) const;
00074 
00075     virtual int                     FlattenedContentsSize() const;
00081 
00082     // \cond DOXYGEN_DOCUMENT_NEVER
00083     inline void*                    operator new(size_t size);
00084     inline void                     operator delete(void* block);
00085     // \endcond
00086 
00087     //----------------------------------------------------------------------------------------------
00088     private:
00089     //----------------------------------------------------------------------------------------------
00090     void                            SetDestination(const AbstractMessageDestination_t& destination);
00091 
00092     //----------------------------------------------------------------------------------------------
00093     private:
00094     //----------------------------------------------------------------------------------------------
00095     AbstractMessageDestination_t    m_destination;
00096 
00097     // Message queue could be a LinkedList_t, but we don't need all that state, and this allows the
00098     // minimum amount of list mutex protection.
00099     Message_t* volatile             m_next;
00100 
00101     static PoolAllocator_t          ms_message_block_pool;
00102 
00103     friend class AbstractMessageDestination_t;
00104     friend class MessageLoop_t;
00105     friend class App_t;
00106     friend class AppPlatformInfo_t;
00107 };
00108 
00109 
00110 
00111 
00112 //==================================================================================================
00113 //==================================================================================================
00114 //===
00115 //=== Inline function implementations
00116 //===
00117 //==================================================================================================
00118 //==================================================================================================
00119 
00120 // \cond DOXYGEN_DOCUMENT_NEVER
00121 
00122 
00123 inline void*
00124 Message_t::operator new(size_t size)
00125 {
00126     return ms_message_block_pool.Allocate(size);
00127 }
00128 
00129 
00130 inline void
00131 Message_t::operator delete(void* block)
00132 {
00133     ms_message_block_pool.Release(block);
00134 }
00135 
00136 
00137 // \endcond
00138 
00139 #endif // _UT_MESSAGE_H_

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