import java.io.IOException;
import java.util.HashMap;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.linuxtools.internal.lttng.core.event.LttngEvent;
import org.eclipse.linuxtools.internal.lttng.core.event.LttngEventContent;
// fCheckpoints.add(new TmfCheckpoint(new LttngTimestamp(0L), new TmfLocation<Long>(0L)));
ITmfContext context = new TmfContext(new TmfLocation<Long>(0L), 0);
fIndexer.updateIndex(context, new LttngTimestamp(0L));
- fParser = (ITmfEventParser) this;
+ fParser = (ITmfEventParser<LttngEvent>) this;
// }
// else {
// indexTrace(true);
return cpuNumber;
}
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#validate(org.eclipse.core.resources.IProject, java.lang.String)
+ */
+ @Override
+ public boolean validate(IProject project, String path) {
+ return fileExists(path);
+ }
+
}
@Override
public boolean validate(final IProject project, final String path) {
- if (super.validate(project, path)) {
+ if (fileExists(path)) {
final String traceLibPath = TraceHelper.getTraceLibDirFromProject(project);
try {
final LTTngTraceVersion version = new LTTngTraceVersion(path, traceLibPath);
// Set the currentEvent to the eventContent
eventContent.setEvent(currentLttngEvent);
- fParser = (ITmfEventParser) this;
+ fParser = (ITmfEventParser<LttngEvent>) this;
fCacheSize = CHECKPOINT_PAGE_SIZE;
// // Bypass indexing if asked
if (location == null) {
curLocation = new LttngLocation();
final TmfContext context = seekEvent(curLocation.getOperationTime());
- context.setRank(ITmfContext.INITIAL_RANK);
+ context.setRank(0);
return context;
} else
curLocation = (LttngLocation) location;
package org.eclipse.linuxtools.internal.lttng.stubs;
-import java.io.IOException;
-
import org.eclipse.linuxtools.internal.lttng.core.event.LttngEvent;
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
import org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser;
* @see org.eclipse.linuxtools.tmf.core.parser.ITmfEventParser#parseNextEvent(org.eclipse.linuxtools.tmf.core.trace.ITmfTrace, org.eclipse.linuxtools.tmf.core.trace.TmfContext)
*/
@Override
- public ITmfEvent parseEvent(ITmfContext context) {
+ public LttngEvent parseEvent(ITmfContext context) {
// TODO Auto-generated method stub
return null;
}
import java.io.IOException;
import java.io.RandomAccessFile;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.linuxtools.internal.lttng.core.event.LttngEvent;
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
import org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser;
* @see org.eclipse.linuxtools.tmf.trace.ITmfTrace#parseEvent()
*/
@Override
- public ITmfEvent parseEvent(final ITmfContext context) {
+ public LttngEvent parseEvent(final ITmfContext context) {
// try {
// paserNextEvent updates the context
final LttngEvent event = (LttngEvent) fParser.parseEvent(context);
return "[LTTngTraceStub]";
}
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#validate(org.eclipse.core.resources.IProject, java.lang.String)
+ */
+ @Override
+ public boolean validate(IProject project, String path) {
+ return fileExists(path);
+ }
+
// // ========================================================================
// // Helper functions
// // ========================================================================
import java.io.RandomAccessFile;
import java.util.Vector;
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
* TODO: Implement me. Please.
*/
@SuppressWarnings("nls")
-public class TmfEventParserStub implements ITmfEventParser<ITmfEvent> {
+public class TmfEventParserStub implements ITmfEventParser<TmfEvent> {
// ------------------------------------------------------------------------
// Attributes
static final String typePrefix = "Type-";
@Override
@SuppressWarnings("unchecked")
- public ITmfEvent parseEvent(final ITmfContext context) {
+ public TmfEvent parseEvent(final ITmfContext context) {
if (! (fEventStream instanceof TmfTraceStub))
return null;
content.append("]");
final TmfEventField root = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, content.toString());
- final ITmfEvent event = new TmfEvent(fEventStream,
+ final TmfEvent event = new TmfEvent(fEventStream,
new TmfTimestamp(ts, -3, 0), // millisecs
source, fTypes[typeIndex], root, reference.toString());
return event;
import java.io.RandomAccessFile;
import java.util.concurrent.locks.ReentrantLock;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
* @param parser
* @throws FileNotFoundException
*/
- @SuppressWarnings("unchecked")
public TmfTraceStub(final String path, final int cacheSize, final boolean waitForCompletion,
final ITmfEventParser<TmfEvent> parser, final ITmfTraceIndexer<?> indexer) throws TmfTraceException {
super(null, TmfEvent.class, path, cacheSize, 0, indexer);
} catch (FileNotFoundException e) {
throw new TmfTraceException(e.getMessage());
}
- fParser = (ITmfEventParser<ITmfEvent>) ((parser != null) ? parser : new TmfEventParserStub(this));
+ fParser = (parser != null) ? parser : new TmfEventParserStub(this);
}
/**
}
@Override
- @SuppressWarnings("rawtypes")
- public double getLocationRatio(final ITmfLocation location) {
+ public double getLocationRatio(ITmfLocation<?> location) {
fLock.lock();
try {
if (fTrace != null)
}
@Override
- public ITmfEvent parseEvent(final ITmfContext context) {
+ public TmfEvent parseEvent(final ITmfContext context) {
fLock.lock();
try {
// parseNextEvent will update the context
if (fTrace != null) {
- final ITmfEvent event = fParser.parseEvent(context.clone());
+ final TmfEvent event = fParser.parseEvent(context.clone());
return event;
}
// }
super.dispose();
}
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#validate(org.eclipse.core.resources.IProject, java.lang.String)
+ */
+ @Override
+ public boolean validate(IProject project, String path) {
+ return fileExists(path);
+ }
+
}
\ No newline at end of file
// Constants
// ------------------------------------------------------------------------
- /**
- * The initial context event rank, before anything is read from the trace
- */
- public long INITIAL_RANK = -1L;
-
/**
* The unknown event rank
*/
- public long UNKNOWN_RANK = -2L;
+ public long UNKNOWN_RANK = -1L;
// ------------------------------------------------------------------------
// Getters
* @param context
* @return
*/
- public ITmfEvent parseEvent(ITmfContext context);
+ public T parseEvent(ITmfContext context);
}
import java.io.File;
import java.io.FileNotFoundException;
-import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.Path;
import org.eclipse.linuxtools.tmf.core.component.TmfEventProvider;
/**
* The trace parser
*/
- protected ITmfEventParser<ITmfEvent> fParser;
+ protected ITmfEventParser<T> fParser;
// ------------------------------------------------------------------------
// Construction
* @param type the trace event type
* @param path the trace path
* @param cacheSize the trace cache size
- * @throws FileNotFoundException
+ * @throws TmfTraceException
*/
protected TmfTrace(final IResource resource, final Class<T> type, final String path, final int cacheSize) throws TmfTraceException {
this(resource, type, path, cacheSize, 0, null);
* @param path the trace path
* @param cacheSize the trace cache size
* @param interval the trace streaming interval
- * @throws FileNotFoundException
+ * @throws TmfTraceException
*/
protected TmfTrace(final IResource resource, final Class<T> type, final String path, final int cacheSize, final long interval) throws TmfTraceException {
this(resource, type, path, cacheSize, interval, null);
* @param path the trace path
* @param cacheSize the trace cache size
* @param indexer the trace indexer
- * @throws FileNotFoundException
+ * @throws TmfTraceException
*/
protected TmfTrace(final IResource resource, final Class<T> type, final String path, final int cacheSize,
final long interval, final ITmfTraceIndexer<?> indexer) throws TmfTraceException {
* @param cacheSize the trace cache size
* @param indexer the trace indexer
* @param parser the trace event parser
- * @throws FileNotFoundException
+ * @throws TmfTraceException
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
protected TmfTrace(final IResource resource, final Class<T> type, final String path, final int cacheSize,
- final long interval, final ITmfTraceIndexer<?> indexer, final ITmfEventParser<ITmfEvent> parser) throws TmfTraceException {
+ final long interval, final ITmfTraceIndexer<?> indexer, final ITmfEventParser<T> parser) throws TmfTraceException {
super();
fCacheSize = (cacheSize > 0) ? cacheSize : DEFAULT_TRACE_CACHE_SIZE;
fStreamingInterval = interval;
*
* @throws FileNotFoundException
*/
+ @SuppressWarnings("unchecked")
protected void initialize(final IResource resource, final String path, final Class<T> type) throws TmfTraceException {
if (path == null)
throw new TmfTraceException("Invalid trace path"); //$NON-NLS-1$
final int sep = path.lastIndexOf(Path.SEPARATOR);
traceName = (sep >= 0) ? path.substring(sep + 1) : path;
}
- if (fParser == null && !(this instanceof ITmfEventParser))
- throw new TmfTraceException("Invalid trace parser"); //$NON-NLS-1$
+ if (fParser == null) {
+ if (this instanceof ITmfEventParser) {
+ fParser = (ITmfEventParser<T>) this;
+ } else {
+ throw new TmfTraceException("Invalid trace parser"); //$NON-NLS-1$
+ }
+ }
super.init(traceName, type);
}
- /* (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#validate(org.eclipse.core.resources.IProject, java.lang.String)
+ /**
+ * Indicates if the path points to an existing file/directory
*
- * Default validation: make sure the trace file exists.
+ * @param path the path to test
+ * @return true if the file/directory exists
*/
- @Override
- public boolean validate(final IProject project, final String path) {
+ protected boolean fileExists(final String path) {
final File file = new File(path);
return file.exists();
}
public synchronized ITmfContext seekEvent(final long rank) {
// A rank <= 0 indicates to seek the first event
- if (rank <= 0)
- return seekEvent((ITmfLocation<?>) null);
+ if (rank <= 0) {
+ ITmfContext context = seekEvent((ITmfLocation<?>) null);
+ context.setRank(0);
+ return context;
+ }
// Position the trace at the checkpoint
final ITmfContext context = fIndexer.seekIndex(rank);
public synchronized ITmfContext seekEvent(final ITmfTimestamp timestamp) {
// A null timestamp indicates to seek the first event
- if (timestamp == null)
- return seekEvent(0);
+ if (timestamp == null) {
+ ITmfContext context = seekEvent((ITmfLocation<?>) null);
+ context.setRank(0);
+ return context;
+ }
// Position the trace at the checkpoint
final ITmfContext context = fIndexer.seekIndex(timestamp);
import java.util.Map.Entry;\r
import java.util.regex.Matcher;\r
\r
+import org.eclipse.core.resources.IProject;\r
import org.eclipse.core.resources.IResource;\r
import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefinition.InputLine;\r
import org.eclipse.linuxtools.tmf.core.event.TmfEvent;\r
\r
@Override\r
public TmfContext seekEvent(final ITmfLocation<?> location) {\r
- final CustomTxtTraceContext context = new CustomTxtTraceContext(NULL_LOCATION, ITmfContext.INITIAL_RANK);\r
+ final CustomTxtTraceContext context = new CustomTxtTraceContext(NULL_LOCATION, ITmfContext.UNKNOWN_RANK);\r
if (NULL_LOCATION.equals(location) || !new File(getPath()).isFile())\r
return context;\r
BufferedRandomAccessFile raFile = null;\r
return context;\r
} catch (final FileNotFoundException e) {\r
e.printStackTrace();\r
- return new CustomTxtTraceContext(NULL_LOCATION, ITmfContext.INITIAL_RANK);\r
+ return new CustomTxtTraceContext(NULL_LOCATION, ITmfContext.UNKNOWN_RANK);\r
} catch (final IOException e) {\r
e.printStackTrace();\r
- return new CustomTxtTraceContext(NULL_LOCATION, ITmfContext.INITIAL_RANK);\r
+ return new CustomTxtTraceContext(NULL_LOCATION, ITmfContext.UNKNOWN_RANK);\r
} finally {\r
if (raFile != null) {\r
try {\r
}\r
\r
@Override\r
- public TmfEvent parseEvent(final ITmfContext tmfContext) {\r
+ public CustomTxtEvent parseEvent(final ITmfContext tmfContext) {\r
if (!(tmfContext instanceof CustomTxtTraceContext))\r
return null;\r
\r
public CustomTraceDefinition getDefinition() {\r
return fDefinition;\r
}\r
+\r
+ /* (non-Javadoc)\r
+ * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#validate(org.eclipse.core.resources.IProject, java.lang.String)\r
+ */\r
+ @Override\r
+ public boolean validate(IProject project, String path) {\r
+ return fileExists(path);\r
+ }\r
}\r
import javax.xml.parsers.DocumentBuilderFactory;\r
import javax.xml.parsers.ParserConfigurationException;\r
\r
+import org.eclipse.core.resources.IProject;\r
import org.eclipse.core.resources.IResource;\r
import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition.InputAttribute;\r
import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition.InputElement;\r
\r
@Override\r
public TmfContext seekEvent(final ITmfLocation<?> location) {\r
- final CustomXmlTraceContext context = new CustomXmlTraceContext(NULL_LOCATION, ITmfContext.INITIAL_RANK);\r
+ final CustomXmlTraceContext context = new CustomXmlTraceContext(NULL_LOCATION, ITmfContext.UNKNOWN_RANK);\r
if (NULL_LOCATION.equals(location) || !new File(getPath()).isFile())\r
return context;\r
try {\r
return context;\r
} catch (final FileNotFoundException e) {\r
e.printStackTrace();\r
- return new CustomXmlTraceContext(NULL_LOCATION, ITmfContext.INITIAL_RANK);\r
+ return new CustomXmlTraceContext(NULL_LOCATION, ITmfContext.UNKNOWN_RANK);\r
} catch (final IOException e) {\r
e.printStackTrace();\r
- return new CustomXmlTraceContext(NULL_LOCATION, ITmfContext.INITIAL_RANK);\r
+ return new CustomXmlTraceContext(NULL_LOCATION, ITmfContext.UNKNOWN_RANK);\r
} finally {\r
if (raFile != null) {\r
try {\r
}\r
\r
@Override\r
- public TmfEvent parseEvent(final ITmfContext tmfContext) {\r
+ public CustomXmlEvent parseEvent(final ITmfContext tmfContext) {\r
if (!(tmfContext instanceof CustomXmlTraceContext))\r
return null;\r
\r
readElement(buffer, raFile);\r
} else if (c == '/' && numRead == 1) {\r
break; // found "</"\r
- } else if (c == '-' && numRead == 3 && buffer.substring(buffer.length() - 3, buffer.length() - 1).equals("!-")) {\r
+ } else if (c == '-' && numRead == 3 && buffer.substring(buffer.length() - 3, buffer.length() - 1).equals("!-")) { //$NON-NLS-1$\r
readComment(buffer, raFile); // found "<!--"\r
} else if (i == '>')\r
if (buffer.charAt(buffer.length() - 2) == '/') {\r
numRead++;\r
final char c = (char)i;\r
buffer.append(c);\r
- if (c == '>' && numRead >= 2 && buffer.substring(buffer.length() - 3, buffer.length() - 1).equals("--"))\r
+ if (c == '>' && numRead >= 2 && buffer.substring(buffer.length() - 3, buffer.length() - 1).equals("--")) //$NON-NLS-1$\r
{\r
break; // found "-->"\r
}\r
public CustomTraceDefinition getDefinition() {\r
return fDefinition;\r
}\r
+\r
+ /* (non-Javadoc)\r
+ * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#validate(org.eclipse.core.resources.IProject, java.lang.String)\r
+ */\r
+ @Override\r
+ public boolean validate(IProject project, String path) {\r
+ return fileExists(path);\r
+ }\r
}\r