1 /**********************************************************************
2 * Copyright (c) 2012, 2013 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
.control
.ui
.views
.remote
;
14 import org
.eclipse
.core
.commands
.ExecutionException
;
15 import org
.eclipse
.core
.runtime
.OperationCanceledException
;
16 import org
.eclipse
.core
.runtime
.Status
;
17 import org
.eclipse
.rse
.core
.model
.IHost
;
18 import org
.eclipse
.rse
.core
.model
.IRSECallback
;
19 import org
.eclipse
.rse
.core
.subsystems
.ICommunicationsListener
;
20 import org
.eclipse
.rse
.core
.subsystems
.IConnectorService
;
21 import org
.eclipse
.rse
.core
.subsystems
.ISubSystem
;
22 import org
.eclipse
.rse
.services
.IService
;
23 import org
.eclipse
.rse
.services
.shells
.IShellService
;
24 import org
.eclipse
.rse
.services
.terminals
.ITerminalService
;
25 import org
.eclipse
.rse
.subsystems
.files
.core
.servicesubsystem
.IFileServiceSubSystem
;
29 * RemoteSystemProxy implementation.
32 * @author Bernd Hufmann
34 public class RemoteSystemProxy
implements IRemoteSystemProxy
{
36 // ------------------------------------------------------------------------
38 // ------------------------------------------------------------------------
40 private final IHost fHost
;
42 // ------------------------------------------------------------------------
44 // ------------------------------------------------------------------------
50 * The host of this proxy
52 public RemoteSystemProxy(IHost host
) {
56 // ------------------------------------------------------------------------
58 // ------------------------------------------------------------------------
61 public IShellService
getShellService() {
62 ISubSystem ss
= getShellServiceSubSystem();
64 return (IShellService
)ss
.getSubSystemConfiguration().getService(fHost
).getAdapter(IShellService
.class);
70 public ITerminalService
getTerminalService() {
71 ISubSystem ss
= getTerminalServiceSubSystem();
73 return (ITerminalService
)ss
.getSubSystemConfiguration().getService(fHost
).getAdapter(ITerminalService
.class);
79 public ISubSystem
getShellServiceSubSystem() {
83 ISubSystem
[] subSystems
= fHost
.getSubSystems();
84 IShellService ssvc
= null;
85 for (int i
= 0; subSystems
!= null && i
< subSystems
.length
; i
++) {
86 IService svc
= subSystems
[i
].getSubSystemConfiguration().getService(fHost
);
88 ssvc
= (IShellService
)svc
.getAdapter(IShellService
.class);
98 public ISubSystem
getTerminalServiceSubSystem() {
102 ISubSystem
[] subSystems
= fHost
.getSubSystems();
103 ITerminalService ssvc
= null;
104 for (int i
= 0; subSystems
!= null && i
< subSystems
.length
; i
++) {
105 IService svc
= subSystems
[i
].getSubSystemConfiguration().getService(fHost
);
107 ssvc
= (ITerminalService
)svc
.getAdapter(ITerminalService
.class);
109 return subSystems
[i
];
117 public IFileServiceSubSystem
getFileServiceSubSystem() {
121 ISubSystem
[] subSystems
= fHost
.getSubSystems();
122 for (int i
= 0; subSystems
!= null && i
< subSystems
.length
; i
++) {
123 if (subSystems
[i
] instanceof IFileServiceSubSystem
) {
124 return (IFileServiceSubSystem
)subSystems
[i
];
131 public int getPort() {
132 if (getShellServiceSubSystem() != null) {
133 return getShellServiceSubSystem().getConnectorService().getPort();
135 return IRemoteSystemProxy
.INVALID_PORT_NUMBER
;
139 public void setPort(int port
) {
140 if ((getShellServiceSubSystem() != null) && (port
> 0)) {
141 getShellServiceSubSystem().getConnectorService().setPort(port
);
146 public void connect(IRSECallback callback
) throws ExecutionException
{
147 ISubSystem shellSubSystem
= getShellServiceSubSystem();
148 if (shellSubSystem
!= null) {
149 if (!shellSubSystem
.isConnected()) {
151 shellSubSystem
.connect(false, callback
);
152 } catch (OperationCanceledException e
) {
153 callback
.done(Status
.CANCEL_STATUS
, null);
155 catch (Exception e
) {
156 throw new ExecutionException(e
.toString(), e
);
159 callback
.done(Status
.OK_STATUS
, null);
165 public void disconnect() throws ExecutionException
{
166 ISubSystem shellSubSystem
= getShellServiceSubSystem();
167 if (shellSubSystem
!= null) {
169 shellSubSystem
.disconnect();
170 } catch (Exception e
) {
171 throw new ExecutionException(e
.toString(), e
);
177 public ICommandShell
createCommandShell() throws ExecutionException
{
178 ICommandShell shell
= new CommandShell(this);
184 public void addCommunicationListener(ICommunicationsListener listener
) {
185 IConnectorService
[] css
= fHost
.getConnectorServices();
186 for (IConnectorService cs
: css
) {
187 cs
.addCommunicationsListener(listener
);
192 public void removeCommunicationListener(ICommunicationsListener listener
) {
193 IConnectorService
[] css
= fHost
.getConnectorServices();
194 for (IConnectorService cs
: css
) {
195 cs
.removeCommunicationsListener(listener
);
200 public boolean isLocal() {
201 return fHost
.getSystemType().isLocal();