00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
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
00074 int size;
00075 int delta;
00076 cModule **vect;
00077 int last_id;
00078
00079
00080 cModule *systemmodp;
00081 cSimpleModule *runningmodp;
00082 cModule *contextmodp;
00083 int contexttype;
00084 cNetworkType *networktype;
00085 cScheduler *schedulerp;
00086
00087 simtime_t sim_time;
00088 long event_num;
00089
00090 int run_number;
00091 cSimpleModule *backtomod;
00092 cException *exception;
00093 int exception_type;
00094
00095 public:
00096
00097 cMessageHeap msgQueue;
00098
00099
00100 void init();
00101
00102
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
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