Signal out-of-order fix + some additional traces.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui.tests / stubs / org / eclipse / linuxtools / lttng / stubs / LTTngTraceStub.java
CommitLineData
6040f86c
ASL
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
13package org.eclipse.linuxtools.lttng.stubs;
14
15import java.io.FileNotFoundException;
16import java.io.IOException;
17import java.io.RandomAccessFile;
18
19import org.eclipse.linuxtools.lttng.event.LttngEvent;
20import org.eclipse.linuxtools.tmf.event.TmfEvent;
21import org.eclipse.linuxtools.tmf.parser.ITmfEventParser;
9f584e4c 22import org.eclipse.linuxtools.tmf.trace.ITmfLocation;
aa9d027b 23import org.eclipse.linuxtools.tmf.trace.ITmfTrace;
9f584e4c
FC
24import org.eclipse.linuxtools.tmf.trace.TmfContext;
25import org.eclipse.linuxtools.tmf.trace.TmfLocation;
6040f86c
ASL
26import org.eclipse.linuxtools.tmf.trace.TmfTrace;
27
28/**
29 * <b><u>LTTngTraceStub</u></b>
30 * <p>
31 * Dummy test trace. Use in conjunction with LTTngEventParserStub.
32 */
33public class LTTngTraceStub extends TmfTrace<LttngEvent> {
34
35 // ========================================================================
36 // Attributes
37 // ========================================================================
38
39 // The actual stream
40 private final RandomAccessFile fTrace;
41
42 // The associated event parser
43 private final ITmfEventParser fParser;
44
45 // ========================================================================
46 // Constructors
47 // ========================================================================
48
49 /**
50 * @param filename
51 * @param parser
52 * @throws FileNotFoundException
53 */
54 public LTTngTraceStub(String filename) throws FileNotFoundException {
55 this(filename, DEFAULT_CACHE_SIZE);
56 }
57
58 /**
59 * @param filename
60 * @param parser
61 * @param cacheSize
62 * @throws FileNotFoundException
63 */
64 public LTTngTraceStub(String filename, int cacheSize) throws FileNotFoundException {
ce785d7d 65 super(filename, LttngEvent.class, filename, cacheSize);
6040f86c
ASL
66 fTrace = new RandomAccessFile(filename, "r");
67 fParser = new LTTngEventParserStub();
b9fb2d51 68 indexTrace(true);
6040f86c 69 }
aa9d027b
WB
70
71 public ITmfTrace createTraceCopy() {
72 ITmfTrace returnedValue = null;
73 try {
74 returnedValue = new LTTngTraceStub(this.getName());
75 }
76 catch (FileNotFoundException e) {
77 e.printStackTrace();
78 }
79 return returnedValue;
80 }
81
6040f86c
ASL
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 */
452ad365 97 @Override
9f584e4c 98 @SuppressWarnings("unchecked")
452ad365 99 public TmfContext seekLocation(ITmfLocation<?> location) {
9f584e4c 100 TmfContext context = null;
6040f86c
ASL
101 try {
102 synchronized(fTrace) {
452ad365 103 fTrace.seek((location != null) ? ((TmfLocation<Long>) location).getLocation() : 0);
9f584e4c 104 context = new TmfContext(getCurrentLocation(), 0);
6040f86c
ASL
105// TmfTraceContext context2 = new TmfTraceContext(getCurrentLocation(), 0);
106// TmfEvent event = parseEvent(context2);
107// context.setTimestamp(event.getTimestamp());
108 }
109 } catch (IOException e) {
110 // TODO Auto-generated catch block
111 e.printStackTrace();
112 }
113 return context;
114 }
115
116 /* (non-Javadoc)
117 * @see org.eclipse.linuxtools.tmf.eventlog.ITmfStreamLocator#getCurrentLocation()
118 */
119 @Override
452ad365 120 public ITmfLocation<?> getCurrentLocation() {
6040f86c 121 try {
9f584e4c 122 return new TmfLocation<Long>(fTrace.getFilePointer());
6040f86c
ASL
123 } catch (IOException e) {
124 // TODO Auto-generated catch block
125 e.printStackTrace();
126 }
127 return null;
128 }
129
130 /* (non-Javadoc)
131 * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#parseEvent()
132 */
133 @Override
9f584e4c 134 public TmfEvent parseEvent(TmfContext context) {
6040f86c
ASL
135 try {
136 // paserNextEvent updates the context
137 TmfEvent event = fParser.parseNextEvent(this, context);
138// if (event != null) {
139// context.setTimestamp(event.getTimestamp());
140// }
141 return event;
142 }
143 catch (IOException e) {
144 e.printStackTrace();
145 }
146 return null;
147 }
148
149 /* (non-Javadoc)
150 * @see java.lang.Object#toString()
151 */
152 @Override
153 public String toString() {
154 return "[LTTngTraceStub]";
155 }
156
157// // ========================================================================
158// // Helper functions
159// // ========================================================================
160//
161// /* (non-Javadoc)
162// * @see org.eclipse.linuxtools.tmf.eventlog.ITmfEventStream#getAttributes()
163// */
164// public Map<String, Object> getAttributes() {
165// // TODO Auto-generated method stub
166// return null;
167// }
168
169}
This page took 0.032632 seconds and 5 git commands to generate.