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 // ------------------------------------------------------------------------
40 // ------------------------------------------------------------------------
42 // ------------------------------------------------------------------------
43 public RemoteSystemProxy(IHost host
) {
47 // ------------------------------------------------------------------------
49 // ------------------------------------------------------------------------
51 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#getShellService(org.eclipse.rse.core.model.IHost)
54 public IShellService
getShellService() {
55 ISubSystem ss
= getShellServiceSubSystem();
57 return (IShellService
)ss
.getSubSystemConfiguration().getService(fHost
).getAdapter(IShellService
.class);
63 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#getTerminalService()
66 public ITerminalService
getTerminalService() {
67 ISubSystem ss
= getTerminalServiceSubSystem();
69 return (ITerminalService
)ss
.getSubSystemConfiguration().getService(fHost
).getAdapter(ITerminalService
.class);
75 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#getShellServiceSubSystem()
78 public ISubSystem
getShellServiceSubSystem() {
82 ISubSystem
[] subSystems
= fHost
.getSubSystems();
83 IShellService ssvc
= null;
84 for (int i
= 0; subSystems
!= null && i
< subSystems
.length
; i
++) {
85 IService svc
= subSystems
[i
].getSubSystemConfiguration().getService(fHost
);
87 ssvc
= (IShellService
)svc
.getAdapter(IShellService
.class);
97 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#getTerminalServiceSubSystem()
100 public ISubSystem
getTerminalServiceSubSystem() {
104 ISubSystem
[] subSystems
= fHost
.getSubSystems();
105 ITerminalService ssvc
= null;
106 for (int i
= 0; subSystems
!= null && i
< subSystems
.length
; i
++) {
107 IService svc
= subSystems
[i
].getSubSystemConfiguration().getService(fHost
);
109 ssvc
= (ITerminalService
)svc
.getAdapter(ITerminalService
.class);
111 return subSystems
[i
];
120 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.remote.IRemoteSystemProxy#getFileServiceSubSystem()
123 public IFileServiceSubSystem
getFileServiceSubSystem() {
127 ISubSystem
[] subSystems
= fHost
.getSubSystems();
128 for (int i
= 0; subSystems
!= null && i
< subSystems
.length
; i
++) {
129 if (subSystems
[i
] instanceof IFileServiceSubSystem
) {
130 return (IFileServiceSubSystem
)subSystems
[i
];
137 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#connect(org.eclipse.rse.core.model.IRSECallback)
140 public void connect(IRSECallback callback
) throws ExecutionException
{
141 ISubSystem shellSubSystem
= getShellServiceSubSystem();
142 if (shellSubSystem
!= null) {
143 if (!shellSubSystem
.isConnected()) {
145 shellSubSystem
.connect(false, callback
);
146 } catch (Exception e
) {
147 throw new ExecutionException(e
.toString(), e
);
150 callback
.done(Status
.OK_STATUS
, null);
156 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#disconnect()
159 public void disconnect() throws ExecutionException
{
160 ISubSystem shellSubSystem
= getShellServiceSubSystem();
161 if (shellSubSystem
!= null) {
163 shellSubSystem
.disconnect();
164 } catch (Exception e
) {
165 throw new ExecutionException(e
.toString(), e
);
171 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#createCommandShell()
174 public ICommandShell
createCommandShell() throws ExecutionException
{
175 ICommandShell shell
= new CommandShell(this);
181 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#addCommunicationListener(org.eclipse.rse.core.subsystems.ICommunicationsListener)
184 public void addCommunicationListener(ICommunicationsListener listener
) {
185 IConnectorService
[] css
= fHost
.getConnectorServices();
186 for (IConnectorService cs
: css
) {
187 cs
.addCommunicationsListener(listener
);
192 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#removeCommunicationListener(org.eclipse.rse.core.subsystems.ICommunicationsListener)
195 public void removeCommunicationListener(ICommunicationsListener listener
) {
196 IConnectorService
[] css
= fHost
.getConnectorServices();
197 for (IConnectorService cs
: css
) {
198 cs
.removeCommunicationsListener(listener
);