1 /**********************************************************************
2 * Copyright (c) 2012 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.service
;
14 import java
.util
.regex
.Matcher
;
16 import org
.eclipse
.core
.commands
.ExecutionException
;
17 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
18 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.Messages
;
21 * <b><u>LTTngControlServiceFactory</u></b>
23 * Factory to create LTTngControlService instances depending on the version of the LTTng Trace Control
24 * installed on the remote host.
27 public class LTTngControlServiceFactory
{
29 // ------------------------------------------------------------------------
31 // ------------------------------------------------------------------------
32 private static LTTngControlServiceFactory fInstance
= null;
34 // ------------------------------------------------------------------------
36 // ------------------------------------------------------------------------
37 private LTTngControlServiceFactory() {
40 // ------------------------------------------------------------------------
42 // ------------------------------------------------------------------------
43 public static synchronized LTTngControlServiceFactory
getInstance() {
44 if (fInstance
== null) {
45 fInstance
= new LTTngControlServiceFactory();
50 // ------------------------------------------------------------------------
52 // ------------------------------------------------------------------------
53 public ILttngControlService
getLttngControlService(ICommandShell shell
) throws ExecutionException
{
55 ICommandResult result
= shell
.executeCommand(LTTngControlServiceConstants
.CONTROL_COMMAND
+ LTTngControlServiceConstants
.COMMAND_VERSION
, new NullProgressMonitor());
57 if ((result
!= null) && (result
.getResult() == 0) && (result
.getOutput().length
>= 1) && (!LTTngControlServiceConstants
.ERROR_PATTERN
.matcher(result
.getOutput()[0]).matches())) {
59 while (index
< result
.getOutput().length
) {
60 String line
= result
.getOutput()[index
];
61 Matcher matcher
= LTTngControlServiceConstants
.VERSION_PATTERN
.matcher(line
);
62 if (matcher
.matches()) {
63 String version
= matcher
.group(1).trim();
64 if (version
.startsWith(LTTngControlServiceConstants
.LTTNG_MAJOR_VERSION_2_0
)) {
65 LTTngControlService service
= new LTTngControlService(shell
);
66 service
.setVersion(version
);
69 throw new ExecutionException(Messages
.TraceControl_UnsupportedVersionError
+ ": " + version
); //$NON-NLS-1$
74 throw new ExecutionException(Messages
.TraceControl_GettingVersionError
);