Commit | Line | Data |
---|---|---|
5d10d135 ASL |
1 | package org.eclipse.linuxtools.lttng.event; |
2 | ||
5d10d135 | 3 | import org.eclipse.linuxtools.tmf.event.TmfEvent; |
3fbd810a | 4 | import org.eclipse.linuxtools.tmf.event.TmfEventSource; |
146a887c | 5 | import org.eclipse.linuxtools.tmf.event.TmfTimestamp; |
3fbd810a | 6 | import org.eclipse.linuxtools.lttng.LttngException; |
28b94d61 | 7 | import org.eclipse.linuxtools.lttng.jni.JniEvent; |
5d10d135 ASL |
8 | |
9 | /** | |
07d9e2ee FC |
10 | * <b><u>LttngEvent</u></b><p> |
11 | * | |
12 | * Lttng specific TmfEvent implementation.<p> | |
13 | * | |
14 | * The main difference from the basic Tmf implementation is that we keep an internal reference to the JniEvent<br> | |
15 | * The conversion from this LttngEvent to the JniEvent is then possible. | |
5d10d135 | 16 | */ |
146a887c | 17 | @SuppressWarnings("unused") |
5d10d135 | 18 | public class LttngEvent extends TmfEvent { |
07d9e2ee | 19 | |
28b94d61 | 20 | // Reference to the JNI JniEvent. Should only be used INTERNALLY |
3fbd810a | 21 | private JniEvent jniEventReference = null; |
28b94d61 | 22 | |
5d10d135 | 23 | /** |
07d9e2ee | 24 | * Constructor with parameters.<p> |
5d10d135 ASL |
25 | * |
26 | * @param timestamp The timestamp of this event | |
27 | * @param source The source of this event | |
28 | * @param type The type of this event | |
29 | * @param content The content of this event | |
30 | * @param reference The reference of this event | |
31 | * @param lttEvent A reference to a valid JniEvent object | |
32 | * | |
33 | * @see org.eclipse.linuxtools.tmf.event.TmfTimestamp | |
07d9e2ee | 34 | * @see org.eclipse.linuxtools.tmf.event.TmfEventSource |
5d10d135 ASL |
35 | * @see org.eclipse.linuxtools.lttng.event.LttngEventType |
36 | * @see org.eclipse.linuxtools.lttng.event.LttngEventContent | |
37 | * @see org.eclipse.linuxtools.lttng.event.LttngEventReference | |
28b94d61 | 38 | * @see org.eclipse.linuxtools.org.eclipse.linuxtools.lttng.jni.JniEvent |
5d10d135 | 39 | */ |
28b94d61 FC |
40 | public LttngEvent(LttngTimestamp timestamp, TmfEventSource source, LttngEventType type, LttngEventContent content, LttngEventReference reference, JniEvent lttEvent) { |
41 | super(timestamp, source, type, reference); | |
3fbd810a | 42 | |
28b94d61 | 43 | fContent = content; |
5d10d135 | 44 | jniEventReference = lttEvent; |
5d10d135 ASL |
45 | } |
46 | ||
3fbd810a | 47 | /** |
07d9e2ee | 48 | * Copy constructor.<p> |
3fbd810a | 49 | * |
07d9e2ee | 50 | * @param oldEvent Event we want to copy from. |
3fbd810a FC |
51 | * |
52 | */ | |
28b94d61 | 53 | public LttngEvent(LttngEvent oldEvent) { |
3fbd810a FC |
54 | this( (LttngTimestamp)oldEvent.getTimestamp(), |
55 | (TmfEventSource)oldEvent.getSource(), | |
56 | (LttngEventType)oldEvent.getType(), | |
57 | (LttngEventContent)oldEvent.getContent(), | |
58 | (LttngEventReference)oldEvent.getReference(), | |
59 | oldEvent.jniEventReference | |
60 | ); | |
61 | } | |
62 | ||
63 | ||
5d10d135 | 64 | /** |
07d9e2ee | 65 | * Return the channel name of this event.<p> |
5d10d135 | 66 | * |
28b94d61 | 67 | * @return Channel (tracefile) for this event |
5d10d135 ASL |
68 | */ |
69 | public String getChannelName() { | |
28b94d61 | 70 | String returnedChannel = ""; |
146a887c | 71 | |
28b94d61 | 72 | return ( (LttngEventType)this.getType() ).getTracefileName(); |
5d10d135 ASL |
73 | } |
74 | ||
75 | /** | |
07d9e2ee | 76 | * Cpu id number of this event.<p> |
5d10d135 | 77 | * |
28b94d61 | 78 | * @return Cpu id |
5d10d135 ASL |
79 | */ |
80 | public long getCpuId() { | |
28b94d61 | 81 | return ( (LttngEventType)this.getType() ).getCpuId(); |
5d10d135 ASL |
82 | } |
83 | ||
84 | /** | |
07d9e2ee | 85 | * Marker name of this event.<p> |
5d10d135 | 86 | * |
28b94d61 | 87 | * @return Marker name |
5d10d135 ASL |
88 | */ |
89 | public String getMarkerName() { | |
146a887c FC |
90 | String returnedValue = ""; |
91 | ||
28b94d61 | 92 | return ( (LttngEventType)this.getType() ).getMarkerName(); |
5d10d135 ASL |
93 | } |
94 | ||
28b94d61 FC |
95 | |
96 | public JniEvent getJniEventReference() { | |
97 | return jniEventReference; | |
98 | } | |
99 | ||
100 | public void setJniEventReference(JniEvent newJniEventReference) { | |
101 | this.jniEventReference = newJniEventReference; | |
102 | } | |
103 | ||
104 | @Override | |
105 | public LttngEventContent getContent() { | |
106 | return (LttngEventContent)fContent; | |
107 | } | |
108 | ||
109 | public void setContent(LttngEventContent newContent) { | |
110 | fContent = newContent; | |
111 | } | |
112 | ||
113 | @Override | |
114 | public LttngEventType getType() { | |
115 | return (LttngEventType)fType; | |
116 | } | |
117 | ||
118 | public void setType(LttngEventType newType) { | |
119 | fType = newType; | |
120 | } | |
121 | ||
122 | ||
5d10d135 | 123 | /** |
07d9e2ee FC |
124 | * Convert this event into a Jni JniEvent.<p> |
125 | * | |
126 | * Note : Some verifications are done to make sure the event is still valid on | |
127 | * the Jni side before conversion.<br> If it is not the case, null will be returned. | |
128 | * | |
129 | * @return The converted JniEvent | |
5d10d135 | 130 | * |
28b94d61 | 131 | * @see org.eclipse.linuxtools.org.eclipse.linuxtools.lttng.jni.JniEvent |
5d10d135 | 132 | */ |
88144d4a | 133 | public JniEvent convertEventTmfToJni() { |
5d10d135 ASL |
134 | JniEvent tmpEvent = null; |
135 | ||
28b94d61 FC |
136 | // ***TODO*** |
137 | // Should we remove the check to save some time?? | |
138 | ||
5d10d135 ASL |
139 | // We don't want to send away events that are outdated as their informations could be invalid |
140 | // If the timestamp between the event and the trace are not coherent we will not perform the conversion | |
141 | if ( jniEventReference.getParentTracefile().getParentTrace().getCurrentEventTimestamp().getTime() == getTimestamp().getValue() ) { | |
142 | tmpEvent = jniEventReference; | |
143 | } | |
28b94d61 FC |
144 | else { |
145 | System.out.println("WRONG TIMESTAMP : " + getTimestamp().getValue() + " vs " + jniEventReference.getParentTracefile().getParentTrace().getCurrentEventTimestamp().getTime()); | |
146 | } | |
5d10d135 ASL |
147 | return tmpEvent; |
148 | } | |
3fbd810a FC |
149 | |
150 | @Override | |
151 | public String toString() { | |
152 | String returnedData=""; | |
153 | ||
154 | returnedData += "Event timestamp:" + this.getTimestamp().getValue() + " "; | |
155 | returnedData += "Channel:" + getChannelName() + " "; | |
156 | returnedData += "CPU Id:" + getCpuId() + " "; | |
157 | returnedData += "Marker:" + getMarkerName() + " "; | |
158 | ||
159 | return returnedData; | |
160 | } | |
5d10d135 | 161 | } |