Commit | Line | Data |
---|---|---|
28b94d61 | 1 | package org.eclipse.linuxtools.lttng.jni; |
88144d4a ASL |
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 | ||
14 | ||
15 | /** | |
07d9e2ee FC |
16 | * <b><u>JniMarkerField</u></b> <p> |
17 | * A JniMarkerField is one of the field of the unparsed content (payload) of an event. <p> | |
18 | * | |
19 | * Provides access to the marker_field C structure (from LTT) in java.<p> | |
20 | * | |
88144d4a ASL |
21 | * Most important attributes in the JniMarkerField are : |
22 | * <ul> | |
23 | * <li> the name (field) of in String | |
24 | * <li> the marker field format (in C style printf format) | |
25 | * </ul> | |
26 | */ | |
27 | public final class JniMarkerField extends Jni_C_Common | |
28 | { | |
29 | // Internal C pointer of the JniEvent used in LTT | |
07d9e2ee | 30 | private Jni_C_Pointer thisMarkerFieldPtr = new Jni_C_Pointer(); |
88144d4a ASL |
31 | |
32 | private String field = ""; | |
33 | private String format = ""; | |
07d9e2ee | 34 | |
88144d4a ASL |
35 | // Native access method |
36 | private native String ltt_getField(long markerFieldPtr); | |
37 | @SuppressWarnings("unused") | |
38 | private native int ltt_getType(long markerFieldPtr); | |
39 | @SuppressWarnings("unused") | |
40 | private native long ltt_getOffset(long markerFieldPtr); | |
41 | @SuppressWarnings("unused") | |
42 | private native long ltt_getSize(long markerFieldPtr); | |
43 | @SuppressWarnings("unused") | |
44 | private native long ltt_getAlignment(long markerFieldPtr); | |
45 | @SuppressWarnings("unused") | |
46 | private native long ltt_getAttributes(long markerFieldPtr); | |
47 | @SuppressWarnings("unused") | |
48 | private native int ltt_getStatic_offset(long markerFieldPtr); | |
49 | private native String ltt_getFormat(long markerFieldPtr); | |
50 | ||
51 | // Debug native function, ask LTT to print marker structure | |
52 | private native void ltt_printMarkerField(long markerFieldPtr); | |
53 | ||
54 | static { | |
55 | System.loadLibrary("lttvtraceread"); | |
56 | } | |
57 | ||
07d9e2ee | 58 | /* |
88144d4a ASL |
59 | * Default constructor is forbidden |
60 | */ | |
61 | @SuppressWarnings("unused") | |
62 | private JniMarkerField() { | |
63 | } | |
64 | ||
65 | /** | |
07d9e2ee | 66 | * Copy constructor.<p> |
88144d4a | 67 | * |
07d9e2ee | 68 | * @param oldMarkerField Reference to the JniMarkerField you want to copy. |
88144d4a ASL |
69 | */ |
70 | public JniMarkerField(JniMarkerField oldMarkerField) { | |
71 | thisMarkerFieldPtr = oldMarkerField.getMarkerFieldPtr(); | |
72 | field = oldMarkerField.getField(); | |
73 | format = oldMarkerField.getFormat(); | |
74 | } | |
75 | ||
76 | /** | |
07d9e2ee | 77 | * Constructor, using pointer.<p> |
88144d4a ASL |
78 | * |
79 | * @param newMarkerFieldPtr Pointer to a C marker_field structure | |
80 | * | |
81 | * @exception JniException | |
82 | */ | |
07d9e2ee | 83 | public JniMarkerField(Jni_C_Pointer newMarkerFieldPtr) throws JniException { |
88144d4a ASL |
84 | thisMarkerFieldPtr = newMarkerFieldPtr; |
85 | ||
86 | // Populate the marker field | |
87 | populateMarkerFieldInformation(); | |
88 | } | |
89 | ||
90 | /* | |
91 | * This function populates the marker field data with data from LTT | |
92 | * | |
93 | */ | |
94 | private void populateMarkerFieldInformation() throws JniException { | |
95 | if (thisMarkerFieldPtr.getPointer() == NULL) { | |
96 | throw new JniMarkerFieldException( | |
97 | "Pointer is NULL, trace closed? (populateMarkerInformation)"); | |
98 | } else { | |
99 | field = ltt_getField(thisMarkerFieldPtr.getPointer()); | |
100 | format = ltt_getFormat(thisMarkerFieldPtr.getPointer()); | |
101 | } | |
102 | } | |
103 | ||
104 | public String getField() { | |
105 | return field; | |
106 | } | |
107 | ||
108 | public String getFormat() { | |
109 | return format; | |
110 | } | |
111 | ||
112 | /** | |
07d9e2ee FC |
113 | * Pointer to the marker_field C structure.<p> |
114 | * | |
115 | * The pointer should only be used <u>INTERNALY</u>, do not use these unless you | |
116 | * know what you are doing.<p> | |
88144d4a ASL |
117 | * |
118 | * @return The actual (long converted) pointer or NULL | |
88144d4a | 119 | * |
28b94d61 | 120 | * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.Jni_C_Pointer |
146a887c | 121 | */ |
07d9e2ee FC |
122 | public Jni_C_Pointer getMarkerFieldPtr() { |
123 | return thisMarkerFieldPtr; | |
146a887c | 124 | } |
07d9e2ee | 125 | |
146a887c FC |
126 | /** |
127 | * Print information for this event. <u>Intended to debug</u><br> | |
88144d4a | 128 | * |
07d9e2ee FC |
129 | * This function will call Ltt to print, so information printed will be the one from |
130 | * the C structure, not the one populated in java.<p> | |
131 | * | |
88144d4a ASL |
132 | * This function will not throw but will complain loudly if pointer is NULL |
133 | */ | |
134 | public void printMarkerFieldInformation() { | |
135 | ||
136 | // If null pointer, print a warning! | |
137 | if (thisMarkerFieldPtr.getPointer() == NULL) { | |
138 | printlnC("Pointer is NULL, cannot print. (printMarkerFieldInformation)"); | |
139 | } else { | |
140 | ltt_printMarkerField(thisMarkerFieldPtr.getPointer()); | |
141 | } | |
142 | } | |
07d9e2ee FC |
143 | |
144 | /** | |
145 | * toString() method. | |
146 | * <u>Intended to debug</u><br> | |
147 | * | |
148 | * @return Attributes of the object concatenated in String | |
149 | */ | |
150 | @Override | |
151 | public String toString() { | |
152 | String returnData = ""; | |
153 | returnData += "field : " + field + "\n"; | |
154 | returnData += "format : " + format + "\n"; | |
155 | ||
156 | return returnData; | |
157 | } | |
88144d4a | 158 | } |