OMNeT++ API 6.1
Discrete Event Simulation Library
cscheduler.h
1 //=========================================================================
2 // CSCHEDULER.H - part of
3 // OMNeT++/OMNEST
4 // Discrete System Simulation in C++
5 //
6 //=========================================================================
7 
8 /*--------------------------------------------------------------*
9  Copyright (C) 2003-2017 Andras Varga
10  Copyright (C) 2006-2017 OpenSim Ltd.
11 
12  This file is distributed WITHOUT ANY WARRANTY. See the file
13  `license' for details on this and other legal matters.
14 *--------------------------------------------------------------*/
15 
16 #ifndef __OMNETPP_CSCHEDULER_H
17 #define __OMNETPP_CSCHEDULER_H
18 
19 #include "cobject.h"
20 #include "simtime_t.h"
21 #include "clifecyclelistener.h"
22 
23 namespace omnetpp {
24 
25 class cEvent;
26 class cSimulation;
27 
47 class SIM_API cScheduler : public cObject, public cISimulationLifecycleListener
48 {
49  protected:
50  cSimulation *sim = nullptr;
51 
52  protected:
57  virtual void lifecycleEvent(SimulationLifecycleEventType eventType, cObject *details) override;
58 
59  public:
64 
68  virtual ~cScheduler() {}
69 
75  virtual std::string str() const override;
76 
80  virtual void setSimulation(cSimulation *_sim);
81 
85  cSimulation *getSimulation() const {return sim;}
86 
90  virtual void startRun() {}
91 
95  virtual void endRun() {}
96 
103  virtual void executionResumed() {}
104 
116  virtual cEvent *guessNextEvent() = 0;
117 
130  virtual cEvent *takeNextEvent() = 0;
131 
149  virtual void putBackEvent(cEvent *event) = 0;
150 };
151 
152 
158 class SIM_API cSequentialScheduler : public cScheduler
159 {
160  public:
165 
169  virtual std::string str() const override;
170 
174  virtual cEvent *guessNextEvent() override;
175 
179  virtual cEvent *takeNextEvent() override;
180 
184  virtual void putBackEvent(cEvent *event) override;
185 };
186 
187 
207 //TODO soft realtime, hard realtime (that is: tries to catch up, or resynchronizes on each event)
208 class SIM_API cRealTimeScheduler : public cScheduler
209 {
210  protected:
211  // configuration:
212  bool doScaling;
213  double factor;
214 
215  // state:
216  int64_t baseTime; // in microseconds
217 
218  protected:
219  virtual void startRun() override;
220  bool waitUntil(int64_t targetTime); // in microseconds
221  int64_t toUsecs(simtime_t t);
222 
223  public:
228 
232  virtual ~cRealTimeScheduler() {}
233 
237  virtual std::string str() const override;
238 
242  virtual void executionResumed() override;
243 
247  virtual cEvent *guessNextEvent() override;
248 
255  virtual cEvent *takeNextEvent() override;
256 
260  virtual void putBackEvent(cEvent *event) override;
261 };
262 
263 } // namespace omnetpp
264 
265 
266 #endif
267 
omnetpp::cScheduler::endRun
virtual void endRun()
Definition: cscheduler.h:95
omnetpp::cObject
cObject is a lightweight class which serves as the root of the OMNeT++ class hierarchy....
Definition: cobject.h:92
omnetpp::cSequentialScheduler::cSequentialScheduler
cSequentialScheduler()
Definition: cscheduler.h:164
omnetpp::cScheduler::cScheduler
cScheduler()
Definition: cscheduler.h:63
omnetpp::cEvent
Represents an event in the discrete event simulator.
Definition: cevent.h:46
omnetpp::cSimulation
Simulation manager class.
Definition: csimulation.h:64
omnetpp::cScheduler
Abstract class to encapsulate event scheduling.
Definition: cscheduler.h:47
omnetpp::cScheduler::~cScheduler
virtual ~cScheduler()
Definition: cscheduler.h:68
omnetpp::SimulationLifecycleEventType
SimulationLifecycleEventType
Event type for cISimulationLifecycleListener's lifecycleEvent() method.
Definition: clifecyclelistener.h:28
omnetpp::SimTime
int64_t-based, base-10 fixed-point simulation time.
Definition: simtime.h:66
omnetpp::cScheduler::getSimulation
cSimulation * getSimulation() const
Definition: cscheduler.h:85
omnetpp::cRealTimeScheduler::cRealTimeScheduler
cRealTimeScheduler()
Definition: cscheduler.h:227
omnetpp::cSequentialScheduler
Event scheduler for sequential simulation.
Definition: cscheduler.h:158
omnetpp::cRealTimeScheduler
Real-time scheduler class.
Definition: cscheduler.h:208
omnetpp::cScheduler::startRun
virtual void startRun()
Definition: cscheduler.h:90
omnetpp::cISimulationLifecycleListener
A callback interface for receiving notifications at various stages simulations, including setting up,...
Definition: clifecyclelistener.h:186
omnetpp::cRealTimeScheduler::~cRealTimeScheduler
virtual ~cRealTimeScheduler()
Definition: cscheduler.h:232
omnetpp::cScheduler::executionResumed
virtual void executionResumed()
Definition: cscheduler.h:103