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