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
.remote
;
14 import org
.eclipse
.core
.commands
.ExecutionException
;
15 import org
.eclipse
.core
.runtime
.Status
;
16 import org
.eclipse
.rse
.core
.model
.IHost
;
17 import org
.eclipse
.rse
.core
.model
.IRSECallback
;
18 import org
.eclipse
.rse
.core
.subsystems
.ICommunicationsListener
;
19 import org
.eclipse
.rse
.core
.subsystems
.IConnectorService
;
20 import org
.eclipse
.rse
.core
.subsystems
.ISubSystem
;
21 import org
.eclipse
.rse
.services
.IService
;
22 import org
.eclipse
.rse
.services
.shells
.IShellService
;
23 import org
.eclipse
.rse
.services
.terminals
.ITerminalService
;
24 import org
.eclipse
.rse
.subsystems
.files
.core
.servicesubsystem
.IFileServiceSubSystem
;
28 * RemoteSystemProxy implementation.
31 * @author Bernd Hufmann
33 public class RemoteSystemProxy
implements IRemoteSystemProxy
{
35 // ------------------------------------------------------------------------
37 // ------------------------------------------------------------------------
38 private final IHost fHost
;
40 // ------------------------------------------------------------------------
42 // ------------------------------------------------------------------------
48 * The host of this proxy
50 public RemoteSystemProxy(IHost host
) {
54 // ------------------------------------------------------------------------
56 // ------------------------------------------------------------------------
58 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#getShellService(org.eclipse.rse.core.model.IHost)
61 public IShellService
getShellService() {
62 ISubSystem ss
= getShellServiceSubSystem();
64 return (IShellService
)ss
.getSubSystemConfiguration().getService(fHost
).getAdapter(IShellService
.class);
70 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#getTerminalService()
73 public ITerminalService
getTerminalService() {
74 ISubSystem ss
= getTerminalServiceSubSystem();
76 return (ITerminalService
)ss
.getSubSystemConfiguration().getService(fHost
).getAdapter(ITerminalService
.class);
82 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#getShellServiceSubSystem()
85 public ISubSystem
getShellServiceSubSystem() {
89 ISubSystem
[] subSystems
= fHost
.getSubSystems();
90 IShellService ssvc
= null;
91 for (int i
= 0; subSystems
!= null && i
< subSystems
.length
; i
++) {
92 IService svc
= subSystems
[i
].getSubSystemConfiguration().getService(fHost
);
94 ssvc
= (IShellService
)svc
.getAdapter(IShellService
.class);
104 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#getTerminalServiceSubSystem()
107 public ISubSystem
getTerminalServiceSubSystem() {
111 ISubSystem
[] subSystems
= fHost
.getSubSystems();
112 ITerminalService ssvc
= null;
113 for (int i
= 0; subSystems
!= null && i
< subSystems
.length
; i
++) {
114 IService svc
= subSystems
[i
].getSubSystemConfiguration().getService(fHost
);
116 ssvc
= (ITerminalService
)svc
.getAdapter(ITerminalService
.class);
118 return subSystems
[i
];
127 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.remote.IRemoteSystemProxy#getFileServiceSubSystem()
130 public IFileServiceSubSystem
getFileServiceSubSystem() {
134 ISubSystem
[] subSystems
= fHost
.getSubSystems();
135 for (int i
= 0; subSystems
!= null && i
< subSystems
.length
; i
++) {
136 if (subSystems
[i
] instanceof IFileServiceSubSystem
) {
137 return (IFileServiceSubSystem
)subSystems
[i
];
144 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#connect(org.eclipse.rse.core.model.IRSECallback)
147 public void connect(IRSECallback callback
) throws ExecutionException
{
148 ISubSystem shellSubSystem
= getShellServiceSubSystem();
149 if (shellSubSystem
!= null) {
150 if (!shellSubSystem
.isConnected()) {
152 shellSubSystem
.connect(false, callback
);
153 } catch (Exception e
) {
154 throw new ExecutionException(e
.toString(), e
);
157 callback
.done(Status
.OK_STATUS
, null);
163 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#disconnect()
166 public void disconnect() throws ExecutionException
{
167 ISubSystem shellSubSystem
= getShellServiceSubSystem();
168 if (shellSubSystem
!= null) {
170 shellSubSystem
.disconnect();
171 } catch (Exception e
) {
172 throw new ExecutionException(e
.toString(), e
);
178 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#createCommandShell()
181 public ICommandShell
createCommandShell() throws ExecutionException
{
182 ICommandShell shell
= new CommandShell(this);
188 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#addCommunicationListener(org.eclipse.rse.core.subsystems.ICommunicationsListener)
191 public void addCommunicationListener(ICommunicationsListener listener
) {
192 IConnectorService
[] css
= fHost
.getConnectorServices();
193 for (IConnectorService cs
: css
) {
194 cs
.addCommunicationsListener(listener
);
199 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#removeCommunicationListener(org.eclipse.rse.core.subsystems.ICommunicationsListener)
202 public void removeCommunicationListener(ICommunicationsListener listener
) {
203 IConnectorService
[] css
= fHost
.getConnectorServices();
204 for (IConnectorService cs
: css
) {
205 cs
.removeCommunicationsListener(listener
);