Refactor TmfTrace and dependencies - introduce ITmfTraceIndexer
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui.tests / stubs / org / eclipse / linuxtools / internal / lttng / stubs / LTTngTraceStub.java
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.internal.lttng.stubs;
14
15 import java.io.FileNotFoundException;
16 import java.io.IOException;
17 import java.io.RandomAccessFile;
18
19 import org.eclipse.core.resources.IResource;
20 import org.eclipse.linuxtools.internal.lttng.core.event.LttngEvent;
21 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
22 import org.eclipse.linuxtools.tmf.core.parser.ITmfEventParser;
23 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
24 import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
25 import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
26 import org.eclipse.linuxtools.tmf.core.trace.TmfLocation;
27 import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
28
29 /**
30 * <b><u>LTTngTraceStub</u></b>
31 * <p>
32 * Dummy test trace. Use in conjunction with LTTngEventParserStub.
33 */
34 @SuppressWarnings("nls")
35 public class LTTngTraceStub extends TmfTrace<LttngEvent> {
36
37 // ========================================================================
38 // Attributes
39 // ========================================================================
40
41 // The actual stream
42 private final RandomAccessFile fTrace;
43
44 // The associated event parser
45 private final ITmfEventParser<LttngEvent> fParser;
46
47 // ========================================================================
48 // Constructors
49 // ========================================================================
50
51 /**
52 * @param filename
53 * @param parser
54 * @throws FileNotFoundException
55 */
56 public LTTngTraceStub(final IResource resource) throws FileNotFoundException {
57 this(resource, DEFAULT_TRACE_CACHE_SIZE);
58 }
59
60 /**
61 * @param filename
62 * @param parser
63 * @param cacheSize
64 * @throws FileNotFoundException
65 */
66 public LTTngTraceStub(final IResource resource, final int cacheSize) throws FileNotFoundException {
67 // super(resource, LttngEvent.class, resource.getName(), cacheSize, true);
68 super(resource, LttngEvent.class, resource.getName(), cacheSize);
69 fTrace = new RandomAccessFile(resource.getName(), "r");
70 fParser = new LTTngEventParserStub();
71 }
72
73 public void indexTrace() {
74 fIndexer.buildIndex(true);
75 }
76
77 // ========================================================================
78 // Accessors
79 // ========================================================================
80
81 public RandomAccessFile getStream() {
82 return fTrace;
83 }
84
85 // ========================================================================
86 // Operators
87 // ========================================================================
88
89 /* (non-Javadoc)
90 * @see org.eclipse.linuxtools.tmf.eventlog.ITmfStreamLocator#seekLocation(java.lang.Object)
91 */
92 @Override
93 @SuppressWarnings("unchecked")
94 public TmfContext seekLocation(final ITmfLocation<?> location) {
95 TmfContext context = null;
96 try {
97 synchronized(fTrace) {
98 fTrace.seek((location != null) ? ((TmfLocation<Long>) location).getLocation() : 0);
99 context = new TmfContext(getCurrentLocation(), 0);
100 // TmfTraceContext context2 = new TmfTraceContext(getCurrentLocation(), 0);
101 // TmfEvent event = parseEvent(context2);
102 // context.setTimestamp(event.getTimestamp());
103 }
104 } catch (final IOException e) {
105 // TODO Auto-generated catch block
106 e.printStackTrace();
107 }
108 return context;
109 }
110
111 @Override
112 public TmfContext seekLocation(final double ratio) {
113 // TODO Auto-generated method stub
114 return null;
115 }
116
117 @Override
118 public double getLocationRatio(final ITmfLocation<?> location) {
119 // TODO Auto-generated method stub
120 return 0;
121 }
122
123 /* (non-Javadoc)
124 * @see org.eclipse.linuxtools.tmf.eventlog.ITmfStreamLocator#getCurrentLocation()
125 */
126 @Override
127 public ITmfLocation<?> getCurrentLocation() {
128 try {
129 return new TmfLocation<Long>(fTrace.getFilePointer());
130 } catch (final IOException e) {
131 // TODO Auto-generated catch block
132 e.printStackTrace();
133 }
134 return null;
135 }
136
137 /* (non-Javadoc)
138 * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#parseEvent()
139 */
140 @Override
141 public ITmfEvent parseEvent(final ITmfContext context) {
142 try {
143 // paserNextEvent updates the context
144 final LttngEvent event = (LttngEvent) fParser.parseNextEvent(this, context);
145 // if (event != null) {
146 // context.setTimestamp(event.getTimestamp());
147 // }
148 return event;
149 }
150 catch (final IOException e) {
151 e.printStackTrace();
152 }
153 return null;
154 }
155
156 /* (non-Javadoc)
157 * @see java.lang.Object#toString()
158 */
159 @Override
160 public String toString() {
161 return "[LTTngTraceStub]";
162 }
163
164 // // ========================================================================
165 // // Helper functions
166 // // ========================================================================
167 //
168 // /* (non-Javadoc)
169 // * @see org.eclipse.linuxtools.tmf.eventlog.ITmfEventStream#getAttributes()
170 // */
171 // public Map<String, Object> getAttributes() {
172 // // TODO Auto-generated method stub
173 // return null;
174 // }
175
176 }
This page took 0.034957 seconds and 5 git commands to generate.