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