lttng: Add a diagram showing the dependencies between plugins
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / service / LTTngControlServiceFactory.java
1 /**********************************************************************
2 * Copyright (c) 2012, 2013. 2013 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org.eclipse.linuxtools.internal.lttng2.ui.views.control.service;
13
14 import java.util.regex.Matcher;
15
16 import org.eclipse.core.commands.ExecutionException;
17 import org.eclipse.core.runtime.NullProgressMonitor;
18 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.logging.ControlCommandLogger;
19 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.messages.Messages;
20 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.preferences.ControlPreferences;
21 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.remote.ICommandResult;
22 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.remote.ICommandShell;
23
24 /**
25 * <p>
26 * Factory to create LTTngControlService instances depending on the version of the LTTng Trace Control
27 * installed on the remote host.
28 * </p>
29 *
30 * @author Bernd Hufmann
31 */
32 public class LTTngControlServiceFactory {
33
34 // ------------------------------------------------------------------------
35 // Attributes
36 // ------------------------------------------------------------------------
37 /**
38 * The singleton instance.
39 */
40 private static LTTngControlServiceFactory fInstance = null;
41
42 // ------------------------------------------------------------------------
43 // Constructor
44 // ------------------------------------------------------------------------
45 /**
46 * Constructor
47 */
48 private LTTngControlServiceFactory() {
49 }
50
51 // ------------------------------------------------------------------------
52 // Accessors
53 // ------------------------------------------------------------------------
54 /**
55 * @return the LTTngControlServiceFactory singleton instance.
56 */
57 public static synchronized LTTngControlServiceFactory getInstance() {
58 if (fInstance == null) {
59 fInstance = new LTTngControlServiceFactory();
60 }
61 return fInstance;
62 }
63
64 // ------------------------------------------------------------------------
65 // Factory method
66 // ------------------------------------------------------------------------
67 /**
68 * Gets the LTTng Control Service implementation based on the version of the
69 * remote LTTng Tools.
70 *
71 * @param shell - the shell implementation to pass to the service
72 * @return - LTTng Control Service implementation
73 * @throws ExecutionException If the command fails
74 */
75 public ILttngControlService getLttngControlService(ICommandShell shell) throws ExecutionException {
76 // get the version
77 String command = LTTngControlServiceConstants.CONTROL_COMMAND + LTTngControlServiceConstants.COMMAND_VERSION;
78
79 if (ControlPreferences.getInstance().isLoggingEnabled()) {
80 ControlCommandLogger.log(command);
81 }
82 ICommandResult result = null;
83
84 try {
85 result = shell.executeCommand(command, new NullProgressMonitor());
86 } catch (ExecutionException e) {
87 throw new ExecutionException(Messages.TraceControl_GettingVersionError + ": " + e); //$NON-NLS-1$
88 }
89
90 if (ControlPreferences.getInstance().isLoggingEnabled()) {
91 ControlCommandLogger.log(LTTngControlService.formatOutput(result));
92 }
93
94 if ((result != null) && (result.getResult() == 0) && (result.getOutput().length >= 1)) {
95 int index = 0;
96 while (index < result.getOutput().length) {
97 String line = result.getOutput()[index];
98 Matcher versionMatcher = LTTngControlServiceConstants.VERSION_PATTERN.matcher(line);
99 if (versionMatcher.matches()) {
100 String version = versionMatcher.group(1).trim();
101 Matcher matcher = LTTngControlServiceConstants.VERSION_2_PATTERN.matcher(version);
102 if (matcher.matches()) {
103 LTTngControlService service = new LTTngControlService(shell);
104 service.setVersion(version);
105 return service;
106 }
107 throw new ExecutionException(Messages.TraceControl_UnsupportedVersionError + ": " + version); //$NON-NLS-1$
108 }
109 index++;
110 }
111 }
112 throw new ExecutionException(Messages.TraceControl_GettingVersionError);
113 }
114 }
This page took 0.037211 seconds and 5 git commands to generate.