1 package org
.eclipse
.linuxtools
.lttng
.jni
;
2 /*******************************************************************************
3 * Copyright (c) 2009 Ericsson
5 * All rights reserved. This program and the accompanying materials are
6 * made available under the terms of the Eclipse Public License v1.0 which
7 * accompanies this distribution, and is available at
8 * http://www.eclipse.org/legal/epl-v10.html
11 * William Bourque (wbourque@gmail.com) - Initial API and implementation
12 *******************************************************************************/
15 import java
.util
.ArrayList
;
16 import java
.util
.HashMap
;
18 import org
.eclipse
.linuxtools
.lttng
.jni
.common
.Jni_C_Pointer
;
19 import org
.eclipse
.linuxtools
.lttng
.jni
.exception
.JniException
;
20 import org
.eclipse
.linuxtools
.lttng
.jni
.exception
.JniMarkerException
;
23 * <b><u>JniMarker</u></b><p>
25 * A JniMarker contain information how to interpret the unparsed content (payload) of an event.<br>
26 * Each JniMarker contains several MarkerFields for each fields in the event's payload.
28 * Provides access to the marker_info C structure (from LTT) in java.
30 * Most important fields in the JniMarker are :
32 * <li> the name of the marker in String
33 * <li> an overview of the marker format (in C style printf format)
34 * <li> a reference to an ArrayList that contains MarkerFields object of this JniMarker
37 public abstract class JniMarker
extends Jni_C_Common
39 // Internal C pointer of the JniEvent used in LTT
40 private Jni_C_Pointer thisMarkerPtr
= new Jni_C_Pointer();
42 private String name
= "";
43 private String formatOverview
= "";
45 // These two contains hold references to the same MarkerField object
46 // The ArrayList can be used to efficiently find a field by its position
47 // The HashMap can be used to find a field by its name
48 private HashMap
<String
, JniMarkerField
> markerFieldsHashMap
= null;
49 private ArrayList
<JniMarkerField
> markerFieldsArrayList
= null;
51 // Native access method
52 protected native String
ltt_getName(long markerPtr
);
53 protected native String
ltt_getFormatOverview(long markerPtr
);
54 protected native long ltt_getSize(long markerPtr
);
55 protected native short ltt_getLargestAlign(long markerPtr
);
56 protected native short ltt_getIntSize(long markerPtr
);
57 protected native short ltt_getLongSize(long markerPtr
);
58 protected native short ltt_getPointerSize(long markerPtr
);
59 protected native short ltt_getSize_tSize(long markerPtr
);
60 protected native void ltt_getAllMarkerFields(long tracePtr
);
61 protected native short ltt_getAlignement(long markerPtr
);
62 protected native long ltt_getNextMarkerPtr(long markerPtr
);
64 // Debug native function, ask LTT to print marker structure
65 protected native void ltt_printMarker(long markerPtr
);
68 // To uncomment as soon as the library will be able to load multiple version at once
70 // System.loadLibrary("lttvtraceread_loader");
74 * Default constructor is forbidden
76 protected JniMarker() {
80 * Copy constructor.<p>
82 * @param oldMarker Reference to the JniMarker you want to copy.
84 public JniMarker(JniMarker oldMarker
) {
85 thisMarkerPtr
= oldMarker
.thisMarkerPtr
;
86 name
= oldMarker
.name
;
87 formatOverview
= oldMarker
.formatOverview
;
88 markerFieldsHashMap
= oldMarker
.markerFieldsHashMap
;
89 markerFieldsArrayList
= oldMarker
.markerFieldsArrayList
;
94 * Constructor, using pointer.<p>
96 * @param newMarkerPtr Pointer to a C marker_info structure
98 * @exception JniException
100 public JniMarker(Jni_C_Pointer newMarkerPtr
) throws JniException
{
101 thisMarkerPtr
= newMarkerPtr
;
102 markerFieldsArrayList
= new ArrayList
<JniMarkerField
>();
103 markerFieldsHashMap
= new HashMap
<String
, JniMarkerField
>();
105 // Populate the marker
106 populateMarkerInformation();
111 * This function populates the marker data with data from LTT
114 private void populateMarkerInformation() throws JniException
{
115 if (thisMarkerPtr
.getPointer() == NULL
) {
116 throw new JniMarkerException("Pointer is NULL, trace closed? (populateMarkerInformatOverviewion)");
118 name
= ltt_getName( thisMarkerPtr
.getPointer() );
119 formatOverview
= ltt_getFormatOverview( thisMarkerPtr
.getPointer() );
120 // To fill the markerFieldArray is a bit different
121 ltt_getAllMarkerFields( thisMarkerPtr
.getPointer() );
126 * Fills a map of all the JniMarkerField associated with this JniMarker.
128 * Note: This function is called from C and there is no way to propagate
129 * exception back to the caller without crashing JNI. Therefore, it MUST
130 * catch all exceptions.
132 * @param markerName Name of the parent marker
133 * @param markerFieldPtr C Pointer (converted in long) to marker_field C Structure
135 @SuppressWarnings("unused")
136 private void addMarkerFieldFromC(String markerFieldName
, long markerFieldPtr
) {
137 // Create a new Jaf_markerField object and insert it in the map
138 // the maker field fill itself with LTT data while being constructed
140 JniMarkerField newMarkerField
= allocateNewJniMarkerField( new Jni_C_Pointer(markerFieldPtr
) );
141 markerFieldsArrayList
.add(newMarkerField
);
142 markerFieldsHashMap
.put(markerFieldName
, newMarkerField
);
144 } catch (JniException e
) {
145 printlnC("Failed to add marker field " + markerFieldName
+ " to marker fields list!(addMarkerFieldFromC)\n\tException raised : " + e
.toString() );
149 // Access to class variable. Most of them doesn't have setter
150 public String
getName() {
154 public String
getFormatOverview() {
155 return formatOverview
;
158 public HashMap
<String
,JniMarkerField
> getMarkerFieldsHashMap() {
159 return markerFieldsHashMap
;
162 public ArrayList
<JniMarkerField
> getMarkerFieldsArrayList() {
163 return markerFieldsArrayList
;
167 * Pointer to the marker_info C structure.<p>
169 * The pointer should only be used <u>INTERNALY</u>, do not use unless you
170 * know what you are doing.<p>
172 * @return The actual (long converted) pointer or NULL
174 * @see org.eclipse.linuxtools.lttng.jni.common.eclipse.linuxtools.lttng.jni.Jni_C_Pointer
176 public Jni_C_Pointer
getMarkerPtr() {
177 return thisMarkerPtr
;
182 * Print information for this JniMarker.
183 * <u>Intended to debug</u><br>
185 * This function will call Ltt to print, so information printed will be the one from
186 * the C structure, not the one populated in java.<p>
188 * This function will not throw but will complain loudly if pointer is NULL
190 public void printMarkerInformation() {
192 // If null pointer, print a warning!
193 if (thisMarkerPtr
.getPointer() == NULL
) {
194 printlnC("Pointer is NULL, cannot print. (printMarkerInformation)");
196 ltt_printMarker(thisMarkerPtr
.getPointer());
201 * Print information for ALL marker fields for this marker.
202 * <u>Intended to debug</u><br>
204 * This function will call Ltt to print, so information printed will be the one from
205 * the C structure, not the one populated in java.
207 public void printAllMarkerFieldsInformation() {
208 Object
[] allMarkersField
= markerFieldsArrayList
.toArray();
210 for (int pos
= 0; pos
< allMarkersField
.length
; pos
++) {
211 printlnC(allMarkersField
[pos
].toString());
217 * <u>Intended to debug</u><br>
219 * @return Attributes of the object concatenated in String
222 public String
toString() {
223 String returnData
= "";
225 returnData
+= "name : " + name
+ "\n";
226 returnData
+= "formatOverview : " + formatOverview
+ "\n";
227 returnData
+= "markerFieldArrayList : " + markerFieldsArrayList
.toArray() + "\n";
233 public abstract JniMarkerField
allocateNewJniMarkerField(Jni_C_Pointer newMarkerFieldPtr
) throws JniException
;