1 /*******************************************************************************
2 * Copyright (c) 2011-2012 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
.ctf
.core
.event
;
15 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StructDeclaration
;
16 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.StreamInputReader
;
17 import org
.eclipse
.linuxtools
.internal
.ctf
.core
.trace
.Stream
;
20 * <b><u>EventDeclaration</u></b>
22 * Represents one type of event.
24 public class EventDeclaration
{
26 // ------------------------------------------------------------------------
28 // ------------------------------------------------------------------------
36 * Event context structure declaration
38 private StructDeclaration context
= null;
41 * Event fields structure declaration
43 private StructDeclaration fields
= null;
46 * Event id (can be null if only event in the stream).
48 private Long id
= null;
51 * Stream to which belongs this event.
53 private Stream stream
= null;
56 * Loglevel of an event
58 private long logLevel
;
60 // ------------------------------------------------------------------------
62 // ------------------------------------------------------------------------
65 * Creates an instance of EventDefinition corresponding to this declaration.
67 * @param streamInputReader
68 * The StreamInputReader for which this definition is created.
69 * @return A new EventDefinition.
71 public EventDefinition
createDefinition(StreamInputReader streamInputReader
) {
72 EventDefinition event
= new EventDefinition(this, streamInputReader
);
74 if (context
!= null) {
75 event
.setContext( context
.createDefinition(event
, "context")); //$NON-NLS-1$
78 if (this.fields
!= null) {
79 event
.setFields(this.fields
.createDefinition(event
, "fields")); //$NON-NLS-1$
86 * Creates a "lost" event. This is a synthetic event that is there to show
87 * that there should be something there.
88 * @return the lost event
90 public synchronized static EventDeclaration
getLostEventDeclaration(){
91 EventDeclaration lostEvent
= new EventDeclaration();
92 lostEvent
.fields
= new StructDeclaration(1);
94 lostEvent
.name
= "Lost event"; //$NON-NLS-1$
98 // ------------------------------------------------------------------------
99 // Getters/Setters/Predicates
100 // ------------------------------------------------------------------------
103 * Sets a name for an event Declaration
104 * @param name the name
106 public void setName(String name
) {
111 * Gets the name of en event declaration
114 public String
getName() {
119 * Sets the context for an event declaration (see CTF specification)
120 * @param context the context in structdeclaration format
122 public void setContext(StructDeclaration context
) {
123 this.context
= context
;
127 * Sets the fields of an event declaration
128 * @param fields the fields in structdeclaration format
130 public void setFields(StructDeclaration fields
) {
131 this.fields
= fields
;
135 * Gets the fields of an event declaration
136 * @return fields the fields in structdeclaration format
138 public StructDeclaration
getFields() {
143 * Gets the context of an event declaration
144 * @return context the fields in structdeclaration format
146 public StructDeclaration
getContext() {
151 * Sets the id of am event declaration
154 public void setId(long id
) {
159 * Gets the id of am event declaration
162 public Long
getId() {
167 * Sets the stream of am event declaration
168 * @param stream the stream
170 public void setStream(Stream stream
) {
171 this.stream
= stream
;
175 * Gets the stream of am event declaration
176 * @return stream the stream
178 public Stream
getStream() {
183 * Is the name of the event declaration set
184 * @return is the name set?
186 public boolean nameIsSet() {
192 * @return is the context set
194 public boolean contextIsSet() {
195 return context
!= null;
200 * @return Is the field set?
202 public boolean fieldsIsSet() {
203 return fields
!= null;
208 * @return is the id set?
210 public boolean idIsSet() {
216 * @return is the stream set?
218 public boolean streamIsSet() {
219 return stream
!= null;
223 * What is the log level of this event
224 * @return the log level.
226 public long getLogLevel() {
232 * @param level the log level
234 public void setLogLevel( long level
){
238 // ------------------------------------------------------------------------
240 // ------------------------------------------------------------------------
243 public boolean equals(Object obj
) {
250 if (!(obj
instanceof EventDeclaration
)) {
253 EventDeclaration other
= (EventDeclaration
) obj
;
254 if (context
== null) {
255 if (other
.context
!= null) {
258 } else if (!context
.equals(other
.context
)) {
261 if (fields
== null) {
262 if (other
.fields
!= null) {
265 } else if (!fields
.equals(other
.fields
)) {
269 if (other
.id
!= null) {
272 } else if (!id
.equals(other
.id
)) {
276 if (other
.name
!= null) {
279 } else if (!name
.equals(other
.name
)) {
282 if (stream
== null) {
283 if (other
.stream
!= null) {
286 } else if (!stream
.equals(other
.stream
)) {
293 public int hashCode() {
294 final int prime
= 31;
296 result
= (prime
* result
)
297 + ((context
== null) ?
0 : context
.hashCode());
298 result
= (prime
* result
) + ((fields
== null) ?
0 : fields
.hashCode());
299 result
= (prime
* result
) + ((id
== null) ?
0 : id
.hashCode());
300 result
= (prime
* result
) + ((name
== null) ?
0 : name
.hashCode());
301 result
= (prime
* result
) + ((stream
== null) ?
0 : stream
.hashCode());