Statistics
| Branch: | Revision:

root / src / sim / cdelaychannel.cc @ fbe00e73

History | View | Annotate | Download (2.35 KB)

1 01873262 Georg Kunz
//========================================================================
2
//  CDELAYCHANNEL.CC - part of
3
//
4
//                 OMNeT++/OMNEST
5
//              Discrete System Simulation in C++
6
//
7
//   Member functions of
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
#include "cdelaychannel.h"
21
#include "cmessage.h"
22
#include "cenvir.h"
23
#include "globals.h"
24
#include "cgate.h"
25
#include "cexception.h"
26
#include "ctimestampedvalue.h"
27
28
#ifdef WITH_PARSIM
29
#include "ccommbuffer.h"
30
#endif
31
32
USING_NAMESPACE
33
34
using std::ostream;
35
36
Register_Class(cDelayChannel);
37
38
simsignal_t cDelayChannel::messageSentSignal;
39
simsignal_t cDelayChannel::messageDiscardedSignal;
40
41
cDelayChannel *cDelayChannel::create(const char *name)
42
{
43
    return dynamic_cast<cDelayChannel *>(cChannelType::getDelayChannelType()->create(name));
44
}
45
46
void cDelayChannel::initialize()
47
{
48
    messageSentSignal = registerSignal("messageSent");
49
    messageDiscardedSignal = registerSignal("messageDiscarded");
50
}
51
52
void cDelayChannel::rereadPars()
53
{
54
    delay = par("delay");
55
    if (delay < 0)
56
        throw cRuntimeError(this, "negative delay %s", SIMTIME_STR(delay));
57
    setFlag(FL_ISDISABLED, par("disabled"));
58
    setFlag(FL_DELAY_NONZERO, delay!=0);
59
}
60
61
void cDelayChannel::handleParameterChange(const char *)
62
{
63
    rereadPars();
64
}
65
66
void cDelayChannel::setDelay(double d)
67
{
68
    par("delay").setDoubleValue(d);
69
}
70
71
void cDelayChannel::setDisabled(bool d)
72
{
73
    par("disabled").setBoolValue(d);
74
}
75
76
void cDelayChannel::processMessage(cMessage *msg, simtime_t t, result_t& result)
77
{
78
    // if channel is disabled, signal that message should be deleted
79
    if (flags & FL_ISDISABLED)
80
    {
81
        result.discard = true;
82
        cTimestampedValue tmp(t, msg);
83
        emit(messageDiscardedSignal, &tmp);
84
        return;
85
    }
86
87
    // propagation delay modeling
88
    result.delay = delay;
89
90
    // emit signals
91
    if (mayHaveListeners(messageSentSignal))
92
    {
93
        MessageSentSignalValue tmp(t, msg, &result);
94
        emit(messageSentSignal, &tmp);
95
    }
96
}