OMNeT++ Simulation Library  5.6.1
cenvir.h
1 //==========================================================================
2 // CENVIR.H - part of
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_CENVIR_H
17 #define __OMNETPP_CENVIR_H
18 
19 #include <sstream>
20 #include <iostream>
21 #include "simkerneldefs.h"
22 #include "simtime_t.h"
23 #include "opp_string.h"
24 #include "clistener.h" // for simsignal_t
25 #include "clifecyclelistener.h"
26 #include "ccanvas.h"
27 
28 namespace osg { class Node; }
29 
30 namespace omnetpp {
31 
32 class cObject;
33 class cOwnedObject;
34 class cLogEntry;
35 class cEvent;
36 class cMessage;
37 class cPar;
38 class cGate;
39 class cComponent;
40 class cComponentType;
41 class cModule;
42 class cSimpleModule;
43 class cStatistic;
44 class cProperty;
45 class cRNG;
46 class cXMLElement;
47 class cEnvir;
48 class cConfiguration;
49 class cConfigurationEx;
50 
51 using std::endl;
52 
53 // internal macro, usage: EVCB.beginSend(...)
54 #define EVCB cSimulation::getActiveEnvir()->suppressNotifications ? (void)0 : (*cSimulation::getActiveEnvir())
55 
73 class SIM_API cEnvir
74 {
75  friend class evbuf;
76  public:
77  // Internal flag for express mode.
78  bool loggingEnabled;
79 
80  // Internal flag. When set to true, the simulation kernel MAY omit calling
81  // the following cEnvir methods: messageScheduled(), messageCancelled(),
82  // beginSend(), messageSendDirect(), messageSendHop(), messageSendHop(),
83  // messageSendHop(), messageDeleted(), moduleReparented(), simulationEvent(),
84  // componentMethodBegin(), moduleCreated(), moduleDeleted(), connectionCreated(),
85  // connectionDeleted(), displayStringChanged().
86  bool suppressNotifications;
87 
88  // Debugging. When set, cRuntimeError constructor executes a debug trap/launches debugger
89  bool debugOnErrors = false;
90 
91  public:
94 
98  cEnvir();
99 
103  virtual ~cEnvir();
105 
108 
115  // note: this cannot be pure virtual, because it has to work even after ev was disposed of
116  virtual void objectDeleted(cObject *object) {}
117 
121  virtual void componentInitBegin(cComponent *component, int stage) {}
122 
130  virtual void simulationEvent(cEvent *event) = 0;
131 
136  virtual void messageScheduled(cMessage *msg) = 0;
137 
142  virtual void messageCancelled(cMessage *msg) = 0;
143 
153  virtual void beginSend(cMessage *msg) = 0;
154 
156  virtual void messageSendDirect(cMessage *msg, cGate *toGate, simtime_t propagationDelay, simtime_t transmissionDelay) = 0;
157 
159  virtual void messageSendHop(cMessage *msg, cGate *srcGate) = 0;
160 
162  virtual void messageSendHop(cMessage *msg, cGate *srcGate, simtime_t propagationDelay, simtime_t transmissionDelay, bool discard) = 0;
163 
165  virtual void endSend(cMessage *msg) = 0;
166 
171  virtual void messageCreated(cMessage *msg) = 0;
172 
177  virtual void messageCloned(cMessage *msg, cMessage* clone) = 0;
178 
184  virtual void messageDeleted(cMessage *msg) = 0;
185 
189  virtual void moduleReparented(cModule *module, cModule *oldparent, int oldId) = 0;
190 
197  virtual void componentMethodBegin(cComponent *from, cComponent *to, const char *methodFmt, va_list va, bool silent) = 0;
198 
203  virtual void componentMethodEnd() = 0;
204 
210  virtual void moduleCreated(cModule *newmodule) = 0;
211 
223  virtual void moduleDeleted(cModule *module) = 0;
224 
228  virtual void gateCreated(cGate *newgate) = 0;
229 
234  virtual void gateDeleted(cGate *gate) = 0;
235 
240  virtual void connectionCreated(cGate *srcgate) = 0;
241 
246  virtual void connectionDeleted(cGate *srcgate) = 0;
247 
252  virtual void displayStringChanged(cComponent *component) = 0;
253 
258  // Note: this may not be pure virtual, as it may get called even after main()
259  // exited and StaticEnv was destructed, and we do not want to get a "pure virtual
260  // method called" error
261  virtual void undisposedObject(cObject *obj) {}
263 
270  virtual const char *getCurrentEventName() { return nullptr; }
271 
276  virtual const char *getCurrentEventClassName() { return nullptr; }
277 
282  virtual cModule *getCurrentEventModule() { return nullptr; }
284 
287 
294  virtual void preconfigure(cComponent *component) = 0;
295 
302  virtual void configure(cComponent *component) = 0;
303 
308  virtual void readParameter(cPar *parameter) = 0;
309 
320  virtual bool isModuleLocal(cModule *parentmod, const char *modname, int index) = 0;
321 
344  virtual cXMLElement *getXMLDocument(const char *filename, const char *xpath=nullptr) = 0;
345 
367  virtual cXMLElement *getParsedXMLString(const char *content, const char *xpath=nullptr) = 0;
368 
382  virtual void forgetXMLDocument(const char *filename) = 0;
383 
396  virtual void forgetParsedXMLString(const char *content) = 0;
397 
407  virtual void flushXMLDocumentCache() = 0;
408 
418  virtual void flushXMLParsedContentCache() = 0;
419 
424  virtual unsigned getExtraStackForEnvir() const = 0;
425 
433  virtual cConfiguration *getConfig() = 0;
434 
440  virtual cConfigurationEx *getConfigEx();
441 
452  virtual std::string resolveResourcePath(const char *fileName, cComponentType *context=nullptr) = 0;
454 
464  virtual bool isGUI() const = 0;
465 
470  bool isLoggingEnabled() const { return loggingEnabled; }
471 
477  virtual bool isExpressMode() const = 0;
478 
483  virtual void bubble(cComponent *component, const char *text) = 0;
484 
488  virtual void log(cLogEntry *entry) = 0;
489 
494  virtual void alert(const char *msg) = 0;
495 
499  virtual void printfmsg(const char *fmt,...);
500 
505  virtual std::string gets(const char *prompt, const char *defaultReply=nullptr) = 0;
506 
512  virtual bool askYesNo(const char *prompt) = 0;
513 
523  virtual void getImageSize(const char *imageName, double& outWidth, double& outHeight) = 0;
524 
532  virtual void getTextExtent(const cFigure::Font& font, const char *text, double& outWidth, double& outHeight, double& outAscent) = 0;
533 
545  virtual void appendToImagePath(const char *directory) = 0;
546 
570  virtual void loadImage(const char *fileName, const char *imageName=nullptr) = 0;
571 
589  virtual cFigure::Rectangle getSubmoduleBounds(const cModule *submodule) = 0;
590 
605  virtual double getZoomLevel(const cModule *module) = 0;
606 
613  virtual double getAnimationTime() const = 0;
614 
624  virtual double getAnimationSpeed() const = 0;
625 
633  virtual double getRemainingAnimationHoldTime() const = 0;
635 
638 
643  virtual int getNumRNGs() const = 0;
644 
648  virtual cRNG *getRNG(int k) = 0;
650 
660 
668  virtual void *registerOutputVector(const char *modulename, const char *vectorname) = 0;
669 
673  virtual void deregisterOutputVector(void *vechandle) = 0;
674 
678  virtual void setVectorAttribute(void *vechandle, const char *name, const char *value) = 0;
679 
685  virtual bool recordInOutputVector(void *vechandle, simtime_t t, double value) = 0;
687 
697 
701  virtual void recordScalar(cComponent *component, const char *name, double value, opp_string_map *attributes=nullptr) = 0;
702 
707  virtual void recordStatistic(cComponent *component, const char *name, cStatistic *statistic, opp_string_map *attributes=nullptr) = 0;
709 
712 
733  virtual void addResultRecorders(cComponent *component, simsignal_t signal, const char *statisticName, cProperty *statisticTemplateProperty) = 0;
735 
743 
747  virtual std::ostream *getStreamForSnapshot() = 0;
748 
752  virtual void releaseStreamForSnapshot(std::ostream *os) = 0;
754 
760  virtual int getArgCount() const = 0;
761 
765  virtual char **getArgVector() const = 0;
766 
770  virtual int getParsimProcId() const = 0;
771 
776  virtual int getParsimNumPartitions() const = 0;
777 
781  virtual unsigned long getUniqueNumber() = 0;
782 
787  virtual void refOsgNode(osg::Node *scene) = 0;
788 
793  virtual void unrefOsgNode(osg::Node *scene) = 0;
794 
808  virtual bool idle() = 0;
809 
824  virtual bool ensureDebugger(cRuntimeError *error = nullptr) = 0;
825 
827 
835  virtual void addLifecycleListener(cISimulationLifecycleListener *listener) = 0;
836 
841  virtual void removeLifecycleListener(cISimulationLifecycleListener *listener) = 0;
842 
843  // internal. TODO it swallows exceptions, which is sometimes desirable, sometimes not!
844  virtual void notifyLifecycleListeners(SimulationLifecycleEventType eventType, cObject *details=nullptr) = 0;
846 };
847 
848 
855 class SIM_API cRunnableEnvir : public cEnvir
856 {
857  public:
862  virtual int run(int argc, char *argv[], cConfiguration *cfg) = 0;
863 };
864 
865 } // namespace omnetpp
866 
867 #endif
868 
869 
The message class in OMNeT++. cMessage objects may represent events, messages, jobs or other entities...
Definition: cmessage.h:95
Thrown when the simulation kernel or other components detect a runtime error.
Definition: cexception.h:283
Common base for module and channel classes.
Definition: ccomponent.h:48
Represents a module gate.
Definition: cgate.h:63
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
Represents an XML element in an XML configuration file.
Definition: cxmlelement.h:73
Abstract interface for random number generator classes.
Definition: crng.h:49
Represents an event in the discrete event simulator.
Definition: cevent.h:43
Represents a module or channel parameter.
Definition: cpar.h:68
virtual const char * getCurrentEventName()
Definition: cenvir.h:270
A callback interface for receiving notifications at various stages simulations, including setting up...
Definition: clifecyclelistener.h:186
virtual cModule * getCurrentEventModule()
Definition: cenvir.h:282
cEnvir represents the "environment" or user interface of the simulation.
Definition: cenvir.h:73
virtual const char * getCurrentEventClassName()
Definition: cenvir.h:276
This class holds various data that is captured when a particular log statement executes. It also contains the text written to the log stream.
Definition: clog.h:369
virtual void componentInitBegin(cComponent *component, int stage)
Definition: cenvir.h:121
This class represents modules in the simulation.
Definition: cmodule.h:47
Stores a (NED) property with its (possibly compound) value.
Definition: cproperty.h:38
Represents a configuration suitable for use with the Envir library.
Definition: cconfiguration.h:282
bool isLoggingEnabled() const
Definition: cenvir.h:470
Lightweight string-to-string map, used internally in some parts of OMNeT++.
Definition: opp_string.h:200
A cEnvir that can be instantiated as a user interface, like Cmdenv and Tkenv.
Definition: cenvir.h:855
virtual void objectDeleted(cObject *object)
Definition: cenvir.h:116
Common base class for cModuleType and cChannelType.
Definition: ccomponenttype.h:49
Definition: cabstracthistogram.h:21
Definition: cenvir.h:28
Represents a rectangle as an (x,y,width,height) tuple.
Definition: ccanvas.h:90
SimulationLifecycleEventType
Event type for cISimulationLifecycleListener&#39;s lifecycleEvent() method.
Definition: clifecyclelistener.h:28
virtual void undisposedObject(cObject *obj)
Definition: cenvir.h:261
int simsignal_t
Signal handle.
Definition: clistener.h:24
cStatistic is an abstract class for computing statistical properties of a random variable.
Definition: cstatistic.h:34
Represents the configuration, as accessed by the simulation kernel.
Definition: cconfiguration.h:70
Represents properties of a font.
Definition: ccanvas.h:157