OMNeT++ Simulation Library  5.6.1
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 
43 class SIM_API cEvent : public cOwnedObject
44 {
45  friend class cMessage; // getArrivalTime()
46  friend class cEventHeap; // heapIndex
47  private:
48  simtime_t arrivalTime; // time of delivery -- set internally
49  short priority; // priority -- used for scheduling events with equal arrival times
50  int heapIndex; // used by cEventHeap (-1 if not on heap; all other values, including negative ones, means "on the heap")
51  eventnumber_t insertOrder; // used by the FES to keep order of events with equal time and priority
52  eventnumber_t previousEventNumber; // most recent event number when envir was notified about this event object (e.g. creating/cloning/sending/scheduling/deleting of this event object)
53 
54  public:
55  // internal: returns the event number which scheduled this event object, or the event
56  // number in which this event object was last executed (e.g. delivered to a module);
57  // stored for recording into the event log file.
58  eventnumber_t getPreviousEventNumber() const {return previousEventNumber;}
59 
60  // internal: sets previousEventNumber.
61  void setPreviousEventNumber(eventnumber_t num) {previousEventNumber = num;}
62 
63  // internal: used by cEventHeap.
64  eventnumber_t getInsertOrder() const {return insertOrder;}
65 
66  // internal: called by the simulation kernel to set the value returned
67  // by the getArrivalTime() method
68  void setArrivalTime(simtime_t t) {arrivalTime = t;}
69 
70  // internal: used by the parallel simulation kernel.
71  virtual int getSrcProcId() const {return -1;}
72 
73  // internal: utility function
74  static int compareBySchedulingOrder(const cEvent *a, const cEvent *b);
75 
76  public:
79 
83  cEvent(const cEvent& event);
84 
88  explicit cEvent(const char *name);
89 
93  virtual ~cEvent();
94 
99  cEvent& operator=(const cEvent& event);
101 
107  virtual cEvent *dup() const override = 0;
108 
113  virtual std::string str() const override;
114 
119  virtual void forEachChild(cVisitor *v) override;
120 
126  virtual void parsimPack(cCommBuffer *buffer) const override;
127 
133  virtual void parsimUnpack(cCommBuffer *buffer) override;
135 
138 
144  void setSchedulingPriority(short p) {priority=p;}
145 
149  short getSchedulingPriority() const {return priority;}
151 
154 
158  bool isScheduled() const {return heapIndex!=-1;}
159 
165  simtime_t_cref getArrivalTime() const {return arrivalTime;}
166 
175  virtual cObject *getTargetObject() const = 0;
177 
184  virtual bool isMessage() const {return false;}
185 
191  virtual bool isStale() {return false;}
192 
200  bool shouldPrecede(const cEvent *event) const;
201 
209  virtual void execute() = 0;
211 };
212 
213 } // namespace omnetpp
214 
215 #endif
216 
The message class in OMNeT++. cMessage objects may represent events, messages, jobs or other entities...
Definition: cmessage.h:95
Root of the OMNeT++ class hierarchy. cObject is a lightweight class without any data members...
Definition: cobject.h:58
int64_t-based, base-10 fixed-point simulation time.
Definition: simtime.h:66
Represents an event in the discrete event simulator.
Definition: cevent.h:43
void setSchedulingPriority(short p)
Definition: cevent.h:144
virtual bool isStale()
Definition: cevent.h:191
The default, binary heap based implementation of the future event set.
Definition: ceventheap.h:35
short getSchedulingPriority() const
Definition: cevent.h:149
Buffer for the communications layer of parallel simulation.
Definition: ccommbuffer.h:41
A cObject that keeps track of its owner. It serves as base class for many classes in the OMNeT++ libr...
Definition: cownedobject.h:104
int64_t eventnumber_t
Sequence number of events during the simulation. Events are numbered from one. (Event number zero is ...
Definition: simkerneldefs.h:78
Enables traversing the tree of (cObject-rooted) simulation objects.
Definition: cvisitor.h:56
bool isScheduled() const
Definition: cevent.h:158
virtual bool isMessage() const
Definition: cevent.h:184
simtime_t_cref getArrivalTime() const
Definition: cevent.h:165
Definition: cabstracthistogram.h:21