1 /*******************************************************************************
2 * Copyright (c) 2011-2013 Ericsson
4 * All rights reserved. This program and the accompanying materials are made
5 * available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Alexandre Montplaisir - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
;
15 import java
.util
.HashSet
;
18 import org
.eclipse
.linuxtools
.ctf
.core
.event
.IEventDeclaration
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEventField
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEventType
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEvent
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEventField
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEventPropertySource
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
25 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
28 * A wrapper class around CTF's Event Definition/Declaration that maps all
29 * types of Declaration to native Java types.
32 * @author Alexandre Montplaisir
35 public final class CtfTmfEvent
extends TmfEvent
{
37 // ------------------------------------------------------------------------
39 // ------------------------------------------------------------------------
41 static final String NO_STREAM
= "No stream"; //$NON-NLS-1$
42 private static final String EMPTY_CTF_EVENT_NAME
= "Empty CTF event"; //$NON-NLS-1$
44 // ------------------------------------------------------------------------
46 // ------------------------------------------------------------------------
48 private final int sourceCPU
;
49 private final long typeId
;
50 private final String eventName
;
51 private final IEventDeclaration fDeclaration
;
53 // ------------------------------------------------------------------------
55 // ------------------------------------------------------------------------
58 * Constructor used by {@link CtfTmfEventFactory#createEvent}
60 CtfTmfEvent(CtfTmfTrace trace
, long rank
, CtfTmfTimestamp timestamp
,
61 ITmfEventField content
, String fileName
, int cpu
,
62 IEventDeclaration declaration
) {
66 String
.valueOf(cpu
), // Source
67 null, // Event type. We don't use TmfEvent's field here, we re-implement getType()
72 fDeclaration
= declaration
;
74 typeId
= declaration
.getId();
75 eventName
= declaration
.getName();
79 * Inner constructor to create "null" events. Don't use this directly in
80 * normal usage, use {@link CtfTmfEventFactory#getNullEvent()} to get an
81 * instance of an empty event.
83 * This needs to be public however because it's used in extension points,
84 * and the framework will use this constructor to get the class type.
86 public CtfTmfEvent() {
88 ITmfContext
.UNKNOWN_RANK
,
89 new CtfTmfTimestamp(-1),
92 new TmfEventField("", new CtfTmfEventField
[0]), //$NON-NLS-1$
96 this.eventName
= EMPTY_CTF_EVENT_NAME
;
97 this.fDeclaration
= null;
100 // ------------------------------------------------------------------------
101 // Getters/Setters/Predicates
102 // ------------------------------------------------------------------------
105 * Gets the cpu core the event was recorded on.
107 * @return The cpu id for a given source. In lttng it's from CPUINFO
109 public int getCPU() {
110 return this.sourceCPU
;
114 * Return this event's ID, according to the trace's metadata.
116 * Watch out, this ID is not constant from one trace to another for the same
117 * event types! Use "getEventName()" for a constant reference.
119 * @return The event ID
121 public long getID() {
126 * Gets the name of a current event.
128 * @return The event name
130 public String
getEventName() {
135 public CtfTmfTrace
getTrace() {
136 /* Should be of the right type, since we take a CtfTmfTrace at the constructor */
137 return (CtfTmfTrace
) super.getTrace();
141 public ITmfEventType
getType() {
142 CtfTmfEventType ctfTmfEventType
= CtfTmfEventType
.get(eventName
);
143 if (ctfTmfEventType
== null) {
144 /* Should only return null the first time */
145 ctfTmfEventType
= new CtfTmfEventType(this.getEventName(), this.getContent());
147 return ctfTmfEventType
;
151 * List the custom CTF attributes for events of this type.
153 * @return The list of custom attribute names. Should not be null, but could
157 public Set
<String
> listCustomAttributes() {
158 if (fDeclaration
== null) {
159 return new HashSet
<String
>();
161 return fDeclaration
.getCustomAttributes();
165 * Get the value of a custom CTF attributes for this event's type.
168 * Name of the the custom attribute
169 * @return Value of this attribute, or null if there is no attribute with
173 public String
getCustomAttribute(String name
) {
174 if (fDeclaration
== null) {
177 return fDeclaration
.getCustomAttribute(name
);
184 public Object
getAdapter(Class adapter
) {
185 if (adapter
== IPropertySource
.class) {
186 return new TmfEventPropertySource(this);