gdbtrace: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.control.ui / src / org / eclipse / linuxtools / internal / lttng2 / control / ui / views / remote / RemoteSystemProxy.java
CommitLineData
eb1bab5b 1/**********************************************************************
00de7b32 2 * Copyright (c) 2012, 2013 Ericsson
cfdb727a 3 *
eb1bab5b
BH
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
cfdb727a
AM
8 *
9 * Contributors:
eb1bab5b
BH
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
8e8c0226 12package org.eclipse.linuxtools.internal.lttng2.control.ui.views.remote;
eb1bab5b
BH
13
14import org.eclipse.core.commands.ExecutionException;
0547d729 15import org.eclipse.core.runtime.OperationCanceledException;
eb1bab5b 16import org.eclipse.core.runtime.Status;
eb1bab5b
BH
17import org.eclipse.rse.core.model.IHost;
18import org.eclipse.rse.core.model.IRSECallback;
19import org.eclipse.rse.core.subsystems.ICommunicationsListener;
20import org.eclipse.rse.core.subsystems.IConnectorService;
21import org.eclipse.rse.core.subsystems.ISubSystem;
22import org.eclipse.rse.services.IService;
23import org.eclipse.rse.services.shells.IShellService;
24import org.eclipse.rse.services.terminals.ITerminalService;
bbb3538a 25import org.eclipse.rse.subsystems.files.core.servicesubsystem.IFileServiceSubSystem;
eb1bab5b
BH
26
27/**
eb1bab5b
BH
28 * <p>
29 * RemoteSystemProxy implementation.
30 * </p>
cfdb727a 31 *
dbd4432d 32 * @author Bernd Hufmann
eb1bab5b
BH
33 */
34public class RemoteSystemProxy implements IRemoteSystemProxy {
cfdb727a 35
eb1bab5b
BH
36 // ------------------------------------------------------------------------
37 // Attributes
38 // ------------------------------------------------------------------------
11252342 39
cfdb727a 40 private final IHost fHost;
bbb3538a 41
eb1bab5b
BH
42 // ------------------------------------------------------------------------
43 // Constructors
44 // ------------------------------------------------------------------------
cfdb727a
AM
45
46 /**
47 * Constructor
48 *
49 * @param host
50 * The host of this proxy
51 */
eb1bab5b
BH
52 public RemoteSystemProxy(IHost host) {
53 fHost = host;
54 }
55
56 // ------------------------------------------------------------------------
57 // Operations
58 // ------------------------------------------------------------------------
11252342 59
eb1bab5b
BH
60 @Override
61 public IShellService getShellService() {
62 ISubSystem ss = getShellServiceSubSystem();
63 if (ss != null) {
64 return (IShellService)ss.getSubSystemConfiguration().getService(fHost).getAdapter(IShellService.class);
65 }
66 return null;
67 }
68
eb1bab5b
BH
69 @Override
70 public ITerminalService getTerminalService() {
71 ISubSystem ss = getTerminalServiceSubSystem();
72 if (ss != null) {
73 return (ITerminalService)ss.getSubSystemConfiguration().getService(fHost).getAdapter(ITerminalService.class);
74 }
75 return null;
76 }
77
eb1bab5b
BH
78 @Override
79 public ISubSystem getShellServiceSubSystem() {
80 if (fHost == null) {
81 return null;
82 }
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);
87 if (svc!=null) {
88 ssvc = (IShellService)svc.getAdapter(IShellService.class);
89 if (ssvc != null) {
cfdb727a
AM
90 return subSystems[i];
91 }
eb1bab5b
BH
92 }
93 }
94 return null;
95 }
96
eb1bab5b
BH
97 @Override
98 public ISubSystem getTerminalServiceSubSystem() {
99 if (fHost == null) {
100 return null;
101 }
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);
106 if (svc!=null) {
107 ssvc = (ITerminalService)svc.getAdapter(ITerminalService.class);
108 if (ssvc != null) {
cfdb727a
AM
109 return subSystems[i];
110 }
eb1bab5b
BH
111 }
112 }
113 return null;
114 }
115
bbb3538a
BH
116 @Override
117 public IFileServiceSubSystem getFileServiceSubSystem() {
118 if (fHost == null) {
119 return null;
120 }
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];
125 }
126 }
127 return null;
128 }
cfdb727a 129
00de7b32
BH
130 @Override
131 public int getPort() {
132 if (getShellServiceSubSystem() != null) {
133 return getShellServiceSubSystem().getConnectorService().getPort();
134 }
135 return IRemoteSystemProxy.INVALID_PORT_NUMBER;
136 }
137
138 @Override
139 public void setPort(int port) {
140 if ((getShellServiceSubSystem() != null) && (port > 0)) {
141 getShellServiceSubSystem().getConnectorService().setPort(port);
142 }
143 }
144
eb1bab5b
BH
145 @Override
146 public void connect(IRSECallback callback) throws ExecutionException {
147 ISubSystem shellSubSystem = getShellServiceSubSystem();
148 if (shellSubSystem != null) {
149 if (!shellSubSystem.isConnected()) {
150 try {
151 shellSubSystem.connect(false, callback);
0547d729
BH
152 } catch (OperationCanceledException e) {
153 callback.done(Status.CANCEL_STATUS, null);
154 }
155 catch (Exception e) {
eb1bab5b
BH
156 throw new ExecutionException(e.toString(), e);
157 }
158 } else {
159 callback.done(Status.OK_STATUS, null);
160 }
161 }
162 }
163
eb1bab5b
BH
164 @Override
165 public void disconnect() throws ExecutionException {
166 ISubSystem shellSubSystem = getShellServiceSubSystem();
167 if (shellSubSystem != null) {
168 try {
169 shellSubSystem.disconnect();
170 } catch (Exception e) {
171 throw new ExecutionException(e.toString(), e);
172 }
173 }
174 }
175
eb1bab5b
BH
176 @Override
177 public ICommandShell createCommandShell() throws ExecutionException {
178 ICommandShell shell = new CommandShell(this);
179 shell.connect();
180 return shell;
181 }
cfdb727a 182
eb1bab5b
BH
183 @Override
184 public void addCommunicationListener(ICommunicationsListener listener) {
185 IConnectorService[] css = fHost.getConnectorServices();
186 for (IConnectorService cs : css) {
187 cs.addCommunicationsListener(listener);
188 }
189 }
190
eb1bab5b
BH
191 @Override
192 public void removeCommunicationListener(ICommunicationsListener listener) {
193 IConnectorService[] css = fHost.getConnectorServices();
194 for (IConnectorService cs : css) {
195 cs.removeCommunicationsListener(listener);
196 }
197 }
a657b111
BH
198
199 @Override
200 public boolean isLocal() {
201 return fHost.getSystemType().isLocal();
202 }
eb1bab5b 203}
This page took 0.15271 seconds and 5 git commands to generate.