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