[Bug 303523] LTTng/TMF udpates:
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.jni / src / org / eclipse / linuxtools / lttng / jni / JniMarker.java
CommitLineData
0152140d
ASL
1package org.eclipse.linuxtools.lttng.jni;
2/*******************************************************************************
3 * Copyright (c) 2009 Ericsson
4 *
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
9 *
10 * Contributors:
11 * William Bourque (wbourque@gmail.com) - Initial API and implementation
12 *******************************************************************************/
13
a9fcdd8d 14
0152140d
ASL
15import java.util.ArrayList;
16import java.util.HashMap;
17
a9fcdd8d 18import org.eclipse.linuxtools.lttng.jni.common.Jni_C_Pointer;
0152140d
ASL
19import org.eclipse.linuxtools.lttng.jni.exception.JniException;
20import org.eclipse.linuxtools.lttng.jni.exception.JniMarkerException;
21
22/**
23 * <b><u>JniMarker</u></b><p>
24 *
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.
27 *
28 * Provides access to the marker_info C structure (from LTT) in java.
29 *
30 * Most important fields in the JniMarker are :
31 * <ul>
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
35 * </ul>
0152140d
ASL
36 */
37public abstract class JniMarker extends Jni_C_Common
38{
39 // Internal C pointer of the JniEvent used in LTT
a9fcdd8d 40 private Jni_C_Pointer thisMarkerPtr = new Jni_C_Pointer();
0152140d
ASL
41
42 private String name = "";
43 private String formatOverview = "";
44
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;
50
51 // Native access method
a9fcdd8d
WB
52 protected native String ltt_getName(long markerPtr);
53 protected native String ltt_getFormatOverview(long markerPtr);
a9fcdd8d 54 protected native long ltt_getSize(long markerPtr);
a9fcdd8d 55 protected native short ltt_getLargestAlign(long markerPtr);
a9fcdd8d 56 protected native short ltt_getIntSize(long markerPtr);
a9fcdd8d 57 protected native short ltt_getLongSize(long markerPtr);
a9fcdd8d 58 protected native short ltt_getPointerSize(long markerPtr);
a9fcdd8d
WB
59 protected native short ltt_getSize_tSize(long markerPtr);
60 protected native void ltt_getAllMarkerFields(long tracePtr);
a9fcdd8d 61 protected native short ltt_getAlignement(long markerPtr);
a9fcdd8d 62 protected native long ltt_getNextMarkerPtr(long markerPtr);
0152140d
ASL
63
64 // Debug native function, ask LTT to print marker structure
a9fcdd8d
WB
65 protected native void ltt_printMarker(long markerPtr);
66
df13e29f
WB
67 // *** FIXME ***
68 // To uncomment as soon as the library will be able to load multiple version at once
69 // static {
70 // System.loadLibrary("lttvtraceread_loader");
71 //}
0152140d
ASL
72
73 /*
74 * Default constructor is forbidden
75 */
76 protected JniMarker() {
77 }
78
79 /**
80 * Copy constructor.<p>
81 *
82 * @param oldMarker Reference to the JniMarker you want to copy.
83 */
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;
90
91 }
92
93 /**
94 * Constructor, using pointer.<p>
95 *
96 * @param newMarkerPtr Pointer to a C marker_info structure
97 *
98 * @exception JniException
99 */
a9fcdd8d 100 public JniMarker(Jni_C_Pointer newMarkerPtr) throws JniException {
0152140d
ASL
101 thisMarkerPtr = newMarkerPtr;
102 markerFieldsArrayList = new ArrayList<JniMarkerField>();
103 markerFieldsHashMap = new HashMap<String, JniMarkerField>();
104
105 // Populate the marker
106 populateMarkerInformation();
107 }
108
109
110 /*
111 * This function populates the marker data with data from LTT
112 *
113 */
114 private void populateMarkerInformation() throws JniException {
115 if (thisMarkerPtr.getPointer() == NULL) {
116 throw new JniMarkerException("Pointer is NULL, trace closed? (populateMarkerInformatOverviewion)");
117 } else {
a9fcdd8d
WB
118 name = ltt_getName( thisMarkerPtr.getPointer() );
119 formatOverview = ltt_getFormatOverview( thisMarkerPtr.getPointer() );
0152140d 120 // To fill the markerFieldArray is a bit different
a9fcdd8d 121 ltt_getAllMarkerFields( thisMarkerPtr.getPointer() );
0152140d
ASL
122 }
123 }
124
125 /*
126 * Fills a map of all the JniMarkerField associated with this JniMarker.
127 *
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.
131 *
132 * @param markerName Name of the parent marker
133 * @param markerFieldPtr C Pointer (converted in long) to marker_field C Structure
134 */
a9fcdd8d
WB
135 @SuppressWarnings("unused")
136 private void addMarkerFieldFromC(String markerFieldName, long markerFieldPtr) {
137 // Create a new Jaf_markerField object and insert it in the map
0152140d
ASL
138 // the maker field fill itself with LTT data while being constructed
139 try {
a9fcdd8d 140 JniMarkerField newMarkerField = allocateNewJniMarkerField( new Jni_C_Pointer(markerFieldPtr) );
0152140d
ASL
141 markerFieldsArrayList.add(newMarkerField);
142 markerFieldsHashMap.put(markerFieldName, newMarkerField);
143
144 } catch (JniException e) {
a9fcdd8d 145 printlnC("Failed to add marker field " + markerFieldName + " to marker fields list!(addMarkerFieldFromC)\n\tException raised : " + e.toString() );
0152140d
ASL
146 }
147 }
148
149 // Access to class variable. Most of them doesn't have setter
150 public String getName() {
151 return name;
152 }
153
154 public String getFormatOverview() {
155 return formatOverview;
156 }
157
158 public HashMap<String,JniMarkerField> getMarkerFieldsHashMap() {
159 return markerFieldsHashMap;
160 }
161
162 public ArrayList<JniMarkerField> getMarkerFieldsArrayList() {
163 return markerFieldsArrayList;
164 }
165
166 /**
167 * Pointer to the marker_info C structure.<p>
168 *
169 * The pointer should only be used <u>INTERNALY</u>, do not use unless you
170 * know what you are doing.<p>
171 *
172 * @return The actual (long converted) pointer or NULL
173 *
a9fcdd8d 174 * @see org.eclipse.linuxtools.lttng.jni.common.eclipse.linuxtools.lttng.jni.Jni_C_Pointer
0152140d 175 */
a9fcdd8d 176 public Jni_C_Pointer getMarkerPtr() {
0152140d
ASL
177 return thisMarkerPtr;
178 }
179
180
181 /**
182 * Print information for this JniMarker.
183 * <u>Intended to debug</u><br>
184 *
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>
187 *
188 * This function will not throw but will complain loudly if pointer is NULL
189 */
190 public void printMarkerInformation() {
a9fcdd8d
WB
191
192 // If null pointer, print a warning!
193 if (thisMarkerPtr.getPointer() == NULL) {
194 printlnC("Pointer is NULL, cannot print. (printMarkerInformation)");
195 } else {
196 ltt_printMarker(thisMarkerPtr.getPointer());
197 }
0152140d
ASL
198 }
199
200 /**
201 * Print information for ALL marker fields for this marker.
202 * <u>Intended to debug</u><br>
203 *
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.
206 */
207 public void printAllMarkerFieldsInformation() {
208 Object[] allMarkersField = markerFieldsArrayList.toArray();
209
210 for (int pos = 0; pos < allMarkersField.length; pos++) {
a9fcdd8d 211 printlnC(allMarkersField[pos].toString());
0152140d
ASL
212 }
213 }
214
215 /**
216 * toString() method.
217 * <u>Intended to debug</u><br>
218 *
219 * @return Attributes of the object concatenated in String
220 */
221 @Override
222 public String toString() {
223 String returnData = "";
224
225 returnData += "name : " + name + "\n";
226 returnData += "formatOverview : " + formatOverview + "\n";
a9fcdd8d
WB
227 returnData += "markerFieldArrayList : " + markerFieldsArrayList.toArray() + "\n";
228
0152140d
ASL
229 return returnData;
230 }
231
232
a9fcdd8d 233 public abstract JniMarkerField allocateNewJniMarkerField(Jni_C_Pointer newMarkerFieldPtr) throws JniException;
0152140d
ASL
234
235}
This page took 0.036167 seconds and 5 git commands to generate.