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