rcp: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ctf.core / src / org / eclipse / tracecompass / tmf / ctf / core / event / CtfTmfEvent.java
index 5c7670987cbcbbf0e6066f2a2cd898fc7bc3c800..334b7409efd1fa60e4219fc10a6c8e5265a59405 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2011, 2014 Ericsson
+ * Copyright (c) 2011, 2015 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License v1.0 which
@@ -19,12 +19,10 @@ import java.util.List;
 import java.util.Set;
 
 import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.tracecompass.ctf.core.event.CTFCallsite;
 import org.eclipse.tracecompass.ctf.core.event.EventDefinition;
 import org.eclipse.tracecompass.ctf.core.event.IEventDeclaration;
 import org.eclipse.tracecompass.ctf.core.event.types.ICompositeDefinition;
 import org.eclipse.tracecompass.ctf.core.event.types.IDefinition;
-import org.eclipse.tracecompass.ctf.core.trace.CTFTrace;
 import org.eclipse.tracecompass.tmf.core.event.ITmfCustomAttributes;
 import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
 import org.eclipse.tracecompass.tmf.core.event.ITmfEventType;
@@ -32,19 +30,17 @@ import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
 import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
 import org.eclipse.tracecompass.tmf.core.event.lookup.ITmfModelLookup;
 import org.eclipse.tracecompass.tmf.core.event.lookup.ITmfSourceLookup;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfNanoTimestamp;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
 import org.eclipse.tracecompass.tmf.ctf.core.CtfConstants;
 import org.eclipse.tracecompass.tmf.ctf.core.event.lookup.CtfTmfCallsite;
-import org.eclipse.tracecompass.tmf.ctf.core.timestamp.CtfTmfTimestamp;
 import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
 
 /**
  * A wrapper class around CTF's Event Definition/Declaration that maps all types
  * of Declaration to native Java types.
  *
- * @version 1.0
  * @author Alexandre Montplaisir
- * @since 2.0
  */
 public class CtfTmfEvent extends TmfEvent
         implements ITmfSourceLookup, ITmfModelLookup, ITmfCustomAttributes {
@@ -64,12 +60,13 @@ public class CtfTmfEvent extends TmfEvent
     private final String fEventName;
     private final IEventDeclaration fEventDeclaration;
     private final @NonNull EventDefinition fEvent;
-    private final String fSource;
     private final String fReference;
 
     /** Lazy-loaded field containing the event's payload */
     private ITmfEventField fContent;
 
+    private CtfTmfEventType fCtfTmfEventType;
+
     // ------------------------------------------------------------------------
     // Constructors
     // ------------------------------------------------------------------------
@@ -77,7 +74,7 @@ public class CtfTmfEvent extends TmfEvent
     /**
      * Constructor used by {@link CtfTmfEventFactory#createEvent}
      */
-    CtfTmfEvent(CtfTmfTrace trace, long rank, CtfTmfTimestamp timestamp,
+    CtfTmfEvent(CtfTmfTrace trace, long rank, TmfNanoTimestamp timestamp,
             String fileName, int cpu, IEventDeclaration declaration, @NonNull EventDefinition eventDefinition) {
         super(trace,
                 rank,
@@ -91,15 +88,13 @@ public class CtfTmfEvent extends TmfEvent
                  * Content handled with a lazy-loaded field re-implemented in
                  * getContent().
                  */
-                null
-        );
+                null);
 
         fEventDeclaration = declaration;
         fSourceCPU = cpu;
         fTypeId = declaration.getId().longValue();
         fEventName = declaration.getName();
         fEvent = eventDefinition;
-        fSource = String.valueOf(cpu);
         fReference = fileName;
     }
 
@@ -117,7 +112,7 @@ public class CtfTmfEvent extends TmfEvent
     CtfTmfEvent(CtfTmfTrace trace) {
         super(trace,
                 ITmfContext.UNKNOWN_RANK,
-                new CtfTmfTimestamp(-1),
+                new TmfNanoTimestamp(-1),
                 null,
                 new TmfEventField("", null, new CtfTmfEventField[0])); //$NON-NLS-1$
         fSourceCPU = -1;
@@ -125,7 +120,6 @@ public class CtfTmfEvent extends TmfEvent
         fEventName = EMPTY_CTF_EVENT_NAME;
         fEventDeclaration = null;
         fEvent = EventDefinition.NULL_EVENT;
-        fSource = null;
         fReference = null;
     }
 
@@ -163,15 +157,6 @@ public class CtfTmfEvent extends TmfEvent
         return fTypeId;
     }
 
-    /**
-     * Return this event's source CPU.
-     *
-     * @return The source CPU
-     */
-    public String getSource() {
-        return fSource;
-    }
-
     /**
      * Return this event's reference
      *
@@ -192,18 +177,23 @@ public class CtfTmfEvent extends TmfEvent
 
     @Override
     public ITmfEventType getType() {
-        CtfTmfEventType ctfTmfEventType = new CtfTmfEventType(fEventName, getContent());
-
-        /* Register the event type in the owning trace, but only if there is one */
-        CtfTmfTrace trace = getTrace();
-        trace.registerEventType(ctfTmfEventType);
+        if (fCtfTmfEventType == null) {
+            fCtfTmfEventType = new CtfTmfEventType(fEventName, getContent());
+
+            /*
+             * Register the event type in the owning trace, but only if there is
+             * one
+             */
+            getTrace().registerEventType(fCtfTmfEventType);
+        }
+        return fCtfTmfEventType;
+    }
 
-        return ctfTmfEventType;
+    @Override
+    public String getName() {
+        return fEventName;
     }
 
-    /**
-     * @since 2.0
-     */
     @Override
     public Set<String> listCustomAttributes() {
         if (fEventDeclaration == null) {
@@ -212,9 +202,6 @@ public class CtfTmfEvent extends TmfEvent
         return fEventDeclaration.getCustomAttributes();
     }
 
-    /**
-     * @since 2.0
-     */
     @Override
     public String getCustomAttribute(String name) {
         if (fEventDeclaration == null) {
@@ -227,36 +214,25 @@ public class CtfTmfEvent extends TmfEvent
      * Get the call site for this event.
      *
      * @return the call site information, or null if there is none
-     * @since 2.0
      */
     @Override
     public CtfTmfCallsite getCallsite() {
-        CTFCallsite callsite = null;
+        CtfTmfCallsite callsite = null;
         CtfTmfTrace trace = getTrace();
-        CTFTrace ctfTrace = trace.getCTFTrace();
-        /* Should not happen, but it is a good check */
-        if (ctfTrace == null) {
-            return null;
-        }
+
         if (getContent() != null) {
             ITmfEventField ipField = getContent().getField(CtfConstants.CONTEXT_FIELD_PREFIX + CtfConstants.IP_KEY);
             if (ipField != null && ipField.getValue() instanceof Long) {
                 long ip = (Long) ipField.getValue();
-                callsite = ctfTrace.getCallsite(fEventName, ip);
+                callsite = trace.getCallsite(fEventName, ip);
             }
         }
         if (callsite == null) {
-            callsite = ctfTrace.getCallsite(fEventName);
-        }
-        if (callsite != null) {
-            return new CtfTmfCallsite(callsite);
+            callsite = trace.getCallsite(fEventName);
         }
-        return null;
+        return callsite;
     }
 
-    /**
-     * @since 2.0
-     */
     @Override
     public String getModelUri() {
         return getCustomAttribute(CtfConstants.MODEL_URI_KEY);
This page took 0.026675 seconds and 5 git commands to generate.