00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __CSIMULATION_H
00021 #define __CSIMULATION_H
00022
00023 #include "simkerneldefs.h"
00024 #include "simtime_t.h"
00025 #include "cmessageheap.h"
00026 #include "cexception.h"
00027
00028 NAMESPACE_BEGIN
00029
00030
00031 class cMessage;
00032 class cGate;
00033 class cModule;
00034 class cSimpleModule;
00035 class cCompoundModule;
00036 class cSimulation;
00037 class cException;
00038 class cScheduler;
00039 class cParsimPartition;
00040 class cNEDFileLoader;
00041 class cHasher;
00042 class cModuleType;
00043 class cEnvir;
00044 class cDefaultList;
00045
00046 SIM_API extern cDefaultList defaultList;
00047
00053 #define simulation (*cSimulation::getActiveSimulation())
00054
00055
00071 class SIM_API cSimulation : public cNamedObject, noncopyable
00072 {
00073 friend class cSimpleModule;
00074 private:
00075
00076 static cSimulation *simPtr;
00077 static cEnvir *evPtr;
00078 static cEnvir *staticEvPtr;
00079
00080
00081 int size;
00082 int delta;
00083 cModule **vect;
00084 int last_id;
00085
00086
00087 cEnvir *ownEvPtr;
00088 cModule *systemmodp;
00089 cSimpleModule *activitymodp;
00090 cComponent *contextmodp;
00091 int contexttype;
00092 cModuleType *networktype;
00093 cScheduler *schedulerp;
00094 simtime_t warmup_period;
00095
00096 int simulationstage;
00097 simtime_t sim_time;
00098 eventnumber_t event_num;
00099
00100 cMessage *msg_for_activity;
00101 cException *exception;
00102
00103 cHasher *hasherp;
00104
00105 private:
00106
00107 void checkActive() {if (getActiveSimulation()!=this) throw cRuntimeError(this, eWRONGSIM);}
00108
00109 public:
00110
00111 cMessageHeap msgQueue;
00112 cMessageHeap& getMessageQueue() {return msgQueue;}
00113
00114 public:
00121 cSimulation(const char *name, cEnvir *env);
00122
00126 virtual ~cSimulation();
00128
00135 virtual void forEachChild(cVisitor *v);
00136
00140 virtual std::string getFullPath() const;
00142
00148 static cSimulation *getActiveSimulation() {return simPtr;}
00149
00154 static cEnvir *getActiveEnvir() {return evPtr;}
00155
00161 static void setActiveSimulation(cSimulation *sim);
00162
00167 static void setStaticEnvir(cEnvir *env);
00168
00172 static cEnvir *getStaticEnvir() {return staticEvPtr;}
00173
00177 cEnvir *getEnvir() const {return ownEvPtr;}
00179
00182
00189 int registerModule(cModule *mod);
00190
00195 void deregisterModule(cModule *mod);
00196
00200 int getLastModuleId() const {return last_id;}
00201
00207 cModule *getModuleByPath(const char *modulepath) const;
00208
00212 cModule *getModule(int id) const {return id>=0 && id<size ? vect[id] : NULL;}
00213
00219 _OPPDEPRECATED cModule& operator[](int id) const {return id>=0 && id<size ? *vect[id] : *(cModule *)NULL;}
00220
00224 void setSystemModule(cModule *p);
00225
00229 cModule *getSystemModule() const {return systemmodp;}
00231
00241
00251 static int loadNedSourceFolder(const char *foldername);
00252
00260 static void loadNedFile(const char *nedfname, const char *expectedPackage=NULL, bool isXML=false);
00261
00272 static void loadNedText(const char *name, const char *nedtext, const char *expectedPackage=NULL, bool isXML=false);
00273
00280 static void doneLoadingNedFiles();
00281
00286 static std::string getNedPackageForFolder(const char *folder);
00287
00293 static void clearLoadedNedFiles();
00295
00298
00304 void setScheduler(cScheduler *scheduler);
00305
00309 cScheduler *getScheduler() const {return schedulerp;}
00310
00314 void setupNetwork(cModuleType *networkType);
00315
00321 void startRun();
00322
00327 void callFinish();
00328
00332 void endRun();
00333
00338 void deleteNetwork();
00340
00349 int getSimulationStage() const {return simulationstage;}
00350
00355 cModuleType *getNetworkType() const {return networktype;}
00356
00362 void setSimTime(simtime_t time) {sim_time = time;}
00363
00368 simtime_t_cref getSimTime() const {return sim_time;}
00369
00373 eventnumber_t getEventNumber() const {return event_num;}
00374
00384 simtime_t_cref getWarmupPeriod() const {return warmup_period;}
00385
00389 void setWarmupPeriod(simtime_t t) {warmup_period = t;}
00391
00394
00406 cSimpleModule *selectNextModule();
00407
00422 cMessage *guessNextEvent();
00423
00433 cSimpleModule *guessNextModule();
00434
00444 simtime_t guessNextSimtime();
00445
00453 void doOneEvent(cSimpleModule *m);
00454
00459 void transferTo(cSimpleModule *p);
00460
00464 void transferToMain();
00465
00471 void insertMsg(cMessage *msg);
00472
00476 void setContext(cComponent *p);
00477
00481 void setContextType(int ctxtype) {contexttype = ctxtype;}
00482
00486 void setGlobalContext() {contextmodp=NULL; cOwnedObject::setDefaultOwner(&defaultList);}
00487
00493 cSimpleModule *getActivityModule() const {return activitymodp;}
00494
00498 cComponent *getContext() const {return contextmodp;}
00499
00507 int getContextType() const {return contexttype;}
00508
00513 cModule *getContextModule() const;
00514
00520 cSimpleModule *getContextSimpleModule() const;
00522
00531 unsigned long getUniqueNumber();
00532
00538 bool snapshot(cObject *obj, const char *label);
00539
00544 cHasher *getHasher() {return hasherp;}
00545
00549 void setHasher(cHasher *hasher);
00551 };
00552
00556 inline simtime_t simTime() {return cSimulation::getActiveSimulation()->getSimTime();}
00557
00558
00559 NAMESPACE_END
00560
00561
00562 #endif
00563