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