Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

tmoutlst.cpp

Go to the documentation of this file.
00001 // $Id$
00002 
00003 //**********************************************************************
00004 //                                                                     *
00005 //    Description:   Singleton list to hold instances of Timeout       *
00006 //                   class.                                            *
00007 //                   Provides a method that iterates through list      *
00008 //                   'running' each Timeout.                           *
00009 //                                                                     *
00010 //    Author:        Chris White (whitecf@bcs.org.uk)                  *
00011 //                                                                     *
00012 //    Copyright (C) 2003  Monitor Computing Services Ltd.              *
00013 //                                                                     *
00014 //    This program is free software; you can redistribute it and/or    *
00015 //    modify it under the terms of the GNU General Public License      *
00016 //    as published by the Free Software Foundation; either version 2   *
00017 //    of the License, or any later version.                            *
00018 //                                                                     *
00019 //    This program is distributed in the hope that it will be useful,  *
00020 //    but WITHOUT ANY WARRANTY; without even the implied warranty of   *
00021 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
00022 //    GNU General Public License for more details.                     *
00023 //                                                                     *
00024 //    You should have received a copy of the GNU General Public        *
00025 //    License (http://www.gnu.org/copyleft/gpl.html) along with this   *
00026 //    program; if not, write to:                                       *
00027 //       The Free Software Foundation Inc.,                            *
00028 //       59 Temple Place - Suite 330,                                  *
00029 //       Boston, MA  02111-1307,                                       *
00030 //       USA.                                                          *
00031 //                                                                     *
00032 //**********************************************************************
00033 //                                                                     *
00034 //    Notes:                                                           *
00035 //                                                                     *
00036 //**********************************************************************
00037 
00038 #include <classlib\listimp.h>
00039 #include <strstrea.h>
00040 
00041 #include "mytrace.h"
00042 #include "timeout.h"
00043 
00044 #include "tmoutlst.h"
00045 
00046 
00047 using namespace Monitor::Utility;
00048 
00049 
00050 
00051 void
00052 TimeoutList::addTimeout(Timeout    &newTimeout)
00053 {
00054 #ifdef _DOENTRYTRACE_
00055     {
00056     string    traceString("TimeoutList::addTimeout[");
00057 
00058     traceString += newTimeout.getTimeoutName();
00059     traceString += "]";
00060 
00061     _USEMYTRACE_(traceString.c_str())
00062     }
00063 #endif
00064     getList().Add(&newTimeout);
00065     listSize()++;
00066 
00067 #ifdef _DOENTRYTRACE_
00068     {
00069     string    traceString("TimeoutList::addTimeout[");
00070 
00071     traceString += newTimeout.getTimeoutName();
00072     traceString += "], new size = ";
00073 
00074     strstream    sizeStr;
00075 
00076     sizeStr << size() << '\0';
00077 
00078     traceString += sizeStr.str();
00079 
00080     _USEMYTRACE_(traceString.c_str())
00081     }
00082 #endif
00083 }
00084 
00085 
00086 
00087 void
00088 TimeoutList::removeTimeout(Timeout    &oldTimeout)
00089 {
00090 #ifdef _DOENTRYTRACE_
00091     {
00092     string    traceString("TimeoutList::removeTimeout[");
00093 
00094     traceString += oldTimeout.getTimeoutName();
00095     traceString += "]";
00096 
00097     _USEMYTRACE_(traceString.c_str())
00098     }
00099 #endif
00100     if (getList().Detach(&oldTimeout))
00101     {
00102         listSize()--;
00103     }
00104 
00105 #ifdef _DOENTRYTRACE_
00106     {
00107     string    traceString("TimeoutList::removeTimeout[");
00108 
00109     traceString += oldTimeout.getTimeoutName();
00110     traceString += "], new size = ";
00111 
00112     strstream    sizeStr;
00113 
00114     sizeStr << size() << '\0';
00115 
00116     traceString += sizeStr.str();
00117 
00118     _USEMYTRACE_(traceString.c_str())
00119     }
00120 #endif
00121 }
00122 
00123 
00124 
00125 void
00126 TimeoutList::destroyTimeout(Timeout    &oldTimeout)
00127 {
00128 #ifdef _DOENTRYTRACE_
00129     string    traceString("TimeoutList::destroyTimeout[");
00130 
00131     traceString += oldTimeout.getTimeoutName();
00132     traceString += "]";
00133 
00134     _USEMYTRACE_(traceString.c_str())
00135 #endif
00136     removeTimeout(oldTimeout);
00137     delete &oldTimeout;
00138 }
00139 
00140 
00141 
00142 void
00143 TimeoutList::runTimeouts()
00144 {
00145     if (!getList().IsEmpty())
00146     {
00147         TIListIteratorImp< Timeout >    timeouts(getList());
00148 
00149         while (0 != timeouts.Current())
00150         {
00151             Timeout    *currentTimeout = timeouts.Current();
00152 
00153             timeouts++;
00154 
00155             if (!currentTimeout->run())
00156             {
00157                 destroyTimeout(*currentTimeout);
00158             }
00159         }
00160     }
00161 }
00162 
00163 
00164 
00165 unsigned
00166 TimeoutList::size()
00167 {
00168     return listSize();
00169 }
00170 
00171 
00172 
00173 TIListImp< Timeout >&
00174 TimeoutList::getList()
00175 {
00176     static TIListImp< Timeout >    timeoutList;
00177 
00178     return timeoutList;
00179 }
00180 
00181 
00182 
00183 unsigned&
00184 TimeoutList::listSize()
00185 {
00186     static unsigned    sizeOfList = 0;
00187 
00188     return sizeOfList;
00189 }
00190 

Generated on Wed Oct 29 20:51:59 2003 for Utility BC Common by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002