2010-11-10 Francois Chouinard <fchouinard@gmail.com> Contribution for Bug315307
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng / src / org / eclipse / linuxtools / lttng / trace / LTTngTraceVersion.java
1 package org.eclipse.linuxtools.lttng.trace;
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 import org.eclipse.linuxtools.lttng.LttngException;
15 import org.eclipse.linuxtools.lttng.jni.exception.JniTraceVersionException;
16 import org.eclipse.linuxtools.lttng.jni.factory.JniTraceVersion;
17
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 */
25 public class LTTngTraceVersion {
26
27 private String tracepath = null;
28 private JniTraceVersion traceVersion = new JniTraceVersion();
29
30 /*
31 * Default constructor is forbidden
32 */
33 @SuppressWarnings("unused")
34 private LTTngTraceVersion() {
35 // Default constructor forbidden
36 }
37
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 */
45 public LTTngTraceVersion(String newPath) throws LttngException {
46 tracepath = newPath;
47
48 // Fill the new traceversion object
49 fillJniTraceVersion(tracepath);
50 }
51
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 */
62 private void fillJniTraceVersion(String newTracepath) throws LttngException {
63 try {
64 traceVersion.readVersionFromTrace(newTracepath);
65 }
66 catch (JniTraceVersionException e) {
67 throw new LttngException( e.toString() );
68 }
69 }
70
71 /**
72 * Get for the full version number as String
73 *
74 * @return version number as String
75 */
76 public String getTraceVersionString() {
77 return traceVersion.getVersionAsString();
78 }
79
80 /**
81 * Get for the major version number
82 *
83 * @return major version number as int
84 */
85 public int getTraceMinorVersion() {
86 return traceVersion.getMinor();
87 }
88
89 /**
90 * Get for the minor version number
91 *
92 * @return minor version number as int
93 */
94 public int getTraceMajorVersion() {
95 return traceVersion.getMajor();
96 }
97
98 /**
99 * Get for the full version number as float
100 *
101 * @return version number as float
102 */
103 public float getTraceFloatVersion() {
104 return traceVersion.getVersionAsFloat();
105 }
106
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 */
114 public boolean isValidLttngTrace() {
115 if ( traceVersion.getVersionAsFloat() > 0 ) {
116 return true;
117 }
118 else {
119 return false;
120 }
121 }
122
123 /**
124 * Get for the currently loaded tracepath
125 *
126 * @return the tracepath currently in use
127 */
128 public String getTracepath() {
129 return tracepath;
130 }
131
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 */
140 public void setTracepath(String newTracepath) {
141 try {
142 fillJniTraceVersion(newTracepath);
143 tracepath = newTracepath;
144 }
145 catch (LttngException e) {
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$
148 }
149 }
150
151 @Override
152 @SuppressWarnings("nls")
153 public String toString() {
154 return "LTTngTraceVersion : [" + getTraceFloatVersion() + "]";
155 }
156
157 }
This page took 0.0502 seconds and 5 git commands to generate.