More javadoc updates
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.jni / src / org / eclipse / linuxtools / lttng / jni / factory / JniTraceFactory.java
CommitLineData
0152140d 1package org.eclipse.linuxtools.lttng.jni.factory;
c357e4b6 2/*******************************************************************************
a3767fd9 3 * Copyright (c) 2009, 2011 Ericsson, MontaVista Software
84b2b1f0 4 *
c357e4b6
WB
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
84b2b1f0 9 *
c357e4b6
WB
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 14
ce38c104
FC
15import org.eclipse.linuxtools.internal.lttng.jni.exception.JniException;
16import org.eclipse.linuxtools.internal.lttng.jni.exception.JniTraceVersionException;
17import org.eclipse.linuxtools.internal.lttng.jni_v2_3.JniTrace_v2_3;
18import org.eclipse.linuxtools.internal.lttng.jni_v2_5.JniTrace_v2_5;
19import org.eclipse.linuxtools.internal.lttng.jni_v2_6.JniTrace_v2_6;
0152140d 20import org.eclipse.linuxtools.lttng.jni.JniTrace;
0152140d 21
c357e4b6 22/**
c357e4b6 23 * This class factory is responsible of returning the correct JniTrace implementation from a (valid) trace path.<p>
84b2b1f0 24 *
c357e4b6
WB
25 * The different version supported are listed below and the same version string are expected to be returned by JniTraceVersion.<br>
26 * Each version need a different Lttv library so each need its liblttvtraceread-X.Y.so installed and available on the system.
84b2b1f0 27 *
d37aaa7f
FC
28 * @version 0.1
29 * @author William Bourque
c357e4b6 30 */
0152140d 31public class JniTraceFactory {
84b2b1f0 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$
84b2b1f0 40
c357e4b6
WB
41 /*
42 * Default constructor is forbidden
43 */
0152140d
ASL
44 private JniTraceFactory(){
45 }
84b2b1f0
AM
46
47 /**
48 * Factory function : return the correct version of the JniTrace from a
49 * given path
50 * <p>
51 * NOTE : The correct Lttv library (liblttvtraceread-X.Y.so) need to be
52 * installed and accessible otherwise this function will return an
53 * Exception.
54 *
55 * If the path is wrong or if the library is not supported (bad version or
56 * missing library) an Exception will be throwed.
57 *
58 * @param path
59 * Path of the trace we want to open
60 * @param traceLibPath
61 * Directory to the trace libraries
62 * @param show_debug
63 * Should JniTrace print debug or not?
64 *
65 * @return a newly allocated JniTrace of the correct version
66 *
67 * @throws JniException
68 * If the JNI call fails
69 */
a3767fd9 70 static public JniTrace getJniTrace(String path, String traceLibPath, boolean show_debug) throws JniException {
84b2b1f0 71
a3767fd9
FC
72 try {
73 JniTraceVersion traceVersion = new JniTraceVersion(path, traceLibPath);
74 JniTrace trace = null;
75 if (traceVersion.getVersionAsString().equals(TraceVersion_v2_6)) {
76 trace = new JniTrace_v2_6(path, show_debug);
7178eb03 77 } else if (traceVersion.getVersionAsString().equals(TraceVersion_v2_5)) {
a3767fd9 78 trace = new JniTrace_v2_5(path, show_debug);
7178eb03 79 } else if (traceVersion.getVersionAsString().equals(TraceVersion_v2_3)) {
a3767fd9
FC
80 trace = new JniTrace_v2_3(path, show_debug);
81 }
82 if (trace != null) {
84b2b1f0 83 if (traceLibPath != null) {
a3767fd9 84 trace.setTraceLibPath(traceLibPath);
84b2b1f0 85 }
a3767fd9
FC
86 trace.openTrace(path);
87 return trace;
a3767fd9 88 }
84b2b1f0
AM
89 String errMsg = "Unrecognized/unsupported trace version\n\n" //$NON-NLS-1$
90 + "Library reported trace version " + traceVersion.getVersionAsString() + "\n\n" //$NON-NLS-1$ //$NON-NLS-2$
91 + "Make sure that you installed the corresponding parsing library (liblttvtraceread-" + traceVersion.getVersionAsString() + ".so) " //$NON-NLS-1$ //$NON-NLS-2$
92 + "and that it can be found from either your LD_LIBRARY_PATH or the Trace Library Path (in LTTng project properties)\n\n" //$NON-NLS-1$
93 + "Refer to the LTTng User Guide for more information"; //$NON-NLS-1$
94 throw new JniException(errMsg);
a3767fd9
FC
95
96 } catch (JniTraceVersionException e) {
7178eb03
FC
97 String errMsg = "Couldn't obtain the trace version\n\n" //$NON-NLS-1$
98 + "This usually means that the library loader (liblttvtraceread_loader.so) could not be found.\n\n" //$NON-NLS-1$
99 + "Make sure you installed the parsing library and that your LD_LIBRARY_PATH or Trace Library Path is set correctly\n\n" //$NON-NLS-1$
100 + "Refer to the LTTng User Guide for more information"; //$NON-NLS-1$
a3767fd9
FC
101
102 throw new JniException(errMsg);
103 }
104 }
84b2b1f0 105
0152140d 106}
This page took 0.037251 seconds and 5 git commands to generate.