Project

General

Profile

Statistics
| Branch: | Revision:

root / src / envir / resultlistener.h @ a3be1d55

History | View | Annotate | Download (3.18 KB)

1
//==========================================================================
2
//  RESULTLISTENER.H - part of
3
//                     OMNeT++/OMNEST
4
//            Discrete System Simulation in C++
5
//
6
//  Author: Andras Varga
7
//
8
//==========================================================================
9

    
10
/*--------------------------------------------------------------*
11
  Copyright (C) 1992-2008 Andras Varga
12
  Copyright (C) 2006-2008 OpenSim Ltd.
13

14
  This file is distributed WITHOUT ANY WARRANTY. See the file
15
  `license' for details on this and other legal matters.
16
*--------------------------------------------------------------*/
17

    
18
#ifndef __ENVIR_RESULTLISTENER_H
19
#define __ENVIR_RESULTLISTENER_H
20

    
21
#include "envirdefs.h"
22
#include "clistener.h"
23

    
24
class ResultFilter;
25
class cComponent;
26

    
27

    
28
/**
29
 * Common abstract base class for result filters and result recorders.
30
 */
31
class ENVIR_API ResultListener : public cIListener
32
{
33
    public:
34
        virtual const char *getClassName() const {return opp_typename(typeid(*this));}
35
        virtual std::string str() const {return opp_typename(typeid(*this));}
36

    
37
        // simplified API that better supports chaining:
38
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, long l) = 0;
39
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, unsigned long l) = 0;
40
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, double d) = 0;
41
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, const SimTime& v) = 0;
42
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, const char *s) = 0;
43
        virtual void receiveSignal(ResultFilter *prev, simtime_t_cref t, cObject *obj) = 0;
44
        virtual void subscribedTo(ResultFilter *prev);
45
        virtual void unsubscribedFrom(ResultFilter *prev);
46
        virtual void finish(ResultFilter *prev) {}
47

    
48
        // original listener API delegates to simplified API:
49
        virtual void receiveSignal(cComponent *source, simsignal_t signalID, long l);
50
        virtual void receiveSignal(cComponent *source, simsignal_t signalID, unsigned long l);
51
        virtual void receiveSignal(cComponent *source, simsignal_t signalID, double d);
52
        virtual void receiveSignal(cComponent *source, simsignal_t signalID, const SimTime& v);
53
        virtual void receiveSignal(cComponent *source, simsignal_t signalID, const char *s);
54
        virtual void receiveSignal(cComponent *source, simsignal_t signalID, cObject *obj);
55
        virtual void subscribedTo(cComponent *component, simsignal_t signalID);
56
        virtual void unsubscribedFrom(cComponent *component, simsignal_t signalID);
57
        virtual void finish(cComponent *component, simsignal_t signalID);
58
};
59

    
60
/**
61
 * Data structure used when setting up chains of ResultFilters and ResultRecorders
62
 */
63
class SignalSource
64
{
65
  private:
66
    ResultFilter *filter;
67
    cComponent *component;
68
    simsignal_t signalID;
69
  public:
70
    SignalSource(ResultFilter *prevFilter) {filter=prevFilter; component=NULL; signalID=-1;}
71
    SignalSource(cComponent *comp, simsignal_t sigID) {filter=NULL; component=comp; signalID=sigID;}
72
    bool isNull() const {return !filter && !component;}
73
    void subscribe(ResultListener *listener) const;
74
};
75

    
76
#endif
77

    
78