tmf: Do not define base aspects in the interface
[deliverable/tracecompass.git] / ctf / org.eclipse.tracecompass.tmf.ctf.core / src / org / eclipse / tracecompass / tmf / ctf / core / trace / CtfTmfTrace.java
index b3cd9261ccc963b5d80a620d929c8065142b0c19..52fb5e7b520dd2d214b06bfead0ba0c5f58300e2 100644 (file)
@@ -22,6 +22,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -45,13 +46,13 @@ import org.eclipse.tracecompass.internal.tmf.ctf.core.trace.iterator.CtfIterator
 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
 import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
 import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
+import org.eclipse.tracecompass.tmf.core.event.aspect.TmfBaseAspects;
 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;
@@ -81,13 +82,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
      */
@@ -97,14 +104,14 @@ public class CtfTmfTrace extends TmfTrace
      * Event aspects available for all CTF traces
      * @since 1.0
      */
-    protected static final @NonNull Collection<ITmfEventAspect> CTF_ASPECTS =
-            checkNotNull(ImmutableList.of(
-                    ITmfEventAspect.BaseAspects.TIMESTAMP,
+    protected static final @NonNull Collection<@NonNull ITmfEventAspect<?>> CTF_ASPECTS =
+            ImmutableList.of(
+                    TmfBaseAspects.getTimestampAspect(),
                     new CtfChannelAspect(),
                     new CtfCpuAspect(),
-                    ITmfEventAspect.BaseAspects.EVENT_TYPE,
-                    ITmfEventAspect.BaseAspects.CONTENTS
-                    ));
+                    TmfBaseAspects.getEventTypeAspect(),
+                    TmfBaseAspects.getContentsAspect()
+                    );
 
     /**
      * The Ctf clock unique identifier field
@@ -117,11 +124,10 @@ 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);
 
     private final @NonNull CtfTmfEventFactory fEventFactory;
 
@@ -199,22 +205,38 @@ public class CtfTmfTrace extends TmfTrace
              * register a trace to that type in the TmfEventTypeManager
              */
             try (CtfIterator iter = fIteratorManager.getIterator(ctx)) {
+                Set<@NonNull ITmfEventField> streamContextNames = new HashSet<>();
                 for (IEventDeclaration ied : iter.getEventDeclarations()) {
                     CtfTmfEventType ctfTmfEventType = fContainedEventTypes.get(ied.getName());
                     if (ctfTmfEventType == null) {
                         List<ITmfEventField> content = new ArrayList<>();
+
                         /* Should only return null the first time */
                         final StructDeclaration fields = ied.getFields();
                         if (fields != null) {
                             for (String fieldName : fields.getFieldsList()) {
                                 content.add(new TmfEventField(checkNotNull(fieldName), null, null));
                             }
+                        }
+
+                        /* Add stream contexts */
+                        final StructDeclaration streamContexts = ied.getStream().getEventContextDecl();
+                        if (streamContextNames.isEmpty()) {
+                            if (streamContexts != null) {
+                                for (String fieldName : streamContexts.getFieldsList()) {
+                                    streamContextNames.add(new TmfEventField(checkNotNull(CtfConstants.CONTEXT_FIELD_PREFIX + fieldName), null, null));
+                                }
+                            }
+                        }
+                        content.addAll(streamContextNames);
+
+                        if (!content.isEmpty()) {
                             ITmfEventField contentTree = new TmfEventField(
                                     ITmfEventField.ROOT_FIELD_ID,
                                     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);
                         }
                     }
@@ -292,7 +314,7 @@ public class CtfTmfTrace extends TmfTrace
     }
 
     @Override
-    public Iterable<ITmfEventAspect> getEventAspects() {
+    public Iterable<ITmfEventAspect<?>> getEventAspects() {
         return CTF_ASPECTS;
     }
 
@@ -426,13 +448,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;
     }
@@ -481,7 +507,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());
     }
 
@@ -600,8 +626,8 @@ public class CtfTmfTrace extends TmfTrace
      * @since 1.0
      */
     @Override
-    public @NonNull TmfNanoTimestamp createTimestamp(long ts) {
-        return new TmfNanoTimestamp(getTimestampTransform().transform(ts));
+    public @NonNull ITmfTimestamp createTimestamp(long ts) {
+        return TmfTimestamp.fromNanos(getTimestampTransform().transform(ts));
     }
 
     private static int fCheckpointSize = -1;
@@ -609,7 +635,7 @@ public class CtfTmfTrace extends TmfTrace
     @Override
     public synchronized int getCheckpointSize() {
         if (fCheckpointSize == -1) {
-            TmfCheckpoint c = new TmfCheckpoint(new TmfNanoTimestamp(0), new CtfLocation(0, 0), 0);
+            TmfCheckpoint c = new TmfCheckpoint(TmfTimestamp.fromNanos(0), new CtfLocation(0, 0), 0);
             ByteBuffer b = ByteBuffer.allocate(ITmfCheckpoint.MAX_SERIALIZE_SIZE);
             b.clear();
             c.serialize(b);
This page took 0.027725 seconds and 5 git commands to generate.