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