96c8b0be554250d90d0e438d9670fd72f786b806
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.core / src / org / eclipse / linuxtools / lttng / core / event / LttngEvent.java
1 package org.eclipse.linuxtools.lttng.core.event;
2
3 import org.eclipse.linuxtools.lttng.jni.JniEvent;
4 import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
5 import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
6
7 /**
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>
15 * The conversion from this LttngEvent to the JniEvent is then possible.
16 */
17 public class LttngEvent extends TmfEvent {
18
19 // Reference to the JNI JniEvent. Should only be used INTERNALLY
20 private JniEvent jniEventReference = null;
21
22 // Parameter-less constructor
23 public LttngEvent() {
24 super();
25 fType = LttngEventType.DEFAULT_EVENT_TYPE;
26 }
27
28 /**
29 * Constructor with parameters.
30 * <p>
31 *
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
38 *
39 * @see org.eclipse.linuxtools.tmf.core.event.TmfTimestamp
40 * @see org.eclipse.linuxtools.tmf.core.event.TmfEventSource
41 * @see org.eclipse.linuxtools.lttng.core.event.LttngEventType
42 * @see org.eclipse.linuxtools.lttng.core.event.LttngEventContent
43 * @see org.eclipse.linuxtools.lttng.core.event.LttngEventReference
44 * @see org.eclipse.linuxtools.org.eclipse.linuxtools.lttng.jni.JniEvent
45 */
46 public LttngEvent(TmfTrace<LttngEvent> parent, LttngTimestamp timestamp, String source, LttngEventType type, LttngEventContent content,
47 String reference, JniEvent lttEvent)
48 {
49 super(timestamp, source, type, reference);
50 fContent = content;
51 jniEventReference = lttEvent;
52 setParentTrace(parent);
53 }
54
55 /**
56 * Copy constructor.
57 * <p>
58 *
59 * @param oldEvent Event we want to copy from.
60 */
61 @SuppressWarnings("unchecked")
62 public LttngEvent(LttngEvent oldEvent) {
63 this(
64 (TmfTrace<LttngEvent>) oldEvent.getTrace(),
65 (LttngTimestamp)oldEvent.getTimestamp(),
66 oldEvent.getSource(),
67 (LttngEventType)oldEvent.getType(),
68 (LttngEventContent)oldEvent.getContent(),
69 oldEvent.getReference(),
70 oldEvent.jniEventReference
71 );
72 }
73 /**
74 * Set a new parent trace for this event
75 *
76 * @param parentTrace The new parent
77 */
78 public void setParentTrace(TmfTrace<LttngEvent> parentTrace) {
79 fTrace = parentTrace;
80 }
81
82
83 /**
84 * Return the channel name of this event.<p>
85 *
86 * @return Channel (tracefile) for this event
87 */
88 public String getChannelName() {
89 return this.getType().getTracefileName();
90 }
91
92 /**
93 * Cpu id number of this event.
94 * <p>
95 *
96 * @return CpuId
97 */
98 public long getCpuId() {
99 return this.getType().getCpuId();
100 }
101
102 /**
103 * Marker name of this event.
104 * <p>
105 *
106 * @return Marker name
107 */
108 public String getMarkerName() {
109 return this.getType().getMarkerName();
110 }
111
112 /**
113 * Marker id of this event.
114 * <p>
115 *
116 * @return Marker id
117 */
118 public int getMarkerId() {
119 return this.getType().getMarkerId();
120 }
121
122 @Override
123 public LttngEventContent getContent() {
124 return (LttngEventContent) fContent;
125 }
126
127 public void setContent(LttngEventContent newContent) {
128 fContent = newContent;
129 }
130
131 public void setReference(String reference) {
132 fReference = reference;
133 }
134
135 @Override
136 public LttngEventType getType() {
137 return (LttngEventType) fType;
138 }
139
140 public void setType(LttngEventType newType) {
141 fType = newType;
142 }
143
144 /**
145 * Set a new JniReference for this event.
146 * <p>
147 *
148 * Note : Reference is used to get back to the Jni during event parsing and
149 * need to be consistent.
150 *
151 * @param newJniEventReference New reference
152 *
153 * @see org.eclipse.linuxtools.org.eclipse.linuxtools.lttng.jni.JniEvent
154 */
155 public synchronized void updateJniEventReference(JniEvent newJniEventReference) {
156 this.jniEventReference = newJniEventReference;
157 }
158
159 /**
160 * Convert this event into a Jni JniEvent.
161 * <p>
162 *
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.
166 *
167 * @return The converted JniEvent
168 *
169 * @see org.eclipse.linuxtools.org.eclipse.linuxtools.lttng.jni.JniEvent
170 */
171 public synchronized JniEvent convertEventTmfToJni() {
172 JniEvent tmpEvent = null;
173
174 // ***TODO***
175 // Should we remove the check to save some time??
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()) {
182 tmpEvent = jniEventReference;
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$
186 }
187 return tmpEvent;
188 }
189
190 @Override
191 @SuppressWarnings("nls")
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();
201 }
202
203 @Override
204 public LttngEvent clone() {
205 LttngEvent clone = (LttngEvent) super.clone();
206 clone.getContent().setEvent(clone);
207 clone.jniEventReference = jniEventReference;
208 return clone;
209 }
210
211 }
This page took 0.033848 seconds and 5 git commands to generate.