3f45e0c3eb6105f242f805dc02cec95ea98e5eef
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core / src / org / eclipse / linuxtools / ctf / core / event / EventDeclaration.java
1 /*******************************************************************************
2 * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others
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
13 package org.eclipse.linuxtools.ctf.core.event;
14
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;
18
19 /**
20 * <b><u>EventDeclaration</u></b>
21 * <p>
22 * Represents one type of event.
23 */
24 public class EventDeclaration {
25
26 // ------------------------------------------------------------------------
27 // Attributes
28 // ------------------------------------------------------------------------
29
30 /**
31 * Name of the event
32 */
33 private String name;
34
35 /**
36 * Event context structure declaration
37 */
38 private StructDeclaration context = null;
39
40 /**
41 * Event fields structure declaration
42 */
43 private StructDeclaration fields = null;
44
45 /**
46 * Event id (can be null if only event in the stream).
47 */
48 private Long id = null;
49
50 /**
51 * Stream to which belongs this event.
52 */
53 private Stream stream = null;
54
55 /**
56 * Loglevel of an event
57 */
58 private long logLevel;
59
60 // ------------------------------------------------------------------------
61 // Constructors
62 // ------------------------------------------------------------------------
63
64 /**
65 * Creates an instance of EventDefinition corresponding to this declaration.
66 *
67 * @param streamInputReader
68 * The StreamInputReader for which this definition is created.
69 * @return A new EventDefinition.
70 */
71 public EventDefinition createDefinition(StreamInputReader streamInputReader) {
72 EventDefinition event = new EventDefinition(this, streamInputReader);
73
74 if (context != null) {
75 event.setContext( context.createDefinition(event, "context")); //$NON-NLS-1$
76 }
77
78 if (this.fields != null) {
79 event.setFields(this.fields.createDefinition(event, "fields")); //$NON-NLS-1$
80 }
81
82 return event;
83 }
84
85 /**
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
89 */
90 public synchronized static EventDeclaration getLostEventDeclaration(){
91 EventDeclaration lostEvent = new EventDeclaration();
92 lostEvent.fields = new StructDeclaration(1);
93 lostEvent.id = -1L;
94 lostEvent.name = "Lost event"; //$NON-NLS-1$
95 return lostEvent;
96 }
97
98 // ------------------------------------------------------------------------
99 // Getters/Setters/Predicates
100 // ------------------------------------------------------------------------
101
102 /**
103 * Sets a name for an event Declaration
104 * @param name the name
105 */
106 public void setName(String name) {
107 this.name = name;
108 }
109
110 /**
111 * Gets the name of en event declaration
112 * @return the name
113 */
114 public String getName() {
115 return name;
116 }
117
118 /**
119 * Sets the context for an event declaration (see CTF specification)
120 * @param context the context in structdeclaration format
121 */
122 public void setContext(StructDeclaration context) {
123 this.context = context;
124 }
125
126 /**
127 * Sets the fields of an event declaration
128 * @param fields the fields in structdeclaration format
129 */
130 public void setFields(StructDeclaration fields) {
131 this.fields = fields;
132 }
133
134 /**
135 * Gets the fields of an event declaration
136 * @return fields the fields in structdeclaration format
137 */
138 public StructDeclaration getFields() {
139 return fields;
140 }
141
142 /**
143 * Gets the context of an event declaration
144 * @return context the fields in structdeclaration format
145 */
146 public StructDeclaration getContext() {
147 return context;
148 }
149
150 /**
151 * Sets the id of am event declaration
152 * @param id the id
153 */
154 public void setId(long id) {
155 this.id = id;
156 }
157
158 /**
159 * Gets the id of am event declaration
160 * return id the id
161 */
162 public Long getId() {
163 return id;
164 }
165
166 /**
167 * Sets the stream of am event declaration
168 * @param stream the stream
169 */
170 public void setStream(Stream stream) {
171 this.stream = stream;
172 }
173
174 /**
175 * Gets the stream of am event declaration
176 * @return stream the stream
177 */
178 public Stream getStream() {
179 return stream;
180 }
181
182 /**
183 * Is the name of the event declaration set
184 * @return is the name set?
185 */
186 public boolean nameIsSet() {
187 return name != null;
188 }
189
190 /**
191 * Is the context set
192 * @return is the context set
193 */
194 public boolean contextIsSet() {
195 return context != null;
196 }
197
198 /**
199 * Is a field set?
200 * @return Is the field set?
201 */
202 public boolean fieldsIsSet() {
203 return fields != null;
204 }
205
206 /**
207 * Is the id set?
208 * @return is the id set?
209 */
210 public boolean idIsSet() {
211 return id != null;
212 }
213
214 /**
215 * Is the stream set?
216 * @return is the stream set?
217 */
218 public boolean streamIsSet() {
219 return stream != null;
220 }
221
222 /**
223 * What is the log level of this event
224 * @return the log level.
225 */
226 public long getLogLevel() {
227 return logLevel;
228 }
229
230 /**
231 * Sets the log level
232 * @param level the log level
233 */
234 public void setLogLevel( long level){
235 logLevel = level;
236 }
237
238 // ------------------------------------------------------------------------
239 // Operations
240 // ------------------------------------------------------------------------
241
242 @Override
243 public boolean equals(Object obj) {
244 if (this == obj) {
245 return true;
246 }
247 if (obj == null) {
248 return false;
249 }
250 if (!(obj instanceof EventDeclaration)) {
251 return false;
252 }
253 EventDeclaration other = (EventDeclaration) obj;
254 if (context == null) {
255 if (other.context != null) {
256 return false;
257 }
258 } else if (!context.equals(other.context)) {
259 return false;
260 }
261 if (fields == null) {
262 if (other.fields != null) {
263 return false;
264 }
265 } else if (!fields.equals(other.fields)) {
266 return false;
267 }
268 if (id == null) {
269 if (other.id != null) {
270 return false;
271 }
272 } else if (!id.equals(other.id)) {
273 return false;
274 }
275 if (name == null) {
276 if (other.name != null) {
277 return false;
278 }
279 } else if (!name.equals(other.name)) {
280 return false;
281 }
282 if (stream == null) {
283 if (other.stream != null) {
284 return false;
285 }
286 } else if (!stream.equals(other.stream)) {
287 return false;
288 }
289 return true;
290 }
291
292 @Override
293 public int hashCode() {
294 final int prime = 31;
295 int result = 1;
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());
302 return result;
303 }
304
305 }
This page took 0.044395 seconds and 5 git commands to generate.