Project

General

Profile

Statistics
| Branch: | Revision:

root / src / eventlog / eventlog.h @ 391dcea0

History | View | Annotate | Download (5.54 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
        typedef std::vector<EventLogEntry *> EventLogEntryList;
56
        EventLogEntryList initializationLogEntries; // all entries from the beginning of the file to the first event
57

    
58
        SimulationBeginEntry *simulationBeginEntry;
59

    
60
        typedef std::map<int, ModuleCreatedEntry *> ModuleIdToModuleCreatedEntryMap;
61
        ModuleIdToModuleCreatedEntryMap moduleIdToModuleCreatedEntryMap;
62

    
63
        typedef std::map<std::pair<int, int>, GateCreatedEntry *> ModuleIdAndGateIdToGateCreatedEntryMap;
64
        ModuleIdAndGateIdToGateCreatedEntryMap moduleIdAndGateIdToGateCreatedEntryMap;
65

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

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

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

    
76
    public:
77
        EventLog(FileReader *index);
78
        ~EventLog();
79

    
80
        virtual ProgressMonitor setProgressMonitor(ProgressMonitor newProgressMonitor);
81
        virtual void setProgressCallInterval(double seconds) { progressCallInterval = (long)(seconds * CLOCKS_PER_SEC); lastProgressCall = clock(); }
82
        virtual void progress();
83

    
84
        void parseInitializationLogEntries();
85

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

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

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

    
113
        virtual EventLogEntry *findEventLogEntry(EventLogEntry *start, const char *search, bool forward, bool caseSensitive);
114

    
115
        virtual eventnumber_t getApproximateNumberOfEvents();
116
        virtual Event *getApproximateEventAt(double percentage);
117

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

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

    
133
NAMESPACE_END
134

    
135

    
136
#endif