Commit | Line | Data |
---|---|---|
8035003b 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; | |
146a887c | 18 | import java.util.Map; |
8035003b ASL |
19 | |
20 | import org.eclipse.linuxtools.tmf.event.TmfEvent; | |
21 | import org.eclipse.linuxtools.tmf.trace.ITmfEventParser; | |
22 | import org.eclipse.linuxtools.tmf.trace.TmfTrace; | |
8035003b ASL |
23 | |
24 | /** | |
25 | * <b><u>LTTngTraceStub</u></b> | |
26 | * <p> | |
146a887c | 27 | * TODO: Implement me. Please. |
8035003b ASL |
28 | */ |
29 | public class LTTngTraceStub extends TmfTrace { | |
30 | ||
31 | // ======================================================================== | |
32 | // Attributes | |
33 | // ======================================================================== | |
34 | ||
35 | // The actual stream | |
146a887c | 36 | private final RandomAccessFile fStream; |
8035003b ASL |
37 | |
38 | // The associated event parser | |
39 | private final ITmfEventParser fParser; | |
40 | ||
41 | // ======================================================================== | |
42 | // Constructors | |
43 | // ======================================================================== | |
44 | ||
45 | /** | |
46 | * @param filename | |
47 | * @param parser | |
48 | * @throws FileNotFoundException | |
49 | */ | |
50 | public LTTngTraceStub(String filename) throws FileNotFoundException { | |
146a887c | 51 | this(filename, DEFAULT_PAGE_SIZE); |
8035003b ASL |
52 | } |
53 | ||
54 | /** | |
55 | * @param filename | |
56 | * @param parser | |
57 | * @param cacheSize | |
58 | * @throws FileNotFoundException | |
59 | */ | |
60 | public LTTngTraceStub(String filename, int cacheSize) throws FileNotFoundException { | |
146a887c FC |
61 | super(filename, cacheSize); |
62 | fStream = new RandomAccessFile(filename, "r"); | |
8035003b ASL |
63 | fParser = new LTTngEventParserStub(); |
64 | indexStream(); | |
65 | } | |
66 | ||
67 | // ======================================================================== | |
68 | // Accessors | |
69 | // ======================================================================== | |
70 | ||
71 | public RandomAccessFile getStream() { | |
146a887c | 72 | return fStream; |
8035003b ASL |
73 | } |
74 | ||
75 | // ======================================================================== | |
76 | // Operators | |
77 | // ======================================================================== | |
78 | ||
79 | /* (non-Javadoc) | |
80 | * @see org.eclipse.linuxtools.tmf.eventlog.ITmfStreamLocator#seekLocation(java.lang.Object) | |
81 | */ | |
146a887c | 82 | public TmfTraceContext seekLocation(Object location) { |
8035003b | 83 | TmfTraceContext context = null; |
146a887c FC |
84 | try { |
85 | fStream.seek((location != null) ? (Long) location : 0); | |
86 | context = new TmfTraceContext(getCurrentLocation(), 0); | |
8035003b | 87 | } catch (IOException e) { |
146a887c FC |
88 | // TODO Auto-generated catch block |
89 | e.printStackTrace(); | |
8035003b ASL |
90 | } |
91 | return context; | |
92 | } | |
93 | ||
94 | /* (non-Javadoc) | |
95 | * @see org.eclipse.linuxtools.tmf.eventlog.ITmfStreamLocator#getCurrentLocation() | |
96 | */ | |
146a887c FC |
97 | public Object getCurrentLocation() { |
98 | try { | |
99 | return new Long(fStream.getFilePointer()); | |
100 | } catch (IOException e) { | |
101 | // TODO Auto-generated catch block | |
102 | e.printStackTrace(); | |
103 | } | |
8035003b ASL |
104 | return null; |
105 | } | |
106 | ||
107 | /* (non-Javadoc) | |
108 | * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#parseEvent() | |
109 | */ | |
146a887c FC |
110 | public TmfEvent parseNextEvent() { |
111 | try { | |
112 | TmfEvent event = fParser.getNextEvent(this); | |
113 | return event; | |
114 | } | |
115 | catch (IOException e) { | |
116 | e.printStackTrace(); | |
117 | } | |
118 | return null; | |
8035003b ASL |
119 | } |
120 | ||
146a887c FC |
121 | // ======================================================================== |
122 | // Helper functions | |
123 | // ======================================================================== | |
8035003b | 124 | |
146a887c FC |
125 | /* (non-Javadoc) |
126 | * @see org.eclipse.linuxtools.tmf.eventlog.ITmfEventStream#getAttributes() | |
127 | */ | |
128 | public Map<String, Object> getAttributes() { | |
129 | // TODO Auto-generated method stub | |
130 | return null; | |
131 | } | |
8035003b ASL |
132 | |
133 | } |