X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=org.eclipse.linuxtools.tmf.core%2Fsrc%2Forg%2Feclipse%2Flinuxtools%2Ftmf%2Fcore%2Fctfadaptor%2FCtfTmfEvent.java;h=c7a2129d743b6ec1bee0f9226caacb077d359c01;hb=bd54d363b79ab554de3036a01c59c40aff78c1a9;hp=d2a3db3a06f9291865d1c6ea05ae0029117cbc25;hpb=d921f72d242cb533e31a80e712d2f87ec7e5c5a3;p=deliverable%2Ftracecompass.git diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEvent.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEvent.java index d2a3db3a06..c7a2129d74 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEvent.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEvent.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 Ericsson + * Copyright (c) 2011-2013 Ericsson * * All rights reserved. This program and the accompanying materials are made * available under the terms of the Eclipse Public License v1.0 which @@ -14,13 +14,15 @@ package org.eclipse.linuxtools.tmf.core.ctfadaptor; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map.Entry; +import java.util.Set; -import org.eclipse.core.runtime.IAdaptable; import org.eclipse.linuxtools.ctf.core.event.CTFCallsite; import org.eclipse.linuxtools.ctf.core.event.EventDefinition; +import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.Definition; import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition; import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; @@ -40,7 +42,7 @@ import org.eclipse.ui.views.properties.IPropertySource; * @author Alexandre Montplaisir * @since 2.0 */ -public final class CtfTmfEvent implements ITmfEvent, IAdaptable, Cloneable { +public final class CtfTmfEvent implements ITmfEvent, Cloneable { // ------------------------------------------------------------------------ // Constants @@ -64,6 +66,7 @@ public final class CtfTmfEvent implements ITmfEvent, IAdaptable, Cloneable { private final String fileName; private final TmfEventField fContent; + private final IEventDeclaration fDeclaration; // ------------------------------------------------------------------------ // Constructors @@ -91,6 +94,7 @@ public final class CtfTmfEvent implements ITmfEvent, IAdaptable, Cloneable { this.fileName = NO_STREAM; this.eventName = EMPTY_CTF_EVENT_NAME; this.fContent = null; + this.fDeclaration = null; return; } @@ -104,6 +108,9 @@ public final class CtfTmfEvent implements ITmfEvent, IAdaptable, Cloneable { /* Read the fields */ this.fContent = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, parseFields(eventDef)); + + /* Keep a reference to this event's CTF declaration */ + this.fDeclaration = eventDef.getDeclaration(); } /** @@ -178,12 +185,8 @@ public final class CtfTmfEvent implements ITmfEvent, IAdaptable, Cloneable { /* There is only one reference to the trace, so we can shallow-copy it */ this.fTrace = other.getTrace(); - /* - * Copy the timestamp - * FIXME This can be switched to a shallow-copy once timestamps are - * made immutable. - */ - this.fTimestamp = new CtfTmfTimestamp(other.fTimestamp.getValue()); + /* Copy the timestamp (immutable) */ + this.fTimestamp = other.fTimestamp; /* Primitives, those will be copied by value */ this.sourceCPU = other.sourceCPU; @@ -193,8 +196,14 @@ public final class CtfTmfEvent implements ITmfEvent, IAdaptable, Cloneable { this.eventName = other.eventName; this.fileName = other.fileName; - /* Copy the fields over */ - this.fContent = other.fContent.clone(); + /* Copy the fields over (immutable) */ + this.fContent = other.fContent; + + /* + * Copy the reference to the custom attributes (should be the same + * object for all events of this type) + */ + this.fDeclaration = other.fDeclaration; } /** @@ -213,6 +222,7 @@ public final class CtfTmfEvent implements ITmfEvent, IAdaptable, Cloneable { this.fileName = NO_STREAM; this.eventName = EMPTY_CTF_EVENT_NAME; this.fContent = new TmfEventField("", new CtfTmfEventField[0]); //$NON-NLS-1$ + this.fDeclaration = null; } // ------------------------------------------------------------------------ @@ -310,14 +320,41 @@ public final class CtfTmfEvent implements ITmfEvent, IAdaptable, Cloneable { return getChannelName(); } + /** + * List the custom CTF attributes for events of this type. + * + * @return The list of custom attribute names. Should not be null, but could + * be empty. + * @since 2.0 + */ + public Set listCustomAttributes() { + if (fDeclaration == null) { + return new HashSet(); + } + return fDeclaration.getCustomAttributes(); + } + + /** + * Get the value of a custom CTF attributes for this event's type. + * + * @param name + * Name of the the custom attribute + * @return Value of this attribute, or null if there is no attribute with + * that name + * @since 2.0 + */ + public String getCustomAttribute(String name) { + if (fDeclaration == null) { + return null; + } + return fDeclaration.getCustomAttribute(name); + } + @Override public CtfTmfEvent clone() { return new CtfTmfEvent(this); } - /* (non-Javadoc) - * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) - */ /** * @since 2.0 */