Main Page Modules Class Hierarchy Compound List File List Compound Members

# csimul.h

    00001 //==========================================================================
    00002 //   CSIMUL.H  -  header for
    00003 //                             OMNeT++
    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-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 __CSIMUL_H
    00020 #define __CSIMUL_H
    00021
    00022 #include "defs.h"
    00023
    00024 #include "util.h"
    00025 #include "errmsg.h"
    00026 #include "chead.h"
    00027 #include "cmsgheap.h"
    00028 #include "ccoroutine.h"
    00029 #include "coutvect.h" //FIXME
    00030
    00031 //=== classes mentioned:
    00032 class  cMessage;
    00033 class  cGate;
    00034 class  cModulePar;
    00035 class  cModule;
    00036 class  cSimpleModule;
    00037 class  cCompoundModule;
    00038 class  cNetMod;
    00039 class  cSimulation;
    00040 class  cNetworkType;
    00041 class  TModInspector;
    00042 class  cStatistic;
    00043 class  cException;
    00044
    00050 SIM_API extern cSimulation simulation;
    00051
    00052 //==========================================================================
    00053
    00066 class SIM_API cSimulation : public cObject
    00067 {
    00068     friend class cSimpleModule;
    00069
    00070   private:
    00071     // variables of the module vector
    00072     int size;                 // size of vector
    00073     int delta;                // if needed, grows by delta
    00074     cModule **vect;           // vector of modules, vect[0] is not used
    00075     int last_id;              // index of last used pos. in vect[]
    00076
    00077     // simulation global vars
    00078     cModule *systemmodp;      // pointer to system module
    00079     cSimpleModule *runningmodp; // the currently executing module (NULL if in main)
    00080     cModule *contextmodp;     // module in context (or NULL)
    00081     cHead *locallistp;        // owner of newly created objects
    00082     cHead locals;             // "global" local objects list
    00083
    00084     cNetMod *netmodp;         // if runs distributed; communications
    00085                               //      (network interface) module
    00086
    00087     simtime_t sim_time;       // simulation time (time of current event)
    00088     long event_num;           // sequence number of current event
    00089
    00090     int netif_check_freq;     // (distributed execution:) frequency of processing
    00091     int netif_check_cntr;     // msgs from other segments
    00092
    00093     cNetworkType *networktype; // ptr to network creator object
    00094     int run_number;            // which simulation run
    00095     cSimpleModule *backtomod;  // used in cSimpleModule::wait/sendmsg
    00096     cCoroutine runningmod_deleter; // used when a simple module deletes itself
    00097     cException *exception;     // helper variable to get exceptions back from activity()
    00098     int exception_type;        // helper variable, also for getting exceptions back from activity()
    00099
    00100   public:
    00101     cMessageHeap msgQueue;     // future messages (FES)
    00102
    00103   public:
    00106
    00111     cSimulation(const cSimulation& r);
    00112
    00116     explicit cSimulation(const char *name);
    00117
    00121     virtual ~cSimulation();
    00123
    00126
    00131     virtual cObject *dup() const  {return new cSimulation(*this);}
    00132
    00137     virtual void forEach(ForeachFunc f);
    00138
    00143     virtual void writeContents(ostream& os);
    00144
    00148     virtual const char *fullPath() const;
    00149
    00153     virtual const char *fullPath(char *buffer, int bufsize) const;
    00154
    00158     cSimulation& operator=(const cSimulation&)  {copyNotSupported();return *this;}
    00160
    00161     // Internal: things that cannot be done from the constructor
    00162     // (because it is called before main()).
    00163     void init();
    00164
    00167
    00171     int addModule(cModule *mod);
    00172
    00176     void deleteModule(int id);
    00177
    00181     int lastModuleId() const    {return last_id;}
    00182
    00186     cModule *moduleByPath(const char *modulepath) const;
    00187
    00191     cModule *module(int id) const  {return id>=0 && id<size ? vect[id] : NULL;}
    00192
    00198     cModule& operator[](int id) const {return id>=0 && id<size ? *vect[id] : *(cModule *)NULL;}
    00199
    00203     void setSystemModule(cModule *p)  {systemmodp = p;}
    00204
    00208     cModule *systemModule() const  {return systemmodp;}
    00210
    00213
    00217     void setNetInterface(cNetMod *netif);
    00218
    00222     cNetMod *netInterface() const  {return netmodp;}
    00223
    00228     void setupNetwork(cNetworkType *net,int run_num);
    00229
    00236     void startRun();
    00237
    00242     void callFinish();
    00243
    00249     void endRun();
    00250
    00255     void deleteNetwork();
    00256
    00263     void setNetIfCheckFreq(int f)     {netif_check_freq=f;}
    00265
    00268
    00273     cNetworkType *networkType() const     {return networktype;}
    00274
    00280     // FIXME: does run number really belong to the simulation kernel??? why not in Envir?
    00281     int  runNumber() const           {return run_number;}
    00282
    00286     simtime_t simTime() const       {return sim_time;}
    00287
    00291     long eventNumber() const         {return event_num;}
    00293
    00296
    00302     cSimpleModule *selectNextModule();
    00303
    00311     void doOneEvent(cSimpleModule *m);
    00312
    00317     void transferTo(cSimpleModule *p);
    00318
    00322     void transferToMain();
    00323
    00327     void setContextModule(cModule *p);
    00328
    00332     void setGlobalContext()  {contextmodp=NULL;locallistp=&locals;}
    00333
    00337     void setLocalList(cHead *p)  {locallistp=p;}
    00338
    00342     cSimpleModule *runningModule() const {return runningmodp;}
    00343
    00347     cModule *contextModule() const {return contextmodp;}
    00348
    00354     cSimpleModule *contextSimpleModule() const;
    00355
    00363     cHead *localList() {return locallistp==NULL?(&locals):locallistp;}
    00365
    00368
    00374     bool snapshot(cObject *obj, const char *label);
    00376 };
    00377
    00378 //==========================================================================
    00379 //=== operator new used by the NEW() macro:
    00380 class ___nosuchclass;
    00381 void *operator new(size_t m,___nosuchclass *);
    00382
    00383 #endif
    00384