Commit | Line | Data |
---|---|---|
a3fc8213 | 1 | /******************************************************************************* |
8e964be1 | 2 | * Copyright (c) 2011-2013 Ericsson |
a3fc8213 AM |
3 | * |
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 | |
8 | * | |
58f3bc52 AM |
9 | * Contributors: |
10 | * Alexandre Montplaisir - Initial API and implementation | |
a3fc8213 AM |
11 | *******************************************************************************/ |
12 | ||
13 | package org.eclipse.linuxtools.tmf.core.ctfadaptor; | |
14 | ||
8e964be1 | 15 | import java.util.HashSet; |
8e964be1 | 16 | import java.util.Set; |
a3fc8213 | 17 | |
8e964be1 | 18 | import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration; |
a3fc8213 AM |
19 | import org.eclipse.linuxtools.tmf.core.event.ITmfEventField; |
20 | import org.eclipse.linuxtools.tmf.core.event.ITmfEventType; | |
6cfa0200 | 21 | import org.eclipse.linuxtools.tmf.core.event.TmfEvent; |
306dc902 | 22 | import org.eclipse.linuxtools.tmf.core.event.TmfEventField; |
93bfd50a | 23 | import org.eclipse.linuxtools.tmf.core.event.TmfEventPropertySource; |
6cfa0200 | 24 | import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; |
93bfd50a | 25 | import org.eclipse.ui.views.properties.IPropertySource; |
a3fc8213 AM |
26 | |
27 | /** | |
d09f973b FC |
28 | * A wrapper class around CTF's Event Definition/Declaration that maps all |
29 | * types of Declaration to native Java types. | |
6256d8ad | 30 | * |
d09f973b FC |
31 | * @version 1.0 |
32 | * @author Alexandre Montplaisir | |
93bfd50a | 33 | * @since 2.0 |
a3fc8213 | 34 | */ |
6cfa0200 | 35 | public final class CtfTmfEvent extends TmfEvent { |
a3fc8213 AM |
36 | |
37 | // ------------------------------------------------------------------------ | |
38 | // Constants | |
39 | // ------------------------------------------------------------------------ | |
40 | ||
6cfa0200 | 41 | static final String NO_STREAM = "No stream"; //$NON-NLS-1$ |
a3fc8213 | 42 | private static final String EMPTY_CTF_EVENT_NAME = "Empty CTF event"; //$NON-NLS-1$ |
aa572e22 | 43 | |
a3fc8213 AM |
44 | // ------------------------------------------------------------------------ |
45 | // Attributes | |
46 | // ------------------------------------------------------------------------ | |
47 | ||
a3fc8213 AM |
48 | private final int sourceCPU; |
49 | private final long typeId; | |
50 | private final String eventName; | |
8e964be1 | 51 | private final IEventDeclaration fDeclaration; |
a3fc8213 AM |
52 | |
53 | // ------------------------------------------------------------------------ | |
54 | // Constructors | |
55 | // ------------------------------------------------------------------------ | |
56 | ||
57 | /** | |
6cfa0200 | 58 | * Constructor used by {@link CtfTmfEventFactory#createEvent} |
a3fc8213 | 59 | */ |
6cfa0200 AM |
60 | CtfTmfEvent(CtfTmfTrace trace, long rank, CtfTmfTimestamp timestamp, |
61 | ITmfEventField content, String fileName, int cpu, | |
62 | IEventDeclaration declaration) { | |
63 | super(trace, | |
64 | rank, | |
65 | timestamp, | |
66 | String.valueOf(cpu), // Source | |
67 | null, // Event type. We don't use TmfEvent's field here, we re-implement getType() | |
68 | content, | |
69 | fileName // Reference | |
70 | ); | |
71 | ||
72 | fDeclaration = declaration; | |
73 | sourceCPU = cpu; | |
74 | typeId = declaration.getId(); | |
75 | eventName = declaration.getName(); | |
a3fc8213 AM |
76 | } |
77 | ||
78 | /** | |
b8a6e46d | 79 | * Inner constructor to create "null" events. Don't use this directly in |
6cfa0200 AM |
80 | * normal usage, use {@link CtfTmfEventFactory#getNullEvent()} to get an |
81 | * instance of an empty event. | |
c26afeaf | 82 | * |
b8a6e46d AM |
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. | |
a3fc8213 | 85 | */ |
ce2388e0 | 86 | public CtfTmfEvent() { |
6cfa0200 AM |
87 | super(null, |
88 | ITmfContext.UNKNOWN_RANK, | |
89 | new CtfTmfTimestamp(-1), | |
90 | null, | |
91 | null, | |
92 | new TmfEventField("", new CtfTmfEventField[0]), //$NON-NLS-1$ | |
93 | NO_STREAM); | |
a3fc8213 AM |
94 | this.sourceCPU = -1; |
95 | this.typeId = -1; | |
a3fc8213 | 96 | this.eventName = EMPTY_CTF_EVENT_NAME; |
8e964be1 | 97 | this.fDeclaration = null; |
a3fc8213 AM |
98 | } |
99 | ||
100 | // ------------------------------------------------------------------------ | |
101 | // Getters/Setters/Predicates | |
102 | // ------------------------------------------------------------------------ | |
103 | ||
a3fc8213 AM |
104 | /** |
105 | * Gets the cpu core the event was recorded on. | |
106 | * | |
58f3bc52 AM |
107 | * @return The cpu id for a given source. In lttng it's from CPUINFO |
108 | */ | |
a3fc8213 AM |
109 | public int getCPU() { |
110 | return this.sourceCPU; | |
111 | } | |
112 | ||
113 | /** | |
58f3bc52 | 114 | * Return this event's ID, according to the trace's metadata. |
a3fc8213 | 115 | * |
58f3bc52 AM |
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. | |
118 | * | |
119 | * @return The event ID | |
120 | */ | |
a3fc8213 AM |
121 | public long getID() { |
122 | return this.typeId; | |
123 | } | |
124 | ||
125 | /** | |
126 | * Gets the name of a current event. | |
127 | * | |
58f3bc52 AM |
128 | * @return The event name |
129 | */ | |
a3fc8213 AM |
130 | public String getEventName() { |
131 | return eventName; | |
132 | } | |
133 | ||
a3fc8213 AM |
134 | @Override |
135 | public CtfTmfTrace getTrace() { | |
6cfa0200 AM |
136 | /* Should be of the right type, since we take a CtfTmfTrace at the constructor */ |
137 | return (CtfTmfTrace) super.getTrace(); | |
a3fc8213 AM |
138 | } |
139 | ||
140 | @Override | |
141 | public ITmfEventType getType() { | |
c26afeaf | 142 | CtfTmfEventType ctfTmfEventType = CtfTmfEventType.get(eventName); |
6cfa0200 AM |
143 | if (ctfTmfEventType == null) { |
144 | /* Should only return null the first time */ | |
145 | ctfTmfEventType = new CtfTmfEventType(this.getEventName(), this.getContent()); | |
c26afeaf MD |
146 | } |
147 | return ctfTmfEventType; | |
a3fc8213 AM |
148 | } |
149 | ||
8e964be1 MK |
150 | /** |
151 | * List the custom CTF attributes for events of this type. | |
152 | * | |
153 | * @return The list of custom attribute names. Should not be null, but could | |
154 | * be empty. | |
155 | * @since 2.0 | |
156 | */ | |
157 | public Set<String> listCustomAttributes() { | |
158 | if (fDeclaration == null) { | |
159 | return new HashSet<String>(); | |
160 | } | |
161 | return fDeclaration.getCustomAttributes(); | |
162 | } | |
163 | ||
164 | /** | |
165 | * Get the value of a custom CTF attributes for this event's type. | |
166 | * | |
167 | * @param name | |
168 | * Name of the the custom attribute | |
169 | * @return Value of this attribute, or null if there is no attribute with | |
170 | * that name | |
171 | * @since 2.0 | |
172 | */ | |
173 | public String getCustomAttribute(String name) { | |
174 | if (fDeclaration == null) { | |
175 | return null; | |
176 | } | |
177 | return fDeclaration.getCustomAttribute(name); | |
178 | } | |
179 | ||
531987c8 PT |
180 | /** |
181 | * @since 2.0 | |
182 | */ | |
93bfd50a PT |
183 | @Override |
184 | public Object getAdapter(Class adapter) { | |
185 | if (adapter == IPropertySource.class) { | |
186 | return new TmfEventPropertySource(this); | |
187 | } | |
188 | return null; | |
189 | } | |
a3fc8213 | 190 | } |