Commit | Line | Data |
---|---|---|
6040f86c ASL |
1 | /******************************************************************************* |
2 | * Copyright (c) 2009 Ericsson | |
3 | * | |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Francois Chouinard (fchouinard@gmail.com) - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.lttng.stubs; | |
14 | ||
15 | import java.io.FileNotFoundException; | |
16 | import java.io.IOException; | |
17 | import java.io.RandomAccessFile; | |
18 | ||
19 | import org.eclipse.linuxtools.lttng.event.LttngEvent; | |
20 | import org.eclipse.linuxtools.tmf.event.TmfEvent; | |
21 | import org.eclipse.linuxtools.tmf.parser.ITmfEventParser; | |
9f584e4c FC |
22 | import org.eclipse.linuxtools.tmf.trace.ITmfLocation; |
23 | import org.eclipse.linuxtools.tmf.trace.TmfContext; | |
24 | import org.eclipse.linuxtools.tmf.trace.TmfLocation; | |
6040f86c ASL |
25 | import org.eclipse.linuxtools.tmf.trace.TmfTrace; |
26 | ||
27 | /** | |
28 | * <b><u>LTTngTraceStub</u></b> | |
29 | * <p> | |
30 | * Dummy test trace. Use in conjunction with LTTngEventParserStub. | |
31 | */ | |
32 | public class LTTngTraceStub extends TmfTrace<LttngEvent> { | |
33 | ||
34 | // ======================================================================== | |
35 | // Attributes | |
36 | // ======================================================================== | |
37 | ||
38 | // The actual stream | |
39 | private final RandomAccessFile fTrace; | |
40 | ||
41 | // The associated event parser | |
42 | private final ITmfEventParser fParser; | |
43 | ||
44 | // ======================================================================== | |
45 | // Constructors | |
46 | // ======================================================================== | |
47 | ||
48 | /** | |
49 | * @param filename | |
50 | * @param parser | |
51 | * @throws FileNotFoundException | |
52 | */ | |
53 | public LTTngTraceStub(String filename) throws FileNotFoundException { | |
54 | this(filename, DEFAULT_CACHE_SIZE); | |
55 | } | |
56 | ||
57 | /** | |
58 | * @param filename | |
59 | * @param parser | |
60 | * @param cacheSize | |
61 | * @throws FileNotFoundException | |
62 | */ | |
63 | public LTTngTraceStub(String filename, int cacheSize) throws FileNotFoundException { | |
b9fb2d51 | 64 | super(LttngEvent.class, filename, cacheSize); |
6040f86c ASL |
65 | fTrace = new RandomAccessFile(filename, "r"); |
66 | fParser = new LTTngEventParserStub(); | |
b9fb2d51 | 67 | indexTrace(true); |
6040f86c | 68 | } |
b9fb2d51 | 69 | |
6040f86c ASL |
70 | // ======================================================================== |
71 | // Accessors | |
72 | // ======================================================================== | |
73 | ||
74 | public RandomAccessFile getStream() { | |
75 | return fTrace; | |
76 | } | |
77 | ||
78 | // ======================================================================== | |
79 | // Operators | |
80 | // ======================================================================== | |
81 | ||
82 | /* (non-Javadoc) | |
83 | * @see org.eclipse.linuxtools.tmf.eventlog.ITmfStreamLocator#seekLocation(java.lang.Object) | |
84 | */ | |
9f584e4c FC |
85 | @SuppressWarnings("unchecked") |
86 | public TmfContext seekLocation(ITmfLocation location) { | |
87 | TmfContext context = null; | |
6040f86c ASL |
88 | try { |
89 | synchronized(fTrace) { | |
9f584e4c FC |
90 | fTrace.seek((location != null) ? ((TmfLocation<Long>) location).getValue() : 0); |
91 | context = new TmfContext(getCurrentLocation(), 0); | |
6040f86c ASL |
92 | // TmfTraceContext context2 = new TmfTraceContext(getCurrentLocation(), 0); |
93 | // TmfEvent event = parseEvent(context2); | |
94 | // context.setTimestamp(event.getTimestamp()); | |
95 | } | |
96 | } catch (IOException e) { | |
97 | // TODO Auto-generated catch block | |
98 | e.printStackTrace(); | |
99 | } | |
100 | return context; | |
101 | } | |
102 | ||
103 | /* (non-Javadoc) | |
104 | * @see org.eclipse.linuxtools.tmf.eventlog.ITmfStreamLocator#getCurrentLocation() | |
105 | */ | |
106 | @Override | |
9f584e4c | 107 | public ITmfLocation getCurrentLocation() { |
6040f86c | 108 | try { |
9f584e4c | 109 | return new TmfLocation<Long>(fTrace.getFilePointer()); |
6040f86c ASL |
110 | } catch (IOException e) { |
111 | // TODO Auto-generated catch block | |
112 | e.printStackTrace(); | |
113 | } | |
114 | return null; | |
115 | } | |
116 | ||
117 | /* (non-Javadoc) | |
118 | * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#parseEvent() | |
119 | */ | |
120 | @Override | |
9f584e4c | 121 | public TmfEvent parseEvent(TmfContext context) { |
6040f86c ASL |
122 | try { |
123 | // paserNextEvent updates the context | |
124 | TmfEvent event = fParser.parseNextEvent(this, context); | |
125 | // if (event != null) { | |
126 | // context.setTimestamp(event.getTimestamp()); | |
127 | // } | |
128 | return event; | |
129 | } | |
130 | catch (IOException e) { | |
131 | e.printStackTrace(); | |
132 | } | |
133 | return null; | |
134 | } | |
135 | ||
136 | /* (non-Javadoc) | |
137 | * @see java.lang.Object#toString() | |
138 | */ | |
139 | @Override | |
140 | public String toString() { | |
141 | return "[LTTngTraceStub]"; | |
142 | } | |
143 | ||
144 | // // ======================================================================== | |
145 | // // Helper functions | |
146 | // // ======================================================================== | |
147 | // | |
148 | // /* (non-Javadoc) | |
149 | // * @see org.eclipse.linuxtools.tmf.eventlog.ITmfEventStream#getAttributes() | |
150 | // */ | |
151 | // public Map<String, Object> getAttributes() { | |
152 | // // TODO Auto-generated method stub | |
153 | // return null; | |
154 | // } | |
155 | ||
156 | } |