*
* @exception JniException
*
- * @see org.eclipse.linuxtools.lttng.jni.common.eclipse.linuxtools.lttng.jni.Jni_C_Pointer
- * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniMarker
- * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniTracefile
+ * @see org.eclipse.linuxtools.lttng.jni.common.Jni_C_Pointer
+ * @see org.eclipse.linuxtools.lttng.jni.JniMarker
+ * @see org.eclipse.linuxtools.lttng.jni.JniTracefile
*/
public JniEvent(Jni_C_Pointer newEventPtr, HashMap<Integer, JniMarker> newMarkersMap, JniTracefile newParentTracefile) throws JniException {
*
* If the move fails, the event will not get populated and the last event data will still be available.
*
- * @return LTT read status, as defined in Jni_C_Common.
+ * @return LTT read status, as defined in Jni_C_Constant.
*
- * @see org.eclipse.linuxtools.lttng.jni.common.eclipse.linuxtools.lttng.jni.Jni_C_Common
+ * @see org.eclipse.linuxtools.lttng.jni.common.Jni_C_Constant
*/
public int readNextEvent() {
// Ask Ltt to read the next event for this particular tracefile
*
* If the seek fails, the event will not get populated and the last event data will still be available.<p>
*
- * @return LTT read status, as defined in Jni_C_Common
+ * @return LTT read status, as defined in Jni_C_Constant
*
- * @see org.eclipse.linuxtools.lttng.jni.common.eclipse.linuxtools.lttng.jni.Jni_C_Common
+ * @see org.eclipse.linuxtools.lttng.jni.common.Jni_C_Constant
*/
public int seekToTime(JniTime seekTime) {
// Ask Ltt to read the next event for this particular tracefile
*
* If the seek fails, we will seek back to the previous position, so the event will stay in a consistent state.<p>
*
- * @return LTT read status, as defined in Jni_C_Common
+ * @return LTT read status, as defined in Jni_C_Constant
*
- * @see org.eclipse.linuxtools.lttng.jni.common.eclipse.linuxtools.lttng.jni.Jni_C_Common
+ * @see org.eclipse.linuxtools.lttng.jni.common.Jni_C_Constant
*/
public int seekOrFallBack(JniTime seekTime) {
// Save the old time
*
* A status different of EOK probably means there is no event associated to this tracefile.
*
- * @return LTT read status, as defined in Jni_C_Common
+ * @return LTT read status, as defined in Jni_C_Constant
*
- * @see org.eclipse.linuxtools.lttng.jni.common.eclipse.linuxtools.lttng.jni.Jni_C_Common
+ * @see org.eclipse.linuxtools.lttng.jni.common.Jni_C_Constant
*/
public int positionToFirstEvent() {
eventState = ltt_positionToFirstEvent(tracefilePtr.getPointer());
*
* @return Reference to the marker for this tracefile's event or null if none.
*
- * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniMarker
+ * @see org.eclipse.linuxtools.lttng.jni.JniMarker
*/
public JniMarker requestEventMarker() {
return markersMap.get(getEventMarkerId());
*
* @return Reference to the JniMarker object for this event or null if none.
*
- * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniMarker
+ * @see org.eclipse.linuxtools.lttng.jni.JniMarker
*/
public String requestEventSource() {
// *** TODO ***
*
* @return Object that contain the parsed payload
*
- * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniParser
+ * @see org.eclipse.linuxtools.lttng.jni.JniParser
*/
public Object parseFieldById(int fieldId) {
return JniParser.parseField(this, fieldId);
*
* @return Object that contain the parsed payload
*
- * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniParser
+ * @see org.eclipse.linuxtools.lttng.jni.JniParser
*/
public Object parseFieldByName(String fieldName) {
return JniParser.parseField(this, fieldName);
*
* @return HashMap<String, Object> which is the parsedContent objects and their name as key.
*
- * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniParser
+ * @see org.eclipse.linuxtools.lttng.jni.JniParser
*/
public HashMap<String, Object> parseAllFields() {
return JniParser.parseAllFields(this);
*
* @return The actual (long converted) pointer or NULL.
*
- * @see org.eclipse.linuxtools.lttng.jni.common.eclipse.linuxtools.lttng.jni.Jni_C_Pointer
+ * @see org.eclipse.linuxtools.lttng.jni.common.Jni_C_Pointer
*/
public Jni_C_Pointer getTracefilePtr() {
return new Jni_C_Pointer( ltt_getTracefilePtr(thisEventPtr.getPointer()) );
*
* @return The actual (long converted) pointer or NULL.
*
- * @see org.eclipse.linuxtools.lttng.jni.common.eclipse.linuxtools.lttng.jni.Jni_C_Pointer
+ * @see org.eclipse.linuxtools.lttng.jni.common.Jni_C_Pointer
*/
public Jni_C_Pointer getEventPtr() {
return thisEventPtr;
*
* @return The parent tracefile
*
- * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniTracefile
+ * @see org.eclipse.linuxtools.lttng.jni.JniTracefile
*/
public JniTracefile getParentTracefile() {
return parentTracefile;
return returnData;
}
+
}
*
* @return The actual (long converted) pointer or NULL
*
- * @see org.eclipse.linuxtools.lttng.jni.common.eclipse.linuxtools.lttng.jni.Jni_C_Pointer
+ * @see org.eclipse.linuxtools.lttng.jni.common.Jni_C_Pointer
*/
public Jni_C_Pointer getMarkerPtr() {
return thisMarkerPtr;
}
+ // ****************************
+ // **** ABSTRACT FUNCTIONS ****
+ // You MUST override those in your version specific implementation
+
+
+ /**
+ * Function place holder to allocate a new JniMarkerField.<p>
+ * <br>
+ * JniMarkerField constructor is non overridable so we need another overridable function to return the correct version of JniMarkerField.<br>
+ * Effect of this function should be the same (allocate a fresh new JniMarkerField).<br>
+ * <br>
+ * <b>!! Override this with you version specific implementation.</b><br>
+ *
+ * @param newMarkerFieldPtr The pointer of an already opened marker_field C Structure
+ *
+ * @return The newly allocated JniMarkerField of the correct version
+ *
+ * @throws JniException The construction (allocation) failed.
+ *
+ * @see org.eclipse.linuxtools.lttng.jni.common.Jni_C_Pointer
+ * @see org.eclipse.linuxtools.lttng.jni.JniMarkerField
+ */
public abstract JniMarkerField allocateNewJniMarkerField(Jni_C_Pointer newMarkerFieldPtr) throws JniException;
}
* @param newMarkerFieldPtr Pointer to a C marker_field structure
*
* @exception JniException
+ *
+ * @see org.eclipse.linuxtools.lttng.jni.common.Jni_C_Pointer
*/
public JniMarkerField(Jni_C_Pointer newMarkerFieldPtr) throws JniException {
thisMarkerFieldPtr = newMarkerFieldPtr;
*
* @return The actual (long converted) pointer or NULL
*
- * @see org.eclipse.linuxtools.lttng.jni.common.eclipse.linuxtools.lttng.jni.Jni_C_Pointer
+ * @see org.eclipse.linuxtools.lttng.jni.common.Jni_C_Pointer
*/
public Jni_C_Pointer getMarkerFieldPtr() {
return thisMarkerFieldPtr;
return returnData;
}
+
}
*
* @return An Object that contain the JniEvent payload parsed by the C, or null, if if was impossible to parse (i.e., wrong position)
*
- * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniEvent
+ * @see org.eclipse.linuxtools.lttng.jni.JniEvent
*/
static public Object parseField(JniEvent eventToParse, int fieldPosition) {
*
* @return An Object that contain the JniEvent payload parsed by the C, or null, if if was impossible to parse (i.e., wrong position)
*
- * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniEvent
+ * @see org.eclipse.linuxtools.lttng.jni.JniEvent
*/
static public Object parseField(JniEvent eventToParse, String fieldName) {
* @param eventToParse The jni event we want to parse.
* @return An HashMap of Object that contain the is the JniEvent's payload parsed by the C
*
- * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniEvent
+ * @see org.eclipse.linuxtools.lttng.jni.JniEvent
*/
static public HashMap<String, Object> parseAllFields(JniEvent eventToParse) {
HashMap<String,JniMarkerField> markerFieldData = eventToParse.requestEventMarker().getMarkerFieldsHashMap();
}
+
/**
* <b><u>ParsedObjectContent</u></b><p>
*
public void setData(Object newData) {
parsedData = newData;
}
-}
\ No newline at end of file
+}
* William Bourque (wbourque@gmail.com) - Initial API and implementation
*******************************************************************************/
-
import java.util.HashMap;
import java.util.Iterator;
import java.util.PriorityQueue;
// Note that all type have been scaled up as there is no "unsigned" in java
// This might be a problem about "unsigned long" as there is no equivalent
// in java
-
+
private String tracepath = ""; // Path of the trace. Should be a directory (like : /tmp/traceX)
private int cpuNumber = 0;
private long archType = 0;
*
* @exception JniException
*
- * @see org.eclipse.linuxtools.lttng.jni.common.eclipse.linuxtools.lttng.jni.Jni_C_Pointer
+ * @see org.eclipse.linuxtools.lttng.jni.common.Jni_C_Pointer
*/
public JniTrace(Jni_C_Pointer newPtr, boolean newPrintDebug) throws JniException {
thisTracePtr = newPtr;
*
* @return The top event in the stack or null if no event is available.
*
- * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniEvent
+ * @see org.eclipse.linuxtools.lttng.jni.JniEvent
*/
public JniEvent findNextEvent() {
return eventsHeap.peek();
*
* @return The next event in the trace or null if no event is available.
*
- * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniEvent
+ * @see org.eclipse.linuxtools.lttng.jni.JniEvent
*/
public JniEvent readNextEvent() {
// Get the "next" event on the top of the heap but DO NOT remove it
*
* @return The next event in the tracefile or null if no event is available.
*
- * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniTracefile
- * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniEvent
+ * @see org.eclipse.linuxtools.lttng.jni.JniTracefile
+ * @see org.eclipse.linuxtools.lttng.jni.JniEvent
*/
public JniEvent readNextEvent(JniTracefile targetTracefile) {
JniEvent returnedEvent = null;
*
* @param seekTime The time where we want to seek to
*
- * @see org.eclipse.linuxtools.lttng.jni.common.eclipse.linuxtools.lttng.jni.JniTime
+ * @see org.eclipse.linuxtools.lttng.jni.common.JniTime
*/
public void seekToTime(JniTime seekTime) {
* @param targetTracefile The tracefile object to read from
* @param seekTime The time where we want to seek to
*
- * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniTracefile
- * @see org.eclipse.linuxtools.lttng.jni.common.eclipse.linuxtools.lttng.jni.JniTime
+ * @see org.eclipse.linuxtools.lttng.jni.JniTracefile
+ * @see org.eclipse.linuxtools.lttng.jni.common.JniTime
*/
public void seekToTime(JniTime seekTime, JniTracefile targetTracefile) {
// Invalidate the current read event
*
* @return The event just after the seeked time or null if none available.
*
- * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniEvent
- * @see org.eclipse.linuxtools.lttng.jni.common.eclipse.linuxtools.lttng.jni.JniTime
+ * @see org.eclipse.linuxtools.lttng.jni.JniEvent
+ * @see org.eclipse.linuxtools.lttng.jni.common.JniTime
*/
public JniEvent seekAndRead(JniTime seekTime) {
JniEvent returnedEvent = null;
*
* Calling readNextEvent() after this function will consider this tracefile moved and is then consistent.<br>
*
- * @param tracefileName The tracefile object to read from
+ * @param targetTracefile The tracefile object to read from
* @param seekTime The time where we want to seek to
*
* @return The event just after the seeked time or null if none available.
*
- * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniTracefile
- * @see org.eclipse.linuxtools.lttng.jni.common.eclipse.linuxtools.lttng.jni.JniTime
- * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniEvent
+ * @see org.eclipse.linuxtools.lttng.jni.JniTracefile
+ * @see org.eclipse.linuxtools.lttng.jni.common.JniTime
+ * @see org.eclipse.linuxtools.lttng.jni.JniEvent
*/
public JniEvent seekAndRead(JniTime seekTime, JniTracefile targetTracefile) {
seekToTime(seekTime, targetTracefile);
*
* @return The tracefile found or null if none.
*
- * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniTracefile
+ * @see org.eclipse.linuxtools.lttng.jni.JniTracefile
*/
public JniTracefile requestTracefileByName(String tracefileName) {
return tracefilesMap.get(tracefileName);
*
* @return Event of the tracefile or null if none found.
*
- * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniEvent
+ * @see org.eclipse.linuxtools.lttng.jni.JniEvent
*/
public JniEvent requestEventByName(String tracefileName) {
JniEvent returnValue = null;
*
* @return Time of the last event read
*
- * @see org.eclipse.linuxtools.lttng.jni.common.eclipse.linuxtools.lttng.jni.JniTime
+ * @see org.eclipse.linuxtools.lttng.jni.common.JniTime
*/
public JniTime getCurrentEventTimestamp() {
JniTime returnedTime = null;
*
* @return The actual (long converted) pointer or NULL.
*
- * @see org.eclipse.linuxtools.lttng.jni.common.eclipse.linuxtools.lttng.jni.Jni_C_Pointer
+ * @see org.eclipse.linuxtools.lttng.jni.common.Jni_C_Pointer
*/
public Jni_C_Pointer getTracePtr() {
return thisTracePtr;
* This function will call Ltt to print, so information printed will be the
* one from the C structure, not the one populated in java.
*
- * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniTracefile
+ * @see org.eclipse.linuxtools.lttng.jni.JniTracefile
*/
public void printAllTracefilesInformation() {
JniTracefile tracefile = null;
return returnData;
}
+
+ // ****************************
+ // **** ABSTRACT FUNCTIONS ****
+ // You MUST override those in your version specific implementation
+
+ /**
+ * Function place holder to load the correct C library.<p>
+ * <br>
+ * Can be as simple as calling ltt_initializeHandle(LIBRARY_NAME) with the correct .so instead of LIBRARY_NAME.<br>
+ * You may also want to perform some check or some additionnal validations.<br>
+ * <br>
+ * <b>!! Override this with you version specific implementation.</b><br>
+ *
+ * @return boolean saying if the initialization was successful.
+ */
public abstract boolean initializeLibrary();
+
+ /**
+ * Function place holder to allocate a new JniTracefile.<p>
+ *
+ * JniTracefile constructor is non overridable so we need another overridable function to return the correct version of JniTracefile.<br>
+ * Effect of this function should be the same (allocate a fresh new JniTracefile)<br>
+ * <br>
+ * <b>!! Override this with you version specific implementation.</b><br>
+ *
+ * @param newPtr The pointer of an already opened LttTracefile C Structure
+ * @param newParentTrace The JniTrace parent of this tracefile.
+ *
+ * @return The newly allocated JniTracefile of the correct version
+ *
+ * @throws JniException The construction (allocation) failed.
+ *
+ * @see org.eclipse.linuxtools.lttng.jni.JniTracefile
+ * @see org.eclipse.linuxtools.lttng.jni.common.Jni_C_Pointer
+ * @see org.eclipse.linuxtools.lttng.jni.JniTrace
+ */
public abstract JniTracefile allocateNewJniTracefile(Jni_C_Pointer newPtr, JniTrace newParentTrace) throws JniException;
-}
\ No newline at end of file
+}
/**
* Constructor, using C pointer.<p>
*
- * @param newPtr The pointer of an already opened LttTracefile C Structure
+ * @param newPtr The pointer of an already opened LttTracefile C Structure
+ * @param newParentTrace The JniTrace parent of this tracefile.
*
* @exception JniException
*
- * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniTrace
- * @see org.eclipse.linuxtools.lttng.jni.common.eclipse.linuxtools.lttng.jni.Jni_C_Pointer
+ * @see org.eclipse.linuxtools.lttng.jni.JniTrace
+ * @see org.eclipse.linuxtools.lttng.jni.common.Jni_C_Pointer
*/
public JniTracefile(Jni_C_Pointer newPtr, JniTrace newParentTrace) throws JniException {
thisTracefilePtr = newPtr;
*
* Note : If the read succeed, the event will be populated.<p>
*
- * @return LTT read status, as defined in Jni_C_Common
+ * @return LTT read status, as defined in Jni_C_Constant
*
- * @see org.eclipse.linuxtools.lttng.jni.common.eclipse.linuxtools.lttng.jni.Jni_C_Common
+ * @see org.eclipse.linuxtools.lttng.jni.common.Jni_C_Constant
*/
public int readNextEvent() {
return currentEvent.readNextEvent();
*
* @param seekTime The timestamp where to seek.
*
- * @return LTT read status, as defined in Jni_C_Common
+ * @return LTT read status, as defined in Jni_C_Constant
*
- * @see org.eclipse.linuxtools.lttng.jni.common.eclipse.linuxtools.lttng.jni.Jni_C_Common
+ * @see org.eclipse.linuxtools.lttng.jni.common.Jni_C_Constant
*/
public int seekToTime(JniTime seekTime) {
return currentEvent.seekToTime(seekTime);
*
* @return The parent trace
*
- * @see org.eclipse.linuxtools.lttng.jni.eclipse.linuxtools.lttng.jni.JniTrace
+ * @see org.eclipse.linuxtools.lttng.jni.JniTrace
*/
public JniTrace getParentTrace() {
return parentTrace;
*
* @return The actual (long converted) pointer or NULL.
*
- * @see org.eclipse.linuxtools.lttng.jni.common.eclipse.linuxtools.lttng.jni.Jni_C_Pointer
+ * @see org.eclipse.linuxtools.lttng.jni.common.Jni_C_Pointer
*/
public Jni_C_Pointer getTracefilePtr() {
return thisTracefilePtr;
}
+ // ****************************
+ // **** ABSTRACT FUNCTIONS ****
+ // You MUST override those in your version specific implementation
+
+
+ /**
+ * Function place holder to allocate a new JniEvent.<p>
+ * <br>
+ * JniEvent constructor is non overridable so we need another overridable function to return the correct version of JniEvent.<br>
+ * Effect of this function should be the same (allocate a fresh new JniEvent).<br>
+ * <br>
+ * <b>!! Override this with you version specific implementation.</b><br>
+ *
+ * @param newEventPtr The pointer of an already opened LttEvent C Structure
+ * @param newMarkersMap An already populated HashMap of JniMarker objects for this new event
+ * @param newParentTracefile The JniTrace parent of this tracefile.
+ *
+ * @return The newly allocated JniEvent of the correct version
+ *
+ * @throws JniException The construction (allocation) failed.
+ *
+ * @see org.eclipse.linuxtools.lttng.jni.JniEvent
+ * @see org.eclipse.linuxtools.lttng.jni.common.Jni_C_Pointer
+ * @see org.eclipse.linuxtools.lttng.jni.JniMarker
+ * @see org.eclipse.linuxtools.lttng.jni.JniTracefile
+ */
public abstract JniEvent allocateNewJniEvent(Jni_C_Pointer newEventPtr, HashMap<Integer, JniMarker> newMarkersMap, JniTracefile newParentTracefile) throws JniException;
- public abstract JniMarker allocateNewJniMarker(Jni_C_Pointer newMarkerPtr) throws JniException;
+
+
+ /**
+ * Function place holder to allocate a new JniMarker.<p>
+ * <br>
+ * JniMarker constructor is non overridable so we need another overridable function to return the correct version of JniMarker.<br>
+ * Effect of this function should be the same (allocate a fresh new JniMarker).<br>
+ * <br>
+ * <b>!! Override this with you version specific implementation.</b><br>
+ *
+ * @param newMarkerPtr The pointer of an already opened marker_info C Structure
+ *
+ * @return The newly allocated JniMarker of the correct version
+ *
+ * @throws JniException The construction (allocation) failed.
+ *
+ * @see org.eclipse.linuxtools.lttng.jni.JniMarker
+ * @see org.eclipse.linuxtools.lttng.jni.common.Jni_C_Pointer
+ */
+ public abstract JniMarker allocateNewJniMarker(Jni_C_Pointer newMarkerPtr) throws JniException;
}
-
public void printlnC(String msg) {
printC(msg + "\n");
}
-}
\ No newline at end of file
+
+}
package org.eclipse.linuxtools.lttng.jni.common;
-
-
+/*******************************************************************************
+ * Copyright (c) 2009 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * William Bourque (wbourque@gmail.com) - Initial API and implementation
+ *******************************************************************************/
/**
* <b><u>JniTime</u></b>
* William Bourque (wbourque@gmail.com) - Initial API and implementation
*******************************************************************************/
-
/**
* <b><u>Jni_C_Common</u></b>
* <p>
// Timestamps are in nanoseconds, this const ease up the math
public static final long NANO = 1000000000;
+ /**
+ * Default constructor
+ */
+ public Jni_C_Constant() {
+ }
+
/**
* "Alternate" .toString()<p>
*
package org.eclipse.linuxtools.lttng.jni.common;
-
+/*******************************************************************************
+ * Copyright (c) 2009 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * William Bourque (wbourque@gmail.com) - Initial API and implementation
+ *******************************************************************************/
/**
* <b><u>Jni_C_Pointer</u></b>
package org.eclipse.linuxtools.lttng.jni.factory;
+/*******************************************************************************
+ * Copyright (c) 2009 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * William Bourque (wbourque@gmail.com) - Initial API and implementation
+ *******************************************************************************/
import org.eclipse.linuxtools.lttng.jni.JniTrace;
import org.eclipse.linuxtools.lttng.jni.exception.JniException;
import org.eclipse.linuxtools.lttng.jni_v2_5.JniTrace_v2_5;
import org.eclipse.linuxtools.lttng.jni_v2_6.JniTrace_v2_6;
+/**
+ * <b><u>JniTraceFactory</u></b>
+ * <p>
+ * This class factory is responsible of returning the correct JniTrace implementation from a (valid) trace path.<p>
+ *
+ * The different version supported are listed below and the same version string are expected to be returned by JniTraceVersion.<br>
+ * Each version need a different Lttv library so each need its liblttvtraceread-X.Y.so installed and available on the system.
+ *
+ */
public class JniTraceFactory {
+ // ***
+ // Version string of the supported library version
+ // These will be used in the switch below to find the correct version
+ // ***
static final String TraceVersion_v2_3 = "2.3";
static final String TraceVersion_v2_5 = "2.5";
static final String TraceVersion_v2_6 = "2.6";
+ /*
+ * Default constructor is forbidden
+ */
private JniTraceFactory(){
- // Default constructor is forbidden
}
+ /**
+ * Factory function : return the correct version of the JniTrace from a given path<p>
+ * NOTE : The correct Lttv library (liblttvtraceread-X.Y.so) need to be installed and accessible otherwise this
+ * function will return an Exception.
+ *
+ * If the path is wrong or if the library is not supported (bad version or missing library) an Exception will be throwed.
+ *
+ * @param path Path of the trace we want to open
+ * @param show_debug Should JniTrace print debug or not?
+ *
+ * @return a newly allocated JniTrace of the correct version
+ *
+ * @throws JniException
+ */
static public JniTrace getJniTrace(String path, boolean show_debug) throws JniException {
try {
JniTraceVersion traceVersion = new JniTraceVersion(path);
- if ( traceVersion.toString().equals(TraceVersion_v2_6) ) {
- return new JniTrace_v2_6(path);
+ if ( traceVersion.getVersionAsString().equals(TraceVersion_v2_6) ) {
+ return new JniTrace_v2_6(path, show_debug);
}
- else if ( traceVersion.toString().equals(TraceVersion_v2_5) ) {
- return new JniTrace_v2_5(path);
+ else if ( traceVersion.getVersionAsString().equals(TraceVersion_v2_5) ) {
+ return new JniTrace_v2_5(path, show_debug);
}
- else if ( traceVersion.toString().equals(TraceVersion_v2_3) ) {
- return new JniTrace_v2_3(path);
+ else if ( traceVersion.getVersionAsString().equals(TraceVersion_v2_3) ) {
+ return new JniTrace_v2_3(path, show_debug);
}
else {
String errMsg = "\nERROR : Unrecognized/unsupported trace version." +
- "\nLibrary reported a trace version " + traceVersion.toString() + "." +
- "\nMake sure you installed the Lttv library that support this version (look for liblttvtraceread-" + traceVersion.toString() + ".so).\n";
+ "\nLibrary reported a trace version " + traceVersion.getVersionAsString() + "." +
+ "\nMake sure you installed the Lttv library that support this version (look for liblttvtraceread-" + traceVersion.getVersionAsString() + ".so).\n";
throw new JniException(errMsg);
}
}
package org.eclipse.linuxtools.lttng.jni.factory;
+/*******************************************************************************
+ * Copyright (c) 2009 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * William Bourque (wbourque@gmail.com) - Initial API and implementation
+ *******************************************************************************/
+import org.eclipse.linuxtools.lttng.jni.exception.JniException;
import org.eclipse.linuxtools.lttng.jni.exception.JniTraceVersionException;
+/**
+ * <b><u>JniTraceVersion</u></b>
+ * <p>
+ * This class is responsible of returning the correct version number of a trace at a certain given path.<p>
+ *
+ * The class will call the C library to get the correct version number from the trace.<p>
+ *
+ * Lttv library loader (liblttvtraceread_loader.so) and the default Lttv library (liblttvtraceread.so) must be installed on system and available to java.
+ *
+ */
public class JniTraceVersion {
+ // Native access functions
protected native void ltt_getTraceVersion(String tracepath);
protected native void ltt_setLibraryPath(String ldLibraryPath);
+ // Variables to store version number
private int majorNumber = 0;
private int minorNumber = 0;
+ // To store the given tracepath
private String tracepath = "";
-
+
+ // Was the trace read already?
+ private boolean wasTraceRead = false;
+
+ /**
+ * Default constructor.<p>
+ *
+ * Do nothing, readVersionFromTrace(path) will need to be called by the user
+ */
public JniTraceVersion() {
// Nothing to do
}
+ /**
+ * Constructor that takes a tracepath parameter.<p>
+ *
+ * This constructor read the version number from the trace, so it might throw.
+ *
+ * @param newTracepath The <b>directory</b> of the trace to read.
+ *
+ * @exception JniException If the library can not be loaded,if the path is wrong or if something go wrong during the read.
+ */
public JniTraceVersion(String newTracepath) throws JniTraceVersionException {
// Read the version number from the trace
- readVersionNumber(newTracepath);
+ readVersionFromTrace(newTracepath);
}
+ /**
+ * Copy constructor.
+ *
+ * @param oldVersion A reference to the JniTraceVersion to copy.
+ */
public JniTraceVersion(JniTraceVersion oldVersion) {
majorNumber = oldVersion.majorNumber;
minorNumber = oldVersion.minorNumber;
}
+ /*
+ * Read the version from the (already set) tracepath.<p>
+ *
+ * This version is used internally and will silently dismiss any exceptions.
+ *
+ */
+ private void readVersionNumberNofail() {
+ try {
+ readVersionFromTrace(tracepath);
+ }
+ catch(JniTraceVersionException e) { }
+ }
+
+ /**
+ * Read the version from the (already set) tracepath.<p>
+ *
+ * This function throw if the library can not be loaded, if the path is wrong or if something go wrong during the read.
+ *
+ */
public void readVersionNumber() throws JniTraceVersionException {
- readVersionNumber(tracepath);
+ readVersionFromTrace(tracepath);
}
- public void readVersionNumber(String tracepath) throws JniTraceVersionException {
+ /**
+ * Read the version from a given tracepath.<p>
+ * MajorVersion and MinorVersion should be set after a successful execution of this function.<br>
+ *
+ * This function throw if the library can not be loaded,if the path is wrong or if something go wrong during the read.
+ *
+ */
+ public void readVersionFromTrace(String newTracepath) throws JniTraceVersionException {
// Verify that the tracepath isn't obliviously wrong (null or empty)
- if ( (tracepath == null) || (tracepath.equals("") ) ) {
+ if ( (newTracepath == null) || (newTracepath.equals("") ) ) {
throw new JniTraceVersionException("ERROR : Tracepath is null or empty! (readVersionNumber)");
}
+ else {
+ // Otherwise set the path in case it was changed
+ tracepath = newTracepath;
+ }
try {
// Load the C library here.
// Assuming the C library loaded correctly, call the JNI here.
ltt_getTraceVersion(tracepath);
+
+ // We can now assume that the trace was read
+ wasTraceRead = true;
}
+ // The library was unable to load -> Lttv not installed or bad version of it?
catch (java.lang.UnsatisfiedLinkError e) {
- throw new JniTraceVersionException("ERROR : Could not get trace version. Is the library missing?\n" +
- " Make sure you setted either \"java.library.path\" or \"LD_LIBRARY_PATH\" (readVersionNumber)");
+ throw new JniTraceVersionException("\nERROR : Could not get trace version. Is the library missing?" +
+ "\nMake sure you setted either \"java.library.path\" or \"LD_LIBRARY_PATH\" (readVersionNumber)\n");
}
+ // Something else failed -> Possibly a bad tracepath was given
catch (Exception e) {
- throw new JniTraceVersionException("ERROR : Call to ltt_getTraceVersion failed. (readVersionNumber)");
+ throw new JniTraceVersionException("\nERROR : Call to ltt_getTraceVersion failed. (readVersionNumber)\n");
}
}
-
+ /**
+ * Get major version number of the trace.<p>
+ * Note : readVersionFromTrace() will be called if it wasn't done but exception will be silently ignored.
+ *
+ * @return major version
+ */
public int getMajor() {
+ if ( wasTraceRead == false ) {
+ readVersionNumberNofail();
+ }
+
return majorNumber;
}
+ /**
+ * Get minor version number of the trace.<p>
+ * Note : readVersionFromTrace() will be called if it wasn't done but exception will be silently ignored.
+ *
+ * @return minor version
+ */
public int getMinor() {
+ if ( wasTraceRead == false ) {
+ readVersionNumberNofail();
+ }
+
return minorNumber;
}
+ /**
+ * Get full version number of the trace.<p>
+ * Note : readVersionFromTrace() will be called if it wasn't done but exception will be silently ignored.
+ *
+ * @return Full Version as float
+ */
public float getVersionAsFloat() {
+ if ( wasTraceRead == false ) {
+ readVersionNumberNofail();
+ }
+
return ((float)majorNumber + ((float)minorNumber)/10);
}
+ /**
+ * Get full version number of the trace.<p>
+ * Note : readVersionFromTrace() will be called if it wasn't done but exception will be silently ignored.
+ *
+ * @return Full Version as string
+ */
+ public String getVersionAsString() {
+ if ( wasTraceRead == false ) {
+ readVersionNumberNofail();
+ }
+
+ return majorNumber + "." + minorNumber;
+ }
+
+ /**
+ * Get for the current tracepath
+ *
+ * @return The tracepath was are currently using.
+ */
public String getTracepath() {
return tracepath;
}
+ /**
+ * Set for the tracepath.<p>
+ * NOTE : Changing this will reset the version number currently loaded.
+ * NOTE2 : readVersionFromTrace() will be called but exception will be silently ignored.
+ *
+ * @param newtracepath The net tracepath
+ */
public void setTracepath(String newtracepath) {
+ majorNumber = 0;
+ minorNumber = 0;
+ wasTraceRead = false;
tracepath = newtracepath;
+
+ // Call the read function. This will fill up all the number if it goes well.
+ readVersionNumberNofail();
}
-
+ /*
+ * This function is be called from the C side to assign the version number the Java variable.
+ */
@SuppressWarnings("unused")
private void setTraceVersionFromC(int newMajor, int newMinor) {
majorNumber = newMajor;
minorNumber = newMinor;
}
+
@Override
public String toString() {
- return majorNumber + "." + minorNumber;
+ return "JniTraceVersion [" + majorNumber + "." + minorNumber + "]";
}
}