Rename xxx.lttng to xxx.lttng.core
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.core / src / org / eclipse / linuxtools / lttng / trace / LTTngTraceVersion.java
1 package org.eclipse.linuxtools.lttng.trace;
2 /*******************************************************************************
3 * Copyright (c) 2009, 2011 Ericsson, MontaVista Software
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 * Yufen Kuo (ykuo@mvista.com) - add support to allow user specify trace library path
13 *******************************************************************************/
14
15 import org.eclipse.linuxtools.lttng.exceptions.LttngException;
16 import org.eclipse.linuxtools.lttng.jni.exception.JniTraceVersionException;
17 import org.eclipse.linuxtools.lttng.jni.factory.JniTraceVersion;
18
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 */
26 public class LTTngTraceVersion {
27
28 private String tracepath = null;
29 private String traceLibPath = null;
30
31 private JniTraceVersion traceVersion = new JniTraceVersion();
32
33 /*
34 * Default constructor is forbidden
35 */
36 @SuppressWarnings("unused")
37 private LTTngTraceVersion() {
38 // Default constructor forbidden
39 }
40
41 /**
42 * Default constructor, takes a tracepath as parameter.
43 *
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).
47 */
48 public LTTngTraceVersion(String newPath, String newLibPath) throws LttngException {
49 tracepath = newPath;
50 traceLibPath = newLibPath;
51 // Fill the new traceversion object
52 fillJniTraceVersion(tracepath, newLibPath);
53 }
54
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>.
60 * @param newTraceLibPath (Valid) path to a LTTng trace library<b>directory</b>.
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 */
66 private void fillJniTraceVersion(String newTracepath, String newTraceLibPath) throws LttngException {
67 try {
68 traceVersion.readVersionFromTrace(newTracepath, newTraceLibPath);
69 }
70 catch (JniTraceVersionException e) {
71 throw new LttngException( e.toString() );
72 }
73 }
74
75 /**
76 * Get for the full version number as String
77 *
78 * @return version number as String
79 */
80 public String getTraceVersionString() {
81 return traceVersion.getVersionAsString();
82 }
83
84 /**
85 * Get for the major version number
86 *
87 * @return major version number as int
88 */
89 public int getTraceMinorVersion() {
90 return traceVersion.getMinor();
91 }
92
93 /**
94 * Get for the minor version number
95 *
96 * @return minor version number as int
97 */
98 public int getTraceMajorVersion() {
99 return traceVersion.getMajor();
100 }
101
102 /**
103 * Get for the full version number as float
104 *
105 * @return version number as float
106 */
107 public float getTraceFloatVersion() {
108 return traceVersion.getVersionAsFloat();
109 }
110
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 */
118 public boolean isValidLttngTrace() {
119 if ( traceVersion.getVersionAsFloat() > 0 ) {
120 return true;
121 }
122 else {
123 return false;
124 }
125 }
126
127 /**
128 * Get for the currently loaded tracepath
129 *
130 * @return the tracepath currently in use
131 */
132 public String getTracepath() {
133 return tracepath;
134 }
135
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.
143 * @param newLibPath The new trace library path to set.
144 */
145 public void setTracepath(String newTracepath, String newLibPath) {
146 try {
147 fillJniTraceVersion(newTracepath, newLibPath);
148 tracepath = newTracepath;
149 traceLibPath = newLibPath;
150 }
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$
154 }
155 }
156
157 @Override
158 @SuppressWarnings("nls")
159 public String toString() {
160 return "LTTngTraceVersion : [" + getTraceFloatVersion() + "]";
161 }
162 public String getTraceLibPath() {
163 return traceLibPath;
164 }
165 }
This page took 0.032958 seconds and 5 git commands to generate.