00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __CENVIR_H
00022 #define __CENVIR_H
00023
00024 #include <stdlib.h>
00025 #include "defs.h"
00026 #include "cpar.h"
00027
00028
00029 class cObject;
00030 class cMessage;
00031 class cSimpleModule;
00032
00033 class TOmnetApp;
00034
00035
00036 class cEnvir;
00037
00043 ENVIR_API extern cEnvir ev;
00044
00045
00046
00047 enum {
00048 SLAVE_MODE = 0,
00049 MASTER_MODE = 1,
00050 NONPARALLEL_MODE = 2,
00051 STARTUPERROR_MODE = 3
00052 };
00053
00054 ENVIR_API bool memoryIsLow();
00055 ENVIR_API bool opp_loadlibrary(const char *libname);
00056
00057
00058
00091 class ENVIR_API cEnvir
00092 {
00093 public:
00094 TOmnetApp *app;
00095 public:
00096 int disable_tracing;
00097 private:
00098 int running_mode;
00099 char prmpt[81];
00100
00101 public:
00107
00111 cEnvir();
00112
00116 ~cEnvir();
00118
00121
00126 void setup(int ac, char *av[]);
00127
00132 void run();
00133
00137 void shutdown();
00139
00142
00149 void objectDeleted(cObject *object);
00150
00157 void messageSent(cMessage *msg);
00158
00166 void messageDelivered(cMessage *msg);
00167
00172 void breakpointHit(const char *lbl, cSimpleModule *mod);
00174
00177
00182 const char *getParameter(int run_no, const char *parname);
00183
00188 const char *getPhysicalMachineFor(const char *logical_mach);
00189
00193 const char *getDisplayString(int run_no, const char *name);
00195
00198
00203 void printfmsg(const char *fmt,...);
00204
00210 void printf(const char *fmt="\n",...);
00211
00216 void puts(const char *s);
00217
00222 bool gets(const char *prompt, char *buf, int len=255);
00223
00230 bool askf(char *buf, int len, const char *promptfmt,...);
00231
00237 bool askYesNo(const char *msgfmt,...);
00238
00242 cEnvir& setPrompt(const char *s);
00243
00247 const char *prompt() const {return prmpt;}
00248
00253 void foreignPuts(const char *hostname, const char *mod, const char *str);
00255
00265
00272 void *registerOutputVector(const char *modulename, const char *vectorname, int tuple);
00273
00277 void deregisterOutputVector(void *vechandle);
00278
00284 bool recordInOutputVector(void *vechandle, simtime_t t, double value);
00285
00291 bool recordInOutputVector(void *vechandle, simtime_t t, double value1, double value2);
00293
00304
00308 void recordScalar(cModule *module, const char *name, double value);
00309
00313 void recordScalar(cModule *module, const char *name, const char *text);
00314
00318 void recordScalar(cModule *module, const char *name, cStatistic *stats);
00320
00328
00332 ostream *getStreamForSnapshot();
00333
00337 void releaseStreamForSnapshot(ostream *os);
00339
00342
00347 unsigned extraStackForEnvir();
00348
00353 int runningMode() const {return running_mode;}
00354
00358 int argCount();
00359
00363 char **argVector();
00365 };
00366
00367
00368
00369
00370 inline cEnvir& operator<< (cEnvir& ev, cPar& p)
00371 {char buf[81]; p.getAsText(buf,80); ev.puts(buf); return ev;}
00372 inline cEnvir& operator<< (cEnvir& ev, const char *s)
00373 {ev.puts(s); return ev;}
00374 inline cEnvir& operator<< (cEnvir& ev, const signed char *s)
00375 {ev.puts((const char *)s); return ev;}
00376 inline cEnvir& operator<< (cEnvir& ev, const unsigned char *s)
00377 {ev.puts((const char *)s); return ev;}
00378 inline cEnvir& operator<< (cEnvir& ev, char c)
00379 {ev.printf("%c",c); return ev;}
00380 inline cEnvir& operator<< (cEnvir& ev, unsigned char c)
00381 {ev.printf("%c",c); return ev;}
00382 inline cEnvir& operator<< (cEnvir& ev, signed char c)
00383 {ev.printf("%c",c); return ev;}
00384 inline cEnvir& operator<< (cEnvir& ev, short i)
00385 {ev.printf("%d", (int)i); return ev;}
00386 inline cEnvir& operator<< (cEnvir& ev, unsigned short i)
00387 {ev.printf("%u", (int)i); return ev;}
00388 inline cEnvir& operator<< (cEnvir& ev, int i)
00389 {ev.printf("%d", i); return ev;}
00390 inline cEnvir& operator<< (cEnvir& ev, unsigned int i)
00391 {ev.printf("%u", i); return ev;}
00392 inline cEnvir& operator<< (cEnvir& ev, long l)
00393 {ev.printf("%ld", l); return ev;}
00394 inline cEnvir& operator<< (cEnvir& ev, unsigned long l)
00395 {ev.printf("%lu", l); return ev;}
00396 inline cEnvir& operator<< (cEnvir& ev, double d)
00397 {ev.printf("%g", d); return ev;}
00398 inline cEnvir& operator<< (cEnvir& ev, long double d)
00399 {ev.printf("%lg", d); return ev;}
00400
00401
00402
00403 inline cEnvir& operator* (cEnvir& ev, char *s)
00404 {return ev.setPrompt((char *)s);}
00405 inline cEnvir& operator* (cEnvir& ev, const signed char *s)
00406 {return ev.setPrompt((const char *)s);}
00407 inline cEnvir& operator* (cEnvir& ev, const unsigned char *s)
00408 {return ev.setPrompt((const char *)s);}
00409
00410
00411 inline cEnvir& operator>> (cEnvir& ev, cPar& p)
00412 {char buf[80];buf[0]=0; ev.gets(ev.prompt(), buf, 80); p.setFromText(buf,'?'); return ev;}
00413 inline cEnvir& operator>> (cEnvir& ev, char *s)
00414 {ev.gets(ev.prompt(),(char *)s, 80); return ev;}
00415 inline cEnvir& operator>> (cEnvir& ev, signed char *s)
00416 {ev.gets(ev.prompt(),(char *)s, 80); return ev;}
00417 inline cEnvir& operator>> (cEnvir& ev, unsigned char *s)
00418 {ev.gets(ev.prompt(),(char *)s, 80); return ev;}
00419 inline cEnvir& operator>> (cEnvir& ev, char& c)
00420 {char buf[80];buf[0]=0; ev.gets(ev.prompt(), buf, 80); c=buf[0]; return ev;}
00421 inline cEnvir& operator>> (cEnvir& ev, signed char& c)
00422 {char buf[80];buf[0]=0; ev.gets(ev.prompt(), buf, 80); c=buf[0]; return ev;}
00423 inline cEnvir& operator>> (cEnvir& ev, unsigned char& c)
00424 {char buf[80];buf[0]=0; ev.gets(ev.prompt(), buf, 80); c=buf[0]; return ev;}
00425 inline cEnvir& operator>> (cEnvir& ev, short& i)
00426 {char buf[80];buf[0]=0; ev.gets(ev.prompt(), buf, 80); i=(short)atol(buf); return ev;}
00427 inline cEnvir& operator>> (cEnvir& ev, int& i)
00428 {char buf[80];buf[0]=0; ev.gets(ev.prompt(), buf, 80); i=(int)atol(buf); return ev;}
00429 inline cEnvir& operator>> (cEnvir& ev, long& l)
00430 {char buf[80];buf[0]=0; ev.gets(ev.prompt(), buf, 80); l=atol(buf); return ev;}
00431 inline cEnvir& operator>> (cEnvir& ev, unsigned short& i)
00432 {char buf[80];buf[0]=0; ev.gets(ev.prompt(), buf, 80); i=(unsigned short)atol(buf); return ev;}
00433 inline cEnvir& operator>> (cEnvir& ev, unsigned int& i)
00434 {char buf[80];buf[0]=0; ev.gets(ev.prompt(), buf, 80); i=(unsigned int)atol(buf); return ev;}
00435 inline cEnvir& operator>> (cEnvir& ev, unsigned long& l)
00436 {char buf[80];buf[0]=0; ev.gets(ev.prompt(), buf, 80); l=(unsigned long)atol(buf); return ev;}
00437 inline cEnvir& operator>> (cEnvir& ev, double& d)
00438 {char buf[80];buf[0]=0; ev.gets(ev.prompt(), buf, 80); d=atof(buf); return ev;}
00439 inline cEnvir& operator>> (cEnvir& ev, long double& d)
00440 {char buf[80];buf[0]=0; ev.gets(ev.prompt(), buf, 80); d=atof(buf); return ev;}
00441
00442 inline cEnvir& endl(cEnvir& ev) {ev.puts("\n"); return ev;}
00443 inline cEnvir& operator<<(cEnvir& ev, cEnvir& (*f)(cEnvir&)) {return (*f)(ev);}
00444
00445 #endif