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
.ui
.views
.control
.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 // ------------------------------------------------------------------------
39 private final IHost fHost
;
41 // ------------------------------------------------------------------------
43 // ------------------------------------------------------------------------
49 * The host of this proxy
51 public RemoteSystemProxy(IHost host
) {
55 // ------------------------------------------------------------------------
57 // ------------------------------------------------------------------------
59 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#getShellService(org.eclipse.rse.core.model.IHost)
62 public IShellService
getShellService() {
63 ISubSystem ss
= getShellServiceSubSystem();
65 return (IShellService
)ss
.getSubSystemConfiguration().getService(fHost
).getAdapter(IShellService
.class);
71 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#getTerminalService()
74 public ITerminalService
getTerminalService() {
75 ISubSystem ss
= getTerminalServiceSubSystem();
77 return (ITerminalService
)ss
.getSubSystemConfiguration().getService(fHost
).getAdapter(ITerminalService
.class);
83 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#getShellServiceSubSystem()
86 public ISubSystem
getShellServiceSubSystem() {
90 ISubSystem
[] subSystems
= fHost
.getSubSystems();
91 IShellService ssvc
= null;
92 for (int i
= 0; subSystems
!= null && i
< subSystems
.length
; i
++) {
93 IService svc
= subSystems
[i
].getSubSystemConfiguration().getService(fHost
);
95 ssvc
= (IShellService
)svc
.getAdapter(IShellService
.class);
105 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#getTerminalServiceSubSystem()
108 public ISubSystem
getTerminalServiceSubSystem() {
112 ISubSystem
[] subSystems
= fHost
.getSubSystems();
113 ITerminalService ssvc
= null;
114 for (int i
= 0; subSystems
!= null && i
< subSystems
.length
; i
++) {
115 IService svc
= subSystems
[i
].getSubSystemConfiguration().getService(fHost
);
117 ssvc
= (ITerminalService
)svc
.getAdapter(ITerminalService
.class);
119 return subSystems
[i
];
128 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.remote.IRemoteSystemProxy#getFileServiceSubSystem()
131 public IFileServiceSubSystem
getFileServiceSubSystem() {
135 ISubSystem
[] subSystems
= fHost
.getSubSystems();
136 for (int i
= 0; subSystems
!= null && i
< subSystems
.length
; i
++) {
137 if (subSystems
[i
] instanceof IFileServiceSubSystem
) {
138 return (IFileServiceSubSystem
)subSystems
[i
];
145 public int getPort() {
146 if (getShellServiceSubSystem() != null) {
147 return getShellServiceSubSystem().getConnectorService().getPort();
149 return IRemoteSystemProxy
.INVALID_PORT_NUMBER
;
153 public void setPort(int port
) {
154 if ((getShellServiceSubSystem() != null) && (port
> 0)) {
155 getShellServiceSubSystem().getConnectorService().setPort(port
);
161 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.remote.IRemoteSystemProxy#connect(org.eclipse.rse.core.model.IRSECallback)
164 public void connect(IRSECallback callback
) throws ExecutionException
{
165 ISubSystem shellSubSystem
= getShellServiceSubSystem();
166 if (shellSubSystem
!= null) {
167 if (!shellSubSystem
.isConnected()) {
169 shellSubSystem
.connect(false, callback
);
170 } catch (OperationCanceledException e
) {
171 callback
.done(Status
.CANCEL_STATUS
, null);
173 catch (Exception e
) {
174 throw new ExecutionException(e
.toString(), e
);
177 callback
.done(Status
.OK_STATUS
, null);
183 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#disconnect()
186 public void disconnect() throws ExecutionException
{
187 ISubSystem shellSubSystem
= getShellServiceSubSystem();
188 if (shellSubSystem
!= null) {
190 shellSubSystem
.disconnect();
191 } catch (Exception e
) {
192 throw new ExecutionException(e
.toString(), e
);
198 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#createCommandShell()
201 public ICommandShell
createCommandShell() throws ExecutionException
{
202 ICommandShell shell
= new CommandShell(this);
208 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#addCommunicationListener(org.eclipse.rse.core.subsystems.ICommunicationsListener)
211 public void addCommunicationListener(ICommunicationsListener listener
) {
212 IConnectorService
[] css
= fHost
.getConnectorServices();
213 for (IConnectorService cs
: css
) {
214 cs
.addCommunicationsListener(listener
);
219 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#removeCommunicationListener(org.eclipse.rse.core.subsystems.ICommunicationsListener)
222 public void removeCommunicationListener(ICommunicationsListener listener
) {
223 IConnectorService
[] css
= fHost
.getConnectorServices();
224 for (IConnectorService cs
: css
) {
225 cs
.removeCommunicationsListener(listener
);