Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (5.68 KB)

1
//=========================================================================
2
//  EVENTLOG.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 __EVENTLOG_H_
18
#define __EVENTLOG_H_
19

    
20
#include <time.h>
21
#include <sstream>
22
#include <set>
23
#include <map>
24
#include "stringpool.h"
25
#include "filereader.h"
26
#include "event.h"
27
#include "ieventlog.h"
28
#include "eventlogindex.h"
29

    
30
NAMESPACE_BEGIN
31

    
32
extern EVENTLOG_API CommonStringPool eventLogStringPool;
33

    
34
class Event;
35
class EventLogEntry;
36

    
37
/**
38
 * Manages an event log file in memory. Caches some events. Clients should not
39
 * store pointers to Events or EventLogEntries, because this class may
40
 * thow them out of the cache any time.
41
 */
42
class EVENTLOG_API EventLog : public IEventLog, public EventLogIndex
43
{
44
    protected:
45
        eventnumber_t numParsedEvents;
46
        eventnumber_t approximateNumberOfEvents;
47

    
48
        long progressCallInterval;
49
        long lastProgressCall; // as returned by clock()
50
        ProgressMonitor progressMonitor;
51

    
52
        Event *firstEvent;
53
        Event *lastEvent;
54

    
55
        bool legacyTrace; // is legacy trace that does not contain EventEndEntries
56

    
57
        typedef std::vector<EventLogEntry *> EventLogEntryList;
58
        EventLogEntryList initializationLogEntries; // all entries from the beginning of the file to the first event
59

    
60
        SimulationBeginEntry *simulationBeginEntry;
61

    
62
        typedef std::map<int, ModuleCreatedEntry *> ModuleIdToModuleCreatedEntryMap;
63
        ModuleIdToModuleCreatedEntryMap moduleIdToModuleCreatedEntryMap;
64

    
65
        typedef std::map<std::pair<int, int>, GateCreatedEntry *> ModuleIdAndGateIdToGateCreatedEntryMap;
66
        ModuleIdAndGateIdToGateCreatedEntryMap moduleIdAndGateIdToGateCreatedEntryMap;
67

    
68
        std::set<const char *> messageClassNames; // message class names seen so far (see Event::parse)
69
        std::set<const char *> messageNames; // message names seen so far (see Event::parse)
70

    
71
        typedef std::map<eventnumber_t, Event *> EventNumberToEventMap;
72
        EventNumberToEventMap eventNumberToEventMap; // all parsed events so far
73

    
74
        typedef std::map<file_offset_t, Event *> OffsetToEventMap;
75
        OffsetToEventMap beginOffsetToEventMap; // all parsed events so far
76
        OffsetToEventMap endOffsetToEventMap; // all parsed events so far
77

    
78
    public:
79
        EventLog(FileReader *index);
80
        ~EventLog();
81

    
82
        virtual ProgressMonitor setProgressMonitor(ProgressMonitor newProgressMonitor);
83
        virtual void setProgressCallInterval(double seconds) { progressCallInterval = (long)(seconds * CLOCKS_PER_SEC); lastProgressCall = clock(); }
84
        virtual void progress();
85
        virtual bool isLegacyTrace() { return legacyTrace; }
86

    
87
        void parseInitializationLogEntries();
88

    
89
        /**
90
         * Returns the event exactly starting at the given offset or NULL if there is no such event.
91
         */
92
        Event *getEventForBeginOffset(file_offset_t offset);
93
        /**
94
         * Returns the event exactly ending at the given offset or NULL if there is no such event.
95
         */
96
        Event *getEventForEndOffset(file_offset_t offset);
97

    
98
        // IEventLog interface
99
        virtual void synchronize(FileReader::FileChangedState change);
100
        virtual FileReader *getFileReader() { return reader; }
101
        virtual eventnumber_t getNumParsedEvents() { return numParsedEvents; }
102
        virtual std::set<const char *>& getMessageNames() { return messageNames; }
103
        virtual std::set<const char *>& getMessageClassNames() { return messageClassNames; }
104
        virtual int getNumModuleCreatedEntries() { return moduleIdToModuleCreatedEntryMap.size(); }
105
        virtual std::vector<ModuleCreatedEntry *> getModuleCreatedEntries();
106
        virtual ModuleCreatedEntry *getModuleCreatedEntry(int moduleId);
107
        virtual GateCreatedEntry *getGateCreatedEntry(int moduleId, int gateId);
108
        virtual SimulationBeginEntry *getSimulationBeginEntry() { return simulationBeginEntry; }
109

    
110
        virtual Event *getFirstEvent();
111
        virtual Event *getLastEvent();
112
        virtual Event *getNeighbourEvent(IEvent *event, eventnumber_t distance = 1);
113
        virtual Event *getEventForEventNumber(eventnumber_t eventNumber, MatchKind matchKind = EXACT);
114
        virtual Event *getEventForSimulationTime(simtime_t simulationTime, MatchKind matchKind = EXACT);
115

    
116
        virtual EventLogEntry *findEventLogEntry(EventLogEntry *start, const char *search, bool forward, bool caseSensitive);
117

    
118
        virtual eventnumber_t getApproximateNumberOfEvents();
119
        virtual Event *getApproximateEventAt(double percentage);
120

    
121
        virtual int getNumInitializationLogEntries() { return initializationLogEntries.size(); }
122
        virtual EventLogEntry *getInitializationLogEntry(int index) { return initializationLogEntries[index]; }
123
        virtual void printInitializationLogEntries(FILE *file = stdout);
124

    
125
    protected:
126
        void parseEvent(Event *event, file_offset_t beginOffset);
127
        void cacheEvent(Event *event);
128
        void cacheEventLogEntries(Event *event);
129
        void uncacheEventLogEntries(Event *event);
130
        void cacheEventLogEntry(EventLogEntry *eventLogEntry);
131
        void uncacheEventLogEntry(EventLogEntry *eventLogEntry);
132
        void deleteAllocatedObjects();
133
        void clearInternalState(FileReader::FileChangedState change = FileReader::OVERWRITTEN);
134
};
135

    
136
NAMESPACE_END
137

    
138

    
139
#endif