OMNeT++ Simulation Library  5.6.1
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 "simtime_t.h"
20 #include "cobject.h"
21 
22 namespace omnetpp {
23 
24 class cComponent;
25 
34 typedef int simsignal_t;
35 
36 #define SIMSIGNAL_NULL ((omnetpp::simsignal_t)-1)
37 
45 {
46  SIMSIGNAL_UNDEF,
47  SIMSIGNAL_BOOL,
48  SIMSIGNAL_LONG,
49  SIMSIGNAL_ULONG,
50  SIMSIGNAL_DOUBLE,
51  SIMSIGNAL_SIMTIME,
52  SIMSIGNAL_STRING,
53  SIMSIGNAL_OBJECT
54 };
55 
66 class SIM_API cIListener
67 {
68  friend class cComponent; // for subscribecount
69  friend class cResultFilter; // for subscribecount
70  private:
71  int subscribeCount;
72  public:
73  cIListener();
74  virtual ~cIListener();
75 
91  virtual void receiveSignal(cComponent *source, simsignal_t signalID, bool b, cObject *details) = 0;
92 
94  virtual void receiveSignal(cComponent *source, simsignal_t signalID, long l, cObject *details) = 0;
95 
97  virtual void receiveSignal(cComponent *source, simsignal_t signalID, unsigned long l, cObject *details) = 0;
98 
100  virtual void receiveSignal(cComponent *source, simsignal_t signalID, double d, cObject *details) = 0;
101 
103  virtual void receiveSignal(cComponent *source, simsignal_t signalID, const SimTime& t, cObject *details) = 0;
104 
106  virtual void receiveSignal(cComponent *source, simsignal_t signalID, const char *s, cObject *details) = 0;
107 
109  virtual void receiveSignal(cComponent *source, simsignal_t signalID, cObject *obj, cObject *details) = 0;
110 
118  virtual void finish(cComponent *component, simsignal_t signalID) {}
119 
125  virtual void subscribedTo(cComponent *component, simsignal_t signalID) {}
126 
142  virtual void unsubscribedFrom(cComponent *component, simsignal_t signalID) {}
143 
147  int getSubscribeCount() const { return subscribeCount; }
148 };
149 
159 class SIM_API cListener : public cIListener
160 {
161  protected:
163  virtual void unsupportedType(simsignal_t signalID, const char *dataType);
164 
165 #ifdef WITH_OMNETPP4x_LISTENER_SUPPORT
166  virtual void receiveSignal(cComponent *source, simsignal_t signalID, bool b);
167  virtual void receiveSignal(cComponent *source, simsignal_t signalID, long l);
168  virtual void receiveSignal(cComponent *source, simsignal_t signalID, unsigned long l);
169  virtual void receiveSignal(cComponent *source, simsignal_t signalID, double d);
170  virtual void receiveSignal(cComponent *source, simsignal_t signalID, const SimTime& t);
171  virtual void receiveSignal(cComponent *source, simsignal_t signalID, const char *s);
172  virtual void receiveSignal(cComponent *source, simsignal_t signalID, cObject *obj);
173 #endif
174 
175  public:
176  virtual void receiveSignal(cComponent *source, simsignal_t signalID, bool b, cObject *details) override;
177  virtual void receiveSignal(cComponent *source, simsignal_t signalID, long l, cObject *details) override;
178  virtual void receiveSignal(cComponent *source, simsignal_t signalID, unsigned long l, cObject *details) override;
179  virtual void receiveSignal(cComponent *source, simsignal_t signalID, double d, cObject *details) override;
180  virtual void receiveSignal(cComponent *source, simsignal_t signalID, const SimTime& t, cObject *details) override;
181  virtual void receiveSignal(cComponent *source, simsignal_t signalID, const char *s, cObject *details) override;
182  virtual void receiveSignal(cComponent *source, simsignal_t signalID, cObject *obj, cObject *details) override;
183 };
184 
185 } // namespace omnetpp
186 
187 #endif
188 
Common base for module and channel classes.
Definition: ccomponent.h:48
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
virtual void finish(cComponent *component, simsignal_t signalID)
Definition: clistener.h:118
virtual void subscribedTo(cComponent *component, simsignal_t signalID)
Definition: clistener.h:125
int getSubscribeCount() const
Definition: clistener.h:147
Base class for result filters.
Definition: cresultfilter.h:72
Definition: cabstracthistogram.h:21
A do-nothing implementation of cIListener, suitable as a base class for other listeners.
Definition: clistener.h:159
SimsignalType
Signal data types.
Definition: clistener.h:44
Interface for listeners in a simulation model.
Definition: clistener.h:66
virtual void unsubscribedFrom(cComponent *component, simsignal_t signalID)
Definition: clistener.h:142
int simsignal_t
Signal handle.
Definition: clistener.h:24