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
.linuxtools
.internal
.lttng2
.ui
.views
.control
.service
.CommandShell
;
17 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.service
.ICommandShell
;
18 import org
.eclipse
.rse
.core
.model
.IHost
;
19 import org
.eclipse
.rse
.core
.model
.IRSECallback
;
20 import org
.eclipse
.rse
.core
.subsystems
.ICommunicationsListener
;
21 import org
.eclipse
.rse
.core
.subsystems
.IConnectorService
;
22 import org
.eclipse
.rse
.core
.subsystems
.ISubSystem
;
23 import org
.eclipse
.rse
.services
.IService
;
24 import org
.eclipse
.rse
.services
.shells
.IShellService
;
25 import org
.eclipse
.rse
.services
.terminals
.ITerminalService
;
26 import org
.eclipse
.rse
.subsystems
.files
.core
.servicesubsystem
.IFileServiceSubSystem
;
29 * <b><u>RemoteSystemProxy</u></b>
31 * RemoteSystemProxy implementation.
34 public class RemoteSystemProxy
implements IRemoteSystemProxy
{
36 // ------------------------------------------------------------------------
38 // ------------------------------------------------------------------------
41 // ------------------------------------------------------------------------
43 // ------------------------------------------------------------------------
44 public RemoteSystemProxy(IHost host
) {
48 // ------------------------------------------------------------------------
50 // ------------------------------------------------------------------------
52 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#getShellService(org.eclipse.rse.core.model.IHost)
55 public IShellService
getShellService() {
56 ISubSystem ss
= getShellServiceSubSystem();
58 return (IShellService
)ss
.getSubSystemConfiguration().getService(fHost
).getAdapter(IShellService
.class);
64 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#getTerminalService()
67 public ITerminalService
getTerminalService() {
68 ISubSystem ss
= getTerminalServiceSubSystem();
70 return (ITerminalService
)ss
.getSubSystemConfiguration().getService(fHost
).getAdapter(ITerminalService
.class);
76 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#getShellServiceSubSystem()
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 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#getTerminalServiceSubSystem()
101 public ISubSystem
getTerminalServiceSubSystem() {
105 ISubSystem
[] subSystems
= fHost
.getSubSystems();
106 ITerminalService ssvc
= null;
107 for (int i
= 0; subSystems
!= null && i
< subSystems
.length
; i
++) {
108 IService svc
= subSystems
[i
].getSubSystemConfiguration().getService(fHost
);
110 ssvc
= (ITerminalService
)svc
.getAdapter(ITerminalService
.class);
112 return subSystems
[i
];
121 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.remote.IRemoteSystemProxy#getFileServiceSubSystem()
124 public IFileServiceSubSystem
getFileServiceSubSystem() {
128 ISubSystem
[] subSystems
= fHost
.getSubSystems();
129 for (int i
= 0; subSystems
!= null && i
< subSystems
.length
; i
++) {
130 if (subSystems
[i
] instanceof IFileServiceSubSystem
) {
131 return (IFileServiceSubSystem
)subSystems
[i
];
138 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#connect(org.eclipse.rse.core.model.IRSECallback)
141 public void connect(IRSECallback callback
) throws ExecutionException
{
142 ISubSystem shellSubSystem
= getShellServiceSubSystem();
143 if (shellSubSystem
!= null) {
144 if (!shellSubSystem
.isConnected()) {
146 shellSubSystem
.connect(false, callback
);
147 } catch (Exception e
) {
148 throw new ExecutionException(e
.toString(), e
);
151 callback
.done(Status
.OK_STATUS
, null);
157 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#disconnect()
160 public void disconnect() throws ExecutionException
{
161 ISubSystem shellSubSystem
= getShellServiceSubSystem();
162 if (shellSubSystem
!= null) {
164 shellSubSystem
.disconnect();
165 } catch (Exception e
) {
166 throw new ExecutionException(e
.toString(), e
);
172 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#createCommandShell()
175 public ICommandShell
createCommandShell() throws ExecutionException
{
176 ICommandShell shell
= new CommandShell(this);
182 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#addCommunicationListener(org.eclipse.rse.core.subsystems.ICommunicationsListener)
185 public void addCommunicationListener(ICommunicationsListener listener
) {
186 IConnectorService
[] css
= fHost
.getConnectorServices();
187 for (IConnectorService cs
: css
) {
188 cs
.addCommunicationsListener(listener
);
193 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#removeCommunicationListener(org.eclipse.rse.core.subsystems.ICommunicationsListener)
196 public void removeCommunicationListener(ICommunicationsListener listener
) {
197 IConnectorService
[] css
= fHost
.getConnectorServices();
198 for (IConnectorService cs
: css
) {
199 cs
.removeCommunicationsListener(listener
);