![]() |
User Manual, Developers Guide and API Documentation |
![]() |
00001 /******************************************************************************* 00002 * This file is part of openWNS (open Wireless Network Simulator) 00003 * _____________________________________________________________________________ 00004 * 00005 * Copyright (C) 2004-2007 00006 * Chair of Communication Networks (ComNets) 00007 * Kopernikusstr. 16, D-52074 Aachen, Germany 00008 * phone: ++49-241-80-27910, 00009 * fax: ++49-241-80-22242 00010 * email: info@openwns.org 00011 * www: http://www.openwns.org 00012 * _____________________________________________________________________________ 00013 * 00014 * openWNS is free software; you can redistribute it and/or modify it under the 00015 * terms of the GNU Lesser General Public License version 2 as published by the 00016 * Free Software Foundation; 00017 * 00018 * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY 00019 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 00020 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00021 * details. 00022 * 00023 * You should have received a copy of the GNU Lesser General Public License 00024 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00025 * 00026 ******************************************************************************/ 00027 00028 #ifndef WNS_EVENTS_SCHEDULER_MAP_HPP 00029 #define WNS_EVENTS_SCHEDULER_MAP_HPP 00030 00031 #include <WNS/events/scheduler/Interface.hpp> 00032 #include <WNS/Subject.hpp> 00033 #include <WNS/container/FastList.hpp> 00034 #include <WNS/container/FastListEnabler.hpp> 00035 #include <WNS/events/scheduler/CommandQueue.hpp> 00036 00037 #include <map> 00038 #include <list> 00039 00040 namespace wns { namespace events { namespace scheduler { 00044 class Map : 00045 public Interface, 00046 public Subject<INotification> 00047 { 00048 public: 00049 00050 // Default constructor 00051 Map(); 00052 00053 // Destructor 00054 virtual 00055 ~Map(); 00056 00057 protected: 00058 class Event : 00059 public virtual IEvent, 00060 public wns::container::SingleFastListEnabler< wns::SmartPtr<Event> > 00061 { 00062 public: 00063 Event(const Callable& callable) : 00064 callable_(callable), 00065 scheduled_(0), 00066 issued_(0), 00067 scheduler_(NULL), 00068 state_(NotSubmitted) 00069 { 00070 } 00071 00072 enum State 00073 { 00074 NotSubmitted, 00075 Queued, 00076 Running, 00077 Finished, 00078 Canceled 00079 }; 00080 00081 virtual void 00082 cancel() 00083 { 00084 scheduler_->doCancelMapEventCalledFromMapEvent(EventPtr(this)); 00085 } 00086 00087 virtual bool 00088 isNotSubmitted() const 00089 { 00090 return NotSubmitted == state_; 00091 } 00092 00093 virtual bool 00094 isQueued() const 00095 { 00096 return Queued == state_; 00097 } 00098 00099 virtual bool 00100 isRunning() const 00101 { 00102 return Running == state_; 00103 } 00104 00105 virtual bool 00106 isFinished() const 00107 { 00108 return Finished == state_; 00109 } 00110 00111 virtual bool 00112 isCanceled() const 00113 { 00114 return Canceled == state_; 00115 } 00116 00117 void 00118 operator()() 00119 { 00120 callable_(); 00121 } 00122 00123 wns::simulator::Time 00124 getScheduled() const 00125 { 00126 return scheduled_; 00127 } 00128 00129 wns::simulator::Time 00130 getIssued() const 00131 { 00132 return issued_; 00133 } 00134 00135 Callable callable_; 00136 00137 wns::simulator::Time scheduled_; 00138 00139 wns::simulator::Time issued_; 00140 00141 Map* scheduler_; 00142 00143 State state_; 00144 }; 00145 00146 typedef wns::SmartPtr<Event> EventPtr; 00147 00151 //{@ 00152 virtual void 00153 doReset(); 00154 00155 virtual wns::simulator::Time 00156 doGetTime() const; 00157 00158 virtual void 00159 doStop(); 00160 00161 virtual void 00162 doStart(); 00163 00164 virtual void 00165 doCancelEvent(const IEventPtr& event); 00166 00167 virtual IEventPtr 00168 doScheduleNow(const Callable& callable); 00169 00170 virtual IEventPtr 00171 doSchedule(const Callable& callable, wns::simulator::Time at); 00172 00173 virtual size_t 00174 doSize() const; 00175 00176 virtual bool 00177 doProcessOneEvent(); 00178 00179 virtual ICommandPtr 00180 doQueueCommand(const Callable& callable); 00181 00182 virtual void 00183 doDequeueCommand(const ICommandPtr& command); 00185 00189 //{@ 00190 virtual void 00191 sendProcessOneEventNotification(); 00192 00193 virtual void 00194 sendCancelEventNotification(); 00195 00196 virtual void 00197 sendScheduleNotification(); 00198 00199 virtual void 00200 sendScheduleDelayNotification(); 00201 00202 virtual void 00203 sendScheduleNowNotification(); 00204 00205 virtual void 00206 sendAddEventNotification(); 00208 00212 //{@ 00213 void 00214 doCancelMapEventCalledFromMapEvent(const EventPtr& event); 00215 00216 void 00217 doCancelMapEvent(const EventPtr& event); 00219 00223 virtual void 00224 onNewSimTime(const wns::simulator::Time& /*next Time*/) 00225 {} 00226 00227 // MEMBER 00228 wns::simulator::Time simTime_; 00229 00230 typedef wns::container::FastList<EventPtr> DiscreteTimeContainer; 00231 // we must use a pointer to the discrete time container, otherwise it 00232 // will be copied around and since it is SingleFastListEnable this will 00233 // result in a run-time error. It would be nice, if this could be turned 00234 // into a compile-time error. 00235 typedef std::map<wns::simulator::Time, DiscreteTimeContainer*> EventContainer; 00236 00237 EventContainer events_; 00238 00239 // Iterators of map don't get invalidiated (therefor we can store the 00240 // iterator here) 00241 EventContainer::iterator nowItr_; 00242 00243 bool stop_; 00244 00245 CommandQueue commandQueue_; 00246 }; 00247 00248 } // scheduler 00249 } // events 00250 } // wns 00251 00252 #endif // NOT defined WNS_EVENTS_SCHEDULER_MAP_HPP
1.5.5