General improvements:
[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 }
89 } catch (IOException e) {
90 // TODO Auto-generated catch block
91 e.printStackTrace();
92 }
93 return context;
94 }
95
96 /* (non-Javadoc)
97 * @see org.eclipse.linuxtools.tmf.eventlog.ITmfStreamLocator#getCurrentLocation()
98 */
99 @Override
100 public Object getCurrentLocation() {
101 try {
102 return new Long(fTrace.getFilePointer());
103 } catch (IOException e) {
104 // TODO Auto-generated catch block
105 e.printStackTrace();
106 }
107 return null;
108 }
109
110 /* (non-Javadoc)
111 * @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#parseEvent()
112 */
113 @Override
114 public TmfEvent parseEvent(TmfTraceContext context) {
115 try {
116 // paserNextEvent updates the context
117 TmfEvent event = fParser.parseNextEvent(this, context);
118 if (event != null) {
119 context.setTimestamp(event.getTimestamp());
120 }
121 return event;
122 }
123 catch (IOException e) {
124 e.printStackTrace();
125 }
126 return null;
127 }
128
129 /* (non-Javadoc)
130 * @see java.lang.Object#toString()
131 */
132 @Override
133 public String toString() {
134 return "[LTTngTraceStub]";
135 }
136
137 // // ========================================================================
138 // // Helper functions
139 // // ========================================================================
140 //
141 // /* (non-Javadoc)
142 // * @see org.eclipse.linuxtools.tmf.eventlog.ITmfEventStream#getAttributes()
143 // */
144 // public Map<String, Object> getAttributes() {
145 // // TODO Auto-generated method stub
146 // return null;
147 // }
148
149 }
This page took 0.033995 seconds and 5 git commands to generate.