16 #ifndef __OMNETPP_CGATE_H
17 #define __OMNETPP_CGATE_H
22 #include "opp_string.h"
23 #include "simtime_t.h"
24 #include "cexception.h"
36 class cDatarateChannel;
43 #define GATEID_LBITS 20
44 #define GATEID_HBITS (8*sizeof(int)-GATEID_LBITS) // default 12
45 #define GATEID_HMASK ((~0U)<<GATEID_LBITS) // default 0xFFF00000
46 #define GATEID_LMASK (~GATEID_HMASK) // default 0x000FFFFF
48 #define MAX_VECTORGATES ((1<<(GATEID_HBITS-1))-2) // default 2046
49 #define MAX_SCALARGATES ((1<<(GATEID_LBITS-1))-2) // default ~500000
50 #define MAX_VECTORGATESIZE ((1<<(GATEID_LBITS-1))-1) // default ~500000
65 friend class cModuleGates;
66 friend class cPlaceholderModule;
87 Name(
const char *name, Type type);
88 bool operator<(
const Name& other)
const;
103 union Gates { cGate *gate; cGate **gatev; };
107 Desc() {owner=
nullptr; vectorSize=-1; name=
nullptr; input.gate=output.gate=
nullptr;}
108 bool inUse()
const {
return name!=
nullptr;}
109 Type getType()
const {
return name->type;}
110 bool isVector()
const {
return vectorSize>=0;}
111 const char *nameFor(Type t)
const {
return (t==INOUT||name->type!=INOUT) ? name->name.c_str() : t==INPUT ? name->namei.c_str() : name->nameo.c_str();}
112 int indexOf(
const cGate *g)
const {ASSERT(isVector());
return g->pos >> 2;}
113 bool deliverOnReceptionStart(
const cGate *g)
const {
return g->pos&2;}
114 Type getTypeOf(
const cGate *g)
const {
return (g->pos&1)==0 ? INPUT : OUTPUT;}
115 bool isInput(
const cGate *g)
const {
return (g->pos&1)==0;}
116 bool isOutput(
const cGate *g)
const {
return (g->pos&1)==1;}
117 int gateSize()
const {ASSERT(isVector());
return vectorSize;}
118 void setInputGate(cGate *g) {ASSERT(getType()!=OUTPUT && !isVector()); input.gate=g; g->desc=
this; g->pos=(-(1<<2));}
119 void setOutputGate(cGate *g) {ASSERT(getType()!=INPUT && !isVector()); output.gate=g; g->desc=
this; g->pos=(-(1<<2))|1;}
120 void setInputGate(cGate *g,
int index) {ASSERT(getType()!=OUTPUT && isVector()); input.gatev[index]=g; g->desc=
this; g->pos=(index<<2);}
121 void setOutputGate(cGate *g,
int index) {ASSERT(getType()!=INPUT && isVector()); output.gatev[index]=g; g->desc=
this; g->pos=(index<<2)|1;}
122 static int capacityFor(
int size) {
return size<8 ? (size+1)&~1 : size<32 ? (size+3)&~3 : size<256 ? (size+15)&~15 : (size+63)&~63;}
126 Desc *desc =
nullptr;
130 int connectionId = -1;
131 cChannel *channel =
nullptr;
132 cGate *prevGate =
nullptr;
133 cGate *nextGate =
nullptr;
135 static int lastConnectionId;
145 static void clearFullnamePool();
148 void installChannel(cChannel *chan);
151 void checkChannels()
const;
153 #ifdef SIMFRONTEND_SUPPORT
155 virtual bool hasChangedSince(int64_t lastRefreshSerial);
164 virtual const char *getName()
const override;
171 virtual const char *getFullName()
const override;
177 virtual void forEachChild(cVisitor *v)
override;
183 virtual std::string str()
const override;
188 virtual cObject *getOwner()
const override;
198 virtual bool deliver(cMessage *msg,
const SendOptions& options,
simtime_t at);
225 cChannel *connectTo(cGate *gate, cChannel *channel=
nullptr,
bool leaveUninitialized=
false);
244 cChannel *reconnectWith(cChannel *channel,
bool leaveUninitialized=
false);
256 bool isGateHalf()
const;
263 cGate *getOtherHalf()
const;
268 const char *getBaseName()
const;
273 const char *getNameSuffix()
const;
279 cProperties *getProperties()
const;
291 static const char *getTypeName(Type t);
296 cModule *getOwnerModule()
const;
322 int getBaseId()
const;
328 int getIndex()
const;
336 int getVectorSize()
const;
341 int size()
const {
return getVectorSize();}
358 void setDeliverImmediately(
bool d);
391 [[deprecated(
"Renamed to setDeliverImmediately() -- please use the new name")]]
397 [[deprecated(
"Renamed to getDeliverImmediately() -- please use the new name")]]
421 cChannel *getTransmissionChannel()
const;
427 cChannel *findTransmissionChannel()
const;
437 cChannel *getIncomingTransmissionChannel()
const;
444 cChannel *findIncomingTransmissionChannel()
const;
477 cGate *getPathStartGate()
const;
483 cGate *getPathEndGate()
const;
488 bool pathContains(
cModule *module,
int gateId=-1);
497 bool isConnectedOutside()
const;
506 bool isConnectedInside()
const;
513 bool isConnected()
const;
519 bool isPathOK()
const;
535 void setDisplayString(
const char *dispstr);