Commit | Line | Data |
---|---|---|
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 | ||
13 | package org.eclipse.linuxtools.ctf.core.event; | |
14 | ||
15 | import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; | |
866e5b51 | 16 | import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader; |
ce2388e0 | 17 | import org.eclipse.linuxtools.internal.ctf.core.trace.Stream; |
866e5b51 FC |
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 | ||
53047a66 MK |
55 | /** |
56 | * Loglevel of an event | |
57 | */ | |
58 | private long logLevel; | |
59 | ||
33656d8e MK |
60 | /** |
61 | * | |
62 | */ | |
63 | static private EventDeclaration lostEvent = null; | |
866e5b51 FC |
64 | // ------------------------------------------------------------------------ |
65 | // Constructors | |
66 | // ------------------------------------------------------------------------ | |
67 | ||
68 | /** | |
69 | * Creates an instance of EventDefinition corresponding to this declaration. | |
70 | * | |
71 | * @param streamInputReader | |
72 | * The StreamInputReader for which this definition is created. | |
73 | * @return A new EventDefinition. | |
74 | */ | |
75 | public EventDefinition createDefinition(StreamInputReader streamInputReader) { | |
76 | EventDefinition event = new EventDefinition(this, streamInputReader); | |
77 | ||
78 | if (context != null) { | |
79 | event.context = context.createDefinition(event, "context"); //$NON-NLS-1$ | |
80 | } | |
81 | ||
82 | if (this.fields != null) { | |
83 | event.fields = this.fields.createDefinition(event, "fields"); //$NON-NLS-1$ | |
84 | } | |
85 | ||
86 | return event; | |
87 | } | |
88 | ||
33656d8e MK |
89 | /** |
90 | * Creates a "lost" event. This is a synthetic event that is there to show | |
91 | * that there should be something there. | |
92 | * @return | |
93 | */ | |
94 | public static EventDeclaration getLostEventDeclaration(){ | |
95 | if(lostEvent == null) { | |
96 | lostEvent = new EventDeclaration(); | |
97 | lostEvent.fields = new StructDeclaration(1); | |
98 | lostEvent.id = (long) -1; | |
99 | lostEvent.name = "Lost event"; //$NON-NLS-1$ | |
100 | } | |
101 | return lostEvent; | |
102 | } | |
103 | ||
866e5b51 FC |
104 | // ------------------------------------------------------------------------ |
105 | // Getters/Setters/Predicates | |
106 | // ------------------------------------------------------------------------ | |
107 | ||
108 | public void setName(String name) { | |
109 | this.name = name; | |
110 | } | |
111 | ||
112 | public String getName() { | |
113 | return name; | |
114 | } | |
115 | ||
116 | public void setContext(StructDeclaration context) { | |
117 | this.context = context; | |
118 | } | |
119 | ||
120 | public void setFields(StructDeclaration fields) { | |
121 | this.fields = fields; | |
122 | } | |
123 | ||
124 | public StructDeclaration getFields() { | |
125 | return fields; | |
126 | } | |
127 | ||
128 | public StructDeclaration getContext() { | |
129 | return context; | |
130 | } | |
131 | ||
132 | public void setId(long id) { | |
133 | this.id = id; | |
134 | } | |
135 | ||
136 | public Long getId() { | |
137 | return id; | |
138 | } | |
139 | ||
140 | public void setStream(Stream stream) { | |
141 | this.stream = stream; | |
142 | } | |
143 | ||
144 | public Stream getStream() { | |
145 | return stream; | |
146 | } | |
147 | ||
148 | public boolean nameIsSet() { | |
149 | return name != null; | |
150 | } | |
151 | ||
152 | public boolean contextIsSet() { | |
153 | return context != null; | |
154 | } | |
155 | ||
156 | public boolean fieldsIsSet() { | |
157 | return fields != null; | |
158 | } | |
159 | ||
160 | public boolean idIsSet() { | |
161 | return id != null; | |
162 | } | |
163 | ||
164 | public boolean streamIsSet() { | |
165 | return stream != null; | |
166 | } | |
167 | ||
53047a66 MK |
168 | public long getLogLevel() { |
169 | return logLevel; | |
170 | } | |
171 | ||
172 | public void setLogLevel( long level){ | |
173 | logLevel = level; | |
174 | } | |
175 | ||
866e5b51 FC |
176 | // ------------------------------------------------------------------------ |
177 | // Operations | |
178 | // ------------------------------------------------------------------------ | |
179 | ||
180 | @Override | |
181 | public boolean equals(Object obj) { | |
182 | if (this == obj) { | |
183 | return true; | |
184 | } | |
185 | if (obj == null) { | |
186 | return false; | |
187 | } | |
188 | if (!(obj instanceof EventDeclaration)) { | |
189 | return false; | |
190 | } | |
191 | EventDeclaration other = (EventDeclaration) obj; | |
192 | if (context == null) { | |
193 | if (other.context != null) { | |
194 | return false; | |
195 | } | |
196 | } else if (!context.equals(other.context)) { | |
197 | return false; | |
198 | } | |
199 | if (fields == null) { | |
200 | if (other.fields != null) { | |
201 | return false; | |
202 | } | |
203 | } else if (!fields.equals(other.fields)) { | |
204 | return false; | |
205 | } | |
206 | if (id == null) { | |
207 | if (other.id != null) { | |
208 | return false; | |
209 | } | |
210 | } else if (!id.equals(other.id)) { | |
211 | return false; | |
212 | } | |
213 | if (name == null) { | |
214 | if (other.name != null) { | |
215 | return false; | |
216 | } | |
217 | } else if (!name.equals(other.name)) { | |
218 | return false; | |
219 | } | |
220 | if (stream == null) { | |
221 | if (other.stream != null) { | |
222 | return false; | |
223 | } | |
224 | } else if (!stream.equals(other.stream)) { | |
225 | return false; | |
226 | } | |
227 | return true; | |
228 | } | |
229 | ||
230 | @Override | |
231 | public int hashCode() { | |
232 | final int prime = 31; | |
233 | int result = 1; | |
234 | result = (prime * result) | |
235 | + ((context == null) ? 0 : context.hashCode()); | |
236 | result = (prime * result) + ((fields == null) ? 0 : fields.hashCode()); | |
237 | result = (prime * result) + ((id == null) ? 0 : id.hashCode()); | |
238 | result = (prime * result) + ((name == null) ? 0 : name.hashCode()); | |
239 | result = (prime * result) + ((stream == null) ? 0 : stream.hashCode()); | |
240 | return result; | |
241 | } | |
242 | ||
243 | } |