cenvir.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __CENVIR_H
00018 #define __CENVIR_H
00019
00020 #include <sstream>
00021 #include <iostream>
00022 #include "simkerneldefs.h"
00023 #include "simtime_t.h"
00024 #include "opp_string.h"
00025 #include "csimulation.h"
00026 #include "clistener.h"
00027
00028 NAMESPACE_BEGIN
00029
00030 class cObject;
00031 class cOwnedObject;
00032 class cMessage;
00033 class cPar;
00034 class cGate;
00035 class cComponent;
00036 class cModule;
00037 class cSimpleModule;
00038 class cStatistic;
00039 class cProperty;
00040 class cRNG;
00041 class cXMLElement;
00042 class cEnvir;
00043 class cConfiguration;
00044 class cConfigurationEx;
00045
00046 using std::endl;
00047
00048
00049 #define EVCB ev.suppress_notifications ? (void)0 : ev
00050
00069 #define ev (*cSimulation::getActiveEnvir())
00070
00071
00086 #define EV ev.isDisabled()?ev:ev
00087
00088
00103 class SIM_API cEnvir
00104 {
00105 friend class evbuf;
00106 public:
00107
00108 bool disable_tracing;
00109
00110
00111 bool record_eventlog;
00112
00113
00114
00115
00116
00117
00118
00119 bool suppress_notifications;
00120
00121
00122 bool debug_on_errors;
00123 bool attach_debugger_on_errors;
00124
00125 protected:
00126
00127 std::ostream out;
00128
00129 protected:
00130
00131 virtual void sputn(const char *s, int n) = 0;
00132
00133
00134 virtual void putsmsg(const char *msg) = 0;
00135
00136
00137 virtual bool askyesno(const char *msg) = 0;
00138
00139
00140 void flushLastLine();
00141
00142 public:
00145
00149 cEnvir();
00150
00154 virtual ~cEnvir();
00156
00159
00166
00167 virtual void objectDeleted(cObject *object) {}
00168
00172 virtual void componentInitBegin(cComponent *component, int stage) {}
00173
00181 virtual void simulationEvent(cMessage *msg) = 0;
00182
00196 virtual void messageSent_OBSOLETE(cMessage *msg, cGate *directToGate=NULL) = 0;
00197
00202 virtual void messageScheduled(cMessage *msg) = 0;
00203
00208 virtual void messageCancelled(cMessage *msg) = 0;
00209
00217 virtual void beginSend(cMessage *msg) = 0;
00218
00220 virtual void messageSendDirect(cMessage *msg, cGate *toGate, simtime_t propagationDelay, simtime_t transmissionDelay) = 0;
00221
00223 virtual void messageSendHop(cMessage *msg, cGate *srcGate) = 0;
00224
00226 virtual void messageSendHop(cMessage *msg, cGate *srcGate, simtime_t propagationDelay, simtime_t transmissionDelay) = 0;
00227
00229 virtual void endSend(cMessage *msg) = 0;
00230
00235 virtual void messageCreated(cMessage *msg) = 0;
00236
00241 virtual void messageCloned(cMessage *msg, cMessage* clone) = 0;
00242
00248 virtual void messageDeleted(cMessage *msg) = 0;
00249
00253 virtual void moduleReparented(cModule *module, cModule *oldparent) = 0;
00254
00261 virtual void componentMethodBegin(cComponent *from, cComponent *to, const char *methodFmt, va_list va, bool silent) = 0;
00262
00267 virtual void componentMethodEnd() = 0;
00268
00274 virtual void moduleCreated(cModule *newmodule) = 0;
00275
00287 virtual void moduleDeleted(cModule *module) = 0;
00288
00292 virtual void gateCreated(cGate *newgate) = 0;
00293
00298 virtual void gateDeleted(cGate *gate) = 0;
00299
00304 virtual void connectionCreated(cGate *srcgate) = 0;
00305
00310 virtual void connectionDeleted(cGate *srcgate) = 0;
00311
00316 virtual void displayStringChanged(cComponent *component) = 0;
00317
00322
00323
00324
00325 virtual void undisposedObject(cObject *obj) {}
00327
00330
00336 virtual void configure(cComponent *component) = 0;
00337
00342 virtual void readParameter(cPar *parameter) = 0;
00343
00354 virtual bool isModuleLocal(cModule *parentmod, const char *modname, int index) = 0;
00355
00378 virtual cXMLElement *getXMLDocument(const char *filename, const char *xpath=NULL) = 0;
00379
00401 virtual cXMLElement *getParsedXMLString(const char *content, const char *xpath=NULL) = 0;
00402
00416 virtual void forgetXMLDocument(const char *filename) = 0;
00417
00430 virtual void forgetParsedXMLString(const char *content) = 0;
00431
00441 virtual void flushXMLDocumentCache() = 0;
00442
00452 virtual void flushXMLParsedContentCache() = 0;
00453
00458 virtual unsigned getExtraStackForEnvir() const = 0;
00459
00467 virtual cConfiguration *getConfig() = 0;
00468
00474 virtual cConfigurationEx *getConfigEx();
00476
00484 virtual bool isGUI() const = 0;
00485
00501 bool isDisabled() const {return disable_tracing && !record_eventlog;}
00502
00507
00508
00509 cEnvir& operator<<(const std::string& t) {out << t; return *this;}
00510
00522 template<typename T> cEnvir& operator<<(const T& t) {out << t; return *this;}
00523
00527 cEnvir& operator<<(std::ostream& (t)(std::ostream&)) {out << t; return *this;}
00528
00533 std::ostream& getOStream() {return out;}
00534
00539 virtual void bubble(cComponent *component, const char *text) = 0;
00540
00545 virtual void printfmsg(const char *fmt,...);
00546
00557
00558 virtual int printf(const char *fmt,...);
00559
00566 virtual cEnvir& flush() = 0;
00567
00571 virtual std::string gets(const char *prompt, const char *defaultreply=NULL) = 0;
00572
00578
00579 virtual bool askYesNo(const char *fmt,...);
00581
00584
00589 virtual int getNumRNGs() const = 0;
00590
00594 virtual cRNG *getRNG(int k) = 0;
00595
00600 virtual void getRNGMappingFor(cComponent *component) = 0;
00602
00612
00620 virtual void *registerOutputVector(const char *modulename, const char *vectorname) = 0;
00621
00625 virtual void deregisterOutputVector(void *vechandle) = 0;
00626
00630 virtual void setVectorAttribute(void *vechandle, const char *name, const char *value) = 0;
00631
00637 virtual bool recordInOutputVector(void *vechandle, simtime_t t, double value) = 0;
00639
00649
00653 virtual void recordScalar(cComponent *component, const char *name, double value, opp_string_map *attributes=NULL) = 0;
00654
00659 virtual void recordStatistic(cComponent *component, const char *name, cStatistic *statistic, opp_string_map *attributes=NULL) = 0;
00661
00664
00685 virtual void addResultRecorders(cComponent *component, simsignal_t signal, const char *statisticName, cProperty *statisticTemplateProperty) = 0;
00687
00695
00699 virtual std::ostream *getStreamForSnapshot() = 0;
00700
00704 virtual void releaseStreamForSnapshot(std::ostream *os) = 0;
00706
00712 virtual int getArgCount() const = 0;
00713
00717 virtual char **getArgVector() const = 0;
00718
00722 virtual int getParsimProcId() const = 0;
00723
00728 virtual int getParsimNumPartitions() const = 0;
00729
00733 virtual unsigned long getUniqueNumber() = 0;
00734
00748 virtual bool idle() = 0;
00749
00754 virtual void attachDebugger() = 0;
00756 };
00757
00758
00766 class SIM_API cRunnableEnvir : public cEnvir
00767 {
00768 public:
00773 virtual int run(int argc, char *argv[], cConfiguration *cfg) = 0;
00774 };
00775
00776 NAMESPACE_END
00777
00778 #endif
00779
00780