INET Framework for OMNeT++/OMNEST
inet::MultiClock Class Reference

#include <MultiClock.h>

Inheritance diagram for inet::MultiClock:
inet::IClock

Public Member Functions

virtual clocktime_t getClockTime () const override
 Returns the current clock time. More...
 
virtual clocktime_t computeClockTimeFromSimTime (simtime_t time) const override
 Returns the clock time for the specified future simulation time according to the current state of the clock. More...
 
virtual simtime_t computeSimTimeFromClockTime (clocktime_t time) const override
 Returns the simulation time (first moment) for the specified future clock time according to the current state of the clock. More...
 
virtual void scheduleClockEventAt (clocktime_t time, ClockEvent *event) override
 Schedules an event to be delivered to the caller module (i.e. More...
 
virtual void scheduleClockEventAfter (clocktime_t delay, ClockEvent *event) override
 Schedules an event to be delivered to the caller module (i.e. More...
 
virtual ClockEventcancelClockEvent (ClockEvent *event) override
 Cancels a previously scheduled clock event. More...
 
virtual void handleClockEvent (ClockEvent *event) override
 Called by the clock event to be executed in the context of this clock. More...
 
virtual void receiveSignal (cComponent *source, int signal, const simtime_t &time, cObject *details) override
 
- Public Member Functions inherited from inet::IClock
virtual ~IClock ()
 

Protected Member Functions

virtual void initialize (int stage) override
 
virtual void handleParameterChange (const char *name) override
 

Protected Attributes

IClockactiveClock = nullptr
 

Member Function Documentation

◆ cancelClockEvent()

virtual ClockEvent* inet::MultiClock::cancelClockEvent ( ClockEvent event)
inlineoverridevirtual

Cancels a previously scheduled clock event.

The clock event ownership is transferred to the caller.

Implements inet::IClock.

32 { return activeClock->cancelClockEvent(event); }

◆ computeClockTimeFromSimTime()

virtual clocktime_t inet::MultiClock::computeClockTimeFromSimTime ( simtime_t  time) const
inlineoverridevirtual

Returns the clock time for the specified future simulation time according to the current state of the clock.

This method implements a monotonic function with respect to the simulation time argument. It's allowed to return a different value for the same argument value if the clock is set between calls. The time argument must be greater than or equal to the current simulation time, otherwise an error is raised. See SIMTIME_AS_CLOCKTIME macro for simple type conversion.

Implements inet::IClock.

◆ computeSimTimeFromClockTime()

virtual simtime_t inet::MultiClock::computeSimTimeFromClockTime ( clocktime_t  time) const
inlineoverridevirtual

Returns the simulation time (first moment) for the specified future clock time according to the current state of the clock.

This method implements a monotonic function with respect to the clock time argument. It's allowed to return a different value for the same argument value if the clock is set between calls. The time argument must be greater or than equal to the current clock time, otherwise an error is raised. See CLOCKTIME_AS_SIMTIME macro for simple type conversion.

Implements inet::IClock.

◆ getClockTime()

virtual clocktime_t inet::MultiClock::getClockTime ( ) const
inlineoverridevirtual

Returns the current clock time.

Note that the clock time is not necessarily monotonous in execution order. For example, the clock time may decrease even at the same simulation time.

Implements inet::IClock.

27 { return activeClock->getClockTime(); }

Referenced by handleParameterChange().

◆ handleClockEvent()

virtual void inet::MultiClock::handleClockEvent ( ClockEvent event)
inlineoverridevirtual

Called by the clock event to be executed in the context of this clock.

This method is primarily useful for clock implementations to update their internal data structures related to individual clock events.

Implements inet::IClock.

33 { activeClock->handleClockEvent(event); }

◆ handleParameterChange()

void inet::MultiClock::handleParameterChange ( const char *  name)
overrideprotectedvirtual
25 {
26  if (name != nullptr) {
27  if (!strcmp(name, "activeClockIndex")) {
28  emit(ClockBase::timeChangedSignal, getClockTime().asSimTime());
29  activeClock = check_and_cast<IClock *>(getSubmodule("clock", par("activeClockIndex")));
30  emit(ClockBase::timeChangedSignal, getClockTime().asSimTime());
31  }
32  }
33 }

◆ initialize()

void inet::MultiClock::initialize ( int  stage)
overrideprotectedvirtual
17 {
18  if (stage == INITSTAGE_LOCAL) {
19  activeClock = check_and_cast<IClock *>(getSubmodule("clock", par("activeClockIndex")));
20  subscribe(ClockBase::timeChangedSignal, this);
21  }
22 }

◆ receiveSignal()

void inet::MultiClock::receiveSignal ( cComponent *  source,
int  signal,
const simtime_t &  time,
cObject *  details 
)
overridevirtual
36 {
37  if (signal == ClockBase::timeChangedSignal) {
38  if (check_and_cast<IClock *>(source) == activeClock)
39  emit(ClockBase::timeChangedSignal, time, details);
40  }
41  else
42  throw cRuntimeError("Unknown signal");
43 }

◆ scheduleClockEventAfter()

virtual void inet::MultiClock::scheduleClockEventAfter ( clocktime_t  delay,
ClockEvent event 
)
inlineoverridevirtual

Schedules an event to be delivered to the caller module (i.e.

the context module) after the given clock time delay has elapsed. The event is anchored to a specific clock time duration, so the actual simulation time when this event is executed is not affected if the clock time is set later. On the other hand, setting the clock drift still affects the simulation time of the event execution.

Implements inet::IClock.

31 { activeClock->scheduleClockEventAfter(delay, event); }

◆ scheduleClockEventAt()

virtual void inet::MultiClock::scheduleClockEventAt ( clocktime_t  time,
ClockEvent event 
)
inlineoverridevirtual

Schedules an event to be delivered to the caller module (i.e.

the context module) at the specified clock time. The event is anchored to a specific clock time value, so the actual simulation time when this event is executed will be affected if the clock time is set later.

Implements inet::IClock.

30 { activeClock->scheduleClockEventAt(time, event); }

Member Data Documentation

◆ activeClock

IClock* inet::MultiClock::activeClock = nullptr
protected

The documentation for this class was generated from the following files:
inet::MultiClock::getClockTime
virtual clocktime_t getClockTime() const override
Returns the current clock time.
Definition: MultiClock.h:27
inet::ClockBase::timeChangedSignal
static simsignal_t timeChangedSignal
Definition: ClockBase.h:21
inet::IClock::getClockTime
virtual clocktime_t getClockTime() const =0
Returns the current clock time.
inet::IClock::cancelClockEvent
virtual ClockEvent * cancelClockEvent(ClockEvent *event)=0
Cancels a previously scheduled clock event.
inet::IClock::handleClockEvent
virtual void handleClockEvent(ClockEvent *event)=0
Called by the clock event to be executed in the context of this clock.
inet::MultiClock::activeClock
IClock * activeClock
Definition: MultiClock.h:20
inet::IClock::computeSimTimeFromClockTime
virtual simtime_t computeSimTimeFromClockTime(clocktime_t time) const =0
Returns the simulation time (first moment) for the specified future clock time according to the curre...
inet::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
inet::IClock::computeClockTimeFromSimTime
virtual clocktime_t computeClockTimeFromSimTime(simtime_t time) const =0
Returns the clock time for the specified future simulation time according to the current state of the...
inet::IClock::scheduleClockEventAfter
virtual void scheduleClockEventAfter(clocktime_t delay, ClockEvent *event)=0
Schedules an event to be delivered to the caller module (i.e.
inet::IClock::scheduleClockEventAt
virtual void scheduleClockEventAt(clocktime_t time, ClockEvent *event)=0
Schedules an event to be delivered to the caller module (i.e.