1 package org
.eclipse
.linuxtools
.lttng
.core
.trace
;
2 /*******************************************************************************
3 * Copyright (c) 2009, 2011 Ericsson, MontaVista Software
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 * Yufen Kuo (ykuo@mvista.com) - add support to allow user specify trace library path
13 *******************************************************************************/
15 import org
.eclipse
.linuxtools
.lttng
.core
.exceptions
.LttngException
;
16 import org
.eclipse
.linuxtools
.lttng
.jni
.exception
.JniTraceVersionException
;
17 import org
.eclipse
.linuxtools
.lttng
.jni
.factory
.JniTraceVersion
;
20 * <b><u>LTTngTraceVersion</u></b><p>
22 * This class is responsible of handling the version number of a trace.<p>
23 * It will return the correct version number and validity information of a trace given its path.<br>
26 public class LTTngTraceVersion
{
28 private String tracepath
= null;
29 private String traceLibPath
= null;
31 private JniTraceVersion traceVersion
= new JniTraceVersion();
34 * Default constructor is forbidden
36 @SuppressWarnings("unused")
37 private LTTngTraceVersion() {
38 // Default constructor forbidden
42 * Default constructor, takes a tracepath as parameter.
44 * @param newPath (Valid) path to a LTTng trace <b>directory</b>.
45 * @param newLibPath (Valid) path to a LTTng trace library<b>directory</b>.
46 * @throws LttngException Throwed if something go wrong (bad tracepath or the C library could not be loaded).
48 public LTTngTraceVersion(String newPath
, String newLibPath
) throws LttngException
{
50 traceLibPath
= newLibPath
;
51 // Fill the new traceversion object
52 fillJniTraceVersion(tracepath
, newLibPath
);
56 * Fill (load version numbers) into the JniTraceVersion object.<p>
57 * This need to be done each time the tracepath is changed.
59 * @param newTracepath (Valid) path to a LTTng trace <b>directory</b>.
60 * @param newTraceLibPath (Valid) path to a LTTng trace library<b>directory</b>.
62 * @throws LttngException If something go wrong (bad tracepath or the C library could not be loaded).
64 * @see org.eclipse.linuxtools.lttng.jni.factory.JniTraceVersion
66 private void fillJniTraceVersion(String newTracepath
, String newTraceLibPath
) throws LttngException
{
68 traceVersion
.readVersionFromTrace(newTracepath
, newTraceLibPath
);
70 catch (JniTraceVersionException e
) {
71 throw new LttngException( e
.toString() );
76 * Get for the full version number as String
78 * @return version number as String
80 public String
getTraceVersionString() {
81 return traceVersion
.getVersionAsString();
85 * Get for the major version number
87 * @return major version number as int
89 public int getTraceMinorVersion() {
90 return traceVersion
.getMinor();
94 * Get for the minor version number
96 * @return minor version number as int
98 public int getTraceMajorVersion() {
99 return traceVersion
.getMajor();
103 * Get for the full version number as float
105 * @return version number as float
107 public float getTraceFloatVersion() {
108 return traceVersion
.getVersionAsFloat();
112 * Verify is the currently loaded path was a valid LTTng tracepath.<p>
114 * Internally, the version number will be checked, any number <= 0 is expected to be wrong.
116 * @return A boolean saying if the tracepath appears to be valid or not.
118 public boolean isValidLttngTrace() {
119 if ( traceVersion
.getVersionAsFloat() > 0 ) {
128 * Get for the currently loaded tracepath
130 * @return the tracepath currently in use
132 public String
getTracepath() {
137 * Set a new tracepath<p>
139 * Note : Setting this will load the new version information into memory.<br>
140 * Errors will be catched but a warning will be printed if something go wrong.
142 * @param newTracepath The new tracepath to set.
143 * @param newLibPath The new trace library path to set.
145 public void setTracepath(String newTracepath
, String newLibPath
) {
147 fillJniTraceVersion(newTracepath
, newLibPath
);
148 tracepath
= newTracepath
;
149 traceLibPath
= newLibPath
;
151 catch (LttngException e
) {
152 System
.out
.println("Could not get the trace version from the given path." + //$NON-NLS-1$
153 "Please check that the given path is a valid LTTng trace. (getTracepath)"); //$NON-NLS-1$
158 @SuppressWarnings("nls")
159 public String
toString() {
160 return "LTTngTraceVersion : [" + getTraceFloatVersion() + "]";
162 public String
getTraceLibPath() {