Statistics
| Branch: | Revision:

root / src / eventlog / ieventlog.h @ e1750c09

History | View | Annotate | Download (8.15 KB)

1 01873262 Georg Kunz
//=========================================================================
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 number of events parsed so far.
94
         */
95
        virtual eventnumber_t getNumParsedEvents() = 0;
96
        /**
97
         * Returns the message names parsed so far.
98
         */
99
        virtual std::set<const char *>& getMessageNames() = 0;
100
        /**
101
         * Returns the message class names parsed so far.
102
         */
103
        virtual std::set<const char *>& getMessageClassNames() = 0;
104
        /**
105
         * Returns the number of module created entries which is actually the next unused module id.
106
         */
107
        virtual int getNumModuleCreatedEntries() = 0;
108
        /**
109
         * Returns the entry with the given index.
110
         */
111
        virtual std::vector<ModuleCreatedEntry *> getModuleCreatedEntries() = 0;
112
        /**
113
         * Returns the entry which describes the module with the given id.
114
         */
115
        virtual ModuleCreatedEntry *getModuleCreatedEntry(int moduleId) = 0;
116
        /**
117
         * Returns the entry which describes the gate with the given ids.
118
         */
119
        virtual GateCreatedEntry *getGateCreatedEntry(int moduleId, int gateId) = 0;
120
121
        /**
122
         * Returns the event log entry describing the whole simulation.
123
         */
124
        virtual SimulationBeginEntry *getSimulationBeginEntry() = 0;
125
126
        /**
127
         * Returns true if the event log does not contain any events.
128
         */
129
        virtual bool isEmpty() { return !getFirstEvent(); }
130
        /**
131
         * Returns the first event or NULL if the log is empty.
132
         */
133
        virtual IEvent *getFirstEvent() = 0;
134
        /**
135
         * Returns the last event or NULL if the log is empty.
136
         */
137
        virtual IEvent *getLastEvent() = 0;
138
        /**
139 12288d0e Simon Tenbusch
         * Returns the first event in RealTime or NULL if the log is empty.
140
         */
141
        virtual IEvent *getFirstEventRealTime() = 0;
142
        /**
143
         * Returns the last event in RealTime or NULL if the log is empty.
144
         */
145
        virtual IEvent *getLastEventRealTime() = 0;
146
147
        virtual void setFirstEventRealTime(Event* e) = 0;
148
        virtual void setLastEventRealTime(Event* e) = 0;
149
        /**
150 01873262 Georg Kunz
         * Returns the requested event or NULL if there is no such event included in the log.
151
         * The given event number may not be included in the log.
152
         */
153
        virtual IEvent *getEventForEventNumber(eventnumber_t eventNumber, MatchKind matchKind = EXACT) = 0;
154
        /**
155
         * Returns the requested event or NULL if there is no such event included in the log.
156
         * The given simulation time may not be included in the log.
157
         */
158
        virtual IEvent *getEventForSimulationTime(simtime_t simulationTime, MatchKind matchKind = EXACT) = 0;
159
160
        /**
161
         * Finds the closest event log entry containing the given text.
162
         */
163
        virtual EventLogEntry *findEventLogEntry(EventLogEntry *start, const char *search, bool forward, bool caseSensitive) = 0;
164
165
        /**
166
         * Returns the approximate number of events present in the log.
167
         * This value may be less, equal or greater than the real number of events if there are many.
168
         */
169
        virtual eventnumber_t getApproximateNumberOfEvents() = 0;
170
        /**
171
         * Returns an event approximately at the given percentage in terms of eventlog size.
172
         */
173
        virtual IEvent *getApproximateEventAt(double percentage) = 0;
174
175
        virtual int getNumInitializationLogEntries() = 0;
176
        virtual EventLogEntry *getInitializationLogEntry(int index) = 0;
177
        /**
178
         * Prints initialization entries present before the first event.
179
         */
180
        virtual void printInitializationLogEntries(FILE *file = stdout) = 0;
181
182 81ad8b66 Georg Kunz
        /**
183
         * returns true if the trace file includes EventEndEntries
184
         */
185
        virtual bool isLegacyTrace() = 0;
186
187 01873262 Georg Kunz
    public:
188
        /**
189
         * Returns the event at the given instance. 0 means the parameter event will be returned.
190
         */
191
        virtual IEvent *getNeighbourEvent(IEvent *event, eventnumber_t distance = 1);
192
193
        /**
194
         * Returns true if the event with the given event number is included in the log.
195
         */
196
        virtual bool isIncludedInLog(eventnumber_t eventNumber) { return getEventForEventNumber(eventNumber) != NULL; }
197
        virtual IEvent *getFirstEventNotBeforeEventNumber(eventnumber_t eventNumber) { return getEventForEventNumber(eventNumber, LAST_OR_NEXT); }
198
        virtual IEvent *getLastEventNotAfterEventNumber(eventnumber_t eventNumber) { return getEventForEventNumber(eventNumber, FIRST_OR_PREVIOUS); }
199
        virtual IEvent *getFirstEventNotBeforeSimulationTime(simtime_t simulationTime) { return getEventForSimulationTime(simulationTime, LAST_OR_NEXT); }
200
        virtual IEvent *getLastEventNotAfterSimulationTime(simtime_t simulationTime) { return getEventForSimulationTime(simulationTime, FIRST_OR_PREVIOUS); }
201
202
        virtual double getApproximatePercentageForEventNumber(eventnumber_t eventNumber);
203
204
        /**
205
         * Prints all or only the events in the requested range from the log.
206
         * The given event numbers may not be included in the log.
207
         */
208
        virtual void printEvents(FILE *file = stdout, eventnumber_t fromEventNumber = -1, eventnumber_t toEventNumber = -1, bool outputEventLogMessages = true);
209
        /**
210
         * Prints initialization entries and calls printEvents.
211
         * The given event numbers may not be included in the log.
212
         */
213
        virtual void print(FILE *file = stdout, eventnumber_t fromEventNumber = -1, eventnumber_t toEventNumber = -1, bool outputInitializationEntries = true, bool outputEventLogMessages = true);
214
};
215
216
NAMESPACE_END
217
218
219
#endif