Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members  

cenvir.h

00001 //==========================================================================
00002 //   CENVIR.H - header for
00003 //                             OMNeT++
00004 //            Discrete System Simulation in C++
00005 //
00006 //
00007 //  Declaration of the following classes:
00008 //    cEnvir    : user interface class
00009 //
00010 //==========================================================================
00011 
00012 /*--------------------------------------------------------------*
00013   Copyright (C) 1992-2003 Andras Varga
00014 
00015   This file is distributed WITHOUT ANY WARRANTY. See the file
00016   `license' for details on this and other legal matters.
00017 *--------------------------------------------------------------*/
00018 
00019 #ifndef __CENVIR_H
00020 #define __CENVIR_H
00021 
00022 #include "defs.h"
00023 
00024 #include <stdlib.h> // atol, atof
00025 #include "cpar.h"
00026 
00027 
00028 class cObject;
00029 class cMessage;
00030 class cSimpleModule;
00031 
00032 class TOmnetApp;
00033 
00034 //=== class declared:
00035 class cEnvir;
00036 
00042 ENVIR_API extern cEnvir ev;
00043 
00044 
00045 // return codes for runningMode()
00046 enum {
00047     SLAVE_MODE = 0,  // must be 0
00048     MASTER_MODE = 1,
00049     NONPARALLEL_MODE = 2,
00050     STARTUPERROR_MODE = 3
00051 };
00052 
00053 ENVIR_API bool memoryIsLow();
00054 ENVIR_API bool opp_loadlibrary(const char *libname);
00055 
00056 //==========================================================================
00057 
00090 class ENVIR_API cEnvir
00091 {
00092   public:
00093     TOmnetApp *app;  // the "simulation application" instance
00094   public:
00095     int disable_tracing;
00096   private:
00097     int running_mode; // MASTER_MODE / SLAVE_MODE / NONPARALLEL_MODE / STARTUPERROR_MODE
00098     char prmpt[81];    // prompt used by prompt() and operator >>
00099 
00100   public:
00106 
00110     cEnvir();
00111 
00115     ~cEnvir();
00117 
00120 
00125     void setup(int ac, char *av[]);
00126 
00132     int 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 
00215     void puts(const char *s);
00216 
00223     void flush();
00224 
00229     bool gets(const char *prompt, char *buf, int len=255);
00230 
00237     bool askf(char *buf, int len, const char *promptfmt,...);
00238 
00244     bool askYesNo(const char *msgfmt,...);
00245 
00249     cEnvir& setPrompt(const char *s);
00250 
00254     const char *prompt() const  {return prmpt;}
00255 
00260     void foreignPuts(const char *hostname, const char *mod, const char *str);
00262 
00272 
00279     void *registerOutputVector(const char *modulename, const char *vectorname, int tuple);
00280 
00284     void deregisterOutputVector(void *vechandle);
00285 
00291     bool recordInOutputVector(void *vechandle, simtime_t t, double value);
00292 
00298     bool recordInOutputVector(void *vechandle, simtime_t t, double value1, double value2);
00300 
00311 
00315     void recordScalar(cModule *module, const char *name, double value);
00316 
00320     void recordScalar(cModule *module, const char *name, const char *text);
00321 
00325     void recordScalar(cModule *module, const char *name, cStatistic *stats);
00327 
00335 
00339     ostream *getStreamForSnapshot();
00340 
00344     void releaseStreamForSnapshot(ostream *os);
00346 
00349 
00354     unsigned extraStackForEnvir();
00355 
00360     int runningMode() const     {return running_mode;}
00361 
00365     int argCount();
00366 
00370     char **argVector();
00372 };
00373 
00374 //==========================================================================
00375 //  Overloaded operators to provide iostream-like I/O for cEnvir
00376 
00377 cEnvir& operator<< (cEnvir& ev, cPar& p);
00378 inline cEnvir& operator<< (cEnvir& ev, const char *s)
00379   {ev.puts(s); return ev;}
00380 inline cEnvir& operator<< (cEnvir& ev, const signed char *s)
00381   {ev.puts((const char *)s); return ev;}
00382 inline cEnvir& operator<< (cEnvir& ev, const unsigned char *s)
00383   {ev.puts((const char *)s); return ev;}
00384 inline cEnvir& operator<< (cEnvir& ev, char c)
00385   {ev.printf("%c",c); return ev;}
00386 inline cEnvir& operator<< (cEnvir& ev, unsigned char c)
00387   {ev.printf("%c",c); return ev;}
00388 inline cEnvir& operator<< (cEnvir& ev, signed char c)
00389   {ev.printf("%c",c); return ev;}
00390 inline cEnvir& operator<< (cEnvir& ev, short i)
00391   {ev.printf("%d", (int)i); return ev;}
00392 inline cEnvir& operator<< (cEnvir& ev, unsigned short i)
00393   {ev.printf("%u", (int)i); return ev;}
00394 inline cEnvir& operator<< (cEnvir& ev, int i)
00395   {ev.printf("%d", i); return ev;}
00396 inline cEnvir& operator<< (cEnvir& ev, unsigned int i)
00397   {ev.printf("%u", i); return ev;}
00398 inline cEnvir& operator<< (cEnvir& ev, long l)
00399   {ev.printf("%ld", l); return ev;}
00400 inline cEnvir& operator<< (cEnvir& ev, unsigned long l)
00401   {ev.printf("%lu", l); return ev;}
00402 inline cEnvir& operator<< (cEnvir& ev, double d)
00403   {ev.printf("%g", d); return ev;}
00404 inline cEnvir& operator<< (cEnvir& ev, long double d)
00405   {ev.printf("%lg", d); return ev;}
00406 
00407 // endl
00408 inline cEnvir& endl(cEnvir& ev) {ev.puts("\n"); return ev;}
00409 inline cEnvir& operator<<(cEnvir& ev, cEnvir& (*f)(cEnvir&)) {return (*f)(ev);}
00410 
00411 // '*' operator is a synonym to ev.setPrompt()
00412 // e.g.: ev*"How many?" >> n;
00413 cEnvir& operator* (cEnvir& ev, char *s);
00414 cEnvir& operator* (cEnvir& ev, const signed char *s);
00415 cEnvir& operator* (cEnvir& ev, const unsigned char *s);
00416 
00417 // NOTE: each >> operator reads a whole line!
00418 cEnvir& operator>> (cEnvir& ev, cPar& p);
00419 cEnvir& operator>> (cEnvir& ev, char *s);
00420 cEnvir& operator>> (cEnvir& ev, signed char *s);
00421 cEnvir& operator>> (cEnvir& ev, unsigned char *s);
00422 cEnvir& operator>> (cEnvir& ev, char& c);
00423 cEnvir& operator>> (cEnvir& ev, signed char& c);
00424 cEnvir& operator>> (cEnvir& ev, unsigned char& c);
00425 cEnvir& operator>> (cEnvir& ev, short& i);
00426 cEnvir& operator>> (cEnvir& ev, int& i);
00427 cEnvir& operator>> (cEnvir& ev, long& l);
00428 cEnvir& operator>> (cEnvir& ev, unsigned short& i);
00429 cEnvir& operator>> (cEnvir& ev, unsigned int& i);
00430 cEnvir& operator>> (cEnvir& ev, unsigned long& l);
00431 cEnvir& operator>> (cEnvir& ev, double& d);
00432 cEnvir& operator>> (cEnvir& ev, long double& d);
00433 
00434 
00435 #endif

Generated at Mon Jun 16 23:37:31 2003 for OMNeT++ by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001