Statistics
| Branch: | Revision:

root / src / eventlog / eventlog.h @ e1750c09

History | View | Annotate | Download (6.04 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
        Event *firstEventRealTime;
56
        Event *lastEventRealTime;
57

    
58
        bool legacyTrace; // is legacy trace that does not contain EventEndEntries
59

    
60
        typedef std::vector<EventLogEntry *> EventLogEntryList;
61
        EventLogEntryList initializationLogEntries; // all entries from the beginning of the file to the first event
62

    
63
        SimulationBeginEntry *simulationBeginEntry;
64

    
65
        typedef std::map<int, ModuleCreatedEntry *> ModuleIdToModuleCreatedEntryMap;
66
        ModuleIdToModuleCreatedEntryMap moduleIdToModuleCreatedEntryMap;
67

    
68
        typedef std::map<std::pair<int, int>, GateCreatedEntry *> ModuleIdAndGateIdToGateCreatedEntryMap;
69
        ModuleIdAndGateIdToGateCreatedEntryMap moduleIdAndGateIdToGateCreatedEntryMap;
70

    
71
        std::set<const char *> messageClassNames; // message class names seen so far (see Event::parse)
72
        std::set<const char *> messageNames; // message names seen so far (see Event::parse)
73

    
74
        typedef std::map<eventnumber_t, Event *> EventNumberToEventMap;
75
        EventNumberToEventMap eventNumberToEventMap; // all parsed events so far
76

    
77
        typedef std::map<file_offset_t, Event *> OffsetToEventMap;
78
        OffsetToEventMap beginOffsetToEventMap; // all parsed events so far
79
        OffsetToEventMap endOffsetToEventMap; // all parsed events so far
80

    
81
    public:
82
        EventLog(FileReader *index);
83
        ~EventLog();
84

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

    
90
        void parseInitializationLogEntries();
91

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

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

    
113
        virtual Event *getFirstEvent();
114
        virtual Event *getLastEvent();
115

    
116
        virtual Event *getFirstEventRealTime();
117
        virtual Event *getLastEventRealTime();
118

    
119
        virtual void setFirstEventRealTime(Event* e) {
120
            firstEventRealTime = e;;
121
        }
122
        virtual void setLastEventRealTime(Event* e){
123
            lastEventRealTime = e;
124
        }
125

    
126
        virtual Event *getNeighbourEvent(IEvent *event, eventnumber_t distance = 1);
127
        virtual Event *getEventForEventNumber(eventnumber_t eventNumber, MatchKind matchKind = EXACT);
128
        virtual Event *getEventForSimulationTime(simtime_t simulationTime, MatchKind matchKind = EXACT);
129

    
130
        virtual EventLogEntry *findEventLogEntry(EventLogEntry *start, const char *search, bool forward, bool caseSensitive);
131

    
132
        virtual eventnumber_t getApproximateNumberOfEvents();
133
        virtual Event *getApproximateEventAt(double percentage);
134

    
135
        virtual int getNumInitializationLogEntries() { return initializationLogEntries.size(); }
136
        virtual EventLogEntry *getInitializationLogEntry(int index) { return initializationLogEntries[index]; }
137
        virtual void printInitializationLogEntries(FILE *file = stdout);
138

    
139
    protected:
140
        void parseEvent(Event *event, file_offset_t beginOffset);
141
        void cacheEvent(Event *event);
142
        void cacheEventLogEntries(Event *event);
143
        void uncacheEventLogEntries(Event *event);
144
        void cacheEventLogEntry(EventLogEntry *eventLogEntry);
145
        void uncacheEventLogEntry(EventLogEntry *eventLogEntry);
146
        void deleteAllocatedObjects();
147
        void clearInternalState(FileReader::FileChangedState change = FileReader::OVERWRITTEN);
148
};
149

    
150
NAMESPACE_END
151

    
152

    
153
#endif