ctf: Allow finalizing CTFTrace's if validation failed
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / service / LTTngControlServiceFactory.java
CommitLineData
276c17e7
BH
1/**********************************************************************
2 * Copyright (c) 2012 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 **********************************************************************/
12package org.eclipse.linuxtools.internal.lttng2.ui.views.control.service;
13
14import java.util.regex.Matcher;
15
16import org.eclipse.core.commands.ExecutionException;
17import org.eclipse.core.runtime.NullProgressMonitor;
18import org.eclipse.linuxtools.internal.lttng2.ui.views.control.Messages;
19
20/**
21 * <b><u>LTTngControlServiceFactory</u></b>
22 * <p>
23 * Factory to create LTTngControlService instances depending on the version of the LTTng Trace Control
24 * installed on the remote host.
25 * </p>
26 */
27public class LTTngControlServiceFactory {
28
29 // ------------------------------------------------------------------------
30 // Attributes
31 // ------------------------------------------------------------------------
c5f68877
BH
32 /**
33 * The singleton instance.
34 */
276c17e7
BH
35 private static LTTngControlServiceFactory fInstance = null;
36
37 // ------------------------------------------------------------------------
38 // Constructor
39 // ------------------------------------------------------------------------
c5f68877
BH
40 /**
41 * Constructor
42 */
276c17e7
BH
43 private LTTngControlServiceFactory() {
44 }
45
46 // ------------------------------------------------------------------------
47 // Accessors
48 // ------------------------------------------------------------------------
c5f68877
BH
49 /**
50 * @return the LTTngControlServiceFactory singleton instance.
51 */
276c17e7
BH
52 public static synchronized LTTngControlServiceFactory getInstance() {
53 if (fInstance == null) {
54 fInstance = new LTTngControlServiceFactory();
55 }
56 return fInstance;
57 }
58
59 // ------------------------------------------------------------------------
60 // Factory method
61 // ------------------------------------------------------------------------
c5f68877
BH
62 /**
63 * Gets the LTTng Control Service implementation based on the version of the
64 * remote LTTng Tools.
65 * @param shell - the shell implementation to pass to the service
66 * @return - LTTng Control Service implementation
67 * @throws ExecutionException
68 */
276c17e7
BH
69 public ILttngControlService getLttngControlService(ICommandShell shell) throws ExecutionException {
70 // get the version
71 ICommandResult result = shell.executeCommand(LTTngControlServiceConstants.CONTROL_COMMAND + LTTngControlServiceConstants.COMMAND_VERSION, new NullProgressMonitor());
72
73 if ((result != null) && (result.getResult() == 0) && (result.getOutput().length >= 1) && (!LTTngControlServiceConstants.ERROR_PATTERN.matcher(result.getOutput()[0]).matches())) {
74 int index = 0;
75 while (index < result.getOutput().length) {
76 String line = result.getOutput()[index];
77 Matcher matcher = LTTngControlServiceConstants.VERSION_PATTERN.matcher(line);
78 if (matcher.matches()) {
79 String version = matcher.group(1).trim();
80 if (version.startsWith(LTTngControlServiceConstants.LTTNG_MAJOR_VERSION_2_0)) {
81 LTTngControlService service = new LTTngControlService(shell);
82 service.setVersion(version);
83 return service;
84 }
85 throw new ExecutionException(Messages.TraceControl_UnsupportedVersionError + ": " + version); //$NON-NLS-1$
86 }
87 index++;
88 }
89 }
90 throw new ExecutionException(Messages.TraceControl_GettingVersionError);
91 }
92}
This page took 0.031558 seconds and 5 git commands to generate.