[Bug304438] Improvement on ITmfLocation
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui.tests / stubs / org / eclipse / linuxtools / 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.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;
22 import org.eclipse.linuxtools.tmf.trace.ITmfLocation;
23 import org.eclipse.linuxtools.tmf.trace.TmfContext;
24 import org.eclipse.linuxtools.tmf.trace.TmfLocation;
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 {
64 super(LttngEvent.class, filename, cacheSize);
65 fTrace = new RandomAccessFile(filename, "r");
66 fParser = new LTTngEventParserStub();
67 indexTrace(true);
68 }
69
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 */
85 @Override
86 @SuppressWarnings("unchecked")
87 public TmfContext seekLocation(ITmfLocation<?> location) {
88 TmfContext context = null;
89 try {
90 synchronized(fTrace) {
91 fTrace.seek((location != null) ? ((TmfLocation<Long>) location).getLocation() : 0);
92 context = new TmfContext(getCurrentLocation(), 0);
93 // TmfTraceContext context2 = new TmfTraceContext(getCurrentLocation(), 0);
94 // TmfEvent event = parseEvent(context2);
95 // context.setTimestamp(event.getTimestamp());
96 }
97 } catch (IOException e) {
98 // TODO Auto-generated catch block
99 e.printStackTrace();
100 }
101 return context;
102 }
103
104 /* (non-Javadoc)
105 * @see org.eclipse.linuxtools.tmf.eventlog.ITmfStreamLocator#getCurrentLocation()
106 */
107 @Override
108 public ITmfLocation<?> getCurrentLocation() {
109 try {
110 return new TmfLocation<Long>(fTrace.getFilePointer());
111 } catch (IOException e) {
112 // TODO Auto-generated catch block
113 e.printStackTrace();
114 }
115 return null;
116 }
117
118 /* (non-Javadoc)
119 * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#parseEvent()
120 */
121 @Override
122 public TmfEvent parseEvent(TmfContext context) {
123 try {
124 // paserNextEvent updates the context
125 TmfEvent event = fParser.parseNextEvent(this, context);
126 // if (event != null) {
127 // context.setTimestamp(event.getTimestamp());
128 // }
129 return event;
130 }
131 catch (IOException e) {
132 e.printStackTrace();
133 }
134 return null;
135 }
136
137 /* (non-Javadoc)
138 * @see java.lang.Object#toString()
139 */
140 @Override
141 public String toString() {
142 return "[LTTngTraceStub]";
143 }
144
145 // // ========================================================================
146 // // Helper functions
147 // // ========================================================================
148 //
149 // /* (non-Javadoc)
150 // * @see org.eclipse.linuxtools.tmf.eventlog.ITmfEventStream#getAttributes()
151 // */
152 // public Map<String, Object> getAttributes() {
153 // // TODO Auto-generated method stub
154 // return null;
155 // }
156
157 }
This page took 0.035026 seconds and 6 git commands to generate.