Rename xxx.lttng to xxx.lttng.core
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf / src / org / eclipse / linuxtools / tmf / event / TmfEvent.java
1 /*******************************************************************************
2 * Copyright (c) 2009 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made 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:
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.event;
14
15 import org.eclipse.linuxtools.tmf.trace.ITmfTrace;
16
17 /**
18 * <b><u>TmfEvent</u></b>
19 * <p>
20 * The basic event structure in the TMF. In its canonical form, an event has:
21 * <ul>
22 * <li> a normalized timestamp
23 * <li> a source (reporter)
24 * <li> a type
25 * <li> a content
26 * </ul>
27 * For convenience, a free-form reference field is also provided. It could be
28 * used as e.g. a location marker in the event stream to distinguish between
29 * otherwise identical events.
30 *
31 * Notice that for performance reasons TmfEvent is NOT immutable. If a copy
32 * of the event is needed, use the copy constructor.
33 */
34 public class TmfEvent extends TmfData implements Cloneable {
35
36 // ------------------------------------------------------------------------
37 // Constants
38 // ------------------------------------------------------------------------
39
40 public static final TmfEvent NullEvent = new TmfEvent();
41
42 // ------------------------------------------------------------------------
43 // Attributes
44 // ------------------------------------------------------------------------
45
46 protected ITmfTrace<?> fParentTrace;
47 protected long fEventRank;
48 protected TmfTimestamp fEffectiveTimestamp;
49 protected TmfTimestamp fOriginalTimestamp;
50 protected TmfEventSource fSource;
51 protected TmfEventType fType;
52 protected TmfEventReference fReference;
53
54 // Content requires a reference to the parent event so it is initialized
55 // using setContent()
56 protected TmfEventContent fContent;
57
58 // ------------------------------------------------------------------------
59 // Constructors
60 // ------------------------------------------------------------------------
61
62 /**
63 * @param trace the parent trace
64 * @param originalTS the original timestamp
65 * @param effectiveTS the effective timestamp
66 * @param source the event source (generator)
67 * @param type the event type
68 * @param reference a free-form reference field
69 */
70 public TmfEvent(ITmfTrace<?> trace, long rank, TmfTimestamp originalTS, TmfTimestamp effectiveTS,
71 TmfEventSource source, TmfEventType type, TmfEventReference reference)
72 {
73 fParentTrace = trace;
74 fEventRank = rank;
75 fOriginalTimestamp = originalTS;
76 fEffectiveTimestamp = effectiveTS;
77 fSource = source;
78 fType = type;
79 fReference = reference;
80 }
81
82 /**
83 * @param originalTS the original timestamp
84 * @param effectiveTS the effective timestamp
85 * @param source the event source (generator)
86 * @param type the event type
87 * @param reference a free-form reference field
88 */
89 public TmfEvent(TmfTimestamp originalTS, TmfTimestamp effectiveTS,
90 TmfEventSource source, TmfEventType type, TmfEventReference reference)
91 {
92 this(null, -1, originalTS, effectiveTS, source, type, reference);
93 }
94
95 /**
96 * @param trace the parent trace
97 * @param timestamp the effective timestamp
98 * @param source the event source (generator)
99 * @param type the event type
100 * @param reference a free-form reference field
101 */
102 public TmfEvent(ITmfTrace<?> parentTrace, TmfTimestamp timestamp, TmfEventSource source,
103 TmfEventType type, TmfEventReference reference)
104 {
105 this(parentTrace, -1, timestamp, timestamp, source, type, reference);
106 }
107
108 /**
109 * @param timestamp the effective timestamp
110 * @param source the event source (generator)
111 * @param type the event type
112 * @param reference a free-form reference field
113 */
114 public TmfEvent(TmfTimestamp timestamp, TmfEventSource source,
115 TmfEventType type, TmfEventReference reference)
116 {
117 this(null, -1, timestamp, timestamp, source, type, reference);
118 }
119
120 /**
121 * Copy constructor
122 *
123 * @param other the original event
124 */
125 public TmfEvent(TmfEvent other) {
126 if (other == null)
127 throw new IllegalArgumentException();
128 fParentTrace = other.fParentTrace;
129 fEventRank = other.fEventRank;
130 fOriginalTimestamp = new TmfTimestamp(other.fOriginalTimestamp);
131 fEffectiveTimestamp = new TmfTimestamp(other.fEffectiveTimestamp);
132 fSource = new TmfEventSource(other.fSource);
133 fType = new TmfEventType(other.fType);
134 fContent = new TmfEventContent(other.fContent);
135 fReference = new TmfEventReference(other.fReference);
136 }
137
138 public TmfEvent() {
139 }
140
141 @Override
142 public boolean isNullRef() {
143 return this == NullEvent;
144 }
145
146 // ------------------------------------------------------------------------
147 // Accessors
148 // ------------------------------------------------------------------------
149
150 /**
151 * @return the parent trace
152 */
153 public ITmfTrace<?> getParentTrace() {
154 return fParentTrace;
155 }
156
157 /**
158 * @return the event rank
159 */
160 public long getEventRank() {
161 return fEventRank;
162 }
163
164 /**
165 * @return the effective event timestamp
166 */
167 public TmfTimestamp getTimestamp() {
168 return fEffectiveTimestamp;
169 }
170
171 /**
172 * @return the original event timestamp
173 */
174 public TmfTimestamp getOriginalTimestamp() {
175 return fOriginalTimestamp;
176 }
177
178 /**
179 * @return the event source
180 */
181 public TmfEventSource getSource() {
182 return fSource;
183 }
184
185 /**
186 * @return the event type
187 */
188 public TmfEventType getType() {
189 return fType;
190 }
191
192 /**
193 * @return the event content
194 */
195 public TmfEventContent getContent() {
196 return fContent;
197 }
198
199 /**
200 * @return the event reference
201 */
202 public TmfEventReference getReference() {
203 return fReference;
204 }
205
206 /**
207 * @param content
208 * the new event content
209 */
210 public void setContent(TmfEventContent content) {
211 fContent = content;
212 }
213
214 /**
215 * @return the event raw text
216 */
217 public String getRawText() {
218 if (fContent != null && fContent.getContent() != null) {
219 return fContent.getContent().toString();
220 }
221 return ""; //$NON-NLS-1$
222 }
223
224 // ------------------------------------------------------------------------
225 // Object
226 // ------------------------------------------------------------------------
227
228 @Override
229 public int hashCode() {
230 int result = 17;
231 result = 37 * result + fSource.hashCode();
232 result = 37 * result + fType.hashCode();
233 result = 37 * result + fEffectiveTimestamp.hashCode();
234 return result;
235 }
236
237 @Override
238 public boolean equals(Object other) {
239 if (!(other instanceof TmfEvent))
240 return false;
241 TmfEvent o = (TmfEvent) other;
242 return fEffectiveTimestamp.equals(o.fEffectiveTimestamp) && fSource.equals(o.fSource) && fType.equals(o.fType) && fContent.equals(o.fContent);
243 }
244
245 @Override
246 @SuppressWarnings("nls")
247 public String toString() {
248 return "[TmfEvent(" + fEffectiveTimestamp + "," + fSource + "," + fType + "," + fContent + ")]";
249 }
250
251 @Override
252 public TmfEvent clone() {
253 TmfEvent clone = null;
254 try {
255 clone = (TmfEvent) super.clone();
256 clone.fParentTrace = fParentTrace;
257 clone.fEventRank = fEventRank;
258 clone.fOriginalTimestamp = fOriginalTimestamp.clone();
259 clone.fEffectiveTimestamp = fEffectiveTimestamp.clone();
260 clone.fSource = fSource.clone();
261 clone.fType = fType.clone();
262 clone.fReference = fReference.clone();
263 clone.fContent = fContent.clone();
264 }
265 catch (CloneNotSupportedException e) {
266 e.printStackTrace();
267 }
268
269 return clone;
270 }
271
272 }
This page took 0.036085 seconds and 5 git commands to generate.