- Main Page
- Modules
- Classes
- Files
- Directories
- Related Pages

# cchannel.h

    00001 //==========================================================================
    00002 //   CCHANNEL.H  -  header for
    00003 //                     OMNeT++/OMNEST
    00004 //            Discrete System Simulation in C++
    00005 //
    00006 //
    00007 //  Declaration of the following classes:
    00008 //    cChannel : channel class
    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 __CCHANNEL_H
    00020 #define __CCHANNEL_H
    00021
    00022 #include "cobject.h"
    00023 #include "cpar.h"
    00024 #include "carray.h"
    00025
    00026 //=== classes mentioned:
    00027 class cPar;
    00028 class cGate;
    00029 class cChannelType;
    00030 class cArray;
    00031 class cMessage;
    00032
    00033
    00040 class SIM_API cChannel : public cObject
    00041 {
    00042     friend class cGate; // to call setFromGate()
    00043   protected:
    00044     cChannelType *channeltypep;  // channel type object or NULL
    00045     cArray *parlistp;            // ptr to list of all parameters
    00046     cGate *fromgatep;            // gate the channel is attached to
    00047     // TBD: add on/off modelling? or to cGate?
    00048
    00049   protected:
    00050     // helper functions
    00051     void _createparlist();
    00052     cArray& _parList() {if (!parlistp) _createparlist(); return *parlistp;}
    00053     void setFromGate(cGate *g) {fromgatep=g;}
    00054
    00055   public:
    00058
    00062     cChannel(const cChannel& ch);
    00063
    00067     explicit cChannel(const char *name=NULL, cChannelType *l=NULL);
    00068
    00072     virtual ~cChannel();
    00073
    00078     cChannel& operator=(const cChannel& msg);
    00080
    00083
    00088     virtual cPolymorphic *dup() const  {return new cChannel(*this);}
    00089
    00094     virtual std::string info() const;
    00095
    00100     virtual void forEachChild(cVisitor *v);
    00101
    00106     virtual void writeContents(std::ostream& os);
    00107
    00113     virtual void netPack(cCommBuffer *buffer);
    00114
    00120     virtual void netUnpack(cCommBuffer *buffer);
    00122
    00125
    00129     cGate *fromGate() const {return fromgatep;}
    00130
    00134     cChannelType *channelType() const {return channeltypep;}
    00136
    00139
    00143     virtual cPar& addPar(const char *s)  {cPar *p=new cPar(s);_parList().add(p);return *p;}
    00144
    00148     virtual cPar& addPar(cPar *p)  {_parList().add(p); return *p;}
    00149
    00154     virtual cPar& par(int n);
    00155
    00160     virtual cPar& par(const char *s);
    00161
    00166     virtual int findPar(const char *s) const;
    00167
    00171     virtual bool hasPar(const char *s) const {return findPar(s)>=0;}
    00172
    00179     virtual cArray& parList();
    00181
    00184
    00190     virtual bool deliver(cMessage *msg, simtime_t at);
    00192 };
    00193
    00194
    00200 class SIM_API cBasicChannel : public cChannel
    00201 {
    00202   private:
    00203     cPar *disabledp;    // if not NULL and value is nonzero, channel is down (will delete all packets). Points to an object in the parlist.
    00204     cPar *delayp;       // propagation delay or NULL. Points to an object in the parlist.
    00205     cPar *errorp;       // bit error rate or NULL. Points to an object in the parlist.
    00206     cPar *dataratep;    // data rate or NULL. Points to an object in the parlist.
    00207     simtime_t transm_finishes; // end of transmission; used if dataratep!=NULL
    00208
    00209   public:
    00212
    00216     explicit cBasicChannel(const char *name=NULL);
    00217
    00221     cBasicChannel(const cBasicChannel& ch);
    00222
    00226     virtual ~cBasicChannel();
    00227
    00232     cBasicChannel& operator=(const cBasicChannel& msg);
    00234
    00237
    00242     virtual cPolymorphic *dup() const  {return new cBasicChannel(*this);}
    00243
    00248     virtual std::string info() const;
    00249
    00254     virtual void forEachChild(cVisitor *v);
    00255
    00260     virtual void writeContents(std::ostream& os);
    00261
    00267     virtual void netPack(cCommBuffer *buffer);
    00268
    00274     virtual void netUnpack(cCommBuffer *buffer);
    00276
    00279
    00284     virtual void setDelay(double d);
    00285
    00294     virtual void setError(double d);
    00295
    00304     virtual void setDatarate(double d);
    00305
    00310     virtual void setDisabled(bool d);
    00311
    00315     virtual void setDelay(cPar *p);
    00316
    00320     virtual void setError(cPar *p);
    00321
    00325     virtual void setDatarate(cPar *p);
    00326
    00330     virtual double delay() const     {return !delayp ? 0.0 : delayp->doubleValue();}
    00331
    00335     virtual double error() const     {return !errorp ? 0.0 : errorp->doubleValue();}
    00336
    00340     virtual double datarate() const  {return !dataratep ? 0.0 : dataratep->doubleValue();}
    00341
    00345     virtual bool disabled() const  {return !disabledp ? false : disabledp->boolValue();}
    00347
    00350
    00354     virtual cPar& addPar(const char *s);
    00355
    00359     virtual cPar& addPar(cPar *p);
    00361
    00364
    00372     virtual bool isBusy() const;
    00373
    00381     virtual simtime_t transmissionFinishes() const {return transm_finishes;}
    00383
    00386
    00390     virtual bool deliver(cMessage *msg, simtime_t at);
    00392 };
    00393
    00394 #endif
    00395
    00396