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.
90 public synchronized static EventDeclaration
getLostEventDeclaration(){
91 EventDeclaration lostEvent
= new EventDeclaration();
92 lostEvent
.fields
= new StructDeclaration(1);
93 lostEvent
.id
= (long) -1;
94 lostEvent
.name
= "Lost event"; //$NON-NLS-1$
98 // ------------------------------------------------------------------------
99 // Getters/Setters/Predicates
100 // ------------------------------------------------------------------------
102 public void setName(String name
) {
106 public String
getName() {
110 public void setContext(StructDeclaration context
) {
111 this.context
= context
;
114 public void setFields(StructDeclaration fields
) {
115 this.fields
= fields
;
118 public StructDeclaration
getFields() {
122 public StructDeclaration
getContext() {
126 public void setId(long id
) {
130 public Long
getId() {
134 public void setStream(Stream stream
) {
135 this.stream
= stream
;
138 public Stream
getStream() {
142 public boolean nameIsSet() {
146 public boolean contextIsSet() {
147 return context
!= null;
150 public boolean fieldsIsSet() {
151 return fields
!= null;
154 public boolean idIsSet() {
158 public boolean streamIsSet() {
159 return stream
!= null;
162 public long getLogLevel() {
166 public void setLogLevel( long level
){
170 // ------------------------------------------------------------------------
172 // ------------------------------------------------------------------------
175 public boolean equals(Object obj
) {
182 if (!(obj
instanceof EventDeclaration
)) {
185 EventDeclaration other
= (EventDeclaration
) obj
;
186 if (context
== null) {
187 if (other
.context
!= null) {
190 } else if (!context
.equals(other
.context
)) {
193 if (fields
== null) {
194 if (other
.fields
!= null) {
197 } else if (!fields
.equals(other
.fields
)) {
201 if (other
.id
!= null) {
204 } else if (!id
.equals(other
.id
)) {
208 if (other
.name
!= null) {
211 } else if (!name
.equals(other
.name
)) {
214 if (stream
== null) {
215 if (other
.stream
!= null) {
218 } else if (!stream
.equals(other
.stream
)) {
225 public int hashCode() {
226 final int prime
= 31;
228 result
= (prime
* result
)
229 + ((context
== null) ?
0 : context
.hashCode());
230 result
= (prime
* result
) + ((fields
== null) ?
0 : fields
.hashCode());
231 result
= (prime
* result
) + ((id
== null) ?
0 : id
.hashCode());
232 result
= (prime
* result
) + ((name
== null) ?
0 : name
.hashCode());
233 result
= (prime
* result
) + ((stream
== null) ?
0 : stream
.hashCode());