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