Project

General

Profile

Statistics
| Branch: | Revision:

root / include / cdelaychannel.h @ aeae20a1

History | View | Annotate | Download (4.29 KB)

1 01873262 Georg Kunz
//==========================================================================
2
//   CDELAYCHANNEL.H  -  header for
3
//                     OMNeT++/OMNEST
4
//            Discrete System Simulation in C++
5
//
6
//
7
//  Declaration of the following classes:
8
//    cDelayChannel : channel class
9
//
10
//==========================================================================
11
12
/*--------------------------------------------------------------*
13
  Copyright (C) 1992-2008 Andras Varga
14
  Copyright (C) 2006-2008 OpenSim Ltd.
15

16
  This file is distributed WITHOUT ANY WARRANTY. See the file
17
  `license' for details on this and other legal matters.
18
*--------------------------------------------------------------*/
19
20
#ifndef __CDELAYCHANNEL_H
21
#define __CDELAYCHANNEL_H
22
23
#include "cchannel.h"
24
#include "csimulation.h"
25
26
NAMESPACE_BEGIN
27
28
/**
29
 * Channel with propagation delay.
30
 *
31
 * @ingroup SimCore
32
 */
33
class SIM_API cDelayChannel : public cChannel //implies noncopyable
34
{
35
  protected:
36
    static simsignal_t messageSentSignal;
37
    static simsignal_t messageDiscardedSignal;
38
39
  private:
40
    enum {
41
      FL_ISDISABLED = 128,
42
      FL_DELAY_NONZERO = 256,
43
    };
44
45
    simtime_t delay; // cached value of propagation delay parameter
46
47
  private:
48
    // internal: checks whether parameters have been set up
49
    void checkState() const  {if (!parametersFinalized()) throw cRuntimeError(this, ePARAMSNOTREADY);}
50
51
  protected:
52
    // internal: update cached copies of parameters
53
    void rereadPars();
54
55
    /**
56
     * Called back when a parameter changes. Redefined from cComponent.
57
     */
58
    virtual void handleParameterChange(const char *parname);
59
60
  public:
61
    /** @name Constructors, destructor */
62
    //@{
63
    /**
64
     * Constructor. This is only for internal purposes, and should not
65
     * be used when creating channels dynamically; use the create()
66
     * factory method instead.
67
     */
68
    explicit cDelayChannel(const char *name=NULL) : cChannel(name) {}
69
70
    /**
71
     * Destructor.
72
     */
73
    virtual ~cDelayChannel() {}
74
75
    /**
76
     * Utility function for dynamic channel creation. Equivalent to
77
     * <tt>cChannelType::getDelayChannelType()->create(name)</tt>.
78
     */
79
    static cDelayChannel *create(const char *name);
80
    //@}
81
82
    /** @name Redefined cChannel member functions. */
83
    //@{
84
    /**
85
     * The cDelayChannel implementation of this method always returns false.
86
     */
87
    virtual bool isTransmissionChannel() const {return false;}
88
89
    /**
90
     * The cDelayChannel implementation of this method always returns zero.
91
     */
92
    virtual double getNominalDatarate() const {return 0;}
93
94
    /**
95
     * The cDelayChannel implementation of this method always returns zero.
96
     */
97
    virtual simtime_t calculateDuration(cMessage *msg) const {return 0;}
98
99
    /**
100
     * The cDelayChannel implementation of this method always returns zero.
101
     */
102
    virtual simtime_t getTransmissionFinishTime() const {return SIMTIME_ZERO;}
103
104
    /**
105
     * The cDelayChannel implementation of this method always returns false.
106
     */
107
    virtual bool isBusy() const {return false;}
108
109
    /**
110
     * The cDelayChannel implementation of this method does nothing.
111
     */
112
    virtual void forceTransmissionFinishTime(simtime_t t) {}
113
    //@}
114
115
    /** @name Setting and getting channel parameters. */
116
    //@{
117
    /**
118
     * Sets the propagation delay of the channel, in seconds.
119
     */
120
    virtual void setDelay(double d);
121
122
    /**
123
     * Disables or enables the channel.
124
     */
125
    virtual void setDisabled(bool d);
126
127
    /**
128
     * Returns the propagation delay of the channel, in seconds.
129
     * This method is equivalent to reading the "delay" parameter, via par("delay").
130
     */
131
    virtual simtime_t getDelay() const {checkState(); return delay;}
132
133
    /**
134
     * Returns whether the channel is disabled. This method is equivalent
135
     * to reading the "disabled" parameter, via par("disabled").
136
     * A disabled channel discards all messages sent on it.
137
     */
138
    virtual bool isDisabled() const  {checkState(); return flags & FL_ISDISABLED;}
139
    //@}
140
141
    /** @name Implementation methods */
142
    //@{
143
    /**
144
     * Initialization.
145
     */
146
    virtual void initialize();
147
148
    /**
149
     * This implementation delivers the message to the opposite gate
150
     * with a delay.
151
     */
152
    virtual void processMessage(cMessage *msg, simtime_t t, result_t& result);
153
    //@}
154
};
155
156
NAMESPACE_END
157
158
159
#endif
160