1 /*******************************************************************************
2 * Copyright (c) 2011-2013 Ericsson, Ecole Polytechnique de Montreal and others
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
9 * Contributors: Matthew Khouzam - Initial API and implementation
10 * Contributors: Simon Marchi - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.ctf
.core
.event
;
15 import java
.util
.HashMap
;
19 import org
.eclipse
.linuxtools
.ctf
.core
.event
.EventDefinition
;
20 import org
.eclipse
.linuxtools
.ctf
.core
.event
.IEventDeclaration
;
21 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StructDeclaration
;
22 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.Stream
;
23 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.StreamInputReader
;
26 * Representation of one type of event. A bit like "int" or "long" but for trace
29 public class EventDeclaration
implements IEventDeclaration
{
31 /** Id of lost events */
32 public static final long LOST_EVENT_ID
= -1L;
34 /** Id of events when not set */
35 public static final long UNSET_EVENT_ID
= -2L;
37 // ------------------------------------------------------------------------
39 // ------------------------------------------------------------------------
47 * Event context structure declaration
49 private StructDeclaration context
= null;
52 * Event fields structure declaration
54 private StructDeclaration fields
= null;
57 * Event id (can be null if only event in the stream).
59 private Long id
= UNSET_EVENT_ID
;
62 * Stream to which belongs this event.
64 private Stream stream
= null;
67 * Loglevel of an event
69 private long logLevel
;
71 /** Map of this event type's custom CTF attributes */
72 private final Map
<String
, String
> customAttributes
= new HashMap
<String
, String
>();
74 // ------------------------------------------------------------------------
76 // ------------------------------------------------------------------------
79 * Default constructor. Use the setters afterwards to set the fields
82 public EventDeclaration() {
86 public EventDefinition
createDefinition(StreamInputReader streamInputReader
) {
87 EventDefinition event
= new EventDefinition(this, streamInputReader
);
89 if (context
!= null) {
90 event
.setContext(context
.createDefinition(event
, "context")); //$NON-NLS-1$
93 if (this.fields
!= null) {
94 event
.setFields(this.fields
.createDefinition(event
, "fields")); //$NON-NLS-1$
101 * Creates a "lost" event. This is a synthetic event that is there to show
102 * that there should be something there.
104 * @return the lost event
106 public static synchronized EventDeclaration
getLostEventDeclaration() {
107 EventDeclaration lostEvent
= new EventDeclaration();
108 lostEvent
.fields
= new StructDeclaration(1);
109 lostEvent
.id
= LOST_EVENT_ID
;
110 lostEvent
.name
= "Lost event"; //$NON-NLS-1$
114 // ------------------------------------------------------------------------
115 // Getters/Setters/Predicates
116 // ------------------------------------------------------------------------
119 * Sets a name for an event Declaration
124 public void setName(String name
) {
129 public String
getName() {
134 * Sets the context for an event declaration (see CTF specification)
137 * the context in structdeclaration format
139 public void setContext(StructDeclaration context
) {
140 this.context
= context
;
144 * Sets the fields of an event declaration
147 * the fields in structdeclaration format
149 public void setFields(StructDeclaration fields
) {
150 this.fields
= fields
;
154 public StructDeclaration
getFields() {
159 public StructDeclaration
getContext() {
164 * Sets the id of am event declaration
169 public void setId(long id
) {
174 public Long
getId() {
179 * Sets the stream of am event declaration
185 public void setStream(Stream stream
) {
186 this.stream
= stream
;
190 public Stream
getStream() {
195 * Is the name of the event declaration set
197 * @return is the name set?
199 public boolean nameIsSet() {
206 * @return is the context set
208 public boolean contextIsSet() {
209 return context
!= null;
215 * @return Is the field set?
217 public boolean fieldsIsSet() {
218 return fields
!= null;
224 * @return is the id set?
226 public boolean idIsSet() {
227 return (id
!= null && id
!= UNSET_EVENT_ID
);
233 * @return is the stream set?
235 public boolean streamIsSet() {
236 return stream
!= null;
240 public long getLogLevel() {
250 public void setLogLevel(long level
) {
255 public Set
<String
> getCustomAttributes() {
256 return customAttributes
.keySet();
260 public String
getCustomAttribute(String key
) {
261 return customAttributes
.get(key
);
265 * Sets a custom attribute value.
268 * the key of the attribute
270 * the value of the attribute
273 public void setCustomAttribute(String key
, String value
) {
274 customAttributes
.put(key
, value
);
277 // ------------------------------------------------------------------------
279 // ------------------------------------------------------------------------
282 public boolean equals(Object obj
) {
289 if (!(obj
instanceof EventDeclaration
)) {
292 EventDeclaration other
= (EventDeclaration
) obj
;
293 if (context
== null) {
294 if (other
.context
!= null) {
297 } else if (!context
.equals(other
.context
)) {
300 if (fields
== null) {
301 if (other
.fields
!= null) {
304 } else if (!fields
.equals(other
.fields
)) {
308 if (other
.id
!= null) {
311 } else if (!id
.equals(other
.id
)) {
315 if (other
.name
!= null) {
318 } else if (!name
.equals(other
.name
)) {
321 if (stream
== null) {
322 if (other
.stream
!= null) {
325 } else if (!stream
.equals(other
.stream
)) {
328 if (!customAttributes
.equals(other
.customAttributes
)) {
335 public int hashCode() {
336 final int prime
= 31;
338 result
= (prime
* result
)
339 + ((context
== null) ?
0 : context
.hashCode());
340 result
= (prime
* result
) + ((fields
== null) ?
0 : fields
.hashCode());
341 result
= (prime
* result
) + ((id
== null) ?
0 : id
.hashCode());
342 result
= (prime
* result
) + ((name
== null) ?
0 : name
.hashCode());
343 result
= (prime
* result
) + ((stream
== null) ?
0 : stream
.hashCode());
344 result
= (prime
* result
) + customAttributes
.hashCode();