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
1 /**********************************************************************
2 * Copyright (c) 2012, 2013 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org.eclipse.linuxtools.internal.lttng2.control.ui.views.remote;
13
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;
26
27 /**
28 * <p>
29 * RemoteSystemProxy implementation.
30 * </p>
31 *
32 * @author Bernd Hufmann
33 */
34 public class RemoteSystemProxy implements IRemoteSystemProxy {
35
36 // ------------------------------------------------------------------------
37 // Attributes
38 // ------------------------------------------------------------------------
39
40 private final IHost fHost;
41
42 // ------------------------------------------------------------------------
43 // Constructors
44 // ------------------------------------------------------------------------
45
46 /**
47 * Constructor
48 *
49 * @param host
50 * The host of this proxy
51 */
52 public RemoteSystemProxy(IHost host) {
53 fHost = host;
54 }
55
56 // ------------------------------------------------------------------------
57 // Operations
58 // ------------------------------------------------------------------------
59
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
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
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) {
90 return subSystems[i];
91 }
92 }
93 }
94 return null;
95 }
96
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) {
109 return subSystems[i];
110 }
111 }
112 }
113 return null;
114 }
115
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 }
129
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
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);
152 } catch (OperationCanceledException e) {
153 callback.done(Status.CANCEL_STATUS, null);
154 }
155 catch (Exception e) {
156 throw new ExecutionException(e.toString(), e);
157 }
158 } else {
159 callback.done(Status.OK_STATUS, null);
160 }
161 }
162 }
163
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
176 @Override
177 public ICommandShell createCommandShell() throws ExecutionException {
178 ICommandShell shell = new CommandShell(this);
179 shell.connect();
180 return shell;
181 }
182
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
191 @Override
192 public void removeCommunicationListener(ICommunicationsListener listener) {
193 IConnectorService[] css = fHost.getConnectorServices();
194 for (IConnectorService cs : css) {
195 cs.removeCommunicationsListener(listener);
196 }
197 }
198
199 @Override
200 public boolean isLocal() {
201 return fHost.getSystemType().isLocal();
202 }
203 }
This page took 0.084701 seconds and 5 git commands to generate.