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