Statistics
| Branch: | Revision:

root / src / eventlog / ieventlog.h @ 81ad8b66

History | View | Annotate | Download (7.74 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 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
         * Returns the requested event or NULL if there is no such event included in the log.
140
         * The given event number may not be included in the log.
141
         */
142
        virtual IEvent *getEventForEventNumber(eventnumber_t eventNumber, MatchKind matchKind = EXACT) = 0;
143
        /**
144
         * Returns the requested event or NULL if there is no such event included in the log.
145
         * The given simulation time may not be included in the log.
146
         */
147
        virtual IEvent *getEventForSimulationTime(simtime_t simulationTime, MatchKind matchKind = EXACT) = 0;
148

    
149
        /**
150
         * Finds the closest event log entry containing the given text.
151
         */
152
        virtual EventLogEntry *findEventLogEntry(EventLogEntry *start, const char *search, bool forward, bool caseSensitive) = 0;
153

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

    
164
        virtual int getNumInitializationLogEntries() = 0;
165
        virtual EventLogEntry *getInitializationLogEntry(int index) = 0;
166
        /**
167
         * Prints initialization entries present before the first event.
168
         */
169
        virtual void printInitializationLogEntries(FILE *file = stdout) = 0;
170

    
171
        /**
172
         * returns true if the trace file includes EventEndEntries
173
         */
174
        virtual bool isLegacyTrace() = 0;
175

    
176
    public:
177
        /**
178
         * Returns the event at the given instance. 0 means the parameter event will be returned.
179
         */
180
        virtual IEvent *getNeighbourEvent(IEvent *event, eventnumber_t distance = 1);
181

    
182
        /**
183
         * Returns true if the event with the given event number is included in the log.
184
         */
185
        virtual bool isIncludedInLog(eventnumber_t eventNumber) { return getEventForEventNumber(eventNumber) != NULL; }
186
        virtual IEvent *getFirstEventNotBeforeEventNumber(eventnumber_t eventNumber) { return getEventForEventNumber(eventNumber, LAST_OR_NEXT); }
187
        virtual IEvent *getLastEventNotAfterEventNumber(eventnumber_t eventNumber) { return getEventForEventNumber(eventNumber, FIRST_OR_PREVIOUS); }
188
        virtual IEvent *getFirstEventNotBeforeSimulationTime(simtime_t simulationTime) { return getEventForSimulationTime(simulationTime, LAST_OR_NEXT); }
189
        virtual IEvent *getLastEventNotAfterSimulationTime(simtime_t simulationTime) { return getEventForSimulationTime(simulationTime, FIRST_OR_PREVIOUS); }
190

    
191
        virtual double getApproximatePercentageForEventNumber(eventnumber_t eventNumber);
192

    
193
        /**
194
         * Prints all or only the events in the requested range from the log.
195
         * The given event numbers may not be included in the log.
196
         */
197
        virtual void printEvents(FILE *file = stdout, eventnumber_t fromEventNumber = -1, eventnumber_t toEventNumber = -1, bool outputEventLogMessages = true);
198
        /**
199
         * Prints initialization entries and calls printEvents.
200
         * The given event numbers may not be included in the log.
201
         */
202
        virtual void print(FILE *file = stdout, eventnumber_t fromEventNumber = -1, eventnumber_t toEventNumber = -1, bool outputInitializationEntries = true, bool outputEventLogMessages = true);
203
};
204

    
205
NAMESPACE_END
206

    
207

    
208
#endif