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;
154 void doDisconnect(
bool shouldCallPreDelete);
156 #ifdef SIMFRONTEND_SUPPORT
158 virtual bool hasChangedSince(int64_t lastRefreshSerial);
167 virtual const char *getName()
const override;
174 virtual const char *getFullName()
const override;
180 virtual void forEachChild(cVisitor *v)
override;
186 virtual std::string str()
const override;
191 virtual cObject *getOwner()
const override;
201 virtual bool deliver(cMessage *msg,
const SendOptions& options,
simtime_t at);
228 cChannel *connectTo(cGate *gate, cChannel *channel=
nullptr,
bool leaveUninitialized=
false);
247 cChannel *reconnectWith(cChannel *channel,
bool leaveUninitialized=
false);
259 bool isGateHalf()
const;
266 cGate *getOtherHalf()
const;
271 const char *getBaseName()
const;
276 const char *getNameSuffix()
const;
282 cProperties *getProperties()
const;
294 static const char *getTypeName(Type t);
299 cModule *getOwnerModule()
const;
325 int getBaseId()
const;
331 int getIndex()
const;
339 int getVectorSize()
const;
344 int size()
const {
return getVectorSize();}
361 void setDeliverImmediately(
bool d);
394 [[deprecated(
"Renamed to setDeliverImmediately() -- please use the new name")]]
400 [[deprecated(
"Renamed to getDeliverImmediately() -- please use the new name")]]
424 cChannel *getTransmissionChannel()
const;
430 cChannel *findTransmissionChannel()
const;
440 cChannel *getIncomingTransmissionChannel()
const;
447 cChannel *findIncomingTransmissionChannel()
const;
480 cGate *getPathStartGate()
const;
486 cGate *getPathEndGate()
const;
491 bool pathContains(
cModule *module,
int gateId=-1);
500 bool isConnectedOutside()
const;
509 bool isConnectedInside()
const;
516 bool isConnected()
const;
522 bool isPathOK()
const;
538 void setDisplayString(
const char *dispstr);