OMNeT++ Simulation Library  6.0.3
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 
21 namespace omnetpp {
22 
23 class cMessage;
24 class cPacket;
25 class cEventHeap;
26 
46 class 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 
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 
152  void setSchedulingPriority(short p);
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 
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 
omnetpp::simtime_t_cref
const typedef simtime_t & simtime_t_cref
Constant reference to a simtime_t.
Definition: simtime_t.h:48
omnetpp::cEvent::getArrivalTime
simtime_t_cref getArrivalTime() const
Definition: cevent.h:173
omnetpp::cObject
cObject is a lightweight class which serves as the root of the OMNeT++ class hierarchy....
Definition: cobject.h:92
omnetpp::cEvent::isPacket
virtual bool isPacket() const
Definition: cevent.h:196
omnetpp::cEvent
Represents an event in the discrete event simulator.
Definition: cevent.h:46
omnetpp::cEvent::~cEvent
virtual ~cEvent()
Definition: cevent.h:98
omnetpp::cVisitor
Enables traversing the tree of (cObject-rooted) simulation objects.
Definition: cvisitor.h:56
omnetpp::SimTime
int64_t-based, base-10 fixed-point simulation time.
Definition: simtime.h:66
omnetpp::cEvent::isScheduled
bool isScheduled() const
Definition: cevent.h:166
omnetpp::eventnumber_t
int64_t eventnumber_t
Sequence number of events during the simulation. Events are numbered from one. (Event number zero is ...
Definition: simkerneldefs.h:78
omnetpp::cEvent::isStale
virtual bool isStale()
Definition: cevent.h:203
omnetpp::cEvent::getSchedulingPriority
short getSchedulingPriority() const
Definition: cevent.h:157
omnetpp::cMessage
The message class in OMNeT++. cMessage objects may represent events, messages, jobs or other entities...
Definition: cmessage.h:95
omnetpp::cEventHeap
The default, binary heap based implementation of the future event set.
Definition: ceventheap.h:35
omnetpp::cEvent::cEvent
cEvent(const cEvent &event)
Definition: cevent.h:88
omnetpp::cEvent::isMessage
virtual bool isMessage() const
Definition: cevent.h:191
omnetpp::cEvent::cEvent
cEvent(const char *name)
Definition: cevent.h:93
omnetpp::cCommBuffer
Buffer for the communications layer of parallel simulation.
Definition: ccommbuffer.h:41
omnetpp::cOwnedObject
A cObject that keeps track of its owner. It serves as base class for many classes in the OMNeT++ libr...
Definition: cownedobject.h:105