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