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
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.ITmfTrace;
24 import org.eclipse.linuxtools.tmf.trace.TmfContext;
25 import org.eclipse.linuxtools.tmf.trace.TmfLocation;
26 import 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 */
33 public 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 {
65 super(filename, LttngEvent.class, filename, cacheSize);
66 fTrace = new RandomAccessFile(filename, "r");
67 fParser = new LTTngEventParserStub();
68 indexTrace(true);
69 }
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
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 seekLocation(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 (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
120 public ITmfLocation<?> getCurrentLocation() {
121 try {
122 return new TmfLocation<Long>(fTrace.getFilePointer());
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
134 public TmfEvent parseEvent(TmfContext context) {
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.044019 seconds and 6 git commands to generate.