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 // ------------------------------------------------------------------------
33 // ------------------------------------------------------------------------
41 * Event context structure declaration
43 private StructDeclaration context
= null;
46 * Event fields structure declaration
48 private StructDeclaration fields
= null;
51 * Event id (can be null if only event in the stream).
53 private Long id
= null;
56 * Stream to which belongs this event.
58 private Stream stream
= null;
61 * Loglevel of an event
63 private long logLevel
;
65 /** Map of this event type's custom CTF attributes */
66 private final Map
<String
, String
> customAttributes
= new HashMap
<String
, String
>();
68 // ------------------------------------------------------------------------
70 // ------------------------------------------------------------------------
73 * Default constructor. Use the setters afterwards to set the fields
76 public EventDeclaration() {
80 public EventDefinition
createDefinition(StreamInputReader streamInputReader
) {
81 EventDefinition event
= new EventDefinition(this, streamInputReader
);
83 if (context
!= null) {
84 event
.setContext(context
.createDefinition(event
, "context")); //$NON-NLS-1$
87 if (this.fields
!= null) {
88 event
.setFields(this.fields
.createDefinition(event
, "fields")); //$NON-NLS-1$
95 * Creates a "lost" event. This is a synthetic event that is there to show
96 * that there should be something there.
98 * @return the lost event
100 public static synchronized EventDeclaration
getLostEventDeclaration() {
101 EventDeclaration lostEvent
= new EventDeclaration();
102 lostEvent
.fields
= new StructDeclaration(1);
104 lostEvent
.name
= "Lost event"; //$NON-NLS-1$
108 // ------------------------------------------------------------------------
109 // Getters/Setters/Predicates
110 // ------------------------------------------------------------------------
113 * Sets a name for an event Declaration
118 public void setName(String name
) {
123 public String
getName() {
128 * Sets the context for an event declaration (see CTF specification)
131 * the context in structdeclaration format
133 public void setContext(StructDeclaration context
) {
134 this.context
= context
;
138 * Sets the fields of an event declaration
141 * the fields in structdeclaration format
143 public void setFields(StructDeclaration fields
) {
144 this.fields
= fields
;
148 public StructDeclaration
getFields() {
153 public StructDeclaration
getContext() {
158 * Sets the id of am event declaration
163 public void setId(long id
) {
168 public Long
getId() {
173 * Sets the stream of am event declaration
179 public void setStream(Stream stream
) {
180 this.stream
= stream
;
184 public Stream
getStream() {
189 * Is the name of the event declaration set
191 * @return is the name set?
193 public boolean nameIsSet() {
200 * @return is the context set
202 public boolean contextIsSet() {
203 return context
!= null;
209 * @return Is the field set?
211 public boolean fieldsIsSet() {
212 return fields
!= null;
218 * @return is the id set?
220 public boolean idIsSet() {
227 * @return is the stream set?
229 public boolean streamIsSet() {
230 return stream
!= null;
234 public long getLogLevel() {
244 public void setLogLevel(long level
) {
249 public Set
<String
> getCustomAttributes() {
250 return customAttributes
.keySet();
254 public String
getCustomAttribute(String key
) {
255 return customAttributes
.get(key
);
259 * Sets a custom attribute value.
262 * the key of the attribute
264 * the value of the attribute
267 public void setCustomAttribute(String key
, String value
) {
268 customAttributes
.put(key
, value
);
271 // ------------------------------------------------------------------------
273 // ------------------------------------------------------------------------
276 public boolean equals(Object obj
) {
283 if (!(obj
instanceof EventDeclaration
)) {
286 EventDeclaration other
= (EventDeclaration
) obj
;
287 if (context
== null) {
288 if (other
.context
!= null) {
291 } else if (!context
.equals(other
.context
)) {
294 if (fields
== null) {
295 if (other
.fields
!= null) {
298 } else if (!fields
.equals(other
.fields
)) {
302 if (other
.id
!= null) {
305 } else if (!id
.equals(other
.id
)) {
309 if (other
.name
!= null) {
312 } else if (!name
.equals(other
.name
)) {
315 if (stream
== null) {
316 if (other
.stream
!= null) {
319 } else if (!stream
.equals(other
.stream
)) {
322 if (!customAttributes
.equals(other
.customAttributes
)) {
329 public int hashCode() {
330 final int prime
= 31;
332 result
= (prime
* result
)
333 + ((context
== null) ?
0 : context
.hashCode());
334 result
= (prime
* result
) + ((fields
== null) ?
0 : fields
.hashCode());
335 result
= (prime
* result
) + ((id
== null) ?
0 : id
.hashCode());
336 result
= (prime
* result
) + ((name
== null) ?
0 : name
.hashCode());
337 result
= (prime
* result
) + ((stream
== null) ?
0 : stream
.hashCode());
338 result
= (prime
* result
) + customAttributes
.hashCode();