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