00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __CMODULE_H
00021 #define __CMODULE_H
00022
00023 #include "defs.h"
00024
00025 #include <time.h>
00026 #include "cobject.h"
00027 #include "ccoroutine.h"
00028 #include "globals.h"
00029 #include "carray.h"
00030 #include "cqueue.h"
00031 #include "cgate.h"
00032 #include "csimul.h"
00033 #include "cdefaultlist.h"
00034
00035
00036 enum {
00037 sENDED,
00038 sREADY
00039 };
00040
00041
00042 enum {
00043 dispSUBMOD=0,
00044 dispENCLOSINGMOD=1,
00045 dispNUMTYPES
00046 };
00047
00048
00049 class cMessage;
00050 class cGate;
00051 class cModulePar;
00052 class cModule;
00053 class cCompoundModule;
00054 class cSimulation;
00055 class cModuleType;
00056
00057
00063
00069 SIM_API void connect(cModule *frm, int frg,
00070 cChannelType *linkp,
00071 cModule *tom, int tog);
00072
00078 SIM_API void connect(cModule *frm, int frg,
00079 cPar *delayp, cPar *errorp, cPar *dataratep,
00080 cModule *tom, int tog);
00082
00091 typedef void (*DisplayStringNotifyFunc)(cModule*,bool,void*);
00092
00093
00094
00106 class SIM_API cModule : public cDefaultList
00107 {
00108 friend class cGate;
00109 friend class cModulePar;
00110 friend class cSimulation;
00111 friend class cModuleType;
00112 friend class cSubModIterator;
00113
00114 public:
00115 static bool pause_in_sendmsg;
00116 static std::string lastmodulefullpath;
00117 static const cModule *lastmodulefullpathmod;
00118
00119 protected:
00120 mutable char *fullname;
00121 cModuleType *mod_type;
00122 int mod_id;
00123
00124
00125
00126
00127 cModule *prevp, *nextp;
00128 cModule *firstsubmodp;
00129 cModule *lastsubmodp;
00130
00131 public:
00132
00133
00134 cArray gatev;
00135 cArray paramv;
00136
00137 protected:
00138 int idx;
00139 int vectsize;
00140
00141 cDisplayString *dispstr;
00142 cDisplayString *bgdispstr;
00143
00144 bool ev_enabled;
00145
00146 short rngmapsize;
00147 int *rngmap;
00148
00149 public:
00150
00151
00152 bool hasDisplayString() {return dispstr!=NULL;}
00153 bool hasBackgroundDisplayString() {return bgdispstr!=NULL;}
00154
00155
00156 void setEvEnabled(bool e) {ev_enabled = e;}
00157 bool isEvEnabled() {return ev_enabled;}
00158
00159
00160 void setRNGMap(short size, int *map) {rngmapsize=size; rngmap=map;}
00161
00162 protected:
00163
00164
00165 virtual void arrived(cMessage *msg,int n,simtime_t t) = 0;
00166
00167
00168 virtual void setId(int n);
00169
00170
00171
00172 virtual void setIndex(int i, int n);
00173
00174
00175
00176 virtual void setModuleType(cModuleType *mtype);
00177
00178
00179 void insertSubmodule(cModule *mod);
00180
00181
00182 void removeSubmodule(cModule *mod);
00183
00184
00185
00186 virtual cGate *createGateObject(const char *gname, char tp);
00187
00188 protected:
00211
00222 virtual void doBuildInside() {}
00223
00228 virtual void initialize(int stage) {if(stage==0) initialize();}
00229
00235 virtual int numInitStages() const {return 1;}
00236
00241 virtual void initialize();
00242
00247 virtual void finish();
00248
00261 virtual void handleParameterChange(const char *parname);
00263
00264 public:
00267
00271 cModule(const cModule& mod);
00272
00280 cModule();
00281
00285 virtual ~cModule();
00286
00291 cModule& operator=(const cModule& mod);
00293
00296
00297
00298
00303 virtual void forEachChild(cVisitor *v);
00304
00308 virtual void setName(const char *s);
00309
00315 virtual const char *fullName() const;
00316
00320 virtual std::string fullPath() const;
00321
00327 virtual const char *fullPath(char *buffer, int bufsize) const;
00329
00332
00337 cGate *addGate(const char *s, char tp, bool isvector=false);
00338
00354 int setGateSize(const char *s, int size);
00355
00359 cPar *addPar(const char *s);
00360
00382 virtual int buildInside();
00384
00387
00392 virtual bool isSimple() const;
00393
00397 cModuleType *moduleType() const {return mod_type;}
00398
00406 int id() const {return mod_id;}
00407
00412 cModule *parentModule() const {return dynamic_cast<cModule *>(owner());}
00413
00417 bool isVector() const {return vectsize>=0;}
00418
00422 int index() const {return idx;}
00423
00428 int size() const {return vectsize<0?1:vectsize;}
00429
00435 cRNG *rng(int k) const {return ev.rng(k<rngmapsize ? rngmap[k] : k);}
00437
00440
00446 int findSubmodule(const char *submodname, int idx=-1);
00447
00453 cModule *submodule(const char *submodname, int idx=-1);
00454
00461 cModule *moduleByRelativePath(const char *path);
00463
00466
00471 int gates() const {return gatev.items();}
00472
00478 cGate *gate(int g) {return (cGate*)gatev[g];}
00479
00485 const cGate *gate(int g) const {return (const cGate*)gatev[g];}
00486
00491 cGate *gate(const char *gatename,int sn=-1);
00492
00496 const cGate *gate(const char *gatename,int sn=-1) const;
00497
00506 int gateSize(const char *gatename) const;
00507
00512 int findGate(const char *gatename, int sn=-1) const;
00513
00517 bool hasGate(const char *gatename, int sn=-1) const {return findGate(gatename,sn)>=0;}
00518
00525 bool checkInternalConnections() const;
00527
00530
00534 int params() const {return paramv.items();}
00535
00540 cPar& par(int p);
00541
00546 cPar& par(const char *parname);
00547
00552 int findPar(const char *parname) const;
00553
00558 cPar& ancestorPar(const char *parname);
00559
00563 bool hasPar(const char *s) const {return findPar(s)>=0;}
00565
00571
00576 virtual void callInitialize();
00577
00582 virtual bool callInitialize(int stage);
00583
00587 virtual void callFinish();
00589
00592
00599 virtual void scheduleStart(simtime_t t) = 0;
00600
00606 virtual void deleteModule();
00607
00629 virtual void changeParentTo(cModule *mod);
00631
00634
00639 cDisplayString& displayString();
00640
00645 cDisplayString& backgroundDisplayString();
00646
00650 void setDisplayString(const char *dispstr, bool immediate=true);
00651
00655 void setBackgroundDisplayString(const char *dispstr, bool immediate=true);
00656
00661 const char *displayString(int type);
00662
00667 void setDisplayString(int type, const char *dispstr, bool immediate=true);
00668
00673 void bubble(const char *text);
00675 };
00676
00677
00678
00686 class SIM_API cCompoundModule : public cModule
00687 {
00688 friend class TCompoundModInspector;
00689
00690 protected:
00691
00692 virtual void arrived(cMessage *msg,int n,simtime_t t);
00693
00694 public:
00697
00701 cCompoundModule(const cCompoundModule& mod);
00702
00707 cCompoundModule();
00708
00712 virtual ~cCompoundModule();
00713
00717 cCompoundModule& operator=(const cCompoundModule& mod);
00719
00722
00727 virtual cPolymorphic *dup() const {return new cCompoundModule(*this);}
00728
00733 virtual std::string info() const;
00735
00738
00743 virtual void scheduleStart(simtime_t t);
00745 };
00746
00747
00748
00761 class SIM_API cSubModIterator
00762 {
00763 private:
00764 cModule *p;
00765
00766 public:
00770 cSubModIterator(const cModule& h) {p = &h ? h.firstsubmodp : NULL;}
00771
00775 void init(const cModule& h) {p = &h ? h.firstsubmodp : NULL;}
00776
00782 cModule *operator()() const {return p;}
00783
00787 bool end() const {return (bool)(p==NULL);}
00788
00794 cModule *operator++(int) {if (!p) return NULL; cModule *t=p; p=p->nextp; return t;}
00795 };
00796
00797
00798
00799 #endif
00800