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
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_INDEX_PAGE_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 @Override
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
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 */
98 @Override
99 @SuppressWarnings("unchecked")
100 public TmfContext seekLocation(ITmfLocation<?> location) {
101 TmfContext context = null;
102 try {
103 synchronized(fTrace) {
104 fTrace.seek((location != null) ? ((TmfLocation<Long>) location).getLocation() : 0);
105 context = new TmfContext(getCurrentLocation(), 0);
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
121 public ITmfLocation<?> getCurrentLocation() {
122 try {
123 return new TmfLocation<Long>(fTrace.getFilePointer());
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
135 public TmfEvent parseEvent(TmfContext context) {
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.040629 seconds and 6 git commands to generate.