cenvir.h Source File¶

API: cenvir.h Source File
API
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
28namespace osg { class Node; }
29
30namespace omnetpp {
31
32class cObject;
33class cOwnedObject;
34class cLogEntry;
35class cEvent;
36class cMessage;
37class cPar;
38class cGate;
39class cComponent;
40class cComponentType;
41class cModule;
42class cSimpleModule;
43class cStatistic;
44class cProperty;
45class cRNG;
46class cXMLElement;
47class cEnvir;
48class cConfiguration;
50struct SendOptions;
51struct ChannelResult;
52
53using std::endl;
54
55// internal macro, usage: EVCB.beginSend(...)
56#define EVCB cSimulation::getActiveEnvir()->suppressNotifications ? (void)0 : (*cSimulation::getActiveEnvir())
57
75class SIM_API cEnvir
76{
77 friend class evbuf;
78 public:
79 // Internal flag for express mode.
80 bool loggingEnabled = true;
81
82 // Internal flag. When set to true, the simulation kernel MAY omit calling
83 // the following cEnvir methods: messageScheduled(), messageCancelled(),
84 // beginSend(), messageSendDirect(), messageSendHop(), messageSendHop(),
85 // messageSendHop(), messageDeleted(), moduleReparented(), simulationEvent(),
86 // componentMethodBegin(), moduleCreated(), moduleDeleted(), connectionCreated(),
87 // connectionDeleted(), displayStringChanged().
88 bool suppressNotifications = false; //FIXME set to true when not needed!
89
90 // Debugging. When set, cRuntimeError constructor executes a debug trap/launches debugger
91 bool debugOnErrors = false;
92
93 // Lifecycle listeners
94 std::vector<cISimulationLifecycleListener*> listeners;
95
96 public:
99
104
108 virtual ~cEnvir() {}
110
113
120 // note: this cannot be pure virtual, because it has to work even after ev was disposed of
121 virtual void objectDeleted(cObject *object) {}
122
126 virtual void componentInitBegin(cComponent *component, int stage) {}
127
135 virtual void simulationEvent(cEvent *event) = 0;
136
141 virtual void messageScheduled(cMessage *msg) = 0;
142
147 virtual void messageCancelled(cMessage *msg) = 0;
148
161 virtual void beginSend(cMessage *msg, const SendOptions& options) = 0;
162
164 virtual void messageSendDirect(cMessage *msg, cGate *toGate, const ChannelResult& result) = 0;
165
167 virtual void messageSendHop(cMessage *msg, cGate *srcGate) = 0;
168
170 virtual void messageSendHop(cMessage *msg, cGate *srcGate, const ChannelResult& result) = 0;
171
173 virtual void endSend(cMessage *msg) = 0;
174
179 virtual void messageCreated(cMessage *msg) = 0;
180
185 virtual void messageCloned(cMessage *msg, cMessage* clone) = 0;
186
192 virtual void messageDeleted(cMessage *msg) = 0;
193
197 virtual void moduleReparented(cModule *module, cModule *oldparent, int oldId) = 0;
198
205 virtual void componentMethodBegin(cComponent *from, cComponent *to, const char *methodFmt, va_list va, bool silent) = 0;
206
211 virtual void componentMethodEnd() = 0;
212
218 virtual void moduleCreated(cModule *newmodule) = 0;
219
231 virtual void moduleDeleted(cModule *module) = 0;
232
236 virtual void gateCreated(cGate *newgate) = 0;
237
242 virtual void gateDeleted(cGate *gate) = 0;
243
248 virtual void connectionCreated(cGate *srcgate) = 0;
249
254 virtual void connectionDeleted(cGate *srcgate) = 0;
255
260 virtual void displayStringChanged(cComponent *component) = 0;
261
266 // Note: this may not be pure virtual, as it may get called even after main()
267 // exited and StaticEnv was destructed, and we do not want to get a "pure virtual
268 // method called" error
269 virtual void undisposedObject(cObject *obj) {}
271
274
278 virtual const char *getCurrentEventName() { return nullptr; }
279
284 virtual const char *getCurrentEventClassName() { return nullptr; }
285
290 virtual cModule *getCurrentEventModule() { return nullptr; }
292
295
302 virtual void preconfigure(cComponent *component) = 0;
303
310 virtual void configure(cComponent *component) = 0;
311
316 virtual void readParameter(cPar *parameter) = 0;
317
328 virtual bool isModuleLocal(cModule *parentmod, const char *modname, int index) = 0;
329
352 virtual cXMLElement *getXMLDocument(const char *filename, const char *xpath=nullptr) = 0;
353
375 virtual cXMLElement *getParsedXMLString(const char *content, const char *xpath=nullptr) = 0;
376
390 virtual void forgetXMLDocument(const char *filename) = 0;
391
404 virtual void forgetParsedXMLString(const char *content) = 0;
405
415 virtual void flushXMLDocumentCache() = 0;
416
426 virtual void flushXMLParsedContentCache() = 0;
427
432 virtual unsigned getExtraStackForEnvir() const = 0;
433
441 virtual cConfiguration *getConfig() = 0;
442
449
460 virtual std::string resolveResourcePath(const char *fileName, cComponentType *context=nullptr) = 0;
462
465
472 virtual bool isGUI() const = 0;
473
478 bool isLoggingEnabled() const { return loggingEnabled; }
479
485 virtual bool isExpressMode() const = 0;
486
491 virtual void bubble(cComponent *component, const char *text) = 0;
492
496 virtual void log(cLogEntry *entry) = 0;
497
502 virtual void alert(const char *msg) = 0;
503
507 _OPP_GNU_ATTRIBUTE(format(printf, 2, 3))
508 virtual void printfmsg(const char *fmt,...);
509
514 virtual std::string gets(const char *prompt, const char *defaultReply=nullptr) = 0;
515
521 virtual bool askYesNo(const char *prompt) = 0;
522
527 virtual std::ostream& getOutputStream() = 0;
528
538 virtual void getImageSize(const char *imageName, double& outWidth, double& outHeight) = 0;
539
547 virtual void getTextExtent(const cFigure::Font& font, const char *text, double& outWidth, double& outHeight, double& outAscent) = 0;
548
560 virtual void appendToImagePath(const char *directory) = 0;
561
585 virtual void loadImage(const char *fileName, const char *imageName=nullptr) = 0;
586
604 virtual cFigure::Rectangle getSubmoduleBounds(const cModule *submodule) = 0;
605
606 /*
607 * Returns the characteristic points (currently the start and end points)
608 * of the connection arrow denoted by its source gate when it is visualized
609 * in the graphical inspector of its containing compound module,
610 * or an empty vector if the connection arrow is not available. This method
611 * is the only way to access the coordinates of connection arrows.
612 * The method may unconditionally return an empty vector when the simulation
613 * is running under Cmdenv or another non-graphical user interface. It is
614 * recommended to use the front() and back() methods of std::vector for
615 * accessing the start and end points in order to be compatible with potential
616 * future OMNeT++ versions that support splines or breakpoints in the arrows.
617 *
618 * Also note that this method may return different values at different
619 * times, e.g. as a result of the user opening and closing inspectors,
620 * hitting the "Relayout" button, or even changing the zoom level or icon
621 * size of graphical module inspectors displaying the parent module.
622 * Visualization code relying on this method is advised to re-read
623 * coordinates in every refreshDisplay() call, and check whether they
624 * changed since last time.
625 */
626 virtual std::vector<cFigure::Point> getConnectionLine(const cGate *sourceGate) = 0;
627
642 virtual double getZoomLevel(const cModule *module) = 0;
643
650 virtual double getAnimationTime() const = 0;
651
661 virtual double getAnimationSpeed() const = 0;
662
670 virtual double getRemainingAnimationHoldTime() const = 0;
672
675
680 virtual int getNumRNGs() const = 0;
681
685 virtual cRNG *getRNG(int k) = 0;
687
697
705 virtual void *registerOutputVector(const char *modulename, const char *vectorname, opp_string_map *attributes=nullptr) = 0;
706
710 virtual void deregisterOutputVector(void *vechandle) = 0;
711
717 virtual bool recordInOutputVector(void *vechandle, simtime_t t, double value) = 0;
719
729
733 virtual void recordScalar(cComponent *component, const char *name, double value, opp_string_map *attributes=nullptr) = 0;
734
739 virtual void recordStatistic(cComponent *component, const char *name, cStatistic *statistic, opp_string_map *attributes=nullptr) = 0;
740
744 virtual void recordParameter(cPar *par) = 0;
745
749 virtual void recordComponentType(cComponent *component) = 0;
751
754
775 virtual void addResultRecorders(cComponent *component, simsignal_t signal, const char *statisticName, cProperty *statisticTemplateProperty) = 0;
777
785
789 virtual std::ostream *getStreamForSnapshot() = 0;
790
794 virtual void releaseStreamForSnapshot(std::ostream *os) = 0;
796
799
802 virtual int getArgCount() const = 0;
803
807 virtual char **getArgVector() const = 0;
808
812 virtual int getParsimProcId() const = 0;
813
818 virtual int getParsimNumPartitions() const = 0;
819
823 virtual unsigned long getUniqueNumber() = 0;
824
829 virtual void refOsgNode(osg::Node *scene) = 0;
830
835 virtual void unrefOsgNode(osg::Node *scene) = 0;
836
850 virtual bool idle() = 0;
851
859 virtual void pausePoint() = 0;
860
875 virtual bool ensureDebugger(cRuntimeError *error = nullptr) = 0;
876
878
881
887
893
898
902 virtual void notifyLifecycleListeners(SimulationLifecycleEventType eventType, cObject *details=nullptr);
904};
905
906
913class SIM_API cRunnableEnvir : public cEnvir
914{
915 public:
920 virtual int run(int argc, char *argv[], cConfiguration *cfg) = 0;
921};
922
923} // namespace omnetpp
924
925#endif
926
927
Common base class for cModuleType and cChannelType.
Definition ccomponenttype.h:50
Common base for module and channel classes.
Definition ccomponent.h:51
Represents a configuration suitable for use with the Envir library.
Definition cconfiguration.h:305
Represents the configuration, as accessed by the simulation kernel.
Definition cconfiguration.h:77
cEnvir represents the "environment" or user interface of the simulation.
Definition cenvir.h:76
virtual cConfiguration * getConfig()=0
virtual void objectDeleted(cObject *object)
Definition cenvir.h:121
virtual void deregisterOutputVector(void *vechandle)=0
virtual void flushXMLParsedContentCache()=0
virtual bool recordInOutputVector(void *vechandle, simtime_t t, double value)=0
virtual void readParameter(cPar *parameter)=0
virtual bool askYesNo(const char *prompt)=0
virtual std::string gets(const char *prompt, const char *defaultReply=nullptr)=0
virtual void recordScalar(cComponent *component, const char *name, double value, opp_string_map *attributes=nullptr)=0
virtual void simulationEvent(cEvent *event)=0
virtual void pausePoint()=0
virtual ~cEnvir()
Definition cenvir.h:108
virtual std::ostream * getStreamForSnapshot()=0
virtual double getAnimationSpeed() const =0
virtual void messageSendHop(cMessage *msg, cGate *srcGate)=0
virtual void getTextExtent(const cFigure::Font &font, const char *text, double &outWidth, double &outHeight, double &outAscent)=0
virtual void preconfigure(cComponent *component)=0
virtual std::ostream & getOutputStream()=0
virtual void messageCancelled(cMessage *msg)=0
virtual void componentMethodEnd()=0
virtual char ** getArgVector() const =0
virtual void unrefOsgNode(osg::Node *scene)=0
virtual std::string resolveResourcePath(const char *fileName, cComponentType *context=nullptr)=0
virtual void moduleCreated(cModule *newmodule)=0
virtual void undisposedObject(cObject *obj)
Definition cenvir.h:269
bool isLoggingEnabled() const
Definition cenvir.h:478
virtual void alert(const char *msg)=0
virtual bool isExpressMode() const =0
virtual bool ensureDebugger(cRuntimeError *error=nullptr)=0
virtual int getParsimNumPartitions() const =0
virtual void removeLifecycleListener(cISimulationLifecycleListener *listener)
virtual double getAnimationTime() const =0
virtual void loadImage(const char *fileName, const char *imageName=nullptr)=0
virtual bool idle()=0
virtual cRNG * getRNG(int k)=0
virtual void messageCloned(cMessage *msg, cMessage *clone)=0
virtual void gateDeleted(cGate *gate)=0
virtual void flushXMLDocumentCache()=0
virtual cXMLElement * getParsedXMLString(const char *content, const char *xpath=nullptr)=0
virtual int getArgCount() const =0
virtual cModule * getCurrentEventModule()
Definition cenvir.h:290
virtual std::vector< cISimulationLifecycleListener * > getLifecycleListeners() const
virtual void messageSendDirect(cMessage *msg, cGate *toGate, const ChannelResult &result)=0
virtual void forgetParsedXMLString(const char *content)=0
virtual void connectionDeleted(cGate *srcgate)=0
virtual void addResultRecorders(cComponent *component, simsignal_t signal, const char *statisticName, cProperty *statisticTemplateProperty)=0
virtual void * registerOutputVector(const char *modulename, const char *vectorname, opp_string_map *attributes=nullptr)=0
virtual void recordComponentType(cComponent *component)=0
virtual cConfigurationEx * getConfigEx()
virtual void beginSend(cMessage *msg, const SendOptions &options)=0
virtual void componentMethodBegin(cComponent *from, cComponent *to, const char *methodFmt, va_list va, bool silent)=0
virtual void gateCreated(cGate *newgate)=0
virtual cFigure::Rectangle getSubmoduleBounds(const cModule *submodule)=0
virtual void getImageSize(const char *imageName, double &outWidth, double &outHeight)=0
virtual unsigned long getUniqueNumber()=0
virtual void messageSendHop(cMessage *msg, cGate *srcGate, const ChannelResult &result)=0
virtual void forgetXMLDocument(const char *filename)=0
virtual void moduleReparented(cModule *module, cModule *oldparent, int oldId)=0
virtual int getNumRNGs() const =0
virtual void releaseStreamForSnapshot(std::ostream *os)=0
virtual void displayStringChanged(cComponent *component)=0
virtual const char * getCurrentEventClassName()
Definition cenvir.h:284
virtual bool isModuleLocal(cModule *parentmod, const char *modname, int index)=0
virtual void bubble(cComponent *component, const char *text)=0
virtual void connectionCreated(cGate *srcgate)=0
virtual void log(cLogEntry *entry)=0
virtual bool isGUI() const =0
virtual int getParsimProcId() const =0
virtual void endSend(cMessage *msg)=0
virtual void refOsgNode(osg::Node *scene)=0
virtual void printfmsg(const char *fmt,...)
virtual void notifyLifecycleListeners(SimulationLifecycleEventType eventType, cObject *details=nullptr)
virtual void messageCreated(cMessage *msg)=0
virtual const char * getCurrentEventName()
Definition cenvir.h:278
cEnvir()
Definition cenvir.h:103
virtual void addLifecycleListener(cISimulationLifecycleListener *listener)
virtual void messageDeleted(cMessage *msg)=0
virtual void recordStatistic(cComponent *component, const char *name, cStatistic *statistic, opp_string_map *attributes=nullptr)=0
virtual cXMLElement * getXMLDocument(const char *filename, const char *xpath=nullptr)=0
virtual void appendToImagePath(const char *directory)=0
virtual double getZoomLevel(const cModule *module)=0
virtual void componentInitBegin(cComponent *component, int stage)
Definition cenvir.h:126
virtual void configure(cComponent *component)=0
virtual void messageScheduled(cMessage *msg)=0
virtual void recordParameter(cPar *par)=0
virtual void moduleDeleted(cModule *module)=0
virtual double getRemainingAnimationHoldTime() const =0
virtual unsigned getExtraStackForEnvir() const =0
Represents an event in the discrete event simulator.
Definition cevent.h:47
A lightweight graphical object for cCanvas.
Definition ccanvas.h:61
Represents a module gate.
Definition cgate.h:63
A callback interface for receiving notifications at various stages simulations, including setting up,...
Definition clifecyclelistener.h:187
This class holds various data that is captured when a particular log statement executes....
Definition clog.h:377
The message class in OMNeT++. cMessage objects may represent events, messages, jobs or other entities...
Definition cmessage.h:96
This class represents modules in the simulation.
Definition cmodule.h:49
cObject is a lightweight class which serves as the root of the OMNeT++ class hierarchy....
Definition cobject.h:93
A cObject that keeps track of its owner. It serves as base class for many classes in the OMNeT++ libr...
Definition cownedobject.h:106
Represents a module or channel parameter.
Definition cpar.h:71
Stores a (NED) property with its (possibly compound) value.
Definition cproperty.h:39
Abstract interface for random number generator classes.
Definition crng.h:49
A cEnvir that can be instantiated as a user interface, like Cmdenv and Tkenv.
Definition cenvir.h:914
virtual int run(int argc, char *argv[], cConfiguration *cfg)=0
Thrown when the simulation kernel or other components detect a runtime error.
Definition cexception.h:343
Base class for all simple module classes.
Definition csimplemodule.h:203
cStatistic is an abstract class for computing statistical properties of a random variable.
Definition cstatistic.h:35
Represents an XML element in an XML configuration file.
Definition cxmlelement.h:76
Lightweight string-to-string map, used internally in some parts of OMNeT++.
Definition opp_string.h:220
SimulationLifecycleEventType
Event type for cISimulationLifecycleListener's lifecycleEvent() method.
Definition clifecyclelistener.h:29
int simsignal_t
Signal handle.
Definition clistener.h:37
SimTime simtime_t
Represents simulation time.
Definition simtime_t.h:40
Allows returning multiple values from the processMessage() method.
Definition cchannel.h:34
Options for the cSimpleModule::send() and cSimpleModule::sendDirect() calls.
Definition csimplemodule.h:82