00001 /* 00002 * Copyright (C) 2003-2009 Olivier Boudeville 00003 * 00004 * This file is part of the OSDL library. 00005 * 00006 * The OSDL library is free software: you can redistribute it and/or modify 00007 * it under the terms of either the GNU Lesser General Public License or 00008 * the GNU General Public License, as they are published by the Free Software 00009 * Foundation, either version 3 of these Licenses, or (at your option) 00010 * any later version. 00011 * 00012 * The OSDL library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU Lesser General Public License and the GNU General Public License 00016 * for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License and of the GNU General Public License along with the OSDL library. 00020 * If not, see <http://www.gnu.org/licenses/>. 00021 * 00022 * Author: Olivier Boudeville (olivier.boudeville@esperide.com) 00023 * 00024 */ 00025 00026 00027 #ifndef OSDL_PERIODIC_SLOT_H_ 00028 #define OSDL_PERIODIC_SLOT_H_ 00029 00030 00031 00032 #include "OSDLPeriodicalActiveObject.h" // for ObjectSchedulingPolicy, etc. 00033 00034 // for ListOfPeriodicalActiveObjects, SchedulingException, etc.: 00035 #include "OSDLEngineCommon.h" 00036 00037 00038 00039 #include <string> 00040 #include <list> 00041 00042 00043 00044 00045 namespace OSDL 00046 { 00047 00048 00049 00050 namespace Engine 00051 { 00052 00053 00054 00055 // Periodic slots register periodical active objects. 00056 class PeriodicalActiveObject ; 00057 00058 00059 00094 class OSDL_DLL PeriodicSlot /* no inheritance, no virtual methods */ 00095 { 00096 00097 00098 public: 00099 00100 00101 00109 explicit PeriodicSlot( Events::Period periodicity ) ; 00110 00111 00112 00114 ~PeriodicSlot() throw() ; 00115 00116 00117 00131 Events::Period add( PeriodicalActiveObject & newObject ) ; 00132 00133 00134 00142 void removeFromSubslot( PeriodicalActiveObject & object ) ; 00143 00144 00145 00159 bool onNextTick( Events::SimulationTick newTick ) ; 00160 00161 00162 00182 void onSimulationSkipped( Events::SimulationTick skipped ) ; 00183 00184 00185 00190 Events::Period getPeriod() const ; 00191 00192 00193 00199 bool isEmpty() const ; 00200 00201 00202 00221 const std::string toString( 00222 Ceylan::VerbosityLevels level = Ceylan::high ) const ; 00223 00224 00225 00226 00227 protected: 00228 00229 00230 00239 Events::Period getSubSlotForSimulationTick( 00240 Events::SimulationTick tick ) const ; 00241 00242 00243 00254 Events::Period getLeastBusySubSlot() const ; 00255 00256 00257 00262 void addInSubSlot( PeriodicalActiveObject & newObject, 00263 Events::Period targetSubSlot ) ; 00264 00265 00266 00284 bool activateAllObjectsInSubSlot( Events::Period subSlot, 00285 Events::SimulationTick currentTime ) ; 00286 00287 00288 00294 Events::Period _period ; 00295 00296 00297 00299 Events::Period _currentSubSlot ; 00300 00301 00302 00313 ListOfPeriodicalActiveObjects ** _subslots ; 00314 00315 00316 00322 Weight * _subslotWeights ; 00323 00324 00325 00326 00327 private: 00328 00329 00330 00339 explicit PeriodicSlot( const PeriodicSlot & source ) ; 00340 00341 00350 PeriodicSlot & operator = ( const PeriodicSlot & source ) ; 00351 00352 00353 } ; 00354 00355 00356 } 00357 00358 } 00359 00360 00361 00362 #endif // OSDL_PERIODIC_SLOT_H_ 00363