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