Merge branch 'master' into lttng-luna
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / ctfadaptor / CtfTmfTrace.java
index 27acd6ae7768fc3f9a37c0d3e7d6068af79ef5f3..700b0a9d7d228c807e0bbe948349375249192527 100644 (file)
 /*******************************************************************************
- * Copyright (c) 2012 Ericsson
+ * Copyright (c) 2012, 2013 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License v1.0 which
  * accompanies this distribution, and is available at
  * http://www.eclipse.org/legal/epl-v10.html
  *
- * Contributors: Matthew Khouzam - Initial API and implementation
+ * Contributors:
+ *   Matthew Khouzam - Initial API and implementation
+ *   Patrick Tasse - Updated for removal of context clone
  *******************************************************************************/
 
 package org.eclipse.linuxtools.tmf.core.ctfadaptor;
 
+import java.util.Collections;
+import java.util.Map;
+
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.linuxtools.ctf.core.event.EventDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration;
 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
 import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
-import org.eclipse.linuxtools.tmf.core.component.TmfEventProvider;
-import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
-import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
-import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
-import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
+import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader;
+import org.eclipse.linuxtools.internal.tmf.core.Activator;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
-import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
-import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest;
-import org.eclipse.linuxtools.tmf.core.signal.TmfSignal;
-import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager;
-import org.eclipse.linuxtools.tmf.core.statesystem.IStateSystemQuerier;
+import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
-import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTraceProperties;
+import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
 
 /**
+ * The CTf trace handler
+ *
+ * @version 1.0
+ * @author Matthew khouzam
  */
-public class CtfTmfTrace extends TmfEventProvider<CtfTmfEvent> implements ITmfTrace<CtfTmfEvent> {
+public class CtfTmfTrace extends TmfTrace
+        implements ITmfEventParser, ITmfTraceProperties {
 
-    // ------------------------------------------------------------------------
+    // -------------------------------------------
     // Constants
-    // ------------------------------------------------------------------------
+    // -------------------------------------------
+    /**
+     * Default cache size for CTF traces
+     */
+    protected static final int DEFAULT_CACHE_SIZE = 50000;
 
-    // ------------------------------------------------------------------------
-    // Attributes
-    // ------------------------------------------------------------------------
+    // -------------------------------------------
+    // Fields
+    // -------------------------------------------
 
-    // the Ctf Trace
+    /* Reference to the CTF Trace */
     private CTFTrace fTrace;
 
-    // The number of events collected
-    protected long fNbEvents = 0;
-
-    // The time span of the event stream
-    private ITmfTimestamp fStartTime = TmfTimestamp.BIG_CRUNCH;
-    private ITmfTimestamp fEndTime = TmfTimestamp.BIG_BANG;
-
-    // The trace resource
-    private IResource fResource;
-
-    /* Reference to the state system assigned to this trace */
-    protected IStateSystemQuerier ss = null;
-
-    // ------------------------------------------------------------------------
-    // Constructors
-    // ------------------------------------------------------------------------
-
-    public CtfTmfTrace() {
-        super();
-    }
-
+    // -------------------------------------------
+    // TmfTrace Overrides
+    // -------------------------------------------
     /**
      * Method initTrace.
-     * @param resource IResource
-     * @param path String
-     * @param eventType Class<CtfTmfEvent>
+     *
+     * @param resource
+     *            The resource associated with this trace
+     * @param path
+     *            The path to the trace file
+     * @param eventType
+     *            The type of events that will be read from this trace
      * @throws TmfTraceException
-     * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#initTrace(IResource, String, Class<CtfTmfEvent>)
+     *             If something when wrong while reading the trace
      */
     @Override
-    public void initTrace(final IResource resource, final String path, final Class<CtfTmfEvent> eventType)
+    public void initTrace(final IResource resource, final String path, final Class<? extends ITmfEvent> eventType)
             throws TmfTraceException {
-        this.fResource = resource;
+        /*
+         * Set the cache size. This has to be done before the call to super()
+         * because the super needs to know the cache size.
+         */
+        setCacheSize();
+
+        super.initTrace(resource, path, eventType);
+
+        @SuppressWarnings("unused")
+        CtfTmfEventType type;
+
         try {
             this.fTrace = new CTFTrace(path);
-            for( int i =0 ; i< this.fTrace.getNbEventTypes(); i++) {
-                EventDeclaration ed = this.fTrace.getEventType(i);
-                ITmfEventField eventField = parseDeclaration(ed);
-                new CtfTmfEventType(ed.getName(), eventField);
+            CtfIteratorManager.addTrace(this);
+            CtfTmfContext ctx;
+            /* Set the start and (current) end times for this trace */
+            ctx = (CtfTmfContext) seekEvent(0L);
+            CtfTmfEvent event = getNext(ctx);
+            if ((ctx.getLocation().equals(CtfIterator.NULL_LOCATION)) || (ctx.getCurrentEvent() == null)) {
+                /* Handle the case where the trace is empty */
+                this.setStartTime(TmfTimestamp.BIG_BANG);
+            } else {
+                final ITmfTimestamp curTime = event.getTimestamp();
+                this.setStartTime(curTime);
+                this.setEndTime(curTime);
             }
+
         } catch (final CTFReaderException e) {
             /*
              * If it failed at the init(), we can assume it's because the file
              * was not found or was not recognized as a CTF trace. Throw into
              * the new type of exception expected by the rest of TMF.
              */
-            throw new TmfTraceException(e.getMessage());
+            throw new TmfTraceException(e.getMessage(), e);
         }
-        CtfIterator iterator = new CtfIterator(this, 0, 0);
-        setStartTime(TmfTimestamp.BIG_BANG);
-        if( !iterator.getLocation().equals(CtfIterator.NULL_LOCATION)) {
-            setStartTime(iterator.getCurrentEvent().getTimestamp());
-        }
-        TmfSignalManager.register(this);
-        // FIXME this should become a request
-        buildStateSystem();
-
-        /* Refresh the project, so it can pick up new files that got created. */
-        if ( resource != null) {
-            try {
-                resource.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
-            } catch (CoreException e) {
-                throw new TmfTraceException(e.getMessage());
-            }
-        }
-    }
-
-    private static ITmfEventField parseDeclaration(EventDeclaration ed) {
-        EventDefinition eventDef = ed.createDefinition(null);
-        return new CtfTmfContent(ITmfEventField.ROOT_FIELD_ID,
-                CtfTmfEvent.parseFields(eventDef));
     }
 
-    /**
-     * Method dispose.
-     * @see org.eclipse.linuxtools.tmf.core.component.ITmfComponent#dispose()
-     */
     @Override
-    public void dispose() {
-        TmfSignalManager.deregister(this);
-    }
-
-    /**
-     * Method broadcast.
-     * @param signal TmfSignal
-     * @see org.eclipse.linuxtools.tmf.core.component.ITmfComponent#broadcast(TmfSignal)
-     */
-    @Override
-    public void broadcast(final TmfSignal signal) {
-        TmfSignalManager.dispatchSignal(signal);
+    public synchronized void dispose() {
+        CtfIteratorManager.removeTrace(this);
+        if (fTrace != null) {
+            fTrace.dispose();
+            fTrace = null;
+        }
+        super.dispose();
     }
 
     /**
      * Method validate.
-     * @param project IProject
-     * @param path String
-     * @return boolean
+     *
+     * @param project
+     *            IProject
+     * @param path
+     *            String
+     * @return IStatus IStatus.error or Status.OK_STATUS
      * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#validate(IProject, String)
+     * @since 2.0
      */
     @Override
-    public boolean validate(final IProject project, final String path) {
+    public IStatus validate(final IProject project, final String path) {
+        IStatus validTrace = Status.OK_STATUS;
         try {
             final CTFTrace temp = new CTFTrace(path);
-            return temp.majortIsSet(); // random test
+            if (!temp.majortIsSet()) {
+                validTrace = new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CtfTmfTrace_MajorNotSet);
+            } else {
+                CTFTraceReader ctfTraceReader = new CTFTraceReader(temp);
+                if (!ctfTraceReader.hasMoreEvents()) {
+                    // TODO: This will need an additional check when we support live traces
+                    // because having no event is valid for a live trace
+                    validTrace = new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CtfTmfTrace_NoEvent);
+                }
+                ctfTraceReader.dispose();
+            }
+            temp.dispose();
         } catch (final CTFReaderException e) {
-            /* Nope, not a CTF trace we can read */
-            return false;
+            validTrace = new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CtfTmfTrace_ReadingError +": " + e.toString()); //$NON-NLS-1$
         }
+        return validTrace;
     }
 
-    // ------------------------------------------------------------------------
-    // Accessors
-    // ------------------------------------------------------------------------
-
     /**
-     * Method getEventType.
-     * @return the trace path
-     * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getEventType()
+     * Method getCurrentLocation. This is not applicable in CTF
+     *
+     * @return null, since the trace has no knowledge of the current location
+     * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getCurrentLocation()
      */
     @Override
-    public Class<CtfTmfEvent> getEventType() {
-        return fType;
-    }
-
-    /**
-     * Method getNbEnvVars.
-     * @return int
-     */
-    public int getNbEnvVars() {
-        return this.fTrace.getEnvironment().size();
-    }
-
-
-    /**
-     * Method getEnvNames.
-     * @return String[]
-     */
-    public String[] getEnvNames() {
-        final String[] s = new String[getNbEnvVars()];
-        return this.fTrace.getEnvironment().keySet().toArray(s);
-    }
-
-    /**
-     * Method getEnvValue.
-     * @param key String
-     * @return String
-     */
-    public String getEnvValue(final String key)    {
-        return this.fTrace.getEnvironment().get(key);
+    public ITmfLocation getCurrentLocation() {
+        return null;
     }
 
-
-    /**
-
-     * @return the trace path * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getPath()
-     */
     @Override
-    public String getPath() {
-        return this.fTrace.getPath();
+    public double getLocationRatio(ITmfLocation location) {
+        final CtfLocation curLocation = (CtfLocation) location;
+        final CtfTmfContext context = new CtfTmfContext(this);
+        context.setLocation(curLocation);
+        context.seek(curLocation.getLocationInfo());
+        final CtfLocationInfo currentTime = ((CtfLocationInfo) context.getLocation().getLocationInfo());
+        final long startTime = getIterator(this, context).getStartTime();
+        final long endTime = getIterator(this, context).getEndTime();
+        return ((double) currentTime.getTimestamp() - startTime)
+                / (endTime - startTime);
     }
 
     /**
-     * Method getName.
-     * @return String
-     * @see org.eclipse.linuxtools.tmf.core.component.ITmfComponent#getName()
+     * Method seekEvent.
+     *
+     * @param location
+     *            ITmfLocation<?>
+     * @return ITmfContext
      */
     @Override
-    public String getName() {
-        String traceName = (fResource != null) ? fResource.getName() : null;
-        // If no resource was provided, extract the display name the trace path
-        if (traceName == null) {
-            final String path = this.fTrace.getPath();
-            final int sep = path.lastIndexOf(IPath.SEPARATOR);
-            traceName = (sep >= 0) ? path.substring(sep + 1) : path;
+    public synchronized ITmfContext seekEvent(final ITmfLocation location) {
+        CtfLocation currentLocation = (CtfLocation) location;
+        CtfTmfContext context = new CtfTmfContext(this);
+        if (fTrace == null) {
+            context.setLocation(null);
+            context.setRank(ITmfContext.UNKNOWN_RANK);
+            return context;
         }
-        return traceName;
-    }
-
-    /**
-     * Method getCacheSize.
-     * @return int
-     * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getCacheSize()
-     */
-    @Override
-    public int getCacheSize() {
-        return 50000; // not true, but it works
-    }
-
-    /**
-     * Method getNbEvents.
-     * @return long
-     * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getNbEvents()
-     */
-    @Override
-    public long getNbEvents() {
-        return this.fNbEvents;
-    }
-
-    /**
-     * Method getTimeRange.
-     * @return TmfTimeRange
-     * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getTimeRange()
-     */
-    @Override
-    public TmfTimeRange getTimeRange() {
-        return new TmfTimeRange(this.fStartTime, this.fEndTime);
-    }
-
-    /**
-     * Method getStartTime.
-     * @return ITmfTimestamp
-     * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getStartTime()
-     */
-    @Override
-    public ITmfTimestamp getStartTime() {
-        return this.fStartTime;
+        /*
+         * The rank is set to 0 if the iterator seeks the beginning. If not, it
+         * will be set to UNKNOWN_RANK, since CTF traces don't support seeking
+         * by rank for now.
+         */
+        if (currentLocation == null) {
+            currentLocation = new CtfLocation(new CtfLocationInfo(0L, 0L));
+            context.setRank(0);
+        }
+        if (currentLocation.getLocationInfo() == CtfLocation.INVALID_LOCATION) {
+            currentLocation = new CtfLocation(getEndTime().getValue() + 1, 0L);
+        }
+        context.setLocation(currentLocation);
+        if (location == null) {
+            CtfTmfEvent event = getIterator(this, context).getCurrentEvent();
+            if (event != null) {
+                currentLocation = new CtfLocation(event.getTimestamp().getValue(), 0);
+            }
+        }
+        if (context.getRank() != 0) {
+            context.setRank(ITmfContext.UNKNOWN_RANK);
+        }
+        return context;
     }
 
-    /**
-     * Method getEndTime.
-     * @return ITmfTimestamp
-     * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getEndTime()
-     */
     @Override
-    public ITmfTimestamp getEndTime() {
-        return this.fEndTime;
+    public synchronized ITmfContext seekEvent(double ratio) {
+        CtfTmfContext context = new CtfTmfContext(this);
+        if (fTrace == null) {
+            context.setLocation(null);
+            context.setRank(ITmfContext.UNKNOWN_RANK);
+            return context;
+        }
+        final long end = this.getEndTime().getValue();
+        final long start = this.getStartTime().getValue();
+        final long diff = end - start;
+        final long ratioTs = Math.round(diff * ratio) + start;
+        context.seek(ratioTs);
+        context.setRank(ITmfContext.UNKNOWN_RANK);
+        return context;
     }
 
     /**
-     * Method getCurrentLocation. This is not applicable in CTF
-     * @return null, since the trace has no knowledge of the current location
-     * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getCurrentLocation()
+     * Method readNextEvent.
+     *
+     * @param context
+     *            ITmfContext
+     * @return CtfTmfEvent
+     * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getNext(ITmfContext)
      */
     @Override
-    public ITmfLocation<?> getCurrentLocation() {
-        return null;
-    }
-
-    // ------------------------------------------------------------------------
-    // Operators
-    // ------------------------------------------------------------------------
+    public synchronized CtfTmfEvent getNext(final ITmfContext context) {
+        if (fTrace == null) {
+            return null;
+        }
+        CtfTmfEvent event = null;
+        if (context instanceof CtfTmfContext) {
+            if (context.getLocation() == null || CtfLocation.INVALID_LOCATION.equals(context.getLocation().getLocationInfo())) {
+                return null;
+            }
+            CtfTmfContext ctfContext = (CtfTmfContext) context;
+            event = ctfContext.getCurrentEvent();
 
-    /**
-     * Method setTimeRange.
-     * @param range TmfTimeRange
-     */
-    protected void setTimeRange(final TmfTimeRange range) {
-        this.fStartTime = range.getStartTime();
-        this.fEndTime = range.getEndTime();
-    }
+            if (event != null) {
+                updateAttributes(context, event.getTimestamp());
+                ctfContext.advance();
+                ctfContext.increaseRank();
+            }
+        }
 
-    /**
-     * Method setStartTime.
-     * @param startTime ITmfTimestamp
-     */
-    protected void setStartTime(final ITmfTimestamp startTime) {
-        this.fStartTime = startTime;
+        return event;
     }
 
     /**
-     * Method setEndTime.
-     * @param endTime ITmfTimestamp
+     * gets the CTFtrace that this is wrapping
+     *
+     * @return the CTF trace
      */
-    protected void setEndTime(final ITmfTimestamp endTime) {
-        this.fEndTime = endTime;
+    public CTFTrace getCTFTrace() {
+        return fTrace;
     }
 
-    // ------------------------------------------------------------------------
-    // TmfProvider
-    // ------------------------------------------------------------------------
+    // -------------------------------------------
+    // ITmfTraceProperties
+    // -------------------------------------------
 
     /**
-     * Method armRequest.
-     * @param request ITmfDataRequest<CtfTmfEvent>
-     * @return ITmfContext
+     * @since 2.0
      */
     @Override
-    public ITmfContext armRequest(final ITmfDataRequest<CtfTmfEvent> request) {
-        if ((request instanceof ITmfEventRequest<?>)
-                && !TmfTimestamp.BIG_BANG
-                .equals(((ITmfEventRequest<CtfTmfEvent>) request)
-                        .getRange().getStartTime())
-                        && (request.getIndex() == 0)) {
-            final ITmfContext context = seekEvent(((ITmfEventRequest<CtfTmfEvent>) request)
-                    .getRange().getStartTime());
-            ((ITmfEventRequest<CtfTmfEvent>) request)
-            .setStartIndex((int) context.getRank());
-            return context;
-        }
-        return seekEvent(request.getIndex());
+    public Map<String, String> getTraceProperties() {
+        return Collections.unmodifiableMap(fTrace.getEnvironment());
     }
 
-//    /**
-//     * The trace reader keeps its own iterator: the "context" parameter here
-//     * will be ignored.
-//     *
-//     * If you wish to specify a new context, instantiate a new CtfIterator and
-//     * seek() it to where you want, and use that to read events.
-//     *
-//     * FIXME merge with getNextEvent below once they both use the same parameter
-//     * type.
-//     * @param context ITmfContext
-//     * @return CtfTmfEvent
-//     */
-//    @Override
-//    public CtfTmfEvent getNext(final ITmfContext context) {
-//        return readNextEvent(context);
-//    }
-
-    // ------------------------------------------------------------------------
-    // ITmfTrace
-    // ------------------------------------------------------------------------
+    // -------------------------------------------
+    // Clocks
+    // -------------------------------------------
 
     /**
-     * Method seekEvent.
-     * @param location ITmfLocation<?>
-     * @return ITmfContext
-     * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#seekEvent(ITmfLocation<?>)
+     * gets the clock offset
+     *
+     * @return the clock offset in ns
      */
-    @Override
-    public ITmfContext seekEvent(final ITmfLocation<?> location) {
-        CtfLocation currentLocation = (CtfLocation) location;
-        if (currentLocation == null) {
-            currentLocation = new CtfLocation(0L);
+    public long getOffset() {
+        if (fTrace != null) {
+            return fTrace.getOffset();
         }
-        CtfIterator context = new CtfIterator(this);
-        context.setLocation(currentLocation);
-        context.setRank(ITmfContext.UNKNOWN_RANK);
-        return context;
-    }
-
-    /**
-     * Method getLocationRatio.
-     * @param location ITmfLocation<?>
-     * @return double
-     * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getLocationRatio(ITmfLocation<?>)
-     */
-    @Override
-    public double getLocationRatio(final ITmfLocation<?> location) {
-        final CtfLocation curLocation = (CtfLocation) location;
-        CtfIterator iterator = new CtfIterator(this);
-        iterator.seek(curLocation.getLocation());
-        return ((double) iterator.getCurrentEvent().getTimestampValue() - iterator
-                .getStartTime())
-                / (iterator.getEndTime() - iterator.getStartTime());
-    }
-
-    /**
-     * Method getStreamingInterval.
-     * @return long
-     * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getStreamingInterval()
-     */
-    @Override
-    public long getStreamingInterval() {
         return 0;
     }
 
     /**
-     * Method seekEvent.
-     * @param timestamp ITmfTimestamp
-     * @return ITmfContext
-     * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#seekEvent(ITmfTimestamp)
+     * Returns whether or not an event is in the metadata of the trace,
+     * therefore if it can possibly be in the trace. It does not verify whether
+     * or not the event is actually in the trace
+     *
+     * @param eventName
+     *            The name of the event to check
+     * @return Whether the event is in the metadata or not
+     * @since 2.1
      */
-    @Override
-    public ITmfContext seekEvent(final ITmfTimestamp timestamp) {
-        CtfIterator context = new CtfIterator(this);
-        context.seek(timestamp.getValue());
-        context.setRank(ITmfContext.UNKNOWN_RANK);
-        return context;
+    public boolean hasEvent(final String eventName) {
+        Map<Long, IEventDeclaration> events = fTrace.getEvents(0L);
+        if (events != null) {
+            for (IEventDeclaration decl : events.values()) {
+                if (decl.getName().equals(eventName)) {
+                    return true;
+                }
+            }
+        }
+        return false;
     }
 
     /**
-     * Seek by rank
-     * @param rank long
-     * @return ITmfContext
-     * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#seekEvent(long)
+     * Return whether all requested events are in the metadata
+     *
+     * @param names
+     *            The array of events to check for
+     * @return Whether all events are in the metadata
+     * @since 2.1
      */
-    @Override
-    public ITmfContext seekEvent(final long rank) {
-        CtfIterator context = new CtfIterator(this);
-        context.seekRank(rank);
-        context.setRank(rank);
-        return context;
+    public boolean hasAllEvents(String[] names) {
+        for (String name : names) {
+            if (!hasEvent(name)) {
+                return false;
+            }
+        }
+        return true;
     }
 
     /**
-     * Seek rank ratio
-     * @param ratio double
-     * @return ITmfContext
-     * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#seekEvent(double)
+     * Returns whether the metadata contains at least one of the requested
+     * events
+     *
+     * @param names
+     *            The array of event names of check for
+     * @return Whether one of the event is present in trace metadata
+     * @since 2.1
      */
-    @Override
-    public ITmfContext seekEvent(final double ratio) {
-        CtfIterator context = new CtfIterator(this);
-        context.seek((long) (this.fNbEvents * ratio));
-        context.setRank(ITmfContext.UNKNOWN_RANK);
-        return context;
+    public boolean hasAtLeastOneOfEvents(String[] names) {
+        for (String name : names) {
+            if (hasEvent(name)) {
+                return true;
+            }
+        }
+        return false;
     }
 
-    /**
-     * Method readNextEvent.
-     * @param context ITmfContext
-     * @return CtfTmfEvent
-     * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getNext(ITmfContext)
-     */
+    // -------------------------------------------
+    // Parser
+    // -------------------------------------------
+
     @Override
-    public CtfTmfEvent getNext(final ITmfContext context) {
+    public CtfTmfEvent parseEvent(ITmfContext context) {
         CtfTmfEvent event = null;
-        if (context instanceof CtfIterator) {
-            CtfIterator ctfIterator = (CtfIterator) context;
-            event = ctfIterator.getCurrentEvent();
-            ctfIterator.advance();
+        if (context instanceof CtfTmfContext) {
+            final ITmfContext tmpContext = seekEvent(context.getLocation());
+            event = getNext(tmpContext);
         }
         return event;
     }
 
     /**
-     * Method getResource.
-     * @return IResource
-     * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getResource()
+     * Sets the cache size for a CtfTmfTrace.
      */
-    @Override
-    public IResource getResource() {
-        return this.fResource;
+    protected void setCacheSize() {
+        setCacheSize(DEFAULT_CACHE_SIZE);
     }
 
-    /**
-     * Method getStateSystem.
-     * @return IStateSystemQuerier
-     */
-    public IStateSystemQuerier getStateSystem() {
-        return this.ss;
-    }
+    // -------------------------------------------
+    // Helpers
+    // -------------------------------------------
 
-    /**
-     * Method getCTFTrace.
-     * @return CTFTrace
-     */
-    CTFTrace getCTFTrace() {
-        return fTrace;
+    private static CtfIterator getIterator(CtfTmfTrace trace, CtfTmfContext context) {
+        return CtfIteratorManager.getIterator(trace, context);
     }
 
-
     /**
-     * Suppressing the warning, because the 'throws' will usually happen in
-     * sub-classes.
-     * @throws TmfTraceException
+     * Get an iterator to the trace
+     *
+     * @return an iterator to the trace
+     * @since 2.0
      */
-    protected void buildStateSystem() throws TmfTraceException {
-        /*
-         * Nothing is done in the basic implementation, please specify
-         * how/if to build a state system in derived classes.
-         */
-        return;
+    public CtfIterator createIterator() {
+        return new CtfIterator(this);
     }
-
 }
This page took 0.034513 seconds and 5 git commands to generate.