Improve package tangle index for LTTng 2.0 control design
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / remote / RemoteSystemProxy.java
CommitLineData
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 **********************************************************************/
115b4a01 12package org.eclipse.linuxtools.internal.lttng2.ui.views.control.remote;
eb1bab5b
BH
13
14import org.eclipse.core.commands.ExecutionException;
15import org.eclipse.core.runtime.Status;
eb1bab5b
BH
16import org.eclipse.rse.core.model.IHost;
17import org.eclipse.rse.core.model.IRSECallback;
18import org.eclipse.rse.core.subsystems.ICommunicationsListener;
19import org.eclipse.rse.core.subsystems.IConnectorService;
20import org.eclipse.rse.core.subsystems.ISubSystem;
21import org.eclipse.rse.services.IService;
22import org.eclipse.rse.services.shells.IShellService;
23import org.eclipse.rse.services.terminals.ITerminalService;
bbb3538a 24import org.eclipse.rse.subsystems.files.core.servicesubsystem.IFileServiceSubSystem;
eb1bab5b
BH
25
26/**
27 * <b><u>RemoteSystemProxy</u></b>
28 * <p>
29 * RemoteSystemProxy implementation.
30 * </p>
31 */
32public class RemoteSystemProxy implements IRemoteSystemProxy {
33
34 // ------------------------------------------------------------------------
35 // Attributes
36 // ------------------------------------------------------------------------
37 private IHost fHost;
bbb3538a 38
eb1bab5b
BH
39 // ------------------------------------------------------------------------
40 // Constructors
41 // ------------------------------------------------------------------------
42 public RemoteSystemProxy(IHost host) {
43 fHost = host;
44 }
45
46 // ------------------------------------------------------------------------
47 // Operations
48 // ------------------------------------------------------------------------
49 /* (non-Javadoc)
115b4a01 50 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#getShellService(org.eclipse.rse.core.model.IHost)
eb1bab5b
BH
51 */
52 @Override
53 public IShellService getShellService() {
54 ISubSystem ss = getShellServiceSubSystem();
55 if (ss != null) {
56 return (IShellService)ss.getSubSystemConfiguration().getService(fHost).getAdapter(IShellService.class);
57 }
58 return null;
59 }
60
61 /* (non-Javadoc)
115b4a01 62 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#getTerminalService()
eb1bab5b
BH
63 */
64 @Override
65 public ITerminalService getTerminalService() {
66 ISubSystem ss = getTerminalServiceSubSystem();
67 if (ss != null) {
68 return (ITerminalService)ss.getSubSystemConfiguration().getService(fHost).getAdapter(ITerminalService.class);
69 }
70 return null;
71 }
72
73 /* (non-Javadoc)
115b4a01 74 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#getShellServiceSubSystem()
eb1bab5b
BH
75 */
76 @Override
77 public ISubSystem getShellServiceSubSystem() {
78 if (fHost == null) {
79 return null;
80 }
81 ISubSystem[] subSystems = fHost.getSubSystems();
82 IShellService ssvc = null;
83 for (int i = 0; subSystems != null && i < subSystems.length; i++) {
84 IService svc = subSystems[i].getSubSystemConfiguration().getService(fHost);
85 if (svc!=null) {
86 ssvc = (IShellService)svc.getAdapter(IShellService.class);
87 if (ssvc != null) {
88 return subSystems[i];
89 }
90 }
91 }
92 return null;
93 }
94
95 /* (non-Javadoc)
115b4a01 96 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#getTerminalServiceSubSystem()
eb1bab5b
BH
97 */
98 @Override
99 public ISubSystem getTerminalServiceSubSystem() {
100 if (fHost == null) {
101 return null;
102 }
103 ISubSystem[] subSystems = fHost.getSubSystems();
104 ITerminalService ssvc = null;
105 for (int i = 0; subSystems != null && i < subSystems.length; i++) {
106 IService svc = subSystems[i].getSubSystemConfiguration().getService(fHost);
107 if (svc!=null) {
108 ssvc = (ITerminalService)svc.getAdapter(ITerminalService.class);
109 if (ssvc != null) {
110 return subSystems[i];
111 }
112 }
113 }
114 return null;
115 }
116
bbb3538a
BH
117 /*
118 * (non-Javadoc)
115b4a01 119 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.remote.IRemoteSystemProxy#getFileServiceSubSystem()
bbb3538a
BH
120 */
121 @Override
122 public IFileServiceSubSystem getFileServiceSubSystem() {
123 if (fHost == null) {
124 return null;
125 }
126 ISubSystem[] subSystems = fHost.getSubSystems();
127 for (int i = 0; subSystems != null && i < subSystems.length; i++) {
128 if (subSystems[i] instanceof IFileServiceSubSystem) {
129 return (IFileServiceSubSystem)subSystems[i];
130 }
131 }
132 return null;
133 }
134
eb1bab5b 135 /* (non-Javadoc)
115b4a01 136 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#connect(org.eclipse.rse.core.model.IRSECallback)
eb1bab5b
BH
137 */
138 @Override
139 public void connect(IRSECallback callback) throws ExecutionException {
140 ISubSystem shellSubSystem = getShellServiceSubSystem();
141 if (shellSubSystem != null) {
142 if (!shellSubSystem.isConnected()) {
143 try {
144 shellSubSystem.connect(false, callback);
145 } catch (Exception e) {
146 throw new ExecutionException(e.toString(), e);
147 }
148 } else {
149 callback.done(Status.OK_STATUS, null);
150 }
151 }
152 }
153
154 /* (non-Javadoc)
115b4a01 155 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#disconnect()
eb1bab5b
BH
156 */
157 @Override
158 public void disconnect() throws ExecutionException {
159 ISubSystem shellSubSystem = getShellServiceSubSystem();
160 if (shellSubSystem != null) {
161 try {
162 shellSubSystem.disconnect();
163 } catch (Exception e) {
164 throw new ExecutionException(e.toString(), e);
165 }
166 }
167 }
168
169 /* (non-Javadoc)
115b4a01 170 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#createCommandShell()
eb1bab5b
BH
171 */
172 @Override
173 public ICommandShell createCommandShell() throws ExecutionException {
174 ICommandShell shell = new CommandShell(this);
175 shell.connect();
176 return shell;
177 }
178
179 /* (non-Javadoc)
115b4a01 180 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#addCommunicationListener(org.eclipse.rse.core.subsystems.ICommunicationsListener)
eb1bab5b
BH
181 */
182 @Override
183 public void addCommunicationListener(ICommunicationsListener listener) {
184 IConnectorService[] css = fHost.getConnectorServices();
185 for (IConnectorService cs : css) {
186 cs.addCommunicationsListener(listener);
187 }
188 }
189
190 /* (non-Javadoc)
115b4a01 191 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.util.IRemoteSystemProxy#removeCommunicationListener(org.eclipse.rse.core.subsystems.ICommunicationsListener)
eb1bab5b
BH
192 */
193 @Override
194 public void removeCommunicationListener(ICommunicationsListener listener) {
195 IConnectorService[] css = fHost.getConnectorServices();
196 for (IConnectorService cs : css) {
197 cs.removeCommunicationsListener(listener);
198 }
199 }
200}
This page took 0.036217 seconds and 5 git commands to generate.