OMNeT++ Simulation Library  5.6.1
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 
48 class SIM_API cScheduler : public cObject, public cISimulationLifecycleListener
49 {
50  protected:
51  cSimulation *sim;
52 
53  protected:
58  virtual void lifecycleEvent(SimulationLifecycleEventType eventType, cObject *details) override;
59 
60  public:
64  cScheduler();
65 
69  virtual ~cScheduler();
70 
76  virtual std::string str() const override;
77 
81  virtual void setSimulation(cSimulation *_sim);
82 
86  cSimulation *getSimulation() const {return sim;}
87 
91  virtual void startRun() {}
92 
96  virtual void endRun() {}
97 
104  virtual void executionResumed() {}
105 
117  virtual cEvent *guessNextEvent() = 0;
118 
131  virtual cEvent *takeNextEvent() = 0;
132 
150  virtual void putBackEvent(cEvent *event) = 0;
151 };
152 
153 
159 class SIM_API cSequentialScheduler : public cScheduler
160 {
161  public:
166 
170  virtual std::string str() const override;
171 
175  virtual cEvent *guessNextEvent() override;
176 
180  virtual cEvent *takeNextEvent() override;
181 
185  virtual void putBackEvent(cEvent *event) override;
186 };
187 
188 
208 //TODO soft realtime, hard realtime (that is: tries to catch up, or resynchronizes on each event)
209 class SIM_API cRealTimeScheduler : public cScheduler
210 {
211  protected:
212  // configuration:
213  bool doScaling;
214  double factor;
215 
216  // state:
217  int64_t baseTime; // in microseconds
218 
219  protected:
220  virtual void startRun() override;
221  bool waitUntil(int64_t targetTime); // in microseconds
222  int64_t toUsecs(simtime_t t);
223 
224  public:
229 
233  virtual ~cRealTimeScheduler();
234 
238  virtual std::string str() const override;
239 
243  virtual void executionResumed() override;
244 
248  virtual cEvent *guessNextEvent() override;
249 
256  virtual cEvent *takeNextEvent() override;
257 
261  virtual void putBackEvent(cEvent *event) override;
262 };
263 
264 } // namespace omnetpp
265 
266 
267 #endif
268 
cSequentialScheduler()
Definition: cscheduler.h:165
Root of the OMNeT++ class hierarchy. cObject is a lightweight class without any data members...
Definition: cobject.h:58
int64_t-based, base-10 fixed-point simulation time.
Definition: simtime.h:66
Event scheduler for sequential simulation.
Definition: cscheduler.h:159
Real-time scheduler class.
Definition: cscheduler.h:209
virtual void executionResumed()
Definition: cscheduler.h:104
Simulation manager class.
Definition: csimulation.h:62
virtual void startRun()
Definition: cscheduler.h:91
Represents an event in the discrete event simulator.
Definition: cevent.h:43
A callback interface for receiving notifications at various stages simulations, including setting up...
Definition: clifecyclelistener.h:186
cSimulation * getSimulation() const
Definition: cscheduler.h:86
Abstract class to encapsulate event scheduling.
Definition: cscheduler.h:48
virtual void endRun()
Definition: cscheduler.h:96
Definition: cabstracthistogram.h:21
SimulationLifecycleEventType
Event type for cISimulationLifecycleListener's lifecycleEvent() method.
Definition: clifecyclelistener.h:28