00001 /* 00002 * This file is part of openMask © INRIA, CNRS, Universite de Rennes 1 1993-2002, thereinafter the Software 00003 * 00004 * The Software has been developped within the Siames Project. 00005 * INRIA, the University of Rennes 1 and CNRS jointly hold intellectual property rights 00006 * 00007 * The Software has been registered with the Agence pour la Protection des 00008 * Programmes (APP) under registration number IDDN.FR.001.510008.00.S.P.2001.000.41200 00009 * 00010 * This file may be distributed under the terms of the Q Public License 00011 * version 1.0 as defined by Trolltech AS of Norway and appearing in the file 00012 * LICENSE.QPL included in the packaging of this file. 00013 * 00014 * Licensees holding valid specific licenses issued by INRIA, CNRS or Université de Rennes 1 00015 * for the software may use this file in accordance with that specific license 00016 * 00017 */ 00018 #ifndef PsnTimerControleurHEADER 00019 #define PsnTimerControleurHEADER 00020 00021 #include <sys/time.h> 00022 #include <time.h> 00023 00024 #include "PsConfigurationParameterDescriptor.h" 00025 #include "PsSystemEventIdentifier.h" 00026 00043 template <typename ControleurAncetre> 00044 class PsTimerController : public ControleurAncetre 00045 { 00046 public: 00048 PsTimerController(PsObjectDescriptor & initialObjects, 00049 const PsDate & initialDate ); 00050 00052 PsTimerController(PsObjectDescriptor & initialObjects, 00053 const PsDate & initialDate, 00054 int argc, 00055 char * argv []) ; 00056 00058 virtual ~PsTimerController(); 00059 00061 virtual void compute(); 00062 00063 00064 protected : 00065 int _numberOfSamples; 00066 PsDate _startSamplingDate; 00067 PsDate _endSamplingDate; 00068 time_t dateReelleDebut ; 00069 time_t dateReelleFin ; 00070 timeval _dateReelleDebut ; 00071 timeval _dateReelleFin ; 00072 }; // PsnTimerControleur 00073 00074 //-------------------------------------------------------- 00075 00076 template <typename ControleurAncetre> 00077 PsTimerController<ControleurAncetre>::PsTimerController(PsObjectDescriptor & initialObjects, 00078 const PsDate & initialDate) 00079 : ControleurAncetre(initialObjects, initialDate), 00080 _startSamplingDate ( initialDate ), 00081 _endSamplingDate ( initialDate+1000 ) 00082 00083 { 00084 if (getConfigurationParameters() != NULL ) 00085 { 00086 const PsConfigurationParameterDescriptor * param = getConfigurationParameters()->getSubDescriptorByName("TimeFrom") ; 00087 if ( param != NULL ) 00088 { 00089 _startSamplingDate=atoi(param->getAssociatedString().c_str() ) ; 00090 } 00091 00092 param = getConfigurationParameters()->getSubDescriptorByName("TimeUntil") ; 00093 if ( param != NULL ) 00094 { 00095 _endSamplingDate = atoi(param->getAssociatedString().c_str() ) ; 00096 } 00097 } 00098 00099 if (_startSamplingDate>_endSamplingDate) 00100 { 00101 cout<<"PsTimerController< >::WARNING : sampling dates dont make an interval"<<endl; 00102 cout<<"PsTimerController< >::WARNING : default sampling dates used "<<endl; 00103 _startSamplingDate=PsController::initialSimulationDate; 00104 _endSamplingDate=PsController::initialSimulationDate+1000; 00105 } 00106 } 00107 00108 template <typename ControleurAncetre> 00109 PsTimerController<ControleurAncetre>::PsTimerController(PsObjectDescriptor & initialObjects, 00110 const PsDate & initialDate, 00111 int argc, 00112 char * argv []) 00113 : ControleurAncetre(initialObjects, initialDate, argc, argv), 00114 _startSamplingDate ( initialDate ), 00115 _endSamplingDate ( initialDate+1000 ) 00116 00117 { 00118 if (getConfigurationParameters() != NULL ) 00119 { 00120 const PsConfigurationParameterDescriptor * param = getConfigurationParameters()->getSubDescriptorByName("TimeFrom") ; 00121 if ( param != NULL ) 00122 { 00123 _startSamplingDate=atoi(param->getAssociatedString().c_str() ) ; 00124 } 00125 00126 param = getConfigurationParameters()->getSubDescriptorByName("TimeUntil") ; 00127 if ( param != NULL ) 00128 { 00129 _endSamplingDate = atoi(param->getAssociatedString().c_str() ) ; 00130 } 00131 } 00132 00133 if (_startSamplingDate>_endSamplingDate) 00134 { 00135 cout<<"PsTimerController< >::WARNING : sampling dates dont make an interval"<<endl; 00136 cout<<"PsTimerController< >::WARNING : default sampling dates used "<<endl; 00137 _startSamplingDate=PsController::initialSimulationDate; 00138 _endSamplingDate=PsController::initialSimulationDate+1000; 00139 } 00140 } 00141 00142 00143 00144 //---------------------------------------------------------- 00145 // destructeur 00146 00147 template <typename ControleurAncetre> 00148 PsTimerController<ControleurAncetre>::~PsTimerController() 00149 { 00150 cout<<"Simulated time between second "<<_startSamplingDate/1000<<" and second "<<_endSamplingDate/1000 00151 <<" was computed in "<<dateReelleFin - dateReelleDebut<<" clock wall seconds"<<endl; 00152 if (_dateReelleFin.tv_usec - _dateReelleDebut.tv_usec<0 ) { 00153 cout<<"More precisly "<<_dateReelleFin.tv_sec - _dateReelleDebut.tv_sec-1<<" seconds and " 00154 <<_dateReelleFin.tv_usec - _dateReelleDebut.tv_usec+1000000<<" microseconds"<<endl; 00155 } 00156 else { 00157 cout<<"More precisly "<<_dateReelleFin.tv_sec - _dateReelleDebut.tv_sec<<" seconds and " 00158 <<_dateReelleFin.tv_usec - _dateReelleDebut.tv_usec<<" microseconds"<<endl; 00159 } 00160 } 00161 00162 template <typename ControleurAncetre> 00163 void PsTimerController<ControleurAncetre>::compute () 00164 { 00165 //initialisation des compteurs du pas de calcul 00166 if ((_startSamplingDate- _stepPeriod <_date)&&(_date<=_startSamplingDate)) { 00167 dateReelleDebut = time(NULL) ; 00168 gettimeofday(&_dateReelleDebut, NULL); 00169 } 00170 if ((_endSamplingDate<=_date)&&(_date<_endSamplingDate + _stepPeriod)) 00171 { 00172 dateReelleFin = time(NULL) ; 00173 gettimeofday(&_dateReelleFin, NULL); 00174 sendEvent (getController(), PsSystemEventIdentifier::MaskStop ) ; 00175 } 00176 ControleurAncetre::compute (); 00177 } 00178 #endif 00179 00180 00181 00182
| Documentation generated on Mon Nov 25 15:25:02 2002 |
Generated with doxygen 1.2.12 by Dimitri van Heesch , 1997-2001 |