Commit | Line | Data |
---|---|---|
5d10d135 | 1 | package org.eclipse.linuxtools.lttng.trace; |
bf57df3f | 2 | /******************************************************************************* |
a3767fd9 | 3 | * Copyright (c) 2009, 2011 Ericsson, MontaVista Software |
bf57df3f WB |
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 | |
a3767fd9 | 12 | * Yufen Kuo (ykuo@mvista.com) - add support to allow user specify trace library path |
bf57df3f | 13 | *******************************************************************************/ |
5d10d135 | 14 | |
c392540b | 15 | import org.eclipse.linuxtools.lttng.exceptions.LttngException; |
5d10d135 ASL |
16 | import org.eclipse.linuxtools.lttng.jni.exception.JniTraceVersionException; |
17 | import org.eclipse.linuxtools.lttng.jni.factory.JniTraceVersion; | |
18 | ||
bf57df3f WB |
19 | /** |
20 | * <b><u>LTTngTraceVersion</u></b><p> | |
21 | * | |
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> | |
24 | * | |
25 | */ | |
5d10d135 ASL |
26 | public class LTTngTraceVersion { |
27 | ||
28 | private String tracepath = null; | |
a3767fd9 FC |
29 | private String traceLibPath = null; |
30 | ||
5d10d135 ASL |
31 | private JniTraceVersion traceVersion = new JniTraceVersion(); |
32 | ||
bf57df3f WB |
33 | /* |
34 | * Default constructor is forbidden | |
35 | */ | |
5d10d135 ASL |
36 | @SuppressWarnings("unused") |
37 | private LTTngTraceVersion() { | |
38 | // Default constructor forbidden | |
39 | } | |
40 | ||
bf57df3f WB |
41 | /** |
42 | * Default constructor, takes a tracepath as parameter. | |
43 | * | |
44 | * @param newPath (Valid) path to a LTTng trace <b>directory</b>. | |
a3767fd9 | 45 | * @param newLibPath (Valid) path to a LTTng trace library<b>directory</b>. |
bf57df3f WB |
46 | * @throws LttngException Throwed if something go wrong (bad tracepath or the C library could not be loaded). |
47 | */ | |
a3767fd9 | 48 | public LTTngTraceVersion(String newPath, String newLibPath) throws LttngException { |
5d10d135 | 49 | tracepath = newPath; |
a3767fd9 | 50 | traceLibPath = newLibPath; |
5d10d135 | 51 | // Fill the new traceversion object |
a3767fd9 | 52 | fillJniTraceVersion(tracepath, newLibPath); |
5d10d135 ASL |
53 | } |
54 | ||
bf57df3f WB |
55 | /* |
56 | * Fill (load version numbers) into the JniTraceVersion object.<p> | |
57 | * This need to be done each time the tracepath is changed. | |
58 | * | |
59 | * @param newTracepath (Valid) path to a LTTng trace <b>directory</b>. | |
a3767fd9 | 60 | * @param newTraceLibPath (Valid) path to a LTTng trace library<b>directory</b>. |
bf57df3f WB |
61 | * |
62 | * @throws LttngException If something go wrong (bad tracepath or the C library could not be loaded). | |
63 | * | |
64 | * @see org.eclipse.linuxtools.lttng.jni.factory.JniTraceVersion | |
65 | */ | |
a3767fd9 | 66 | private void fillJniTraceVersion(String newTracepath, String newTraceLibPath) throws LttngException { |
5d10d135 | 67 | try { |
a3767fd9 | 68 | traceVersion.readVersionFromTrace(newTracepath, newTraceLibPath); |
5d10d135 ASL |
69 | } |
70 | catch (JniTraceVersionException e) { | |
d89d14e1 | 71 | throw new LttngException( e.toString() ); |
5d10d135 ASL |
72 | } |
73 | } | |
74 | ||
bf57df3f WB |
75 | /** |
76 | * Get for the full version number as String | |
77 | * | |
78 | * @return version number as String | |
79 | */ | |
5d10d135 | 80 | public String getTraceVersionString() { |
bf57df3f | 81 | return traceVersion.getVersionAsString(); |
5d10d135 ASL |
82 | } |
83 | ||
bf57df3f WB |
84 | /** |
85 | * Get for the major version number | |
86 | * | |
87 | * @return major version number as int | |
88 | */ | |
5d10d135 ASL |
89 | public int getTraceMinorVersion() { |
90 | return traceVersion.getMinor(); | |
91 | } | |
92 | ||
bf57df3f WB |
93 | /** |
94 | * Get for the minor version number | |
95 | * | |
96 | * @return minor version number as int | |
97 | */ | |
5d10d135 ASL |
98 | public int getTraceMajorVersion() { |
99 | return traceVersion.getMajor(); | |
100 | } | |
101 | ||
bf57df3f WB |
102 | /** |
103 | * Get for the full version number as float | |
104 | * | |
105 | * @return version number as float | |
106 | */ | |
5d10d135 ASL |
107 | public float getTraceFloatVersion() { |
108 | return traceVersion.getVersionAsFloat(); | |
109 | } | |
110 | ||
bf57df3f WB |
111 | /** |
112 | * Verify is the currently loaded path was a valid LTTng tracepath.<p> | |
113 | * | |
114 | * Internally, the version number will be checked, any number <= 0 is expected to be wrong. | |
115 | * | |
116 | * @return A boolean saying if the tracepath appears to be valid or not. | |
117 | */ | |
5d10d135 ASL |
118 | public boolean isValidLttngTrace() { |
119 | if ( traceVersion.getVersionAsFloat() > 0 ) { | |
120 | return true; | |
121 | } | |
122 | else { | |
123 | return false; | |
124 | } | |
125 | } | |
126 | ||
bf57df3f WB |
127 | /** |
128 | * Get for the currently loaded tracepath | |
129 | * | |
130 | * @return the tracepath currently in use | |
131 | */ | |
5d10d135 ASL |
132 | public String getTracepath() { |
133 | return tracepath; | |
134 | } | |
135 | ||
bf57df3f WB |
136 | /** |
137 | * Set a new tracepath<p> | |
138 | * | |
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. | |
141 | * | |
142 | * @param newTracepath The new tracepath to set. | |
a3767fd9 | 143 | * @param newLibPath The new trace library path to set. |
bf57df3f | 144 | */ |
a3767fd9 | 145 | public void setTracepath(String newTracepath, String newLibPath) { |
5d10d135 | 146 | try { |
a3767fd9 | 147 | fillJniTraceVersion(newTracepath, newLibPath); |
5d10d135 | 148 | tracepath = newTracepath; |
a3767fd9 | 149 | traceLibPath = newLibPath; |
5d10d135 ASL |
150 | } |
151 | catch (LttngException e) { | |
9c4eb5f7 FC |
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$ | |
5d10d135 ASL |
154 | } |
155 | } | |
156 | ||
157 | @Override | |
3b38ea61 | 158 | @SuppressWarnings("nls") |
5d10d135 ASL |
159 | public String toString() { |
160 | return "LTTngTraceVersion : [" + getTraceFloatVersion() + "]"; | |
161 | } | |
a3767fd9 FC |
162 | public String getTraceLibPath() { |
163 | return traceLibPath; | |
164 | } | |
5d10d135 | 165 | } |