csimulation.h Source File¶

API: csimulation.h Source File
API
csimulation.h
1//==========================================================================
2// CSIMULATION.H - header for
3// OMNeT++/OMNEST
4// Discrete System Simulation in C++
5//
6//==========================================================================
7
8/*--------------------------------------------------------------*
9 Copyright (C) 1992-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_CSIMULATION_H
17#define __OMNETPP_CSIMULATION_H
18
19#include "simkerneldefs.h"
20#include "simtime_t.h"
21#include "ccomponent.h"
22#include "ccontextswitcher.h"
23#include "cexception.h"
24
25namespace omnetpp {
26
27class cEvent;
28class cMessage;
29class cGate;
30class cComponent;
31class cModule;
32class cChannel;
33class cSimpleModule;
34class cSimulation;
35class cException;
36class cFutureEventSet;
37class cScheduler;
38class cParsimPartition;
39class cNedFileLoader;
41class cModuleType;
42class cEnvir;
43class cSoftOwner;
44class cIRngManager;
45class cUsageCollector; // (internal)
46
47SIM_API extern cSoftOwner globalOwningContext; // also in globals.h
48
49
65class SIM_API cSimulation : public cNamedObject, noncopyable
66{
67 friend class cSimpleModule;
68 private:
69 // global variables
70 static cSimulation *activeSimulation;
71 static cEnvir *activeEnvir;
72 static cEnvir *staticEnvir; // the environment to activate when activeSimulation becomes nullptr
73
74 // variables of the module vector
75 int size = 0; // size of componentv[]
76 int delta = 32; // if needed, grows by delta
77 cComponent **componentv = nullptr; // vector of modules/channels, componentv[0] is not used for historical reasons
78 int lastComponentId = 0; // index of last used pos. in componentv[]
79
80 // simulation vars
81 cEnvir *envir = nullptr; // the environment that belongs to this simulation object
82 cModule *systemModule = nullptr; // pointer to system (root) module
83 cSimpleModule *currentActivityModule = nullptr; // the module currently executing activity() (nullptr if handleMessage() or in main)
84 cComponent *contextComponent = nullptr; // component in context (or nullptr)
85 ContextType contextType; // the innermost context type
86 cModuleType *networkType = nullptr; // network type
87 cIRngManager *rngManager = nullptr; // component-rng mapping
88 cFutureEventSet *fes = nullptr; // stores future events
89 cScheduler *scheduler = nullptr; // event scheduler
90 simtime_t warmupPeriod; // warm-up period
91
92 ContextType simulationStage; // simulation stage
93 simtime_t currentSimtime; // simulation time (time of current event)
94 eventnumber_t currentEventNumber = 0; // sequence number of current event
95
96 cException *exception; // helper variable to get exceptions back from activity()
97 bool trapOnNextEvent = false; // when set, next handleMessage or activity() will execute debugger interrupt
98
99 bool parameterMutabilityCheck = true; // when disabled, module parameters can be set without them being declared @mutable
100
101 cFingerprintCalculator *fingerprint = nullptr; // used for fingerprint calculation
102 cUsageCollector *usageCollector = nullptr; // used for coverage tests and for detecting unread parameters
103
104 private:
105 // internal
106 void checkActive() {if (getActiveSimulation()!=this) throw cRuntimeError(this, E_WRONGSIM);}
107
108 public:
109 // internal
110 void setParameterMutabilityCheck(bool b) {parameterMutabilityCheck = b;}
111 bool getParameterMutabilityCheck() const {return parameterMutabilityCheck;}
112 // internal, for cUsageCollector
113 void parametersAdded(cComponent *component);
114 void parameterAccessed(cPar *par);
115
116 public:
119
123 cSimulation(const char *name, cEnvir *env);
124
128 virtual ~cSimulation();
130
133
137 virtual void forEachChild(cVisitor *v) override;
138
142 virtual std::string getFullPath() const override;
144
147
150 static cSimulation *getActiveSimulation() {return activeSimulation;}
151
156 static cEnvir *getActiveEnvir() {return activeEnvir;}
157
164
169 static void setStaticEnvir(cEnvir *env);
170
174 static cEnvir *getStaticEnvir() {return staticEnvir;}
175
179 cEnvir *getEnvir() const {return envir;}
181
184
192
198
202 int getLastComponentId() const {return lastComponentId;}
203
216 cModule *getModuleByPath(const char *modulePath) const;
217
230 cModule *findModuleByPath(const char *modulePath) const;
231
236 cComponent *getComponent(int id) const {return id<0 || id>=size ? nullptr : componentv[id];}
237
242 cModule *getModule(int id) const {return id<0 || id>=size || !componentv[id] ? nullptr : componentv[id]->isModule() ? (cModule *)componentv[id] : nullptr;}
243
248 cChannel *getChannel(int id) const {return id<0 || id>=size || !componentv[id] ? nullptr : componentv[id]->isChannel() ? (cChannel *)componentv[id] : nullptr;}
249
254
258 cModule *getSystemModule() const {return systemModule;}
260
270
283 static int loadNedSourceFolder(const char *folderName, const char *excludedPackages="");
284
292 static void loadNedFile(const char *nedFilename, const char *expectedPackage=nullptr, bool isXML=false);
293
304 static void loadNedText(const char *name, const char *nedText, const char *expectedPackage=nullptr, bool isXML=false);
305
312 static void doneLoadingNedFiles();
313
318 static std::string getNedPackageForFolder(const char *folder);
320
323
329 void setScheduler(cScheduler *scheduler);
330
334 cScheduler *getScheduler() const {return scheduler;}
335
342
346 cFutureEventSet *getFES() const {return fes;}
347
353 virtual void setRngManager(cIRngManager *rngManager);
354
359 cIRngManager *getRngManager() const {return rngManager;}
360
366
370 void setupNetwork(cModuleType *networkType);
371
378
384
391
394
400 int getSimulationStage() const {return simulationStage;}
401
406 cModuleType *getNetworkType() const {return networkType;}
407
413 void setSimTime(simtime_t time) {currentSimtime = time;}
414
420 simtime_t_cref getSimTime() const {return currentSimtime;}
421
426 eventnumber_t getEventNumber() const {return currentEventNumber;}
427
437 simtime_t_cref getWarmupPeriod() const {return warmupPeriod;}
438
442 void setWarmupPeriod(simtime_t t) {warmupPeriod = t;}
444
447
453
459 cSimpleModule *guessNextModule();
460
466
478
482 void putBackEvent(cEvent *event);
483
488 void executeEvent(cEvent *event);
489
494
499 void transferTo(cSimpleModule *module);
500
505
511 void insertEvent(cEvent *event);
512
516 void setContext(cComponent *component);
517
521 void setContextType(ContextType type) {contextType = type;}
522
526 void setGlobalContext() {contextComponent=nullptr; cOwnedObject::setOwningContext(&globalOwningContext);}
527
533 cSimpleModule *getActivityModule() const {return currentActivityModule;}
534
538 cComponent *getContext() const {return contextComponent;}
539
547 ContextType getContextType() const {return contextType;}
548
554
560 cSimpleModule *getContextSimpleModule() const;
561
567 void requestTrapOnNextEvent() {trapOnNextEvent = true;}
568
572 void clearTrapOnNextEvent() {trapOnNextEvent = false;}
573
578 bool isTrapOnNextEventRequested() const {return trapOnNextEvent;}
580
583
589 unsigned long getUniqueNumber();
590
596 void snapshot(cObject *obj, const char *label);
597
603
609};
610
617
624
632
633} // namespace omnetpp
634
635
636#endif
637
Base class for channels.
Definition cchannel.h:47
Common base for module and channel classes.
Definition ccomponent.h:51
bool isModule() const
Definition ccomponent.h:472
bool isChannel() const
Definition ccomponent.h:477
cEnvir represents the "environment" or user interface of the simulation.
Definition cenvir.h:76
Represents an event in the discrete event simulator.
Definition cevent.h:47
Exception class.
Definition cexception.h:55
This class defines the interface for fingerprint calculators.
Definition cfingerprint.h:36
Abstract base class for the future event set (FES), a central data structure for discrete event simul...
Definition cfutureeventset.h:33
Represents a module gate.
Definition cgate.h:63
Abstract interface for managing random number generators (RNGs) for simulation components (modules an...
Definition crngmanager.h:44
The message class in OMNeT++. cMessage objects may represent events, messages, jobs or other entities...
Definition cmessage.h:96
Abstract class for creating a module of a specific type.
Definition ccomponenttype.h:212
This class represents modules in the simulation.
Definition cmodule.h:49
cNamedObject()
Definition cnamedobject.h:57
cObject is a lightweight class which serves as the root of the OMNeT++ class hierarchy....
Definition cobject.h:93
Represents a module or channel parameter.
Definition cpar.h:71
Thrown when the simulation kernel or other components detect a runtime error.
Definition cexception.h:343
Abstract class to encapsulate event scheduling.
Definition cscheduler.h:48
Base class for all simple module classes.
Definition csimplemodule.h:203
Simulation manager class.
Definition csimulation.h:66
void setScheduler(cScheduler *scheduler)
void transferTo(cSimpleModule *module)
void snapshot(cObject *obj, const char *label)
void setContextType(ContextType type)
Definition csimulation.h:521
cScheduler * getScheduler() const
Definition csimulation.h:334
static void setActiveSimulation(cSimulation *sim)
void requestTrapOnNextEvent()
Definition csimulation.h:567
cModule * getModule(int id) const
Definition csimulation.h:242
simtime_t guessNextSimtime()
void setGlobalContext()
Definition csimulation.h:526
cSimpleModule * getContextSimpleModule() const
unsigned long getUniqueNumber()
void insertEvent(cEvent *event)
bool isTrapOnNextEventRequested() const
Definition csimulation.h:578
void setSimTime(simtime_t time)
Definition csimulation.h:413
cModuleType * getNetworkType() const
Definition csimulation.h:406
void executeEvent(cEvent *event)
simtime_t_cref getSimTime() const
Definition csimulation.h:420
static cSimulation * getActiveSimulation()
Definition csimulation.h:150
static void setStaticEnvir(cEnvir *env)
ContextType getContextType() const
Definition csimulation.h:547
static std::string getNedPackageForFolder(const char *folder)
int getSimulationStage() const
Definition csimulation.h:400
cSimulation(const char *name, cEnvir *env)
void setFingerprintCalculator(cFingerprintCalculator *fingerprint)
cFutureEventSet * getFES() const
Definition csimulation.h:346
void putBackEvent(cEvent *event)
simtime_t_cref getWarmupPeriod() const
Definition csimulation.h:437
cModule * findModuleByPath(const char *modulePath) const
static cEnvir * getStaticEnvir()
Definition csimulation.h:174
cSimpleModule * getActivityModule() const
Definition csimulation.h:533
static cEnvir * getActiveEnvir()
Definition csimulation.h:156
void setSystemModule(cModule *module)
cEnvir * getEnvir() const
Definition csimulation.h:179
void setFES(cFutureEventSet *fes)
void setContext(cComponent *component)
cModule * getModuleByPath(const char *modulePath) const
static int loadNedSourceFolder(const char *folderName, const char *excludedPackages="")
cIRngManager * getRngManager() const
Definition csimulation.h:359
eventnumber_t getEventNumber() const
Definition csimulation.h:426
void clearTrapOnNextEvent()
Definition csimulation.h:572
cModule * getContextModule() const
cComponent * getComponent(int id) const
Definition csimulation.h:236
cFingerprintCalculator * getFingerprintCalculator()
Definition csimulation.h:602
static void loadNedText(const char *name, const char *nedText, const char *expectedPackage=nullptr, bool isXML=false)
cModule * getSystemModule() const
Definition csimulation.h:258
static void doneLoadingNedFiles()
int registerComponent(cComponent *component)
cEvent * guessNextEvent()
virtual std::string getFullPath() const override
void deregisterComponent(cComponent *component)
virtual void forEachChild(cVisitor *v) override
void setSimulationTimeLimit(simtime_t simTimeLimit)
cChannel * getChannel(int id) const
Definition csimulation.h:248
void setupNetwork(cModuleType *networkType)
cSimpleModule * guessNextModule()
cEvent * takeNextEvent()
virtual void setRngManager(cIRngManager *rngManager)
static void loadNedFile(const char *nedFilename, const char *expectedPackage=nullptr, bool isXML=false)
void setWarmupPeriod(simtime_t t)
Definition csimulation.h:442
cComponent * getContext() const
Definition csimulation.h:538
int getLastComponentId() const
Definition csimulation.h:202
Internal class, used as a base class for modules and channels. It is not intended for subclassing out...
Definition csoftowner.h:34
Enables traversing the tree of (cObject-rooted) simulation objects.
Definition cvisitor.h:57
cSimulation * getSimulation()
Returns the currently active simulation, or nullptr if there is none.
Definition csimulation.h:623
cEnvir * getEnvir()
Returns the environment object for the currently active simulation. This function never returns nullp...
Definition csimulation.h:631
int64_t eventnumber_t
Sequence number of events during the simulation. Events are numbered from one. (Event number zero is ...
Definition simkerneldefs.h:78
simtime_t simTime()
Returns the current simulation time.
Definition csimulation.h:616
SimTime simtime_t
Represents simulation time.
Definition simtime_t.h:40
const simtime_t & simtime_t_cref
Constant reference to a simtime_t.
Definition simtime_t.h:48