tmf: change ITmfTraceProperties to a more generic ITmfPropertiesProvider
[deliverable/tracecompass.git] / ctf / org.eclipse.tracecompass.tmf.ctf.core / src / org / eclipse / tracecompass / tmf / ctf / core / trace / CtfTmfTrace.java
index 5328b5b293424fdfaced06611f015c7f39b0b2b6..6ad176f06b1c56d217a3c4916a21a15d8cd1c6d0 100644 (file)
@@ -47,11 +47,11 @@ import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
 import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
 import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
 import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
+import org.eclipse.tracecompass.tmf.core.project.model.ITmfPropertiesProvider;
 import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
 import org.eclipse.tracecompass.tmf.core.timestamp.TmfNanoTimestamp;
 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
-import org.eclipse.tracecompass.tmf.core.trace.ITmfTraceProperties;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTraceWithPreDefinedEvents;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTrace;
 import org.eclipse.tracecompass.tmf.core.trace.TraceValidationStatus;
@@ -66,6 +66,7 @@ import org.eclipse.tracecompass.tmf.ctf.core.context.CtfLocation;
 import org.eclipse.tracecompass.tmf.ctf.core.context.CtfLocationInfo;
 import org.eclipse.tracecompass.tmf.ctf.core.context.CtfTmfContext;
 import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
+import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEventFactory;
 import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEventType;
 import org.eclipse.tracecompass.tmf.ctf.core.event.aspect.CtfChannelAspect;
 import org.eclipse.tracecompass.tmf.ctf.core.event.aspect.CtfCpuAspect;
@@ -80,13 +81,19 @@ import com.google.common.collect.ImmutableSet;
  * @author Matthew khouzam
  */
 public class CtfTmfTrace extends TmfTrace
-        implements ITmfTraceProperties, ITmfPersistentlyIndexable,
+        implements ITmfPropertiesProvider, ITmfPersistentlyIndexable,
         ITmfTraceWithPreDefinedEvents {
 
     // -------------------------------------------
     // Constants
     // -------------------------------------------
 
+    /**
+     * Clock offset property
+     * @since 2.0
+     */
+    public static final String CLOCK_OFFSET = "clock_offset"; //$NON-NLS-1$
+
     /**
      * Default cache size for CTF traces
      */
@@ -96,7 +103,7 @@ public class CtfTmfTrace extends TmfTrace
      * Event aspects available for all CTF traces
      * @since 1.0
      */
-    protected static final @NonNull Collection<ITmfEventAspect> CTF_ASPECTS =
+    protected static final @NonNull Collection<@NonNull ITmfEventAspect> CTF_ASPECTS =
             checkNotNull(ImmutableList.of(
                     ITmfEventAspect.BaseAspects.TIMESTAMP,
                     new CtfChannelAspect(),
@@ -116,15 +123,42 @@ public class CtfTmfTrace extends TmfTrace
     // Fields
     // -------------------------------------------
 
-    private final Map<String, CtfTmfEventType> fContainedEventTypes =
-            Collections.synchronizedMap(new HashMap<String, CtfTmfEventType>());
+    private final Map<@NonNull String, @NonNull CtfTmfEventType> fContainedEventTypes =
+            Collections.synchronizedMap(new HashMap<>());
 
-    private final CtfIteratorManager fIteratorManager =
-            new CtfIteratorManager(this);
+    private final CtfIteratorManager fIteratorManager = new CtfIteratorManager(this);
 
-    /* Reference to the CTF Trace */
+    private final @NonNull CtfTmfEventFactory fEventFactory;
+
+    /** Reference to the CTF Trace */
     private CTFTrace fTrace;
 
+    // -------------------------------------------
+    // Constructor
+    // -------------------------------------------
+
+    /**
+     * Default constructor
+     */
+    public CtfTmfTrace() {
+        super();
+
+        /* Use default event factory */
+        fEventFactory = CtfTmfEventFactory.instance();
+    }
+
+    /**
+     * Constructor for sub-classes to specify their own event factory.
+     *
+     * @param eventFactory
+     *            The event factory to use to generate trace events
+     * @since 2.0
+     */
+    protected CtfTmfTrace(@NonNull CtfTmfEventFactory eventFactory) {
+        super();
+        fEventFactory = eventFactory;
+    }
+
     // -------------------------------------------
     // TmfTrace Overrides
     // -------------------------------------------
@@ -185,7 +219,7 @@ public class CtfTmfTrace extends TmfTrace
                                     null,
                                     content.toArray(new ITmfEventField[content.size()]));
 
-                            ctfTmfEventType = new CtfTmfEventType(ied.getName(), contentTree);
+                            ctfTmfEventType = new CtfTmfEventType(checkNotNull(ied.getName()), contentTree);
                             fContainedEventTypes.put(ctfTmfEventType.getName(), ctfTmfEventType);
                         }
                     }
@@ -397,13 +431,17 @@ public class CtfTmfTrace extends TmfTrace
     }
 
     // -------------------------------------------
-    // ITmfTraceProperties
+    // ITmfPropertiesProvider
     // -------------------------------------------
 
+    /**
+     * @since 2.0
+     */
     @Override
-    public Map<String, String> getTraceProperties() {
+    public Map<String, String> getProperties() {
         Map<String, String> properties = new HashMap<>();
         properties.putAll(fTrace.getEnvironment());
+        properties.put(CLOCK_OFFSET, Long.toUnsignedString(fTrace.getOffset()));
         properties.put(Messages.CtfTmfTrace_HostID, getHostId());
         return properties;
     }
@@ -452,7 +490,7 @@ public class CtfTmfTrace extends TmfTrace
      * Gets the list of declared events
      */
     @Override
-    public Set<CtfTmfEventType> getContainedEventTypes() {
+    public Set<@NonNull CtfTmfEventType> getContainedEventTypes() {
         return ImmutableSet.copyOf(fContainedEventTypes.values());
     }
 
@@ -495,6 +533,16 @@ public class CtfTmfTrace extends TmfTrace
     // CtfIterator factory methods
     // -------------------------------------------
 
+    /**
+     * Get the event factory for this trace to generate new events for it.
+     *
+     * @return The event factory
+     * @since 2.0
+     */
+    public @NonNull CtfTmfEventFactory getEventFactory() {
+        return fEventFactory;
+    }
+
     /**
      * Get an iterator to the trace
      *
This page took 0.033364 seconds and 5 git commands to generate.