Contribute CNF based TMF project handling
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng / 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 }
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.event.TmfTimestamp
40 * @see org.eclipse.linuxtools.tmf.event.TmfEventSource
41 * @see org.eclipse.linuxtools.lttng.event.LttngEventType
42 * @see org.eclipse.linuxtools.lttng.event.LttngEventContent
43 * @see org.eclipse.linuxtools.lttng.event.LttngEventReference
44 * @see org.eclipse.linuxtools.org.eclipse.linuxtools.lttng.jni.JniEvent
45 */
46 public LttngEvent(TmfTrace<LttngEvent> parent, LttngTimestamp timestamp, TmfEventSource source, LttngEventType type, LttngEventContent content,
47 LttngEventReference reference, JniEvent lttEvent) {
48 super(timestamp, source, type, reference);
49
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.getParentTrace(),
65 (LttngTimestamp)oldEvent.getTimestamp(),
66 (TmfEventSource)oldEvent.getSource(),
67 (LttngEventType)oldEvent.getType(),
68 (LttngEventContent)oldEvent.getContent(),
69 (LttngEventReference)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 fParentTrace = 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 @Override
132 public LttngEventType getType() {
133 return (LttngEventType) fType;
134 }
135
136 public void setType(LttngEventType newType) {
137 fType = newType;
138 }
139
140 /**
141 * Set a new JniReference for this event.
142 * <p>
143 *
144 * Note : Reference is used to get back to the Jni during event parsing and
145 * need to be consistent.
146 *
147 * @param newJniEventReference New reference
148 *
149 * @see org.eclipse.linuxtools.org.eclipse.linuxtools.lttng.jni.JniEvent
150 */
151 public synchronized void updateJniEventReference(JniEvent newJniEventReference) {
152 this.jniEventReference = newJniEventReference;
153 }
154
155 /**
156 * Convert this event into a Jni JniEvent.
157 * <p>
158 *
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.
162 *
163 * @return The converted JniEvent
164 *
165 * @see org.eclipse.linuxtools.org.eclipse.linuxtools.lttng.jni.JniEvent
166 */
167 public synchronized JniEvent convertEventTmfToJni() {
168 JniEvent tmpEvent = null;
169
170 // ***TODO***
171 // Should we remove the check to save some time??
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()) {
178 tmpEvent = jniEventReference;
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$
182 }
183 return tmpEvent;
184 }
185
186 @Override
187 @SuppressWarnings("nls")
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();
197 }
198
199 @Override
200 public LttngEvent clone() {
201 LttngEvent clone = (LttngEvent) super.clone();
202 clone.getContent().setEvent(clone);
203 clone.jniEventReference = jniEventReference;
204 return clone;
205 }
206
207 }
This page took 0.035232 seconds and 5 git commands to generate.