Merge branch 'master' into lttng_2_0_control_dev
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / internal / lttng / ui / views / control / remote / RemoteSystemProxy.java
1 /**********************************************************************
2 * Copyright (c) 2012 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.lttng.ui.views.control.remote;
13
14 import org.eclipse.core.commands.ExecutionException;
15 import org.eclipse.core.runtime.Status;
16 import org.eclipse.linuxtools.internal.lttng.ui.views.control.service.CommandShell;
17 import org.eclipse.linuxtools.internal.lttng.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;
27
28 /**
29 * <b><u>RemoteSystemProxy</u></b>
30 * <p>
31 * RemoteSystemProxy implementation.
32 * </p>
33 */
34 public class RemoteSystemProxy implements IRemoteSystemProxy {
35
36 // ------------------------------------------------------------------------
37 // Attributes
38 // ------------------------------------------------------------------------
39 private IHost fHost;
40
41 // ------------------------------------------------------------------------
42 // Constructors
43 // ------------------------------------------------------------------------
44 public RemoteSystemProxy(IHost host) {
45 fHost = host;
46 }
47
48 // ------------------------------------------------------------------------
49 // Operations
50 // ------------------------------------------------------------------------
51 /* (non-Javadoc)
52 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.util.IRemoteSystemProxy#getShellService(org.eclipse.rse.core.model.IHost)
53 */
54 @Override
55 public IShellService getShellService() {
56 ISubSystem ss = getShellServiceSubSystem();
57 if (ss != null) {
58 return (IShellService)ss.getSubSystemConfiguration().getService(fHost).getAdapter(IShellService.class);
59 }
60 return null;
61 }
62
63 /* (non-Javadoc)
64 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.util.IRemoteSystemProxy#getTerminalService()
65 */
66 @Override
67 public ITerminalService getTerminalService() {
68 ISubSystem ss = getTerminalServiceSubSystem();
69 if (ss != null) {
70 return (ITerminalService)ss.getSubSystemConfiguration().getService(fHost).getAdapter(ITerminalService.class);
71 }
72 return null;
73 }
74
75 /* (non-Javadoc)
76 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.util.IRemoteSystemProxy#getShellServiceSubSystem()
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 /* (non-Javadoc)
98 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.util.IRemoteSystemProxy#getTerminalServiceSubSystem()
99 */
100 @Override
101 public ISubSystem getTerminalServiceSubSystem() {
102 if (fHost == null) {
103 return null;
104 }
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);
109 if (svc!=null) {
110 ssvc = (ITerminalService)svc.getAdapter(ITerminalService.class);
111 if (ssvc != null) {
112 return subSystems[i];
113 }
114 }
115 }
116 return null;
117 }
118
119 /*
120 * (non-Javadoc)
121 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.remote.IRemoteSystemProxy#getFileServiceSubSystem()
122 */
123 @Override
124 public IFileServiceSubSystem getFileServiceSubSystem() {
125 if (fHost == null) {
126 return null;
127 }
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];
132 }
133 }
134 return null;
135 }
136
137 /* (non-Javadoc)
138 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.util.IRemoteSystemProxy#connect(org.eclipse.rse.core.model.IRSECallback)
139 */
140 @Override
141 public void connect(IRSECallback callback) throws ExecutionException {
142 ISubSystem shellSubSystem = getShellServiceSubSystem();
143 if (shellSubSystem != null) {
144 if (!shellSubSystem.isConnected()) {
145 try {
146 shellSubSystem.connect(false, callback);
147 } catch (Exception e) {
148 throw new ExecutionException(e.toString(), e);
149 }
150 } else {
151 callback.done(Status.OK_STATUS, null);
152 }
153 }
154 }
155
156 /* (non-Javadoc)
157 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.util.IRemoteSystemProxy#disconnect()
158 */
159 @Override
160 public void disconnect() throws ExecutionException {
161 ISubSystem shellSubSystem = getShellServiceSubSystem();
162 if (shellSubSystem != null) {
163 try {
164 shellSubSystem.disconnect();
165 } catch (Exception e) {
166 throw new ExecutionException(e.toString(), e);
167 }
168 }
169 }
170
171 /* (non-Javadoc)
172 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.util.IRemoteSystemProxy#createCommandShell()
173 */
174 @Override
175 public ICommandShell createCommandShell() throws ExecutionException {
176 ICommandShell shell = new CommandShell(this);
177 shell.connect();
178 return shell;
179 }
180
181 /* (non-Javadoc)
182 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.util.IRemoteSystemProxy#addCommunicationListener(org.eclipse.rse.core.subsystems.ICommunicationsListener)
183 */
184 @Override
185 public void addCommunicationListener(ICommunicationsListener listener) {
186 IConnectorService[] css = fHost.getConnectorServices();
187 for (IConnectorService cs : css) {
188 cs.addCommunicationsListener(listener);
189 }
190 }
191
192 /* (non-Javadoc)
193 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.util.IRemoteSystemProxy#removeCommunicationListener(org.eclipse.rse.core.subsystems.ICommunicationsListener)
194 */
195 @Override
196 public void removeCommunicationListener(ICommunicationsListener listener) {
197 IConnectorService[] css = fHost.getConnectorServices();
198 for (IConnectorService cs : css) {
199 cs.removeCommunicationsListener(listener);
200 }
201 }
202 }
This page took 0.034285 seconds and 5 git commands to generate.