Remove all existing @since annotations
[deliverable/tracecompass.git] / org.eclipse.tracecompass.ctf.core / src / org / eclipse / tracecompass / internal / ctf / core / event / EventDeclaration.java
CommitLineData
866e5b51 1/*******************************************************************************
60ae41e1 2 * Copyright (c) 2011, 2014 Ericsson, Ecole Polytechnique de Montreal and others
866e5b51
FC
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 *
9 * Contributors: Matthew Khouzam - Initial API and implementation
10 * Contributors: Simon Marchi - Initial API and implementation
11 *******************************************************************************/
12
f357bcd4 13package org.eclipse.tracecompass.internal.ctf.core.event;
866e5b51 14
8e964be1
MK
15import java.util.HashMap;
16import java.util.Map;
17import java.util.Set;
18
a4fa4e36 19import org.eclipse.jdt.annotation.NonNull;
453a59f0 20import org.eclipse.tracecompass.ctf.core.CTFReaderException;
f357bcd4
AM
21import org.eclipse.tracecompass.ctf.core.CTFStrings;
22import org.eclipse.tracecompass.ctf.core.event.EventDefinition;
23import org.eclipse.tracecompass.ctf.core.event.IEventDeclaration;
24import org.eclipse.tracecompass.ctf.core.event.io.BitBuffer;
25import org.eclipse.tracecompass.ctf.core.event.scope.LexicalScope;
26import org.eclipse.tracecompass.ctf.core.event.types.Declaration;
27import org.eclipse.tracecompass.ctf.core.event.types.IntegerDeclaration;
28import org.eclipse.tracecompass.ctf.core.event.types.StructDeclaration;
29import org.eclipse.tracecompass.ctf.core.event.types.StructDefinition;
f357bcd4
AM
30import org.eclipse.tracecompass.ctf.core.trace.CTFStream;
31import org.eclipse.tracecompass.ctf.core.trace.CTFStreamInputReader;
866e5b51
FC
32
33/**
be6df2d8
AM
34 * Representation of one type of event. A bit like "int" or "long" but for trace
35 * events.
866e5b51 36 */
8e964be1 37public class EventDeclaration implements IEventDeclaration {
866e5b51 38
b73145e2
JCK
39 /** Id of lost events */
40 public static final long LOST_EVENT_ID = -1L;
41
42 /** Id of events when not set */
43 public static final long UNSET_EVENT_ID = -2L;
44
866e5b51
FC
45 // ------------------------------------------------------------------------
46 // Attributes
47 // ------------------------------------------------------------------------
48
49 /**
50 * Name of the event
51 */
75259c16 52 private String fName;
866e5b51
FC
53
54 /**
55 * Event context structure declaration
56 */
75259c16 57 private StructDeclaration fContext = null;
866e5b51
FC
58
59 /**
60 * Event fields structure declaration
61 */
75259c16 62 private StructDeclaration fFields = null;
866e5b51 63
866e5b51
FC
64 /**
65 * Stream to which belongs this event.
66 */
d84419e1 67 private CTFStream fStream = null;
866e5b51 68
53047a66
MK
69 /**
70 * Loglevel of an event
71 */
75259c16 72 private long fLogLevel;
53047a66 73
8e964be1 74 /** Map of this event type's custom CTF attributes */
75259c16 75 private final Map<String, String> fCustomAttributes = new HashMap<>();
8e964be1 76
5f715709
MK
77 private int fId = (int) UNSET_EVENT_ID;
78
866e5b51
FC
79 // ------------------------------------------------------------------------
80 // Constructors
81 // ------------------------------------------------------------------------
82
be6df2d8
AM
83 /**
84 * Default constructor. Use the setters afterwards to set the fields
85 * accordingly.
86 */
8e964be1
MK
87 public EventDeclaration() {
88 }
be6df2d8 89
8e964be1 90 @Override
d84419e1 91 public EventDefinition createDefinition(CTFStreamInputReader streamInputReader, @NonNull BitBuffer input, long timestamp) throws CTFReaderException {
a4fa4e36 92 StructDeclaration streamEventContextDecl = streamInputReader.getStreamEventContextDecl();
70f60307 93 StructDefinition streamEventContext = streamEventContextDecl != null ? streamEventContextDecl.createDefinition(fStream.getTrace(), LexicalScope.STREAM_EVENT_CONTEXT, input) : null;
a4fa4e36 94 StructDefinition packetContext = streamInputReader.getPacketReader().getCurrentPacketEventHeader();
70f60307
MK
95 StructDefinition eventContext = fContext != null ? fContext.createDefinition(fStream.getTrace(), LexicalScope.CONTEXT, input) : null;
96 StructDefinition eventPayload = fFields != null ? fFields.createDefinition(fStream.getTrace(), LexicalScope.FIELDS, input) : null;
a4fa4e36
MK
97
98 // a bit lttng specific
99 // CTF doesn't require a timestamp,
100 // but it's passed to us
101 return new EventDefinition(
102 this,
103 streamInputReader,
104 timestamp,
105 streamEventContext,
106 eventContext,
107 packetContext,
108 eventPayload);
866e5b51
FC
109 }
110
33656d8e
MK
111 /**
112 * Creates a "lost" event. This is a synthetic event that is there to show
113 * that there should be something there.
8e964be1 114 *
9ac2eb62 115 * @return the lost event
33656d8e 116 */
0594c61c 117 public static synchronized EventDeclaration getLostEventDeclaration() {
debcffff 118 EventDeclaration lostEvent = new EventDeclaration();
a4fa4e36
MK
119 String[] fieldNames = new String[] { CTFStrings.LOST_EVENTS_FIELD, CTFStrings.LOST_EVENTS_DURATION };
120 Declaration[] fieldDeclarations = new Declaration[] { IntegerDeclaration.UINT_32B_DECL, IntegerDeclaration.UINT_64B_DECL };
121 lostEvent.fFields = new StructDeclaration(fieldNames, fieldDeclarations);
5f715709 122 lostEvent.fId = (int) LOST_EVENT_ID;
75259c16 123 lostEvent.fName = CTFStrings.LOST_EVENT_NAME;
33656d8e
MK
124 return lostEvent;
125 }
126
866e5b51
FC
127 // ------------------------------------------------------------------------
128 // Getters/Setters/Predicates
129 // ------------------------------------------------------------------------
130
9ac2eb62
MK
131 /**
132 * Sets a name for an event Declaration
8e964be1
MK
133 *
134 * @param name
135 * the name
9ac2eb62 136 */
866e5b51 137 public void setName(String name) {
75259c16 138 fName = name;
866e5b51
FC
139 }
140
8e964be1 141 @Override
866e5b51 142 public String getName() {
75259c16 143 return fName;
866e5b51
FC
144 }
145
9ac2eb62
MK
146 /**
147 * Sets the context for an event declaration (see CTF specification)
8e964be1
MK
148 *
149 * @param context
150 * the context in structdeclaration format
9ac2eb62 151 */
866e5b51 152 public void setContext(StructDeclaration context) {
75259c16 153 fContext = context;
866e5b51
FC
154 }
155
9ac2eb62
MK
156 /**
157 * Sets the fields of an event declaration
8e964be1
MK
158 *
159 * @param fields
160 * the fields in structdeclaration format
9ac2eb62 161 */
866e5b51 162 public void setFields(StructDeclaration fields) {
75259c16 163 fFields = fields;
866e5b51
FC
164 }
165
8e964be1 166 @Override
866e5b51 167 public StructDeclaration getFields() {
75259c16 168 return fFields;
866e5b51
FC
169 }
170
8e964be1 171 @Override
866e5b51 172 public StructDeclaration getContext() {
75259c16 173 return fContext;
866e5b51
FC
174 }
175
9ac2eb62 176 /**
ecb12461 177 * Sets the id of an event declaration
8e964be1
MK
178 *
179 * @param id
180 * the id
9ac2eb62 181 */
866e5b51 182 public void setId(long id) {
5f715709
MK
183 if (id < 0 || id > Integer.MAX_VALUE) {
184 throw new IllegalArgumentException("id out of range"); //$NON-NLS-1$
185 }
186 fId = (int) id;
866e5b51
FC
187 }
188
8e964be1 189 @Override
866e5b51 190 public Long getId() {
5f715709
MK
191 return Long.valueOf(fId);
192 }
193
194 /**
195 * Faster get id assuming you have less than a billion event types
196 *
197 * @return the event id
198 */
199 public int id() {
75259c16 200 return fId;
866e5b51
FC
201 }
202
9ac2eb62 203 /**
ecb12461 204 * Sets the stream of an event declaration
8e964be1
MK
205 *
206 * @param stream
207 * the stream
9ac2eb62 208 */
d84419e1 209 public void setStream(CTFStream stream) {
75259c16 210 fStream = stream;
866e5b51
FC
211 }
212
8e964be1 213 @Override
d84419e1 214 public CTFStream getStream() {
75259c16 215 return fStream;
866e5b51
FC
216 }
217
9ac2eb62
MK
218 /**
219 * Is the name of the event declaration set
8e964be1 220 *
9ac2eb62
MK
221 * @return is the name set?
222 */
866e5b51 223 public boolean nameIsSet() {
75259c16 224 return fName != null;
866e5b51
FC
225 }
226
9ac2eb62
MK
227 /**
228 * Is the context set
8e964be1 229 *
9ac2eb62
MK
230 * @return is the context set
231 */
866e5b51 232 public boolean contextIsSet() {
75259c16 233 return fContext != null;
866e5b51
FC
234 }
235
9ac2eb62
MK
236 /**
237 * Is a field set?
8e964be1 238 *
9ac2eb62
MK
239 * @return Is the field set?
240 */
866e5b51 241 public boolean fieldsIsSet() {
75259c16 242 return fFields != null;
866e5b51
FC
243 }
244
9ac2eb62
MK
245 /**
246 * Is the id set?
8e964be1 247 *
9ac2eb62
MK
248 * @return is the id set?
249 */
866e5b51 250 public boolean idIsSet() {
5f715709 251 return (fId != UNSET_EVENT_ID);
866e5b51
FC
252 }
253
9ac2eb62
MK
254 /**
255 * Is the stream set?
8e964be1 256 *
9ac2eb62
MK
257 * @return is the stream set?
258 */
866e5b51 259 public boolean streamIsSet() {
75259c16 260 return fStream != null;
866e5b51
FC
261 }
262
8e964be1 263 @Override
53047a66 264 public long getLogLevel() {
75259c16 265 return fLogLevel;
53047a66
MK
266 }
267
9ac2eb62
MK
268 /**
269 * Sets the log level
8e964be1
MK
270 *
271 * @param level
272 * the log level
9ac2eb62 273 */
8e964be1 274 public void setLogLevel(long level) {
75259c16 275 fLogLevel = level;
53047a66
MK
276 }
277
8e964be1
MK
278 @Override
279 public Set<String> getCustomAttributes() {
75259c16 280 return fCustomAttributes.keySet();
8e964be1
MK
281 }
282
283 @Override
284 public String getCustomAttribute(String key) {
75259c16 285 return fCustomAttributes.get(key);
8e964be1
MK
286 }
287
288 /**
289 * Sets a custom attribute value.
290 *
291 * @param key
292 * the key of the attribute
293 * @param value
294 * the value of the attribute
8e964be1
MK
295 */
296 public void setCustomAttribute(String key, String value) {
75259c16 297 fCustomAttributes.put(key, value);
8e964be1
MK
298 }
299
866e5b51
FC
300 // ------------------------------------------------------------------------
301 // Operations
302 // ------------------------------------------------------------------------
303
304 @Override
305 public boolean equals(Object obj) {
306 if (this == obj) {
307 return true;
308 }
309 if (obj == null) {
310 return false;
311 }
312 if (!(obj instanceof EventDeclaration)) {
313 return false;
314 }
315 EventDeclaration other = (EventDeclaration) obj;
75259c16
MK
316 if (fContext == null) {
317 if (other.fContext != null) {
866e5b51
FC
318 return false;
319 }
75259c16 320 } else if (!fContext.equals(other.fContext)) {
866e5b51
FC
321 return false;
322 }
75259c16
MK
323 if (fFields == null) {
324 if (other.fFields != null) {
866e5b51
FC
325 return false;
326 }
75259c16 327 } else if (!fFields.equals(other.fFields)) {
866e5b51
FC
328 return false;
329 }
5f715709 330 if (fId != (other.fId)) {
866e5b51
FC
331 return false;
332 }
75259c16
MK
333 if (fName == null) {
334 if (other.fName != null) {
866e5b51
FC
335 return false;
336 }
75259c16 337 } else if (!fName.equals(other.fName)) {
866e5b51
FC
338 return false;
339 }
75259c16
MK
340 if (fStream == null) {
341 if (other.fStream != null) {
866e5b51
FC
342 return false;
343 }
75259c16 344 } else if (!fStream.equals(other.fStream)) {
866e5b51
FC
345 return false;
346 }
75259c16 347 if (!fCustomAttributes.equals(other.fCustomAttributes)) {
8e964be1
MK
348 return false;
349 }
866e5b51
FC
350 return true;
351 }
352
353 @Override
354 public int hashCode() {
355 final int prime = 31;
356 int result = 1;
357 result = (prime * result)
75259c16
MK
358 + ((fContext == null) ? 0 : fContext.hashCode());
359 result = (prime * result) + ((fFields == null) ? 0 : fFields.hashCode());
5f715709 360 result = (prime * result) + fId;
75259c16
MK
361 result = (prime * result) + ((fName == null) ? 0 : fName.hashCode());
362 result = (prime * result) + ((fStream == null) ? 0 : fStream.hashCode());
363 result = (prime * result) + fCustomAttributes.hashCode();
866e5b51
FC
364 return result;
365 }
366
367}
This page took 0.087082 seconds and 5 git commands to generate.