cscheduler.h Source File

API: cscheduler.h Source File
API
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
23namespace omnetpp {
24
25class cEvent;
26class cSimulation;
27
47class 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
158class 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)
208class 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
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
Represents an event in the discrete event simulator.
Definition cevent.h:47
A callback interface for receiving notifications at various stages simulations, including setting up,...
Definition clifecyclelistener.h:187
cObject()
Definition cobject.h:124
virtual void executionResumed() override
virtual cEvent * takeNextEvent() override
virtual cEvent * guessNextEvent() override
virtual void putBackEvent(cEvent *event) override
virtual void startRun() override
cRealTimeScheduler()
Definition cscheduler.h:227
virtual std::string str() const override
virtual ~cRealTimeScheduler()
Definition cscheduler.h:232
virtual void startRun()
Definition cscheduler.h:90
virtual void putBackEvent(cEvent *event)=0
cScheduler()
Definition cscheduler.h:63
virtual cEvent * guessNextEvent()=0
virtual void executionResumed()
Definition cscheduler.h:103
virtual cEvent * takeNextEvent()=0
cSimulation * getSimulation() const
Definition cscheduler.h:85
virtual void endRun()
Definition cscheduler.h:95
virtual ~cScheduler()
Definition cscheduler.h:68
virtual void lifecycleEvent(SimulationLifecycleEventType eventType, cObject *details) override
virtual std::string str() const override
virtual void setSimulation(cSimulation *_sim)
cSequentialScheduler()
Definition cscheduler.h:164
virtual cEvent * takeNextEvent() override
virtual cEvent * guessNextEvent() override
virtual void putBackEvent(cEvent *event) override
virtual std::string str() const override
Simulation manager class.
Definition csimulation.h:66
SimulationLifecycleEventType
Event type for cISimulationLifecycleListener's lifecycleEvent() method.
Definition clifecyclelistener.h:29
SimTime simtime_t
Represents simulation time.
Definition simtime_t.h:40