# csimul.h

    00001 //==========================================================================
    00002 //   CSIMUL.H  -  header for
    00003 //                     OMNeT++/OMNEST
    00004 //            Discrete System Simulation in C++
    00005 //
    00006 //
    00007 //  Declaration of the following classes:
    00008 //    cSimulation  : simulation management class; only one instance
    00009 //
    00010 //==========================================================================
    00011
    00012 /*--------------------------------------------------------------*
    00013   Copyright (C) 1992-2005 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 __CSIMUL_H
    00020 #define __CSIMUL_H
    00021
    00022 #include "defs.h"
    00023
    00024 #include "util.h"
    00025 #include "errmsg.h"
    00026 #include "globals.h"
    00027 #include "cmsgheap.h"
    00028 #include "ccoroutine.h"
    00029 #include "coutvect.h"
    00030
    00031 //=== classes mentioned:
    00032 class  cMessage;
    00033 class  cGate;
    00034 class  cModulePar;
    00035 class  cModule;
    00036 class  cSimpleModule;
    00037 class  cCompoundModule;
    00038 class  cSimulation;
    00039 class  cNetworkType;
    00040 class  cException;
    00041 class  cScheduler;
    00042 class  cParsimPartition;
    00043
    00044
    00050 SIM_API extern cSimulation simulation;
    00051
    00052
    00068 class SIM_API cSimulation : public cObject
    00069 {
    00070     friend class cSimpleModule;
    00071
    00072   private:
    00073     // variables of the module vector
    00074     int size;                 // size of vector
    00075     int delta;                // if needed, grows by delta
    00076     cModule **vect;           // vector of modules, vect[0] is not used
    00077     int last_id;              // index of last used pos. in vect[]
    00078
    00079     // simulation global vars
    00080     cModule *systemmodp;      // pointer to system module
    00081     cSimpleModule *runningmodp; // the module currently executing activity() (NULL if handleMessage() or in main)
    00082     cModule *contextmodp;     // module in context (or NULL)
    00083     int contexttype;          // CTX_BUILD, CTX_EVENT, CTX_INITIALIZE or CTX_FINISH
    00084     cNetworkType *networktype; // network type
    00085     cScheduler *schedulerp;   // event scheduler
    00086
    00087     simtime_t sim_time;       // simulation time (time of current event)
    00088     long event_num;           // sequence number of current event
    00089
    00090     int run_number;            // which simulation run
    00091     cSimpleModule *backtomod;  // used in cSimpleModule::wait/sendmsg
    00092     cException *exception;     // helper variable to get exceptions back from activity()
    00093     int exception_type;        // helper variable, also for getting exceptions back from activity()
    00094
    00095   public:
    00096     // internal: FES
    00097     cMessageHeap msgQueue;     // future messages (FES)
    00098
    00099     // internal: things that cannot be done from the constructor of global object
    00100     void init();
    00101
    00102     // internal: complements init().
    00103     void shutdown();
    00104
    00105   public:
    00108
    00113     cSimulation(const cSimulation& r);
    00114
    00118     explicit cSimulation(const char *name);
    00119
    00123     virtual ~cSimulation();
    00125
    00128
    00133     virtual cPolymorphic *dup() const  {return new cSimulation(*this);}
    00134
    00139     virtual void forEachChild(cVisitor *v);
    00140
    00145     virtual void writeContents(std::ostream& os);
    00146
    00150     virtual std::string fullPath() const;
    00151
    00155     virtual const char *fullPath(char *buffer, int bufsize) const;
    00156
    00160     cSimulation& operator=(const cSimulation&)  {copyNotSupported();return *this;}
    00162
    00165
    00172     int registerModule(cModule *mod);
    00173
    00178     void deregisterModule(cModule *mod);
    00179
    00183     int lastModuleId() const    {return last_id;}
    00184
    00189     cModule *moduleByPath(const char *modulepath) const;
    00190
    00194     cModule *module(int id) const  {return id>=0 && id<size ? vect[id] : NULL;}
    00195
    00201     cModule& operator[](int id) const {return id>=0 && id<size ? *vect[id] : *(cModule *)NULL;}
    00202
    00206     void setSystemModule(cModule *p);
    00207
    00211     cModule *systemModule() const  {return systemmodp;}
    00213
    00216
    00221     void setScheduler(cScheduler *sched);
    00222
    00226     cScheduler *scheduler() const  {return schedulerp;}
    00227
    00232     void loadNedFile(const char *nedfile);
    00233
    00237     void setupNetwork(cNetworkType *net,int run_num);
    00238
    00244     void startRun();
    00245
    00250     void callFinish();
    00251
    00255     void endRun();
    00256
    00261     void deleteNetwork();
    00263
    00266
    00271     cNetworkType *networkType() const     {return networktype;}
    00272
    00278     // TBD does run number really belong to the simulation kernel? why not in Envir?
    00279     int  runNumber() const           {return run_number;}
    00280
    00286     void setSimTime(simtime_t time) { sim_time = time; }
    00287
    00291     simtime_t simTime() const       {return sim_time;}
    00292
    00296     long eventNumber() const         {return event_num;}
    00298
    00301
    00313     cSimpleModule *selectNextModule();
    00314
    00329     cMessage *guessNextEvent();
    00330
    00340     cSimpleModule *guessNextModule();
    00341
    00351     simtime_t guessNextSimtime();
    00352
    00360     void doOneEvent(cSimpleModule *m);
    00361
    00366     void transferTo(cSimpleModule *p);
    00367
    00371     void transferToMain();
    00372
    00376     void setContextModule(cModule *p);
    00377
    00381     void setContextType(int ctxtype)  {contexttype = ctxtype;}
    00382
    00386     void setGlobalContext()  {contextmodp=NULL; cObject::setDefaultOwner(&defaultList);}
    00387
    00391     cSimpleModule *runningModule() const {return runningmodp;}
    00392
    00396     cModule *contextModule() const {return contextmodp;}
    00397
    00403     int contextType() const {return contexttype;}
    00404
    00410     cSimpleModule *contextSimpleModule() const;
    00412
    00421     unsigned long getUniqueNumber();
    00422
    00428     bool snapshot(cObject *obj, const char *label);
    00429
    00431 };
    00432
    00433 #endif
    00434