Commit | Line | Data |
---|---|---|
0152140d | 1 | package org.eclipse.linuxtools.lttng.jni.factory; |
c357e4b6 | 2 | /******************************************************************************* |
a3767fd9 | 3 | * Copyright (c) 2009, 2011 Ericsson, MontaVista Software |
c357e4b6 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 |
c357e4b6 | 13 | *******************************************************************************/ |
0152140d ASL |
14 | |
15 | import org.eclipse.linuxtools.lttng.jni.JniTrace; | |
16 | import org.eclipse.linuxtools.lttng.jni.exception.JniException; | |
17 | import org.eclipse.linuxtools.lttng.jni.exception.JniTraceVersionException; | |
18 | import org.eclipse.linuxtools.lttng.jni_v2_3.JniTrace_v2_3; | |
19 | import org.eclipse.linuxtools.lttng.jni_v2_5.JniTrace_v2_5; | |
20 | import org.eclipse.linuxtools.lttng.jni_v2_6.JniTrace_v2_6; | |
21 | ||
c357e4b6 WB |
22 | /** |
23 | * <b><u>JniTraceFactory</u></b> | |
24 | * <p> | |
25 | * This class factory is responsible of returning the correct JniTrace implementation from a (valid) trace path.<p> | |
26 | * | |
27 | * The different version supported are listed below and the same version string are expected to be returned by JniTraceVersion.<br> | |
28 | * Each version need a different Lttv library so each need its liblttvtraceread-X.Y.so installed and available on the system. | |
29 | * | |
30 | */ | |
0152140d ASL |
31 | public class JniTraceFactory { |
32 | ||
c357e4b6 WB |
33 | // *** |
34 | // Version string of the supported library version | |
35 | // These will be used in the switch below to find the correct version | |
36 | // *** | |
3b38ea61 FC |
37 | static final String TraceVersion_v2_3 = "2.3"; //$NON-NLS-1$ |
38 | static final String TraceVersion_v2_5 = "2.5"; //$NON-NLS-1$ | |
39 | static final String TraceVersion_v2_6 = "2.6"; //$NON-NLS-1$ | |
0152140d | 40 | |
c357e4b6 WB |
41 | /* |
42 | * Default constructor is forbidden | |
43 | */ | |
0152140d ASL |
44 | private JniTraceFactory(){ |
45 | } | |
46 | ||
c357e4b6 WB |
47 | /** |
48 | * Factory function : return the correct version of the JniTrace from a given path<p> | |
49 | * NOTE : The correct Lttv library (liblttvtraceread-X.Y.so) need to be installed and accessible otherwise this | |
50 | * function will return an Exception. | |
51 | * | |
52 | * If the path is wrong or if the library is not supported (bad version or missing library) an Exception will be throwed. | |
53 | * | |
54 | * @param path Path of the trace we want to open | |
a3767fd9 | 55 | * @param traceLibPath Directory to the trace libraries |
c357e4b6 WB |
56 | * @param show_debug Should JniTrace print debug or not? |
57 | * | |
58 | * @return a newly allocated JniTrace of the correct version | |
59 | * | |
60 | * @throws JniException | |
61 | */ | |
a3767fd9 | 62 | static public JniTrace getJniTrace(String path, String traceLibPath, boolean show_debug) throws JniException { |
0152140d | 63 | |
a3767fd9 FC |
64 | try { |
65 | JniTraceVersion traceVersion = new JniTraceVersion(path, traceLibPath); | |
66 | JniTrace trace = null; | |
67 | if (traceVersion.getVersionAsString().equals(TraceVersion_v2_6)) { | |
68 | trace = new JniTrace_v2_6(path, show_debug); | |
69 | } else if (traceVersion.getVersionAsString().equals( | |
70 | TraceVersion_v2_5)) { | |
71 | trace = new JniTrace_v2_5(path, show_debug); | |
72 | } else if (traceVersion.getVersionAsString().equals( | |
73 | TraceVersion_v2_3)) { | |
74 | trace = new JniTrace_v2_3(path, show_debug); | |
75 | } | |
76 | if (trace != null) { | |
77 | if (traceLibPath != null) | |
78 | trace.setTraceLibPath(traceLibPath); | |
79 | trace.openTrace(path); | |
80 | return trace; | |
81 | } else { | |
82 | String errMsg = "\nERROR : Unrecognized/unsupported trace version." + //$NON-NLS-1$ | |
83 | "\nLibrary reported a trace version " | |
84 | + traceVersion.getVersionAsString() | |
85 | + "." + //$NON-NLS-1$ //$NON-NLS-2$ | |
86 | "\nMake sure you installed the Lttv library that support this version (look for liblttvtraceread-" | |
87 | + traceVersion.getVersionAsString() + ".so).\n"; //$NON-NLS-1$ //$NON-NLS-2$ | |
88 | throw new JniException(errMsg); | |
89 | } | |
90 | ||
91 | } catch (JniTraceVersionException e) { | |
92 | String errMsg = "\nERROR : Call to JniTraceVersion() failed." + //$NON-NLS-1$ | |
93 | "\nThis usually means that the library (liblttvtraceread_loader.so) could not be found." | |
94 | + //$NON-NLS-1$ | |
95 | "\nMake sure the LTTv library is installed and that your LD_LIBRARY_PATH is set correctly (see help for more details)\n."; //$NON-NLS-1$ | |
96 | ||
97 | throw new JniException(errMsg); | |
98 | } | |
99 | } | |
0152140d ASL |
100 | |
101 | } |