/*******************************************************************************
- * Copyright (c) 2009 Ericsson
+ * Copyright (c) 2009, 2010 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
import java.io.RandomAccessFile;
import org.eclipse.linuxtools.tmf.event.TmfEvent;
+import org.eclipse.linuxtools.tmf.parser.ITmfEventParser;
/**
* <b><u>TmfTraceStub</u></b>
* <p>
* Dummy test trace. Use in conjunction with TmfEventParserStub.
*/
-public class TmfTraceStub extends TmfTrace {
+public class TmfTraceStub extends TmfTrace<TmfEvent> {
- // ========================================================================
+ // ------------------------------------------------------------------------
// Attributes
- // ========================================================================
+ // ------------------------------------------------------------------------
// The actual stream
private final RandomAccessFile fTrace;
// The associated event parser
private final ITmfEventParser fParser;
- // ========================================================================
+ // ------------------------------------------------------------------------
// Constructors
- // ========================================================================
+ // ------------------------------------------------------------------------
/**
* @param filename
/**
* @param filename
+ * @param cacheSize
* @throws FileNotFoundException
*/
- public TmfTraceStub(String filename, boolean waitForCompletion) throws FileNotFoundException {
- this(filename, DEFAULT_CACHE_SIZE, waitForCompletion);
+ public TmfTraceStub(String filename, int cacheSize) throws FileNotFoundException {
+ this(filename, cacheSize, false);
}
/**
* @param filename
- * @param cacheSize
* @throws FileNotFoundException
*/
- public TmfTraceStub(String filename, int cacheSize) throws FileNotFoundException {
- this(filename, cacheSize, false);
+ public TmfTraceStub(String filename, boolean waitForCompletion) throws FileNotFoundException {
+ this(filename, DEFAULT_CACHE_SIZE, waitForCompletion);
}
/**
* @throws FileNotFoundException
*/
public TmfTraceStub(String filename, int cacheSize, boolean waitForCompletion) throws FileNotFoundException {
- super(filename, cacheSize, waitForCompletion);
+ super(TmfEvent.class, filename, cacheSize);
fTrace = new RandomAccessFile(filename, "r");
fParser = new TmfEventParserStub();
- indexStream();
+ indexTrace(waitForCompletion);
}
- // ========================================================================
+ // ------------------------------------------------------------------------
// Accessors
- // ========================================================================
+ // ------------------------------------------------------------------------
public RandomAccessFile getStream() {
return fTrace;
}
- // ========================================================================
+ // ------------------------------------------------------------------------
// Operators
- // ========================================================================
+ // ------------------------------------------------------------------------
/* (non-Javadoc)
* @see org.eclipse.linuxtools.tmf.eventlog.ITmfStreamLocator#seekLocation(java.lang.Object)
*/
public TmfTraceContext seekLocation(Object location) {
- TmfTraceContext context = null;
try {
synchronized(fTrace) {
+ // Position the trace, read the event (to obtain its timestamp)
+ // and then re-position the trace (not great...)
fTrace.seek((location != null) ? (Long) location : 0);
- context = new TmfTraceContext(getCurrentLocation(), null, 0);
+ TmfTraceContext context = new TmfTraceContext(getCurrentLocation());
+ return context;
}
} catch (IOException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
}
- return context;
+ return null;
}
/* (non-Javadoc)
try {
// paserNextEvent updates the context
TmfEvent event = fParser.parseNextEvent(this, context);
- if (event != null) {
- context.setTimestamp(event.getTimestamp());
- }
return event;
}
catch (IOException e) {
return null;
}
- // ========================================================================
- // Helper functions
- // ========================================================================
-
-}
+}
\ No newline at end of file