Refactor TmfTrace and dependencies - remove getTrace()
[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_INDEX_PAGE_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 fTrace = new RandomAccessFile(resource.getName(), "r");
69 fParser = new LTTngEventParserStub();
70 // indexTrace(true);
71 }
72
73 // ========================================================================
74 // Accessors
75 // ========================================================================
76
77 public RandomAccessFile getStream() {
78 return fTrace;
79 }
80
81 // ========================================================================
82 // Operators
83 // ========================================================================
84
85 /* (non-Javadoc)
86 * @see org.eclipse.linuxtools.tmf.eventlog.ITmfStreamLocator#seekLocation(java.lang.Object)
87 */
88 @Override
89 @SuppressWarnings("unchecked")
90 public TmfContext seekLocation(final ITmfLocation<?> location) {
91 TmfContext context = null;
92 try {
93 synchronized(fTrace) {
94 fTrace.seek((location != null) ? ((TmfLocation<Long>) location).getLocation() : 0);
95 context = new TmfContext(getCurrentLocation(), 0);
96 // TmfTraceContext context2 = new TmfTraceContext(getCurrentLocation(), 0);
97 // TmfEvent event = parseEvent(context2);
98 // context.setTimestamp(event.getTimestamp());
99 }
100 } catch (final IOException e) {
101 // TODO Auto-generated catch block
102 e.printStackTrace();
103 }
104 return context;
105 }
106
107 @Override
108 public TmfContext seekLocation(final double ratio) {
109 // TODO Auto-generated method stub
110 return null;
111 }
112
113 @Override
114 public double getLocationRatio(final ITmfLocation<?> location) {
115 // TODO Auto-generated method stub
116 return 0;
117 }
118
119 /* (non-Javadoc)
120 * @see org.eclipse.linuxtools.tmf.eventlog.ITmfStreamLocator#getCurrentLocation()
121 */
122 @Override
123 public ITmfLocation<?> getCurrentLocation() {
124 try {
125 return new TmfLocation<Long>(fTrace.getFilePointer());
126 } catch (final IOException e) {
127 // TODO Auto-generated catch block
128 e.printStackTrace();
129 }
130 return null;
131 }
132
133 /* (non-Javadoc)
134 * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#parseEvent()
135 */
136 @Override
137 public ITmfEvent parseEvent(final ITmfContext context) {
138 try {
139 // paserNextEvent updates the context
140 final LttngEvent event = (LttngEvent) fParser.parseNextEvent(this, context);
141 // if (event != null) {
142 // context.setTimestamp(event.getTimestamp());
143 // }
144 return event;
145 }
146 catch (final IOException e) {
147 e.printStackTrace();
148 }
149 return null;
150 }
151
152 /* (non-Javadoc)
153 * @see java.lang.Object#toString()
154 */
155 @Override
156 public String toString() {
157 return "[LTTngTraceStub]";
158 }
159
160 // // ========================================================================
161 // // Helper functions
162 // // ========================================================================
163 //
164 // /* (non-Javadoc)
165 // * @see org.eclipse.linuxtools.tmf.eventlog.ITmfEventStream#getAttributes()
166 // */
167 // public Map<String, Object> getAttributes() {
168 // // TODO Auto-generated method stub
169 // return null;
170 // }
171
172 }
This page took 0.034321 seconds and 5 git commands to generate.