OMNeT++ Simulation Library  6.0.3
clistener.h
1 //==========================================================================
2 // CLISTENER.H - part of
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_CLISTENER_H
17 #define __OMNETPP_CLISTENER_H
18 
19 #include <vector>
20 #include <utility>
21 #include "simtime_t.h"
22 #include "simtime_t.h"
23 #include "cobject.h"
24 
25 namespace omnetpp {
26 
27 class cComponent;
28 
37 typedef int simsignal_t;
38 
39 #define SIMSIGNAL_NULL ((omnetpp::simsignal_t)-1)
40 
48 {
49  SIMSIGNAL_UNDEF,
50  SIMSIGNAL_BOOL,
51  SIMSIGNAL_INT, // intval_t
52  SIMSIGNAL_UINT, // uintval_t
53  SIMSIGNAL_DOUBLE,
54  SIMSIGNAL_SIMTIME,
55  SIMSIGNAL_STRING,
56  SIMSIGNAL_OBJECT,
57  SIMSIGNAL_LONG [[deprecated]] = SIMSIGNAL_INT,
58  SIMSIGNAL_ULONG [[deprecated]] = SIMSIGNAL_UINT
59 };
60 
71 class SIM_API cIListener
72 {
73  friend class cComponent; // for subscribecount
74  friend class cResultFilter; // for subscribecount
75  private:
76  std::vector<std::pair<cComponent*,simsignal_t>> subscriptions;
77 
78  protected:
83  virtual void unsubscribeAll();
84 
85  public:
90 
94  cIListener(const cIListener& other) {}
95 
104  virtual ~cIListener();
105 
121  virtual void receiveSignal(cComponent *source, simsignal_t signalID, bool b, cObject *details) = 0;
122 
124  virtual void receiveSignal(cComponent *source, simsignal_t signalID, intval_t i, cObject *details) = 0;
125 
127  virtual void receiveSignal(cComponent *source, simsignal_t signalID, uintval_t i, cObject *details) = 0;
128 
130  virtual void receiveSignal(cComponent *source, simsignal_t signalID, double d, cObject *details) = 0;
131 
133  virtual void receiveSignal(cComponent *source, simsignal_t signalID, const SimTime& t, cObject *details) = 0;
134 
136  virtual void receiveSignal(cComponent *source, simsignal_t signalID, const char *s, cObject *details) = 0;
137 
139  virtual void receiveSignal(cComponent *source, simsignal_t signalID, cObject *obj, cObject *details) = 0;
140 
148  virtual void finish(cComponent *component, simsignal_t signalID) {}
149 
155  virtual void subscribedTo(cComponent *component, simsignal_t signalID) {}
156 
173  virtual void unsubscribedFrom(cComponent *component, simsignal_t signalID) {}
174 
178  virtual int getSubscribeCount() const {return subscriptions.size();}
179 };
180 
190 class SIM_API cListener : public cIListener
191 {
192  protected:
194  virtual void unsupportedType(simsignal_t signalID, const char *dataType);
195 
196  public:
197  virtual void receiveSignal(cComponent *source, simsignal_t signalID, bool b, cObject *details) override;
198  virtual void receiveSignal(cComponent *source, simsignal_t signalID, intval_t i, cObject *details) override;
199  virtual void receiveSignal(cComponent *source, simsignal_t signalID, uintval_t i, cObject *details) override;
200  virtual void receiveSignal(cComponent *source, simsignal_t signalID, double d, cObject *details) override;
201  virtual void receiveSignal(cComponent *source, simsignal_t signalID, const SimTime& t, cObject *details) override;
202  virtual void receiveSignal(cComponent *source, simsignal_t signalID, const char *s, cObject *details) override;
203  virtual void receiveSignal(cComponent *source, simsignal_t signalID, cObject *obj, cObject *details) override;
204 
205 #ifdef _WIN32
206  [[deprecated]] virtual void receiveSignal(cComponent *source, simsignal_t signalID, long i, cObject *details);
207  [[deprecated]] virtual void receiveSignal(cComponent *source, simsignal_t signalID, unsigned long i, cObject *details);
208 #endif
209 
210 };
211 
212 } // namespace omnetpp
213 
214 #endif
215 
omnetpp::simsignal_t
int simsignal_t
Signal handle.
Definition: clistener.h:27
omnetpp::cObject
cObject is a lightweight class which serves as the root of the OMNeT++ class hierarchy....
Definition: cobject.h:92
omnetpp::cListener
A do-nothing implementation of cIListener, suitable as a base class for other listeners.
Definition: clistener.h:190
omnetpp::cIListener
Interface for listeners in a simulation model.
Definition: clistener.h:71
omnetpp::SimTime
int64_t-based, base-10 fixed-point simulation time.
Definition: simtime.h:66
omnetpp::cIListener::unsubscribedFrom
virtual void unsubscribedFrom(cComponent *component, simsignal_t signalID)
Definition: clistener.h:173
omnetpp::uintval_t
uint64_t uintval_t
Unsigned integer type which is guaranteed to be at least 64 bits wide. It is used throughout the libr...
Definition: simkerneldefs.h:109
omnetpp::cIListener::cIListener
cIListener(const cIListener &other)
Definition: clistener.h:94
omnetpp::cIListener::subscribedTo
virtual void subscribedTo(cComponent *component, simsignal_t signalID)
Definition: clistener.h:155
omnetpp::SimsignalType
SimsignalType
Signal data types.
Definition: clistener.h:47
omnetpp::intval_t
int64_t intval_t
Signed integer type which is guaranteed to be at least 64 bits wide. It is used throughout the librar...
Definition: simkerneldefs.h:101
omnetpp::cIListener::cIListener
cIListener()
Definition: clistener.h:89
omnetpp::cComponent
Common base for module and channel classes.
Definition: ccomponent.h:49
omnetpp::cIListener::finish
virtual void finish(cComponent *component, simsignal_t signalID)
Definition: clistener.h:148
omnetpp::cResultFilter
Base class for result filters.
Definition: cresultfilter.h:72
omnetpp::cIListener::getSubscribeCount
virtual int getSubscribeCount() const
Definition: clistener.h:178