Fix clone of CtfTmfTimestamp in CtfTmfEvent.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / ctfadaptor / CtfTmfEvent.java
index ea42c0e303be1dd99838a07d29fe5c610c0d6e66..4fc75aa137c11f4849f17e2866877ccea38cb03f 100644 (file)
@@ -13,6 +13,7 @@ package org.eclipse.linuxtools.tmf.core.ctfadaptor;
 
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map.Entry;
 
@@ -25,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
@@ -38,7 +40,7 @@ public final class CtfTmfEvent implements ITmfEvent {
 
     private static final String NO_STREAM = "No stream"; //$NON-NLS-1$
     private static final String EMPTY_CTF_EVENT_NAME = "Empty CTF event"; //$NON-NLS-1$
-    private static final String CONTEXT_ID = "Ctf Event"; //$NON-NLS-1$
+
 
     // ------------------------------------------------------------------------
     // Attributes
@@ -62,7 +64,11 @@ public final class CtfTmfEvent implements ITmfEvent {
      * the StreamInputReader).
      *
      * @param eventDef
-     * @param top
+     *            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) {
@@ -79,8 +85,7 @@ public final class CtfTmfEvent implements ITmfEvent {
         }
 
         /* Read the base event info */
-        Long offset = originTrace.getCTFTrace().getOffset();
-        this.timestamp = eventDef.timestamp + offset;
+        this.timestamp = this.getTrace().getCTFTrace().timestampCyclesToNanos(eventDef.getTimestamp());
         this.sourceCPU = eventDef.getCPU();
         this.typeId = eventDef.getDeclaration().getId();
         this.eventName = eventDef.getDeclaration().getName();
@@ -96,9 +101,10 @@ public final class CtfTmfEvent implements ITmfEvent {
      * mess, and put them into something ITmfEventField can cope with.
      *
      * @param eventDef
-     * @return
+     *            CTF EventDefinition to read
+     * @return CtfTmfEventField[] The array of fields that were read
      */
-    private static CtfTmfEventField[] parseFields(EventDefinition eventDef) {
+    public static CtfTmfEventField[] parseFields(EventDefinition eventDef) {
         List<CtfTmfEventField> fields = new ArrayList<CtfTmfEventField>();
 
         StructDefinition structFields = eventDef.getFields();
@@ -106,16 +112,12 @@ public final class CtfTmfEvent implements ITmfEvent {
         String curFieldName;
         Definition curFieldDef;
         CtfTmfEventField curField;
-
-        for (Entry<String, Definition> entry : definitions.entrySet()) {
+        Iterator<Entry<String, Definition>> it = definitions.entrySet().iterator();
+        while(it.hasNext()) {
+            Entry<String, Definition> entry = it.next();
             curFieldName = entry.getKey();
             curFieldDef = entry.getValue();
             curField = CtfTmfEventField.parseField(curFieldDef, curFieldName);
-            if (curField == null) {
-//                TmfCorePlugin.getDefault().log(
-//                        "We've parsed an unimplemented field type for event \"" + this.eventName //$NON-NLS-1$
-//                                + "\", field \"" + curFieldName + "\" of type " + curFieldDef.getClass().toString()); //$NON-NLS-1$ //$NON-NLS-2$
-            }
             fields.add(curField);
         }
 
@@ -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;
@@ -153,7 +161,7 @@ public final class CtfTmfEvent implements ITmfEvent {
         this.typeId = -1;
         this.fileName = NO_STREAM;
         this.eventName = EMPTY_CTF_EVENT_NAME;
-        this.fContent = null;
+        this.fContent = new CtfTmfContent("", new CtfTmfEventField[0]); //$NON-NLS-1$
     }
 
     // ------------------------------------------------------------------------
@@ -165,8 +173,7 @@ public final class CtfTmfEvent implements ITmfEvent {
     /**
      * Get a null event
      *
-     * @return an empty event.
-     */
+     * @return an empty event. */
     public static CtfTmfEvent getNullEvent() {
         if (nullEvent == null) {
             nullEvent = new CtfTmfEvent();
@@ -177,8 +184,7 @@ public final class CtfTmfEvent implements ITmfEvent {
     /**
      * Gets the current timestamp of the event
      *
-     * @return the current timestamp (long)
-     */
+     * @return the current timestamp (long) */
     public long getTimestampValue() {
         return this.timestamp;
     }
@@ -186,8 +192,7 @@ public final class CtfTmfEvent implements ITmfEvent {
     /**
      * Gets the cpu core the event was recorded on.
      *
-     * @return the cpu id for a given source. In lttng it's from CPUINFO
-     */
+     * @return the cpu id for a given source. In lttng it's from CPUINFO */
     public int getCPU() {
         return this.sourceCPU;
     }
@@ -197,8 +202,8 @@ public final class CtfTmfEvent implements ITmfEvent {
      * this ID is not constant from one trace to another for the same event
      * types! Use "getEventName()" for a constant reference.
      *
-     * @return the event ID
-     */
+
+     * @return the event ID */
     public long getID() {
         return this.typeId;
     }
@@ -206,8 +211,7 @@ public final class CtfTmfEvent implements ITmfEvent {
     /**
      * Gets the name of a current event.
      *
-     * @return the event name
-     */
+     * @return the event name */
     public String getEventName() {
         return eventName;
     }
@@ -215,17 +219,26 @@ public final class CtfTmfEvent implements ITmfEvent {
     /**
      * Gets the channel name of a field.
      *
-     * @return the channel name.
-     */
+     * @return the channel name. */
     public String getChannelName() {
         return this.fileName;
     }
 
+    /**
+     * Method getTrace.
+     * @return CtfTmfTrace
+     * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getTrace()
+     */
     @Override
     public CtfTmfTrace getTrace() {
         return fTrace;
     }
 
+    /**
+     * Method getRank.
+     * @return long
+     * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getRank()
+     */
     @Override
     public long getRank() {
         // TODO Auto-generated method stub
@@ -236,6 +249,11 @@ public final class CtfTmfEvent implements ITmfEvent {
 
     // TODO Benchmark if the singleton approach is faster than just
     // instantiating a final fTimestramp right away at creation time
+    /**
+     * Method getTimestamp.
+     * @return ITmfTimestamp
+     * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getTimestamp()
+     */
     @Override
     public ITmfTimestamp getTimestamp() {
         if (fTimestamp == null) {
@@ -245,6 +263,11 @@ public final class CtfTmfEvent implements ITmfEvent {
     }
 
     String fSource = null;
+    /**
+     * Method getSource.
+     * @return String
+     * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getSource()
+     */
     @Override
     public String getSource() {
         // TODO Returns CPU for now
@@ -254,21 +277,36 @@ public final class CtfTmfEvent implements ITmfEvent {
         return fSource;
     }
 
-    private CtfTmfEventType type = null;
+    /**
+     * Method getType.
+     * @return ITmfEventType
+     * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getType()
+     */
     @Override
     public ITmfEventType getType() {
-        if(type == null){
-            type = new CtfTmfEventType(CONTEXT_ID, eventName, fContent);
+        CtfTmfEventType ctfTmfEventType = CtfTmfEventType.get(eventName);
+        if( ctfTmfEventType == null ){
+            ctfTmfEventType = new CtfTmfEventType( this.getEventName(), this.getContent());
         }
-        return type;
+        return ctfTmfEventType;
     }
 
+    /**
+     * Method getContent.
+     * @return ITmfEventField
+     * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getContent()
+     */
     @Override
     public ITmfEventField getContent() {
         return fContent;
     }
 
     String fReference = null;
+    /**
+     * Method getReference.
+     * @return String
+     * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#getReference()
+     */
     @Override
     public String getReference() {
         if( fReference == null){
@@ -277,6 +315,11 @@ public final class CtfTmfEvent implements ITmfEvent {
         return fReference;
     }
 
+    /**
+     * Method clone.
+     * @return CtfTmfEvent
+     * @see org.eclipse.linuxtools.tmf.core.event.ITmfEvent#clone()
+     */
     @Override
     public CtfTmfEvent clone() {
         return new CtfTmfEvent(this);
This page took 0.028611 seconds and 5 git commands to generate.