import java.util.ArrayList;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
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
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
* 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) {
}
/* 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();
* 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
*/
- private static CtfTmfEventField[] parseFields(EventDefinition eventDef) {
+ public static CtfTmfEventField[] parseFields(EventDefinition eventDef) {
List<CtfTmfEventField> fields = new ArrayList<CtfTmfEventField>();
StructDefinition structFields = eventDef.getFields();
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);
}
* Copy constructor
*
* @param other
+ * CtfTmfEvent to copy
*/
public CtfTmfEvent(CtfTmfEvent other) {
this.fTrace = other.getTrace();
/* 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;
this.typeId = -1;
this.fileName = NO_STREAM;
this.eventName = EMPTY_CTF_EVENT_NAME;
- this.fContent = new CtfTmfContent("", new CtfTmfEventField[0]);
-
+ this.fContent = new CtfTmfContent("", new CtfTmfEventField[0]); //$NON-NLS-1$
}
// ------------------------------------------------------------------------
return fSource;
}
- private CtfTmfEventType type = null;
/**
* Method getType.
* @return ITmfEventType
*/
@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;
}
/**