Add update site information to features
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng / src / org / eclipse / linuxtools / lttng / event / LttngEvent.java
CommitLineData
5d10d135
ASL
1package org.eclipse.linuxtools.lttng.event;
2
a3fe52fc 3import org.eclipse.linuxtools.lttng.jni.JniEvent;
5d10d135 4import org.eclipse.linuxtools.tmf.event.TmfEvent;
3fbd810a 5import org.eclipse.linuxtools.tmf.event.TmfEventSource;
b7f0ec69 6import org.eclipse.linuxtools.tmf.trace.TmfTrace;
5d10d135
ASL
7
8/**
07d9e2ee
FC
9 * <b><u>LttngEvent</u></b><p>
10 *
11 * Lttng specific TmfEvent implementation.<p>
12 *
13 * The main difference from the basic Tmf implementation is that we keep an internal reference to the JniEvent<br>
14 * The conversion from this LttngEvent to the JniEvent is then possible.
5d10d135
ASL
15 */
16public class LttngEvent extends TmfEvent {
07d9e2ee 17
28b94d61 18 // Reference to the JNI JniEvent. Should only be used INTERNALLY
3fbd810a 19 private JniEvent jniEventReference = null;
b7f0ec69
WB
20
21 // Reference to the parent trace that own this event
22 private TmfTrace<LttngEvent> parentTrace = null;
23
5d10d135 24 /**
07d9e2ee 25 * Constructor with parameters.<p>
5d10d135
ASL
26 *
27 * @param timestamp The timestamp of this event
28 * @param source The source of this event
29 * @param type The type of this event
30 * @param content The content of this event
31 * @param reference The reference of this event
32 * @param lttEvent A reference to a valid JniEvent object
33 *
34 * @see org.eclipse.linuxtools.tmf.event.TmfTimestamp
07d9e2ee 35 * @see org.eclipse.linuxtools.tmf.event.TmfEventSource
5d10d135
ASL
36 * @see org.eclipse.linuxtools.lttng.event.LttngEventType
37 * @see org.eclipse.linuxtools.lttng.event.LttngEventContent
38 * @see org.eclipse.linuxtools.lttng.event.LttngEventReference
28b94d61 39 * @see org.eclipse.linuxtools.org.eclipse.linuxtools.lttng.jni.JniEvent
5d10d135 40 */
b7f0ec69 41 public LttngEvent(TmfTrace<LttngEvent> parent, LttngTimestamp timestamp, TmfEventSource source, LttngEventType type, LttngEventContent content, LttngEventReference reference, JniEvent lttEvent) {
28b94d61 42 super(timestamp, source, type, reference);
3fbd810a 43
28b94d61 44 fContent = content;
5d10d135 45 jniEventReference = lttEvent;
b7f0ec69 46 setParentTrace(parent);
5d10d135
ASL
47 }
48
3fbd810a 49 /**
07d9e2ee 50 * Copy constructor.<p>
3fbd810a 51 *
07d9e2ee 52 * @param oldEvent Event we want to copy from.
3fbd810a 53 */
a3fe52fc 54 public LttngEvent(LttngEvent oldEvent) {
b7f0ec69
WB
55 this(
56 oldEvent.getParentTrace(),
57 (LttngTimestamp)oldEvent.getTimestamp(),
3fbd810a
FC
58 (TmfEventSource)oldEvent.getSource(),
59 (LttngEventType)oldEvent.getType(),
60 (LttngEventContent)oldEvent.getContent(),
61 (LttngEventReference)oldEvent.getReference(),
62 oldEvent.jniEventReference
63 );
64 }
65
66
5d10d135 67 /**
f9673903 68 * Return the parent trace associated with this event
b7f0ec69
WB
69 *
70 * @return Parent trace
71 */
72 public TmfTrace<LttngEvent> getParentTrace() {
73 return parentTrace;
74 }
75
76 /**
77 * Set a new parent trace for this event
78 *
79 * @param parentTrace The new parent
80 */
81 public void setParentTrace(TmfTrace<LttngEvent> parentTrace) {
82 this.parentTrace = parentTrace;
83 }
84
85
86 /**
07d9e2ee 87 * Return the channel name of this event.<p>
5d10d135 88 *
28b94d61 89 * @return Channel (tracefile) for this event
5d10d135
ASL
90 */
91 public String getChannelName() {
28b94d61 92 return ( (LttngEventType)this.getType() ).getTracefileName();
5d10d135
ASL
93 }
94
95 /**
07d9e2ee 96 * Cpu id number of this event.<p>
5d10d135 97 *
a3fe52fc 98 * @return CpuId
5d10d135
ASL
99 */
100 public long getCpuId() {
28b94d61 101 return ( (LttngEventType)this.getType() ).getCpuId();
5d10d135
ASL
102 }
103
104 /**
07d9e2ee 105 * Marker name of this event.<p>
5d10d135 106 *
28b94d61 107 * @return Marker name
5d10d135
ASL
108 */
109 public String getMarkerName() {
28b94d61 110 return ( (LttngEventType)this.getType() ).getMarkerName();
5d10d135
ASL
111 }
112
b12f4544
FC
113 /**
114 * Marker id of this event.<p>
115 *
116 * @return Marker id
117 */
118 public int getMarkerId() {
119 return ( (LttngEventType)this.getType() ).getMarkerId();
120 }
121
28b94d61
FC
122 @Override
123 public LttngEventContent getContent() {
124 return (LttngEventContent)fContent;
125 }
126
127 public void setContent(LttngEventContent newContent) {
128 fContent = newContent;
129 }
130
131 @Override
132 public LttngEventType getType() {
133 return (LttngEventType)fType;
134 }
135
136 public void setType(LttngEventType newType) {
137 fType = newType;
138 }
139
b7f0ec69
WB
140 /**
141 * Set a new JniReference for this event.<p>
142 *
143 * Note : Reference is used to get back to the Jni during event parsing and need to be consistent.
144 *
145 * @param newJniEventReference New reference
146 *
147 * @see org.eclipse.linuxtools.org.eclipse.linuxtools.lttng.jni.JniEvent
148 */
47e81b11 149 public synchronized void updateJniEventReference(JniEvent newJniEventReference) {
b7f0ec69
WB
150 this.jniEventReference = newJniEventReference;
151 }
28b94d61 152
5d10d135 153 /**
07d9e2ee
FC
154 * Convert this event into a Jni JniEvent.<p>
155 *
156 * Note : Some verifications are done to make sure the event is still valid on
157 * the Jni side before conversion.<br> If it is not the case, null will be returned.
158 *
159 * @return The converted JniEvent
5d10d135 160 *
28b94d61 161 * @see org.eclipse.linuxtools.org.eclipse.linuxtools.lttng.jni.JniEvent
5d10d135 162 */
a55a769e 163 public synchronized JniEvent convertEventTmfToJni() {
5d10d135
ASL
164 JniEvent tmpEvent = null;
165
28b94d61
FC
166 // ***TODO***
167 // Should we remove the check to save some time??
168
5d10d135
ASL
169 // We don't want to send away events that are outdated as their informations could be invalid
170 // If the timestamp between the event and the trace are not coherent we will not perform the conversion
a55a769e
WB
171 if ( jniEventReference.getParentTracefile().getParentTrace().getCurrentEventTimestamp().getTime() == getTimestamp().getValue() ) {
172 tmpEvent = jniEventReference;
173 }
174 else {
9c4eb5f7 175 System.out.println("convertEventTmfToJni() failed: Unsynced Timestamp > TMF:" + getTimestamp().getValue() + " <--> JNI:" + jniEventReference.getParentTracefile().getParentTrace().getCurrentEventTimestamp().getTime()); //$NON-NLS-1$//$NON-NLS-2$
a55a769e 176 }
5d10d135
ASL
177 return tmpEvent;
178 }
3fbd810a
FC
179
180 @Override
3b38ea61 181 @SuppressWarnings("nls")
3fbd810a 182 public String toString() {
550d787e
FC
183 StringBuffer result= new StringBuffer("[LttngEvent(");
184 result.append("Timestamp:" + getTimestamp().getValue());
185 result.append(",Channel:" + getChannelName());
186 result.append(",CPU:" + getCpuId());
187 result.append(",Marker:" + getMarkerName());
188 result.append(",Content:" + getContent() + ")]");
3fbd810a 189
550d787e 190 return result.toString();
3fbd810a 191 }
f9673903
FC
192
193 @Override
194 public LttngEvent clone() {
1a971e96
FC
195 LttngEvent clone = (LttngEvent) super.clone();
196 clone.getContent().setEvent(clone);
197 clone.parentTrace = parentTrace;
198 clone.jniEventReference = jniEventReference;
199 return clone;
f9673903 200 }
1a971e96 201
5d10d135 202}
This page took 0.038399 seconds and 5 git commands to generate.