Statistics
| Branch: | Revision:

root / src / eventlog / ieventlog.h @ 842775ab

History | View | Annotate | Download (7.2 KB)

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

    
10
/*--------------------------------------------------------------*
11
  Copyright (C) 2006-2008 OpenSim Ltd.
12

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

    
17
#ifndef __IEVENTLOG_H_
18
#define __IEVENTLOG_H_
19

    
20
#include <sstream>
21
#include <set>
22
#include <vector>
23
#include "filereader.h"
24
#include "eventlogdefs.h"
25
#include "ievent.h"
26

    
27
NAMESPACE_BEGIN
28

    
29
class IEventLog;
30

    
31
class EVENTLOG_API ProgressMonitor
32
{
33
    public:
34
        typedef void (*MonitorFunction)(IEventLog *, void *);
35

    
36
        MonitorFunction monitorFunction;
37
        void *data;
38

    
39
    public:
40
        ProgressMonitor()
41
        {
42
            monitorFunction = NULL;
43
            data = NULL;
44
        }
45

    
46
        ProgressMonitor(MonitorFunction monitorFunction, void *data)
47
        {
48
            this->monitorFunction = monitorFunction;
49
            this->data = data;
50
        }
51

    
52
        void progress(IEventLog *eventLog) { if (monitorFunction) monitorFunction(eventLog, data); }
53
};
54

    
55
class EVENTLOG_API IEventLog
56
{
57
    protected:
58
        /**
59
         * Remembers the last IEvent returned by getNeighbourEvent so that subsequent calls might return much faster.
60
         */
61
        eventnumber_t lastNeighbourEventNumber;
62
        IEvent *lastNeighbourEvent;
63

    
64
    public:
65
        IEventLog();
66
        virtual ~IEventLog() {}
67

    
68
        /**
69
         * Sets the progress monitor which will be notified when a long running operation has some progress.
70
         */
71
        virtual ProgressMonitor setProgressMonitor(ProgressMonitor progressMonitor) = 0;
72
        /**
73
         * Set the minimum interval between progress callbacks for long running event log operations.
74
         */
75
        virtual void setProgressCallInterval(double seconds) = 0;
76
        /**
77
         * Progress notification. May be used to cancel long running operations.
78
         */
79
        virtual void progress() = 0;
80

    
81
        /**
82
         * Synchorizes state when the underlying log file has been changed.
83
         * Either new events were appended or the whole file has been overwritten.
84
         */
85
        virtual void synchronize(FileReader::FileChangedState change);
86

    
87
        /**
88
         * Returns the file reader used to read in events.
89
         */
90
        virtual FileReader *getFileReader() = 0;
91

    
92
        /**
93
         * Returns the distance between subsequent keyframes in terms of event numbers.
94
         */
95
        virtual int getKeyframeBlockSize() = 0;
96

    
97
        /**
98
         * Returns the number of events parsed so far.
99
         */
100
        virtual eventnumber_t getNumParsedEvents() = 0;
101
        /**
102
         * Returns the message names parsed so far.
103
         */
104
        virtual std::set<const char *>& getMessageNames() = 0;
105
        /**
106
         * Returns the message class names parsed so far.
107
         */
108
        virtual std::set<const char *>& getMessageClassNames() = 0;
109
        /**
110
         * Returns the number of module created entries which is actually the next unused module id.
111
         */
112
        virtual int getNumModuleCreatedEntries() = 0;
113
        /**
114
         * Returns the entry with the given index.
115
         */
116
        virtual std::vector<ModuleCreatedEntry *> getModuleCreatedEntries() = 0;
117
        /**
118
         * Returns the entry which describes the module with the given id.
119
         */
120
        virtual ModuleCreatedEntry *getModuleCreatedEntry(int moduleId) = 0;
121
        /**
122
         * Returns the entry which describes the gate with the given ids.
123
         */
124
        virtual GateCreatedEntry *getGateCreatedEntry(int moduleId, int gateId) = 0;
125

    
126
        /**
127
         * Returns the event log entry describing the whole simulation.
128
         */
129
        virtual SimulationBeginEntry *getSimulationBeginEntry() = 0;
130

    
131
        /**
132
         * Returns true if the event log does not contain any events.
133
         */
134
        virtual bool isEmpty() { return !getFirstEvent(); }
135
        /**
136
         * Returns the first event or NULL if the log is empty.
137
         */
138
        virtual IEvent *getFirstEvent() = 0;
139
        /**
140
         * Returns the last event or NULL if the log is empty.
141
         */
142
        virtual IEvent *getLastEvent() = 0;
143
        /**
144
         * Returns the requested event or NULL if there is no such event included in the log.
145
         * The given event number may not be included in the log.
146
         */
147
        virtual IEvent *getEventForEventNumber(eventnumber_t eventNumber, MatchKind matchKind = EXACT, bool useCacheOnly = false) = 0;
148
        /**
149
         * Returns the requested event or NULL if there is no such event included in the log.
150
         * The given simulation time may not be included in the log.
151
         */
152
        virtual IEvent *getEventForSimulationTime(simtime_t simulationTime, MatchKind matchKind = EXACT, bool useCacheOnly = false) = 0;
153

    
154
        /**
155
         * Finds the closest event log entry containing the given text.
156
         */
157
        virtual EventLogEntry *findEventLogEntry(EventLogEntry *start, const char *search, bool forward, bool caseSensitive) = 0;
158

    
159
        /**
160
         * Returns the approximate number of events present in the log.
161
         * This value may be less, equal or greater than the real number of events if there are many.
162
         */
163
        virtual eventnumber_t getApproximateNumberOfEvents() = 0;
164
        /**
165
         * Returns an event approximately at the given percentage in terms of eventlog size.
166
         */
167
        virtual IEvent *getApproximateEventAt(double percentage) = 0;
168

    
169
    public:
170
        /**
171
         * Returns the event at the given distance. 0 means the parameter event will be returned.
172
         */
173
        virtual IEvent *getNeighbourEvent(IEvent *event, eventnumber_t distance = 1);
174

    
175
        /**
176
         * Returns true if the event with the given event number is included in the log.
177
         */
178
        virtual bool isIncludedInLog(eventnumber_t eventNumber) { return getEventForEventNumber(eventNumber) != NULL; }
179
        virtual IEvent *getFirstEventNotBeforeEventNumber(eventnumber_t eventNumber) { return getEventForEventNumber(eventNumber, LAST_OR_NEXT); }
180
        virtual IEvent *getLastEventNotAfterEventNumber(eventnumber_t eventNumber) { return getEventForEventNumber(eventNumber, FIRST_OR_PREVIOUS); }
181
        virtual IEvent *getFirstEventNotBeforeSimulationTime(simtime_t simulationTime) { return getEventForSimulationTime(simulationTime, LAST_OR_NEXT); }
182
        virtual IEvent *getLastEventNotAfterSimulationTime(simtime_t simulationTime) { return getEventForSimulationTime(simulationTime, FIRST_OR_PREVIOUS); }
183

    
184
        virtual double getApproximatePercentageForEventNumber(eventnumber_t eventNumber);
185

    
186
        /**
187
         * Prints the contents into specified file.
188
         * The given event numbers may not be present in the log.
189
         */
190
        virtual void print(FILE *file = stdout, eventnumber_t fromEventNumber = -1, eventnumber_t toEventNumber = -1, bool outputEventLogMessages = true);
191

    
192
    protected:
193
        void clearInternalState();
194
};
195

    
196
NAMESPACE_END
197

    
198

    
199
#endif