# cgate.h

    00001 //==========================================================================
    00002 //   CGATE.H  -  header for
    00003 //                     OMNeT++/OMNEST
    00004 //            Discrete System Simulation in C++
    00005 //
    00006 //
    00007 //  Declaration of the following classes:
    00008 //    cGate       : module gate
    00009 //
    00010 //==========================================================================
    00011
    00012 /*--------------------------------------------------------------*
    00013   Copyright (C) 1992-2005 Andras Varga
    00014
    00015   This file is distributed WITHOUT ANY WARRANTY. See the file
    00016   `license' for details on this and other legal matters.
    00017 *--------------------------------------------------------------*/
    00018
    00019 #ifndef __CGATE_H
    00020 #define __CGATE_H
    00021
    00022 #include "cobject.h"
    00023
    00024 //=== classes mentioned here:
    00025 class  cGate;
    00026 class  cModule;
    00027 class  cPar;
    00028 class  cMessage;
    00029 class  cChannelType;
    00030 class  cChannel;
    00031 class  cDisplayString;
    00032
    00033 //==========================================================================
    00034
    00043 class SIM_API cGate : public cObject
    00044 {
    00045     friend class cModule;
    00046   protected:
    00047     mutable char *fullname; // buffer to store full name of object
    00048     int  serno;         // index if gate vector, 0 otherwise
    00049     int  vectsize;      // gate vector size (-1 if not vector, 0 if zero-sized gate vector)
    00050     char typ;           // type of gate: 'I' or 'O'
    00051
    00052     cChannel *channelp; // channel object (if exists)
    00053
    00054     cModule *omodp;     // owner module
    00055     int gateid;         // gate number within the module
    00056
    00057     cGate *fromgatep;   // previous and next gate
    00058     cGate *togatep;     //   in the route
    00059
    00060     cDisplayString *dispstr; // the display string (created on demand)
    00061
    00062   public:
    00063     // internal: used from Tkenv: find out if cGate has a display string.
    00064     // displayString() would create the object immediately which we want to avoid.
    00065     bool hasDisplayString() {return dispstr!=NULL;}
    00066
    00067   public:
    00070
    00074     cGate(const cGate& gate);
    00075
    00079     explicit cGate(const char *name, char tp);
    00080
    00084     virtual ~cGate();
    00085
    00090     cGate& operator=(const cGate& gate);
    00092
    00095
    00100     virtual cPolymorphic *dup() const  {return new cGate(*this);}
    00101
    00106     virtual void forEachChild(cVisitor *v);
    00107
    00112     virtual std::string info() const;
    00113
    00119     virtual const char *fullName() const;
    00120
    00124     virtual void setName(const char *s);
    00125
    00129     virtual std::string fullPath() const;
    00130
    00135     virtual const char *fullPath(char *buffer, int bufsize) const;
    00136
    00141     virtual void writeContents(std::ostream& os);
    00143
    00151     virtual bool deliver(cMessage *msg, simtime_t at);
    00152
    00155
    00161     void setOwnerModule(cModule *m, int gid);
    00162
    00168     void setIndex(int sn, int vs);
    00170
    00173
    00185     void connectTo(cGate *g, cChannel *chan=NULL);
    00186
    00194     void disconnect();
    00195
    00202     void setFrom(cGate *g);
    00203
    00210     void setTo(cGate *g);
    00212
    00215
    00222     void setChannel(cChannel *ch);
    00223
    00227     cChannel *channel() const {return channelp;}
    00229
    00232
    00236     char type() const      {return typ;}
    00237
    00241     cModule *ownerModule() const {return omodp;}
    00242
    00247     int id() const         {return gateid;}
    00248
    00252     bool isVector() const  {return vectsize>=0;}
    00253
    00258     int index() const      {return serno;}
    00259
    00267     int size()  const      {return vectsize<0?1:vectsize;}
    00269
    00272
    00278     void setLink(cChannelType *l);
    00279
    00287     void setDelay(cPar *p);
    00288
    00296     void setError(cPar *p);
    00297
    00305     void setDataRate(cPar *p);
    00306
    00314     cPar *delay() const;
    00315
    00323     cPar *error() const;
    00324
    00332     cPar *datarate() const;
    00334
    00337
    00343     bool isBusy() const;
    00344
    00350     simtime_t transmissionFinishes() const;
    00352
    00355
    00361     cGate *fromGate() const {return fromgatep;}
    00362
    00368     cGate *toGate() const   {return togatep;}
    00369
    00374     cGate *sourceGate() const;
    00375
    00380     cGate *destinationGate() const;
    00381
    00385     int routeContains(cModule *m, int g=-1);
    00386
    00394     bool isConnectedOutside() const;
    00395
    00403     bool isConnectedInside() const;
    00404
    00410     bool isConnected() const;
    00411
    00416     bool isRouteOK() const;
    00418
    00425     cDisplayString& displayString();
    00426
    00430     void setDisplayString(const char *dispstr, bool immediate=true);
    00432 };
    00433
    00434 #endif
    00435