cevent.h Source File

API: cevent.h Source File
API
cevent.h
1//==========================================================================
2// CEVENT.H - header for
3// OMNeT++/OMNEST
4// Discrete System Simulation in C++
5//
6//==========================================================================
7
8/*--------------------------------------------------------------*
9 Copyright (C) 1992-2017 Andras Varga
10 Copyright (C) 2006-2017 OpenSim Ltd.
11
12 This file is distributed WITHOUT ANY WARRANTY. See the file
13 `license' for details on this and other legal matters.
14*--------------------------------------------------------------*/
15
16#ifndef __OMNETPP_CEVENT_H
17#define __OMNETPP_CEVENT_H
18
19#include "cownedobject.h"
20
21namespace omnetpp {
22
23class cMessage;
24class cPacket;
25class cEventHeap;
26
46class SIM_API cEvent : public cOwnedObject
47{
48 friend class cMessage; // getArrivalTime()
49 friend class cEventHeap; // heapIndex
50
51 private:
52 simtime_t arrivalTime; // time of delivery -- set internally
53 short priority = 0; // priority -- used for scheduling events with equal arrival times
54 int heapIndex = -1; // used by cEventHeap (-1 if not on heap; all other values, including negative ones, means "on the heap")
55 eventnumber_t insertOrder = -1; // used by the FES to keep order of events with equal time and priority
56 eventnumber_t previousEventNumber = -1; // most recent event number when envir was notified about this event object (e.g. creating/cloning/sending/scheduling/deleting of this event object)
57
58 public:
59 // internal: returns the event number which scheduled this event object, or the event
60 // number in which this event object was last executed (e.g. delivered to a module);
61 // stored for recording into the event log file.
62 eventnumber_t getPreviousEventNumber() const {return previousEventNumber;}
63
64 // internal: sets previousEventNumber.
65 void setPreviousEventNumber(eventnumber_t num) {previousEventNumber = num;}
66
67 // internal: used by cEventHeap.
68 eventnumber_t getInsertOrder() const {return insertOrder;}
69
70 // internal: called by the simulation kernel to set the value returned
71 // by the getArrivalTime() method; must not be called while the event is
72 // in the FES, because it would break ordering.
73 void setArrivalTime(simtime_t t) {ASSERT(!isScheduled()); arrivalTime = t;}
74
75 // internal: used by the parallel simulation kernel.
76 virtual int getSrcProcId() const {return -1;}
77
78 // internal: utility function
79 static int compareBySchedulingOrder(const cEvent *a, const cEvent *b);
80
81 public:
84
88 cEvent(const cEvent& event) : cOwnedObject(event) {operator=(event);}
89
93 explicit cEvent(const char *name) : cOwnedObject(name, false) {} // note: name pooling is off by default, as unique message names are quite common
94
98 virtual ~cEvent() {}
99
104 cEvent& operator=(const cEvent& event);
106
109
112 virtual cEvent *dup() const override = 0;
113
118 virtual std::string str() const override;
119
124 virtual void forEachChild(cVisitor *v) override;
125
131 virtual void parsimPack(cCommBuffer *buffer) const override;
132
138 virtual void parsimUnpack(cCommBuffer *buffer) override;
140
143
153
157 short getSchedulingPriority() const {return priority;}
159
162
166 bool isScheduled() const {return heapIndex!=-1;}
167
173 simtime_t_cref getArrivalTime() const {return arrivalTime;}
174
183 virtual cObject *getTargetObject() const = 0;
185
188
191 virtual bool isMessage() const {return false;}
192
196 virtual bool isPacket() const {return false;}
197
203 virtual bool isStale() {return false;}
204
212 bool shouldPrecede(const cEvent *event) const;
213
221 virtual void execute() = 0;
223};
224
225} // namespace omnetpp
226
227#endif
228
Buffer for the communications layer of parallel simulation.
Definition ccommbuffer.h:42
The default, binary heap based implementation of the future event set.
Definition ceventheap.h:36
short getSchedulingPriority() const
Definition cevent.h:157
cEvent & operator=(const cEvent &event)
void setSchedulingPriority(short p)
bool isScheduled() const
Definition cevent.h:166
cEvent(const cEvent &event)
Definition cevent.h:88
virtual cObject * getTargetObject() const =0
virtual ~cEvent()
Definition cevent.h:98
virtual void parsimPack(cCommBuffer *buffer) const override
simtime_t_cref getArrivalTime() const
Definition cevent.h:173
virtual bool isPacket() const
Definition cevent.h:196
virtual void parsimUnpack(cCommBuffer *buffer) override
virtual bool isMessage() const
Definition cevent.h:191
virtual void forEachChild(cVisitor *v) override
bool shouldPrecede(const cEvent *event) const
virtual std::string str() const override
virtual void execute()=0
virtual bool isStale()
Definition cevent.h:203
virtual cEvent * dup() const override=0
cEvent(const char *name)
Definition cevent.h:93
The message class in OMNeT++. cMessage objects may represent events, messages, jobs or other entities...
Definition cmessage.h:96
A subclass of cMessage to represent packets, frames, datagrams, application messages,...
Definition cpacket.h:53
Enables traversing the tree of (cObject-rooted) simulation objects.
Definition cvisitor.h:57
int64_t eventnumber_t
Sequence number of events during the simulation. Events are numbered from one. (Event number zero is ...
Definition simkerneldefs.h:78
SimTime simtime_t
Represents simulation time.
Definition simtime_t.h:40
const simtime_t & simtime_t_cref
Constant reference to a simtime_t.
Definition simtime_t.h:48