- Tweaked the FW a little to accommodate LTTng indexing
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / 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.tmf.event.TmfEvent;
20 import org.eclipse.linuxtools.tmf.trace.ITmfEventParser;
21 import org.eclipse.linuxtools.tmf.trace.TmfTrace;
22 import org.eclipse.linuxtools.tmf.trace.TmfTraceContext;
23
24 /**
25 * <b><u>LTTngTraceStub</u></b>
26 * <p>
27 * Dummy test trace. Use in conjunction with LTTngEventParserStub.
28 */
29 public class LTTngTraceStub extends TmfTrace {
30
31 // ========================================================================
32 // Attributes
33 // ========================================================================
34
35 // The actual stream
36 private final RandomAccessFile fTrace;
37
38 // The associated event parser
39 private final ITmfEventParser fParser;
40
41 // ========================================================================
42 // Constructors
43 // ========================================================================
44
45 /**
46 * @param filename
47 * @param parser
48 * @throws FileNotFoundException
49 */
50 public LTTngTraceStub(String filename) throws FileNotFoundException {
51 this(filename, DEFAULT_CACHE_SIZE);
52 }
53
54 /**
55 * @param filename
56 * @param parser
57 * @param cacheSize
58 * @throws FileNotFoundException
59 */
60 public LTTngTraceStub(String filename, int cacheSize) throws FileNotFoundException {
61 super(filename, cacheSize, false);
62 fTrace = new RandomAccessFile(filename, "r");
63 fParser = new LTTngEventParserStub();
64 indexStream();
65 }
66
67 // ========================================================================
68 // Accessors
69 // ========================================================================
70
71 public RandomAccessFile getStream() {
72 return fTrace;
73 }
74
75 // ========================================================================
76 // Operators
77 // ========================================================================
78
79 /* (non-Javadoc)
80 * @see org.eclipse.linuxtools.tmf.eventlog.ITmfStreamLocator#seekLocation(java.lang.Object)
81 */
82 public TmfTraceContext seekLocation(Object location) {
83 TmfTraceContext context = null;
84 try {
85 synchronized(fTrace) {
86 fTrace.seek((location != null) ? (Long) location : 0);
87 context = new TmfTraceContext(getCurrentLocation(), null, 0);
88 TmfTraceContext context2 = new TmfTraceContext(getCurrentLocation(), null, 0);
89 TmfEvent event = parseEvent(context2);
90 context.setTimestamp(event.getTimestamp());
91 }
92 } catch (IOException e) {
93 // TODO Auto-generated catch block
94 e.printStackTrace();
95 }
96 return context;
97 }
98
99 /* (non-Javadoc)
100 * @see org.eclipse.linuxtools.tmf.eventlog.ITmfStreamLocator#getCurrentLocation()
101 */
102 @Override
103 public Object getCurrentLocation() {
104 try {
105 return new Long(fTrace.getFilePointer());
106 } catch (IOException e) {
107 // TODO Auto-generated catch block
108 e.printStackTrace();
109 }
110 return null;
111 }
112
113 /* (non-Javadoc)
114 * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#parseEvent()
115 */
116 @Override
117 public TmfEvent parseEvent(TmfTraceContext context) {
118 try {
119 // paserNextEvent updates the context
120 TmfEvent event = fParser.parseNextEvent(this, context);
121 // if (event != null) {
122 // context.setTimestamp(event.getTimestamp());
123 // }
124 return event;
125 }
126 catch (IOException e) {
127 e.printStackTrace();
128 }
129 return null;
130 }
131
132 /* (non-Javadoc)
133 * @see java.lang.Object#toString()
134 */
135 @Override
136 public String toString() {
137 return "[LTTngTraceStub]";
138 }
139
140 // // ========================================================================
141 // // Helper functions
142 // // ========================================================================
143 //
144 // /* (non-Javadoc)
145 // * @see org.eclipse.linuxtools.tmf.eventlog.ITmfEventStream#getAttributes()
146 // */
147 // public Map<String, Object> getAttributes() {
148 // // TODO Auto-generated method stub
149 // return null;
150 // }
151
152 }
This page took 0.033635 seconds and 5 git commands to generate.