Commit | Line | Data |
---|---|---|
5945cec9 | 1 | package org.eclipse.linuxtools.internal.lttng.core.event; |
5d10d135 | 2 | |
a3fe52fc | 3 | import org.eclipse.linuxtools.lttng.jni.JniEvent; |
6c13869b | 4 | import org.eclipse.linuxtools.tmf.core.event.TmfEvent; |
6c13869b | 5 | import org.eclipse.linuxtools.tmf.core.trace.TmfTrace; |
5d10d135 ASL |
6 | |
7 | /** | |
12c155f5 FC |
8 | * <b><u>LttngEvent</u></b> |
9 | * <p> | |
10 | * Lttng specific TmfEvent implementation. | |
11 | * <p> | |
12 | * The main difference from the basic Tmf implementation is that we keep an | |
13 | * internal reference to the JniEvent | |
14 | * <p> | |
07d9e2ee | 15 | * The conversion from this LttngEvent to the JniEvent is then possible. |
5d10d135 ASL |
16 | */ |
17 | public class LttngEvent extends TmfEvent { | |
12c155f5 | 18 | |
28b94d61 | 19 | // Reference to the JNI JniEvent. Should only be used INTERNALLY |
3fbd810a | 20 | private JniEvent jniEventReference = null; |
b7f0ec69 | 21 | |
12c155f5 FC |
22 | // Parameter-less constructor |
23 | public LttngEvent() { | |
24 | super(); | |
7b477cc3 | 25 | super.setType(LttngEventType.DEFAULT_EVENT_TYPE); |
12c155f5 FC |
26 | } |
27 | ||
5d10d135 | 28 | /** |
12c155f5 FC |
29 | * Constructor with parameters. |
30 | * <p> | |
5d10d135 | 31 | * |
12c155f5 FC |
32 | * @param timestamp The timestamp of this event |
33 | * @param source The source of this event | |
34 | * @param type The type of this event | |
35 | * @param content The content of this event | |
36 | * @param reference The reference of this event | |
37 | * @param lttEvent A reference to a valid JniEvent object | |
5d10d135 | 38 | * |
6c13869b FC |
39 | * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp |
40 | * @see org.eclipse.linuxtools.tmf.core.event.TmfEventSource | |
5945cec9 FC |
41 | * @see org.eclipse.linuxtools.internal.lttng.core.event.LttngEventType |
42 | * @see org.eclipse.linuxtools.internal.lttng.core.event.LttngEventContent | |
6c13869b | 43 | * @see org.eclipse.linuxtools.lttng.core.event.LttngEventReference |
28b94d61 | 44 | * @see org.eclipse.linuxtools.org.eclipse.linuxtools.lttng.jni.JniEvent |
5d10d135 | 45 | */ |
99005796 | 46 | public LttngEvent(TmfTrace<LttngEvent> parent, LttngTimestamp timestamp, String source, LttngEventType type, LttngEventContent content, |
4641c2f7 FC |
47 | String reference, JniEvent lttEvent) |
48 | { | |
f7703ed6 | 49 | super(parent, timestamp, source, type, content, reference); |
5d10d135 | 50 | jniEventReference = lttEvent; |
7b477cc3 | 51 | super.setTrace(parent); |
5d10d135 | 52 | } |
12c155f5 | 53 | |
3fbd810a | 54 | /** |
12c155f5 FC |
55 | * Copy constructor. |
56 | * <p> | |
3fbd810a | 57 | * |
12c155f5 | 58 | * @param oldEvent Event we want to copy from. |
3fbd810a | 59 | */ |
2c8610f7 | 60 | @SuppressWarnings("unchecked") |
a3fe52fc | 61 | public LttngEvent(LttngEvent oldEvent) { |
b7f0ec69 | 62 | this( |
ce970a71 | 63 | (TmfTrace<LttngEvent>) oldEvent.getTrace(), |
b7f0ec69 | 64 | (LttngTimestamp)oldEvent.getTimestamp(), |
99005796 | 65 | oldEvent.getSource(), |
3fbd810a FC |
66 | (LttngEventType)oldEvent.getType(), |
67 | (LttngEventContent)oldEvent.getContent(), | |
4641c2f7 | 68 | oldEvent.getReference(), |
3fbd810a FC |
69 | oldEvent.jniEventReference |
70 | ); | |
71 | } | |
b7f0ec69 WB |
72 | /** |
73 | * Set a new parent trace for this event | |
74 | * | |
12c155f5 | 75 | * @param parentTrace The new parent |
b7f0ec69 WB |
76 | */ |
77 | public void setParentTrace(TmfTrace<LttngEvent> parentTrace) { | |
7b477cc3 | 78 | super.setTrace(parentTrace); |
b7f0ec69 WB |
79 | } |
80 | ||
81 | ||
82 | /** | |
07d9e2ee | 83 | * Return the channel name of this event.<p> |
5d10d135 | 84 | * |
28b94d61 | 85 | * @return Channel (tracefile) for this event |
5d10d135 ASL |
86 | */ |
87 | public String getChannelName() { | |
12c155f5 | 88 | return this.getType().getTracefileName(); |
5d10d135 | 89 | } |
12c155f5 | 90 | |
5d10d135 | 91 | /** |
12c155f5 FC |
92 | * Cpu id number of this event. |
93 | * <p> | |
5d10d135 | 94 | * |
a3fe52fc | 95 | * @return CpuId |
5d10d135 ASL |
96 | */ |
97 | public long getCpuId() { | |
12c155f5 | 98 | return this.getType().getCpuId(); |
5d10d135 | 99 | } |
12c155f5 | 100 | |
5d10d135 | 101 | /** |
12c155f5 FC |
102 | * Marker name of this event. |
103 | * <p> | |
5d10d135 | 104 | * |
28b94d61 | 105 | * @return Marker name |
5d10d135 ASL |
106 | */ |
107 | public String getMarkerName() { | |
12c155f5 | 108 | return this.getType().getMarkerName(); |
5d10d135 | 109 | } |
12c155f5 | 110 | |
b12f4544 | 111 | /** |
12c155f5 FC |
112 | * Marker id of this event. |
113 | * <p> | |
b12f4544 FC |
114 | * |
115 | * @return Marker id | |
116 | */ | |
117 | public int getMarkerId() { | |
12c155f5 | 118 | return this.getType().getMarkerId(); |
b12f4544 | 119 | } |
12c155f5 | 120 | |
28b94d61 FC |
121 | @Override |
122 | public LttngEventContent getContent() { | |
7b477cc3 | 123 | return (LttngEventContent) super.getContent(); |
28b94d61 | 124 | } |
12c155f5 | 125 | |
28b94d61 | 126 | public void setContent(LttngEventContent newContent) { |
7b477cc3 | 127 | super.setContent(newContent); |
28b94d61 | 128 | } |
12c155f5 | 129 | |
f4c52cea | 130 | @Override |
4641c2f7 | 131 | public void setReference(String reference) { |
7b477cc3 | 132 | super.setReference(reference); |
4641c2f7 FC |
133 | } |
134 | ||
28b94d61 FC |
135 | @Override |
136 | public LttngEventType getType() { | |
7b477cc3 | 137 | return (LttngEventType) super.getType(); |
28b94d61 | 138 | } |
12c155f5 | 139 | |
28b94d61 | 140 | public void setType(LttngEventType newType) { |
7b477cc3 | 141 | super.setType(newType); |
28b94d61 | 142 | } |
12c155f5 | 143 | |
b7f0ec69 | 144 | /** |
12c155f5 FC |
145 | * Set a new JniReference for this event. |
146 | * <p> | |
b7f0ec69 | 147 | * |
12c155f5 FC |
148 | * Note : Reference is used to get back to the Jni during event parsing and |
149 | * need to be consistent. | |
b7f0ec69 | 150 | * |
12c155f5 | 151 | * @param newJniEventReference New reference |
b7f0ec69 WB |
152 | * |
153 | * @see org.eclipse.linuxtools.org.eclipse.linuxtools.lttng.jni.JniEvent | |
154 | */ | |
47e81b11 | 155 | public synchronized void updateJniEventReference(JniEvent newJniEventReference) { |
b7f0ec69 WB |
156 | this.jniEventReference = newJniEventReference; |
157 | } | |
12c155f5 | 158 | |
5d10d135 | 159 | /** |
12c155f5 FC |
160 | * Convert this event into a Jni JniEvent. |
161 | * <p> | |
07d9e2ee | 162 | * |
12c155f5 FC |
163 | * Note : Some verifications are done to make sure the event is still valid |
164 | * on the Jni side before conversion.<br> | |
165 | * If it is not the case, null will be returned. | |
07d9e2ee FC |
166 | * |
167 | * @return The converted JniEvent | |
5d10d135 | 168 | * |
28b94d61 | 169 | * @see org.eclipse.linuxtools.org.eclipse.linuxtools.lttng.jni.JniEvent |
5d10d135 | 170 | */ |
a55a769e | 171 | public synchronized JniEvent convertEventTmfToJni() { |
5d10d135 | 172 | JniEvent tmpEvent = null; |
12c155f5 | 173 | |
28b94d61 FC |
174 | // ***TODO*** |
175 | // Should we remove the check to save some time?? | |
12c155f5 FC |
176 | |
177 | // We don't want to send away events that are outdated as their | |
178 | // informations could be invalid | |
179 | // If the timestamp between the event and the trace are not coherent we | |
180 | // will not perform the conversion | |
181 | if (jniEventReference.getParentTracefile().getParentTrace().getCurrentEventTimestamp().getTime() == getTimestamp().getValue()) { | |
a55a769e | 182 | tmpEvent = jniEventReference; |
12c155f5 FC |
183 | } else { |
184 | System.out | |
185 | .println("convertEventTmfToJni() failed: Unsynced Timestamp > TMF:" + getTimestamp().getValue() + " <--> JNI:" + jniEventReference.getParentTracefile().getParentTrace().getCurrentEventTimestamp().getTime()); //$NON-NLS-1$//$NON-NLS-2$ | |
a55a769e | 186 | } |
5d10d135 ASL |
187 | return tmpEvent; |
188 | } | |
12c155f5 | 189 | |
3fbd810a | 190 | @Override |
3b38ea61 | 191 | @SuppressWarnings("nls") |
12c155f5 FC |
192 | public String toString() { |
193 | StringBuffer result = new StringBuffer("[LttngEvent("); | |
194 | result.append("Timestamp:" + getTimestamp().getValue()); | |
195 | result.append(",Channel:" + getChannelName()); | |
196 | result.append(",CPU:" + getCpuId()); | |
197 | result.append(",Marker:" + getMarkerName()); | |
198 | result.append(",Content:" + getContent() + ")]"); | |
199 | ||
200 | return result.toString(); | |
3fbd810a | 201 | } |
12c155f5 | 202 | |
f9673903 FC |
203 | @Override |
204 | public LttngEvent clone() { | |
1a971e96 FC |
205 | LttngEvent clone = (LttngEvent) super.clone(); |
206 | clone.getContent().setEvent(clone); | |
1a971e96 FC |
207 | clone.jniEventReference = jniEventReference; |
208 | return clone; | |
f9673903 | 209 | } |
1a971e96 | 210 | |
212550ba FC |
211 | /* (non-Javadoc) |
212 | * @see java.lang.Object#hashCode() | |
213 | */ | |
214 | @Override | |
215 | public synchronized int hashCode() { | |
216 | final int prime = 31; | |
217 | int result = super.hashCode(); | |
218 | result = prime * result + ((jniEventReference == null) ? 0 : jniEventReference.hashCode()); | |
219 | return result; | |
220 | } | |
221 | ||
222 | /* (non-Javadoc) | |
223 | * @see java.lang.Object#equals(java.lang.Object) | |
224 | */ | |
225 | @Override | |
226 | public synchronized boolean equals(Object obj) { | |
227 | if (this == obj) { | |
228 | return true; | |
229 | } | |
230 | if (!super.equals(obj)) { | |
231 | return false; | |
232 | } | |
233 | if (!(obj instanceof LttngEvent)) { | |
234 | return false; | |
235 | } | |
236 | LttngEvent other = (LttngEvent) obj; | |
237 | if (jniEventReference == null) { | |
238 | if (other.jniEventReference != null) { | |
239 | return false; | |
240 | } | |
241 | } else if (!jniEventReference.equals(other.jniEventReference)) { | |
242 | return false; | |
243 | } | |
244 | return true; | |
245 | } | |
246 | ||
5d10d135 | 247 | } |