Commit | Line | Data |
---|---|---|
eb1bab5b BH |
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 | **********************************************************************/ | |
31a6a4e4 | 12 | package org.eclipse.linuxtools.internal.lttng.ui.views.control.remote; |
eb1bab5b BH |
13 | |
14 | import org.eclipse.core.commands.ExecutionException; | |
15 | import org.eclipse.core.runtime.Status; | |
31a6a4e4 BH |
16 | import org.eclipse.linuxtools.internal.lttng.ui.views.control.service.CommandShell; |
17 | import org.eclipse.linuxtools.internal.lttng.ui.views.control.service.ICommandShell; | |
eb1bab5b BH |
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; | |
bbb3538a | 26 | import org.eclipse.rse.subsystems.files.core.servicesubsystem.IFileServiceSubSystem; |
eb1bab5b BH |
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; | |
bbb3538a | 40 | |
eb1bab5b BH |
41 | // ------------------------------------------------------------------------ |
42 | // Constructors | |
43 | // ------------------------------------------------------------------------ | |
44 | public RemoteSystemProxy(IHost host) { | |
45 | fHost = host; | |
46 | } | |
47 | ||
48 | // ------------------------------------------------------------------------ | |
49 | // Operations | |
50 | // ------------------------------------------------------------------------ | |
51 | /* (non-Javadoc) | |
31a6a4e4 | 52 | * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.util.IRemoteSystemProxy#getShellService(org.eclipse.rse.core.model.IHost) |
eb1bab5b BH |
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) | |
31a6a4e4 | 64 | * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.util.IRemoteSystemProxy#getTerminalService() |
eb1bab5b BH |
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) | |
31a6a4e4 | 76 | * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.util.IRemoteSystemProxy#getShellServiceSubSystem() |
eb1bab5b BH |
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) | |
31a6a4e4 | 98 | * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.util.IRemoteSystemProxy#getTerminalServiceSubSystem() |
eb1bab5b BH |
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 | ||
bbb3538a BH |
119 | /* |
120 | * (non-Javadoc) | |
31a6a4e4 | 121 | * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.remote.IRemoteSystemProxy#getFileServiceSubSystem() |
bbb3538a BH |
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 | ||
eb1bab5b | 137 | /* (non-Javadoc) |
31a6a4e4 | 138 | * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.util.IRemoteSystemProxy#connect(org.eclipse.rse.core.model.IRSECallback) |
eb1bab5b BH |
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) | |
31a6a4e4 | 157 | * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.util.IRemoteSystemProxy#disconnect() |
eb1bab5b BH |
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) | |
31a6a4e4 | 172 | * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.util.IRemoteSystemProxy#createCommandShell() |
eb1bab5b BH |
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) | |
31a6a4e4 | 182 | * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.util.IRemoteSystemProxy#addCommunicationListener(org.eclipse.rse.core.subsystems.ICommunicationsListener) |
eb1bab5b BH |
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) | |
31a6a4e4 | 193 | * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.util.IRemoteSystemProxy#removeCommunicationListener(org.eclipse.rse.core.subsystems.ICommunicationsListener) |
eb1bab5b BH |
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 | } |