UTTask.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_TASK_H_
00026 #define _UT_TASK_H_
00027 
00028 
00029 //==================================================================================================
00030 //=== Project headers
00031 //==================================================================================================
00032 #include "UTLists.h"
00033 
00034 
00035 //==================================================================================================
00036 //=== Forward name declarations
00037 //==================================================================================================
00038 class MessageLoop_t;
00039 class AbstractMessageReceiver_t;
00040 
00041 
00042 //==================================================================================================
00043 //=== Constants
00044 //==================================================================================================
00047 enum quit_response_t
00048 {
00049     eQUIT_allowed,
00050     eQUIT_deferred,
00051     eQUIT_denied
00052 };
00053 
00054 
00055 //==================================================================================================
00056 class UT_EXPORT Task_t
00057 //==================================================================================================
00058 : private BTreeNode_t< Task_t, Task_t* >
00082 {
00083     //----------------------------------------------------------------------------------------------
00084     public:
00085     //----------------------------------------------------------------------------------------------
00086                                         Task_t();
00088 
00089     virtual                             ~Task_t();
00093 
00094     inline int32                        Token() const;
00097 
00098     inline MessageLoop_t*               MessageLoop() const;
00102 
00103     //----------------------------------------------------------------------------------------------
00104     protected:
00105     //----------------------------------------------------------------------------------------------
00106     virtual void                        AddedToMessageLoop(MessageLoop_t* message_loop);
00108     
00109     virtual void                        RemovedFromMessageLoop(MessageLoop_t* message_loop);
00111 
00112     virtual quit_response_t             QuitRequested();
00130 
00131     void                                ResumeQuit();
00137 
00138     void                                CancelQuit();
00142 
00143     virtual void                        Quit();
00150 
00151     //----------------------------------------------------------------------------------------------
00152     private:
00153     //----------------------------------------------------------------------------------------------
00154     inline int                          Compare(Task_t* address) const;
00155     inline                              operator Task_t*() const;
00156 
00157     //----------------------------------------------------------------------------------------------
00158     private:
00159     //----------------------------------------------------------------------------------------------
00160     int32                               m_task_token;
00161     MessageLoop_t*                      m_message_loop;
00162     bool                                m_quit_notified;
00163 
00164     friend class BTreeNode_t< Task_t, Task_t* >;
00165     friend class BTree_t< Task_t, Task_t* >;
00166     friend class MessageLoop_t;
00167 };
00168 
00169 
00170 
00171 
00172 //==================================================================================================
00173 //==================================================================================================
00174 //===
00175 //=== Inline function implementations: class Task_t
00176 //===
00177 //==================================================================================================
00178 //==================================================================================================
00179 inline int32
00180 Task_t::Token() const
00181 {
00182     return m_task_token;
00183 }
00184 
00185 
00186 inline MessageLoop_t*
00187 Task_t::MessageLoop() const
00188 {
00189     return m_message_loop;
00190 }
00191 
00192 
00193 inline int
00194 Task_t::Compare(Task_t* address) const
00195 {
00196     if(this < address)
00197         return -1;
00198     else if(this > address)
00199         return 1;
00200     else
00201         return 0;
00202 }
00203 
00204 
00205 inline
00206 Task_t::operator Task_t*() const
00207 {
00208     return const_cast<Task_t*>(this);
00209 }
00210 
00211 
00212 #endif // _UT_TASK_H_

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