Fix clone of CtfTmfTimestamp in CtfTmfEvent.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / ctfadaptor / CtfTmfEvent.java
index 4ef6ae992cac399ea0e0c973173606d274cb87cf..4fc75aa137c11f4849f17e2866877ccea38cb03f 100644 (file)
@@ -26,12 +26,13 @@ import org.eclipse.linuxtools.tmf.core.event.ITmfEventType;
 import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
 
 /**
- * <b><u>CTFEvent</u></b>
- * <p>
- * This is a wrapper class around CTF's Event Definition/Declaration so that we
- * can map all types of Declaration to native Java types.
+ * 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
  */
-public final class CtfTmfEvent implements ITmfEvent {
+public final class CtfTmfEvent implements ITmfEvent, Cloneable {
 
     // ------------------------------------------------------------------------
     // Constants
@@ -63,9 +64,11 @@ public final class CtfTmfEvent implements ITmfEvent {
      * the StreamInputReader).
      *
      * @param eventDef
-
-     * @param fileName String
-     * @param originTrace CtfTmfTrace
+     *            CTF EventDefinition object corresponding to this trace event
+     * @param fileName
+     *            The path to the trace file
+     * @param originTrace
+     *            The trace from which this event originates
      */
     public CtfTmfEvent(EventDefinition eventDef, String fileName,
             CtfTmfTrace originTrace) {
@@ -82,8 +85,7 @@ public final class CtfTmfEvent implements ITmfEvent {
         }
 
         /* Read the base event info */
-        Long offset = originTrace.getCTFTrace().getOffset();
-        this.timestamp = eventDef.getTimestamp() + offset;
+        this.timestamp = this.getTrace().getCTFTrace().timestampCyclesToNanos(eventDef.getTimestamp());
         this.sourceCPU = eventDef.getCPU();
         this.typeId = eventDef.getDeclaration().getId();
         this.eventName = eventDef.getDeclaration().getName();
@@ -99,8 +101,8 @@ public final class CtfTmfEvent implements ITmfEvent {
      * mess, and put them into something ITmfEventField can cope with.
      *
      * @param eventDef
-
-     * @return CtfTmfEventField[]
+     *            CTF EventDefinition to read
+     * @return CtfTmfEventField[] The array of fields that were read
      */
     public static CtfTmfEventField[] parseFields(EventDefinition eventDef) {
         List<CtfTmfEventField> fields = new ArrayList<CtfTmfEventField>();
@@ -126,6 +128,7 @@ public final class CtfTmfEvent implements ITmfEvent {
      * Copy constructor
      *
      * @param other
+     *            CtfTmfEvent to copy
      */
     public CtfTmfEvent(CtfTmfEvent other) {
         this.fTrace = other.getTrace();
@@ -140,11 +143,16 @@ public final class CtfTmfEvent implements ITmfEvent {
 
         /* Copy the fields over */
         this.fContent = (CtfTmfContent) other.fContent.clone();
+        this.fTimestamp = other.fTimestamp.clone();
     }
 
     /**
-     * Inner constructor to create "null" events. Don't use this directly, use
-     * CTFEvent.getNullEvent();
+     * Inner constructor to create "null" events. Don't use this directly in
+     * normal usage, use CtfTmfEvent.getNullEvent() to get an instance of an
+     * empty event.
+     *
+     * This needs to be public however because it's used in extension points,
+     * and the framework will use this constructor to get the class type.
      */
     public CtfTmfEvent() {
         this.fTrace = null;
@@ -154,7 +162,6 @@ public final class CtfTmfEvent implements ITmfEvent {
         this.fileName = NO_STREAM;
         this.eventName = EMPTY_CTF_EVENT_NAME;
         this.fContent = new CtfTmfContent("", new CtfTmfEventField[0]); //$NON-NLS-1$
-
     }
 
     // ------------------------------------------------------------------------
@@ -277,7 +284,11 @@ public final class CtfTmfEvent implements ITmfEvent {
      */
     @Override
     public ITmfEventType getType() {
-        return CtfTmfEventType.get(eventName);
+        CtfTmfEventType ctfTmfEventType = CtfTmfEventType.get(eventName);
+        if( ctfTmfEventType == null ){
+            ctfTmfEventType = new CtfTmfEventType( this.getEventName(), this.getContent());
+        }
+        return ctfTmfEventType;
     }
 
     /**
This page took 0.024541 seconds and 5 git commands to generate.