00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __CENVIR_H
00021 #define __CENVIR_H
00022
00023 #include <sstream>
00024 #include <iostream>
00025 #include "defs.h"
00026
00027 class cObject;
00028 class cMessage;
00029 class cGate;
00030 class cModule;
00031 class cSimpleModule;
00032 class cStatistic;
00033 class cRNG;
00034 class cConfiguration;
00035 class cXMLElement;
00036 class TOmnetApp;
00037 class cEnvir;
00038
00039 using std::endl;
00040
00041
00042
00043
00044
00045
00046 template <class E, class T = std::char_traits<E> >
00047 class basic_evbuf : public std::basic_stringbuf<E,T> {
00048 public:
00049 basic_evbuf(cEnvir *ev) : _ev(ev) {}
00050 bool isempty() {return pptr()==pbase();}
00051 protected:
00052 virtual int sync();
00053 virtual std::streamsize xsputn(const E *s, std::streamsize n) {
00054 #if !defined(_MSC_VER) || _MSC_VER>1200
00055 std::streamsize r = std::basic_stringbuf<E,T>::xsputn(s,n);
00056 #else
00057
00058
00059
00060
00061 const E *_S = s;
00062 std::streamsize _N = n;
00063 std::streamsize _M, _Ns;
00064 for (_Ns = 0; 0 < _N; )
00065 if (pptr() != 0 && 0 < (_M = epptr() - pptr()))
00066 {if (_N < _M)
00067 _M = _N;
00068 T::copy(pptr(), _S, _M);
00069 _S += _M, _Ns += _M, _N -= _M, pbump(_M); }
00070 else if (T::eq_int_type(T::eof(),
00071 overflow(T::to_int_type(*_S))))
00072 break;
00073 else
00074 ++_S, ++_Ns, --_N;
00075 std::streamsize r = _Ns;
00076 #endif
00077 for(;n>0;n--,s++)
00078 if (*s=='\n')
00079 {sync();break;}
00080 return r;
00081 }
00082 cEnvir *_ev;
00083 };
00084
00085 typedef basic_evbuf<char> evbuf;
00086
00087
00106 ENVIR_API extern cEnvir ev;
00107
00108 ENVIR_API bool memoryIsLow();
00109
00110
00111
00142 class ENVIR_API cEnvir : public std::ostream
00143 {
00144 public:
00145
00146 TOmnetApp *app;
00147 bool disable_tracing;
00148 bool debug_on_errors;
00149 private:
00150
00151 evbuf ev_buf;
00152 bool isgui;
00153
00154 public:
00155
00156
00157
00158 void sputn(const char *s, int n);
00159
00160
00161
00162 void flushlastline() {if (!ev_buf.isempty()) ev_buf.sputn("\n",1);}
00163
00164 public:
00170
00174 cEnvir();
00175
00179 ~cEnvir();
00181
00184
00189 void setup(int ac, char *av[]);
00190
00196 int run();
00197
00201 void shutdown();
00203
00206
00213 void objectDeleted(cObject *object);
00214
00228 void messageSent(cMessage *msg, cGate *directToGate=NULL);
00229
00233 void moduleReparented(cModule *module, cModule *oldparent);
00234
00242 void messageDelivered(cMessage *msg);
00243
00248 void breakpointHit(const char *lbl, cSimpleModule *mod);
00249
00255 void moduleMethodCalled(cModule *from, cModule *to, const char *method);
00256
00262 void moduleCreated(cModule *newmodule);
00263
00275 void moduleDeleted(cModule *module);
00276
00281 void connectionCreated(cGate *srcgate);
00282
00287 void connectionRemoved(cGate *srcgate);
00288
00293 void displayStringChanged(cGate *gate);
00294
00298
00299 void displayStringChanged(cModule *submodule);
00300
00304 void backgroundDisplayStringChanged(cModule *parentmodule);
00306
00309
00315 std::string getParameter(int run_no, const char *parname);
00316
00321 bool getParameterUseDefault(int run_no, const char *parname);
00322
00332 bool isModuleLocal(cModule *parentmod, const char *modname, int index);
00333
00355 cXMLElement *getXMLDocument(const char *filename, const char *path=NULL);
00356
00361 unsigned extraStackForEnvir();
00362
00370 cConfiguration *config();
00372
00375
00381 bool isGUI() {return isgui;}
00382
00399 bool disabled() {return disable_tracing;}
00400
00404 void bubble(cModule *mod, const char *text);
00405
00410 void printfmsg(const char *fmt,...);
00411
00419 void printf(const char *fmt="\n",...);
00420
00425 void puts(const char *s);
00426
00433 cEnvir& flush();
00434
00439 std::string gets(const char *prompt, const char *defaultreply=NULL);
00440
00444 bool gets(const char *prompt, char *buf, int len=255);
00445
00451 bool askYesNo(const char *msgfmt,...);
00453
00456
00461 int numRNGs();
00462
00466 cRNG *rng(int k);
00467
00472 void getRNGMappingFor(cModule *mod);
00474
00484
00491 void *registerOutputVector(const char *modulename, const char *vectorname, int tuple);
00492
00496 void deregisterOutputVector(void *vechandle);
00497
00503 bool recordInOutputVector(void *vechandle, simtime_t t, double value);
00504
00510 bool recordInOutputVector(void *vechandle, simtime_t t, double value1, double value2);
00512
00522
00526 void recordScalar(cModule *module, const char *name, double value);
00528
00536
00540 std::ostream *getStreamForSnapshot();
00541
00545 void releaseStreamForSnapshot(std::ostream *os);
00547
00553 int argCount();
00554
00558 char **argVector();
00559
00563 unsigned long getUniqueNumber();
00564
00578 bool idle();
00580 };
00581
00582 template <class E, class T>
00583 int basic_evbuf<E,T>::sync() {
00584 _ev->sputn(this->pbase(), this->pptr()-this->pbase());
00585 setp(this->pbase(),this->epptr());
00586 return 0;
00587 }
00588
00589 #endif