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