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 #include "OSDLActiveObject.h" 00028 00029 #include "OSDLEvents.h" // for SimulationTick 00030 #include "OSDLScheduler.h" // for GetExistingScheduler 00031 00032 00033 00034 00035 using std::string ; 00036 using std::list ; 00037 00038 00039 #include "Ceylan.h" // for Log 00040 using namespace Ceylan::Log ; 00041 00042 00043 using namespace OSDL::Engine ; 00044 using namespace OSDL::Events ; 00045 00046 00047 00048 00049 00050 ActiveObject::ActiveObject( ObjectSchedulingPolicy policy, Weight weight ) : 00051 _policy( policy ), 00052 _weight( weight ), 00053 _registered( false ), 00054 _birthTick( 0 ) 00055 { 00056 00057 00058 } 00059 00060 00061 00062 ActiveObject::~ActiveObject() throw() 00063 { 00064 00065 // Each child class should have taken care of the unregistering: 00066 if ( _registered ) 00067 LogPlug::error( "ActiveObject destructor: object " + toString() 00068 + " was still registered." ) ; 00069 00070 } 00071 00072 00073 00074 00075 00076 // Settings section. 00077 00078 00079 00080 ObjectSchedulingPolicy ActiveObject::getPolicy() const 00081 { 00082 00083 return _policy ; 00084 00085 } 00086 00087 00088 00089 Weight ActiveObject::getWeight() const 00090 { 00091 00092 return _weight ; 00093 00094 } 00095 00096 00097 00098 void ActiveObject::setBirthTick( SimulationTick birthSimulationTick ) 00099 { 00100 00101 _birthTick = birthSimulationTick ; 00102 00103 } 00104 00105 00106 00107 SimulationTick ActiveObject::getBirthTick() const 00108 { 00109 00110 return _birthTick ; 00111 00112 } 00113 00114 00115 00116 void ActiveObject::onSkip( SimulationTick skippedStep ) 00117 { 00118 00119 LogPlug::warning( "An active object (" 00120 + toString( Ceylan::low )+ ") had his simulation tick " 00121 + Ceylan::toString( skippedStep ) + " skipped." ) ; 00122 00123 } 00124 00125 00126 00127 void ActiveObject::onImpossibleActivation( SimulationTick missedStep ) 00128 { 00129 00130 throw SchedulingException( "Active object (" + toString( Ceylan::low ) 00131 + ") could not be activated for simulation tick " 00132 + Ceylan::toString( missedStep ) + "." ) ; 00133 00134 } 00135 00136 00137 00138 const string ActiveObject::toString( Ceylan::VerbosityLevels level ) const 00139 { 00140 00141 string policy ; 00142 00143 switch( _policy ) 00144 { 00145 00146 case relaxed: 00147 policy = "relaxed" ; 00148 break ; 00149 00150 case strict: 00151 policy = "strict" ; 00152 break ; 00153 00154 default: 00155 policy = "unknown (abnormal)" ; 00156 break ; 00157 00158 } 00159 00160 00161 string birth ; 00162 00163 if ( _birthTick == 0 ) 00164 birth = "was never scheduled" ; 00165 else 00166 birth = "has been scheduled for the first time at simulation tick #" 00167 + Ceylan::toString( _birthTick ) ; 00168 00169 return "Active object, with the " + policy + " policy, a weight of " 00170 + Ceylan::toString( _weight ) + ", which is " 00171 + ( _registered ? "registered" : "not registered yet" ) 00172 + " and which " + birth ; 00173 00174 } 00175