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 *******************************************************************************/
14 import java
.util
.ArrayList
;
15 import java
.util
.HashMap
;
17 import org
.eclipse
.linuxtools
.internal
.lttng
.jni
.common
.Jni_C_Pointer_And_Library_Id
;
18 import org
.eclipse
.linuxtools
.internal
.lttng
.jni
.exception
.JniException
;
19 import org
.eclipse
.linuxtools
.internal
.lttng
.jni
.exception
.JniMarkerException
;
22 * <b><u>JniMarker</u></b><p>
24 * A JniMarker contain information how to interpret the unparsed content (payload) of an event.<br>
25 * Each JniMarker contains several MarkerFields for each fields in the event's payload.
27 * Provides access to the marker_info C structure (from LTT) in java.
29 * Most important fields in the JniMarker are :
31 * <li> the name of the marker in String
32 * <li> an overview of the marker format (in C style printf format)
33 * <li> a reference to an ArrayList that contains MarkerFields object of this JniMarker
37 * This class is ABSTRACT, you need to extends it to support your specific LTTng version.<br>
38 * Please look at the abstract functions to override at the bottom of this file.<p>
41 public abstract class JniMarker
extends Jni_C_Common
43 // Internal C pointer of the JniEvent used in LTT
44 private Jni_C_Pointer_And_Library_Id thisMarkerPtr
= new Jni_C_Pointer_And_Library_Id();
46 private String name
= ""; //$NON-NLS-1$
47 private String formatOverview
= ""; //$NON-NLS-1$
49 // These two contains hold references to the same MarkerField object
50 // The ArrayList can be used to efficiently find a field by its position
51 // The HashMap can be used to find a field by its name
52 private HashMap
<String
, JniMarkerField
> markerFieldsHashMap
= null;
53 private ArrayList
<JniMarkerField
> markerFieldsArrayList
= null;
55 // Native access method
56 protected native String
ltt_getName(int libId
, long markerPtr
);
57 protected native String
ltt_getFormatOverview(int libId
, long markerPtr
);
58 protected native long ltt_getSize(int libId
, long markerPtr
);
59 protected native short ltt_getLargestAlign(int libId
, long markerPtr
);
60 protected native short ltt_getIntSize(int libId
, long markerPtr
);
61 protected native short ltt_getLongSize(int libId
, long markerPtr
);
62 protected native short ltt_getPointerSize(int libId
, long markerPtr
);
63 protected native short ltt_getSize_tSize(int libId
, long markerPtr
);
64 protected native void ltt_getAllMarkerFields(int libId
, long tracePtr
);
65 protected native short ltt_getAlignement(int libId
, long markerPtr
);
66 protected native long ltt_getNextMarkerPtr(int libId
, long markerPtr
);
68 // Debug native function, ask LTT to print marker structure
69 protected native void ltt_printMarker(int libId
, long markerPtr
);
72 * Default constructor is forbidden
74 protected JniMarker() {
78 * Copy constructor.<p>
80 * @param oldMarker Reference to the JniMarker you want to copy.
82 public JniMarker(JniMarker oldMarker
) {
83 thisMarkerPtr
= oldMarker
.thisMarkerPtr
;
84 name
= oldMarker
.name
;
85 formatOverview
= oldMarker
.formatOverview
;
86 markerFieldsHashMap
= oldMarker
.markerFieldsHashMap
;
87 markerFieldsArrayList
= oldMarker
.markerFieldsArrayList
;
92 * Constructor, using pointer.<p>
94 * @param newMarkerPtr Pointer to a C marker_info structure
96 * @exception JniException
98 public JniMarker(Jni_C_Pointer_And_Library_Id newMarkerPtr
) throws JniException
{
99 thisMarkerPtr
= newMarkerPtr
;
100 markerFieldsArrayList
= new ArrayList
<JniMarkerField
>();
101 markerFieldsHashMap
= new HashMap
<String
, JniMarkerField
>();
103 // Populate the marker
104 populateMarkerInformation();
109 * This function populates the marker data with data from LTT
112 private void populateMarkerInformation() throws JniException
{
113 if (thisMarkerPtr
.getPointer() == NULL
) {
114 throw new JniMarkerException("Pointer is NULL, trace closed? (populateMarkerInformatOverviewion)"); //$NON-NLS-1$
116 name
= ltt_getName(thisMarkerPtr
.getLibraryId(), thisMarkerPtr
.getPointer());
117 formatOverview
= ltt_getFormatOverview(thisMarkerPtr
.getLibraryId(), thisMarkerPtr
.getPointer());
118 // To fill the markerFieldArray is a bit different
119 ltt_getAllMarkerFields(thisMarkerPtr
.getLibraryId(), thisMarkerPtr
.getPointer());
124 * Fills a map of all the JniMarkerField associated with this JniMarker.
126 * Note: This function is called from C and there is no way to propagate
127 * exception back to the caller without crashing JNI. Therefore, it MUST
128 * catch all exceptions.
130 * @param markerName Name of the parent marker
131 * @param markerFieldPtr C Pointer (converted in long) to marker_field C Structure
133 private void addMarkerFieldFromC(String markerFieldName
, long markerFieldPtr
) {
134 // Create a new Jni_markerField object and insert it in the map
135 // the maker field fill itself with LTT data while being constructed
137 JniMarkerField newMarkerField
= allocateNewJniMarkerField( new Jni_C_Pointer_And_Library_Id(thisMarkerPtr
.getLibraryId(), markerFieldPtr
));
138 markerFieldsArrayList
.add(newMarkerField
);
139 markerFieldsHashMap
.put(markerFieldName
, newMarkerField
);
141 } catch (JniException e
) {
142 printlnC(thisMarkerPtr
.getLibraryId(), "Failed to add marker field " + markerFieldName
+ " to marker fields list!(addMarkerFieldFromC)\n\tException raised : " + e
.toString() ); //$NON-NLS-1$ //$NON-NLS-2$
146 // Access to class variable. Most of them doesn't have setter
147 public String
getName() {
151 public String
getFormatOverview() {
152 return formatOverview
;
155 public HashMap
<String
,JniMarkerField
> getMarkerFieldsHashMap() {
156 return markerFieldsHashMap
;
159 public ArrayList
<JniMarkerField
> getMarkerFieldsArrayList() {
160 return markerFieldsArrayList
;
164 * Pointer to the marker_info C structure.<p>
166 * The pointer should only be used <u>INTERNALY</u>, do not use unless you
167 * know what you are doing.<p>
169 * @return The actual (long converted) pointer or NULL
171 * @see org.eclipse.linuxtools.internal.lttng.jni.common.Jni_C_Pointer_And_Library_Id
173 public Jni_C_Pointer_And_Library_Id
getMarkerPtr() {
174 return thisMarkerPtr
;
179 * Print information for this JniMarker.
180 * <u>Intended to debug</u><br>
182 * This function will call Ltt to print, so information printed will be the one from
183 * the C structure, not the one populated in java.<p>
185 * This function will not throw but will complain loudly if pointer is NULL
187 public void printMarkerInformation() {
188 ltt_printMarker(thisMarkerPtr
.getLibraryId(), thisMarkerPtr
.getPointer());
192 * Print information for ALL marker fields for this marker.
193 * <u>Intended to debug</u><br>
195 * This function will call Ltt to print, so information printed will be the one from
196 * the C structure, not the one populated in java.
198 public void printAllMarkerFieldsInformation() {
199 Object
[] allMarkersField
= markerFieldsArrayList
.toArray();
201 for (int pos
= 0; pos
< allMarkersField
.length
; pos
++) {
202 printlnC(thisMarkerPtr
.getLibraryId(), allMarkersField
[pos
].toString());
208 * <u>Intended to debug</u><br>
210 * @return Attributes of the object concatenated in String
213 @SuppressWarnings("nls")
214 public String
toString() {
215 String returnData
= "";
217 returnData
+= "name : " + name
+ "\n";
218 returnData
+= "formatOverview : " + formatOverview
+ "\n";
219 returnData
+= "markerFieldArrayList : " + markerFieldsArrayList
.hashCode() + " (size : " + markerFieldsArrayList
.size() + " )" + "\n";
225 // ****************************
226 // **** ABSTRACT FUNCTIONS ****
227 // You MUST override those in your version specific implementation
231 * Function place holder to allocate a new JniMarkerField.<p>
233 * JniMarkerField constructor is non overridable so we need another overridable function to return the correct version of JniMarkerField.<br>
234 * Effect of this function should be the same (allocate a fresh new JniMarkerField).<br>
236 * <b>!! Override this with you version specific implementation.</b><br>
238 * @param newMarkerFieldPtr The pointer and library id of an already opened marker_field C Structure
240 * @return The newly allocated JniMarkerField of the correct version
242 * @throws JniException The construction (allocation) failed.
244 * @see org.eclipse.linuxtools.internal.lttng.jni.common.Jni_C_Pointer_And_Library_Id
245 * @see org.eclipse.linuxtools.lttng.jni.JniMarkerField
247 public abstract JniMarkerField
allocateNewJniMarkerField(Jni_C_Pointer_And_Library_Id newMarkerFieldPtr
) throws JniException
;