Commit | Line | Data |
---|---|---|
e8d771d5 BH |
1 | /******************************************************************************* |
2 | * Copyright (c) 2011 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 | * Polytechnique Montréal - Initial API and implementation | |
11 | * Bernd Hufmann - Productification, enhancements and fixes | |
12 | * | |
13 | *******************************************************************************/ | |
638eac44 | 14 | package org.eclipse.linuxtools.internal.lttng.ui.tracecontrol.actions; |
e8d771d5 BH |
15 | |
16 | import java.util.Iterator; | |
17 | import java.util.concurrent.TimeUnit; | |
18 | ||
19 | import org.eclipse.jface.action.IAction; | |
20 | import org.eclipse.jface.viewers.ISelection; | |
21 | import org.eclipse.jface.viewers.IStructuredSelection; | |
22 | import org.eclipse.jface.window.Window; | |
23 | import org.eclipse.jface.wizard.WizardDialog; | |
5945cec9 FC |
24 | import org.eclipse.linuxtools.internal.lttng.core.tracecontrol.model.TraceResource; |
25 | import org.eclipse.linuxtools.internal.lttng.core.tracecontrol.model.TraceResource.TraceState; | |
26 | import org.eclipse.linuxtools.internal.lttng.core.tracecontrol.model.config.TraceChannel; | |
27 | import org.eclipse.linuxtools.internal.lttng.core.tracecontrol.model.config.TraceChannels; | |
28 | import org.eclipse.linuxtools.internal.lttng.core.tracecontrol.model.config.TraceConfig; | |
29 | import org.eclipse.linuxtools.internal.lttng.core.tracecontrol.service.ILttControllerService; | |
0977b009 | 30 | import org.eclipse.linuxtools.internal.lttng.ui.Activator; |
638eac44 FC |
31 | import org.eclipse.linuxtools.internal.lttng.ui.tracecontrol.Messages; |
32 | import org.eclipse.linuxtools.internal.lttng.ui.tracecontrol.TraceControlConstants; | |
33 | import org.eclipse.linuxtools.internal.lttng.ui.tracecontrol.subsystems.TraceSubSystem; | |
34 | import org.eclipse.linuxtools.internal.lttng.ui.tracecontrol.wizards.ConfigureTraceWizard; | |
e8d771d5 BH |
35 | import org.eclipse.rse.core.events.ISystemRemoteChangeEvents; |
36 | import org.eclipse.rse.core.model.ISystemRegistry; | |
37 | import org.eclipse.rse.core.model.SystemStartHere; | |
38 | import org.eclipse.rse.services.clientserver.messages.SystemMessageException; | |
39 | import org.eclipse.rse.ui.SystemBasePlugin; | |
40 | import org.eclipse.swt.widgets.Shell; | |
41 | import org.eclipse.tm.tcf.protocol.IToken; | |
42 | import org.eclipse.tm.tcf.util.TCFTask; | |
43 | import org.eclipse.ui.IObjectActionDelegate; | |
44 | import org.eclipse.ui.IViewActionDelegate; | |
45 | import org.eclipse.ui.IViewPart; | |
46 | import org.eclipse.ui.IWorkbenchPart; | |
47 | import org.eclipse.ui.IWorkbenchWindow; | |
48 | import org.eclipse.ui.IWorkbenchWindowActionDelegate; | |
49 | ||
50 | /** | |
51 | * <b><u>ConfigureTrace</u></b> | |
52 | * <p> | |
53 | * Action implementation to configure a trace. | |
54 | * </p> | |
55 | */ | |
56 | public class ConfigureTrace implements IObjectActionDelegate, IWorkbenchWindowActionDelegate, IViewActionDelegate { | |
57 | ||
58 | // ------------------------------------------------------------------------ | |
59 | // Attributes | |
60 | // ------------------------------------------------------------------------ | |
61 | private TraceResource fSelectedTrace = null; | |
62 | private IStructuredSelection fSelection = null; | |
63 | ||
64 | // ------------------------------------------------------------------------ | |
65 | // Constructors | |
66 | // ------------------------------------------------------------------------ | |
67 | ||
68 | public ConfigureTrace() { | |
69 | } | |
70 | ||
71 | // ------------------------------------------------------------------------ | |
72 | // Operations | |
73 | // ------------------------------------------------------------------------ | |
74 | ||
75 | /* | |
76 | * (non-Javadoc) | |
77 | * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart) | |
78 | */ | |
79 | @Override | |
80 | public void setActivePart(IAction arg0, IWorkbenchPart arg1) { | |
81 | } | |
82 | ||
83 | /* | |
84 | * (non-Javadoc) | |
85 | * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) | |
86 | */ | |
87 | @Override | |
88 | public void run(IAction arg0) { | |
89 | ConfigureTraceWizard wizard = new ConfigureTraceWizard(); | |
90 | wizard.init(SystemBasePlugin.getActiveWorkbenchWindow().getWorkbench(), fSelection); | |
91 | WizardDialog wDialog= new WizardDialog(getShell(), wizard); | |
92 | wDialog.open(); | |
93 | if (wDialog.getReturnCode() != Window.OK) { | |
94 | return; | |
95 | } | |
96 | ||
97 | final TraceConfig result = wizard.getTraceConfig(); | |
98 | ||
99 | if (result != null) { | |
c6f55e56 | 100 | // try { |
e8d771d5 BH |
101 | |
102 | // Update channel settings | |
103 | TraceChannels channels = result.getTraceChannels(); | |
104 | ||
105 | for (Iterator<String> iterator = channels.keySet().iterator(); iterator.hasNext();) { | |
106 | String chanName = (String) iterator.next(); | |
107 | TraceChannel chan = channels.get(chanName); | |
108 | ||
109 | boolean doIt = false; | |
110 | ||
111 | // If we channel settings have been updated send the relevant command to the agent | |
112 | TraceChannel other = new TraceChannel(chan.getName()); | |
113 | ||
114 | if (fSelectedTrace.getTraceConfig() == null || fSelectedTrace.getTraceConfig().getTraceChannels() == null) { | |
115 | // Do the update since channels haven't been configured previously (or we re-connected to the agent) | |
116 | doIt = true; | |
117 | } else if (fSelectedTrace.getTraceConfig() != null && fSelectedTrace.getTraceConfig().getTraceChannels() != null) { | |
118 | // Channels has been configured previously, compare new settings with old. Do the update if necessary | |
119 | TraceChannel other2 = fSelectedTrace.getTraceConfig().getTraceChannels().get(chanName); | |
120 | if (other2 != null) { | |
121 | other = other2; | |
122 | } | |
123 | ||
124 | doIt = !(chan.equals(other)); | |
125 | } | |
126 | ||
127 | // Please note that currently, the agent doesn't support the retrieval of channel settings. | |
128 | // Therefore, the current settings might not be known! | |
129 | ||
130 | if (doIt) { | |
131 | if (!fSelectedTrace.isUst()) { | |
132 | // Update kernel tracing related parameters (not applicable for UST) | |
133 | ||
134 | if (chan.isEnabledStatusKnown()) { | |
135 | if(!other.isEnabledStatusKnown() || (chan.isEnabled() != other.isEnabled()) ) { | |
136 | setChannelEnable(chan.getName(), chan.isEnabled()); | |
137 | } | |
138 | } | |
139 | ||
140 | if (chan.isChannelOverrideStatusKnown()) { | |
141 | if(!other.isChannelOverrideStatusKnown() || (chan.isChannelOverride() != other.isChannelOverride())) { | |
142 | setChannelOverwrite(chanName, chan.isChannelOverride()); | |
143 | } | |
144 | } | |
145 | ||
146 | if (chan.getSubbufNum() != other.getSubbufNum()) { | |
147 | setChannelSubbufNum(chanName, chan.getSubbufNum()); | |
148 | } | |
149 | ||
150 | if (chan.getSubbufSize() != other.getSubbufSize()) { | |
151 | setChannelSubbufSize(chanName, chan.getSubbufSize()); | |
152 | } | |
153 | } | |
154 | ||
155 | if (chan.getTimer() != other.getTimer()) { | |
156 | setChannelTimer(chanName, chan.getTimer()); | |
157 | } | |
158 | } | |
159 | } | |
160 | // Update state of trace | |
161 | if (fSelectedTrace.getTraceState() == TraceState.CREATED) { | |
162 | fSelectedTrace.setTraceState(TraceState.CONFIGURED); | |
163 | } | |
164 | ||
165 | fSelectedTrace.setTraceConfig(result); | |
166 | ||
167 | ISystemRegistry registry = SystemStartHere.getSystemRegistry(); | |
168 | registry.fireRemoteResourceChangeEvent(ISystemRemoteChangeEvents.SYSTEM_REMOTE_RESOURCE_CHANGED, fSelectedTrace, fSelectedTrace.getParent(), fSelectedTrace.getSubSystem(), null); | |
169 | ||
c6f55e56 FC |
170 | // } catch (SystemMessageException e) { |
171 | // SystemMessageException sysExp; | |
172 | // if (e instanceof SystemMessageException) { | |
173 | // sysExp = (SystemMessageException)e; | |
174 | // } else { | |
175 | // sysExp = new SystemMessageException(LTTngUiPlugin.getDefault().getMessage(e)); | |
176 | // } | |
177 | // | |
178 | // SystemBasePlugin.logError(Messages.Lttng_Control_ErrorConfigureTrace + " (" + //$NON-NLS-1$ | |
179 | // Messages.Lttng_Resource_Trace + ": " + fSelectedTrace.getName() + ")", sysExp); //$NON-NLS-1$ //$NON-NLS-2$ | |
180 | // } | |
e8d771d5 BH |
181 | } |
182 | } | |
183 | ||
184 | /* | |
185 | * (non-Javadoc) | |
186 | * | |
187 | * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) | |
188 | */ | |
189 | @SuppressWarnings("unchecked") | |
190 | @Override | |
191 | public void selectionChanged(IAction action, ISelection selection) { | |
192 | if (selection instanceof IStructuredSelection) { | |
193 | // store the selected targets to be used when running | |
194 | Iterator<IStructuredSelection> theSet = ((IStructuredSelection) selection).iterator(); | |
195 | fSelection = (IStructuredSelection) selection; | |
196 | while (theSet.hasNext()) { | |
197 | Object obj = theSet.next(); | |
198 | if (obj instanceof TraceResource) { | |
199 | fSelectedTrace = (TraceResource)obj; | |
200 | break; | |
201 | } | |
202 | } | |
203 | } | |
204 | else { | |
205 | fSelection = null; | |
206 | } | |
207 | ||
208 | } | |
209 | ||
210 | /** | |
211 | * Returns the active workbench shell of this plug-in. | |
212 | * | |
213 | * @return active workbench shell. | |
214 | */ | |
215 | protected Shell getShell() { | |
216 | return SystemBasePlugin.getActiveWorkbenchShell(); | |
217 | } | |
218 | ||
219 | /* | |
220 | * (non-Javadoc) | |
221 | * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow) | |
222 | */ | |
223 | @Override | |
224 | public void init(IWorkbenchWindow window) { | |
225 | ||
226 | } | |
227 | ||
228 | /* | |
229 | * (non-Javadoc) | |
230 | * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose() | |
231 | */ | |
232 | @Override | |
233 | public void dispose() { | |
234 | } | |
235 | ||
236 | /* | |
237 | * (non-Javadoc) | |
238 | * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart) | |
239 | */ | |
240 | @Override | |
241 | public void init(IViewPart view) { | |
242 | } | |
243 | ||
244 | /* | |
245 | * Enable or disable a channel on the remote system. | |
246 | */ | |
247 | private void setChannelEnable(final String channelName, final boolean enabled) { | |
248 | try { | |
249 | final ILttControllerService service = ((TraceSubSystem)fSelectedTrace.getSubSystem()).getControllerService(); | |
250 | ||
251 | // Create future task | |
252 | new TCFTask<Boolean>() { | |
253 | @Override | |
254 | public void run() { | |
255 | ||
256 | // Set marker enable using Lttng controller service proxy | |
257 | service.setChannelEnable(fSelectedTrace.getParent().getParent().getName(), | |
258 | fSelectedTrace.getParent().getName(), | |
259 | fSelectedTrace.getName(), | |
260 | channelName, | |
261 | enabled, | |
262 | new ILttControllerService.DoneSetChannelEnable() { | |
263 | ||
264 | @Override | |
265 | public void doneSetChannelEnable(IToken token, Exception error, Object str) { | |
266 | if (error != null) { | |
267 | // Notify with error | |
268 | error(error); | |
269 | return; | |
270 | } | |
271 | ||
272 | // Notify about success | |
273 | done(Boolean.valueOf(true)); | |
274 | } | |
275 | }); | |
276 | }}.get(TraceControlConstants.DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS); | |
277 | } catch (Exception e) { | |
278 | SystemMessageException sysExp; | |
279 | if (e instanceof SystemMessageException) { | |
280 | sysExp = (SystemMessageException)e; | |
281 | } else { | |
638eac44 | 282 | sysExp = new SystemMessageException(Activator.getDefault().getMessage(e)); |
e8d771d5 BH |
283 | } |
284 | SystemBasePlugin.logError(Messages.Lttng_Control_ErrorSetChannelEnable + " (" + //$NON-NLS-1$ | |
285 | Messages.Lttng_Resource_Trace + ": " + fSelectedTrace.getName() + ", " + //$NON-NLS-1$ //$NON-NLS-2$ | |
286 | Messages.Lttng_Resource_Channel + ": " + channelName + ")", sysExp); //$NON-NLS-1$ //$NON-NLS-2$ | |
287 | } | |
288 | } | |
289 | ||
290 | // setChannelOverwrite* provider target trace channel enable | |
291 | private void setChannelOverwrite(final String channelName, final boolean override) { | |
292 | try { | |
293 | final ILttControllerService service = ((TraceSubSystem)fSelectedTrace.getSubSystem()).getControllerService(); | |
294 | ||
295 | // Create future task | |
296 | new TCFTask<Boolean>() { | |
297 | @Override | |
298 | public void run() { | |
299 | ||
300 | // Set marker enable using Lttng controller service proxy | |
301 | service.setChannelOverwrite(fSelectedTrace.getParent().getParent().getName(), | |
302 | fSelectedTrace.getParent().getName(), | |
303 | fSelectedTrace.getName(), | |
304 | channelName, | |
305 | override, | |
306 | new ILttControllerService.DoneSetChannelOverwrite() { | |
307 | ||
308 | @Override | |
309 | public void doneSetChannelOverwrite(IToken token, Exception error, Object str) { | |
310 | if (error != null) { | |
311 | // Notify with error | |
312 | error(error); | |
313 | return; | |
314 | } | |
315 | ||
316 | // Notify about success | |
317 | done(Boolean.valueOf(true)); | |
318 | } | |
319 | }); | |
320 | }}.get(TraceControlConstants.DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS); | |
321 | } catch (Exception e) { | |
322 | SystemMessageException sysExp; | |
323 | if (e instanceof SystemMessageException) { | |
324 | sysExp = (SystemMessageException)e; | |
325 | } else { | |
638eac44 | 326 | sysExp = new SystemMessageException(Activator.getDefault().getMessage(e)); |
e8d771d5 BH |
327 | } |
328 | SystemBasePlugin.logError(Messages.Lttng_Control_ErrorSetChannelOverwrite + " (" + //$NON-NLS-1$ | |
329 | Messages.Lttng_Resource_Trace + ": " + fSelectedTrace.getName() + ", " + //$NON-NLS-1$ //$NON-NLS-2$ | |
330 | Messages.Lttng_Resource_Channel + ": " + channelName + ")", sysExp); //$NON-NLS-1$ //$NON-NLS-2$ | |
331 | } | |
332 | } | |
333 | ||
334 | /* | |
335 | * Setup the number of sub-buffers on the remote system. | |
336 | */ | |
337 | private void setChannelSubbufNum(final String channelName, final long numSubBuf) { | |
338 | try { | |
339 | final ILttControllerService service = ((TraceSubSystem)fSelectedTrace.getSubSystem()).getControllerService(); | |
340 | ||
341 | // Create future task | |
342 | new TCFTask<Boolean>() { | |
343 | @Override | |
344 | public void run() { | |
345 | ||
346 | // Set marker enable using Lttng controller service proxy | |
347 | service.setChannelSubbufNum(fSelectedTrace.getParent().getParent().getName(), | |
348 | fSelectedTrace.getParent().getName(), | |
349 | fSelectedTrace.getName(), | |
350 | channelName, | |
351 | numSubBuf, | |
352 | new ILttControllerService.DoneSetChannelSubbufNum() { | |
353 | ||
354 | @Override | |
355 | public void doneSetChannelSubbufNum(IToken token, Exception error, Object str) { | |
356 | if (error != null) { | |
357 | // Notify with error | |
358 | error(error); | |
359 | return; | |
360 | } | |
361 | ||
362 | // Notify about success | |
363 | done(Boolean.valueOf(true)); | |
364 | } | |
365 | }); | |
366 | }}.get(TraceControlConstants.DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS); | |
367 | } catch (Exception e) { | |
368 | SystemMessageException sysExp; | |
369 | if (e instanceof SystemMessageException) { | |
370 | sysExp = (SystemMessageException)e; | |
371 | } else { | |
638eac44 | 372 | sysExp = new SystemMessageException(Activator.getDefault().getMessage(e)); |
e8d771d5 BH |
373 | } |
374 | SystemBasePlugin.logError(Messages.Lttng_Control_ErrorSetSubbufNum + " (" + //$NON-NLS-1$ | |
375 | Messages.Lttng_Resource_Trace + ": " + fSelectedTrace.getName() + ", " + //$NON-NLS-1$ //$NON-NLS-2$ | |
376 | Messages.Lttng_Resource_Channel + ": " + channelName + ")", sysExp); //$NON-NLS-1$ //$NON-NLS-2$ | |
377 | } | |
378 | } | |
379 | ||
380 | /* | |
381 | * Setup the size of the sub-buffer on the remote system. | |
382 | */ | |
383 | private void setChannelSubbufSize(final String channelName, final long subBufSize) { | |
384 | try { | |
385 | final ILttControllerService service = ((TraceSubSystem)fSelectedTrace.getSubSystem()).getControllerService(); | |
386 | ||
387 | // Create future task | |
388 | new TCFTask<Boolean>() { | |
389 | @Override | |
390 | public void run() { | |
391 | ||
392 | // Set marker enable using Lttng controller service proxy | |
393 | service.setChannelSubbufSize(fSelectedTrace.getParent().getParent().getName(), | |
394 | fSelectedTrace.getParent().getName(), | |
395 | fSelectedTrace.getName(), | |
396 | channelName, | |
397 | subBufSize, | |
398 | new ILttControllerService.DoneSetChannelSubbufSize() { | |
399 | ||
400 | @Override | |
401 | public void doneSetChannelSubbufSize(IToken token, Exception error, Object str) { | |
402 | if (error != null) { | |
403 | // Notify with error | |
404 | error(error); | |
405 | return; | |
406 | } | |
407 | ||
408 | // Notify about success | |
409 | done(Boolean.valueOf(true)); | |
410 | } | |
411 | }); | |
412 | }}.get(TraceControlConstants.DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS); | |
413 | } catch (Exception e) { | |
414 | SystemMessageException sysExp; | |
415 | if (e instanceof SystemMessageException) { | |
416 | sysExp = (SystemMessageException)e; | |
417 | } else { | |
638eac44 | 418 | sysExp = new SystemMessageException(Activator.getDefault().getMessage(e)); |
e8d771d5 BH |
419 | } |
420 | SystemBasePlugin.logError(Messages.Lttng_Control_ErrorSetSubbufSize + " (" + //$NON-NLS-1$ | |
421 | Messages.Lttng_Resource_Trace + ": " + fSelectedTrace.getName() + ", " + //$NON-NLS-1$ //$NON-NLS-2$ | |
422 | Messages.Lttng_Resource_Channel + ": " + channelName + ")", sysExp); //$NON-NLS-1$ //$NON-NLS-2$ | |
423 | } | |
424 | } | |
425 | ||
426 | /* | |
427 | * Setup up the channel timer on the remote system. | |
428 | */ | |
429 | private void setChannelTimer(final String channelName, final long timer) { | |
430 | try { | |
431 | final ILttControllerService service = ((TraceSubSystem)fSelectedTrace.getSubSystem()).getControllerService(); | |
432 | ||
433 | // Create future task | |
434 | new TCFTask<Boolean>() { | |
435 | @Override | |
436 | public void run() { | |
437 | ||
438 | // Set marker enable using Lttng controller service proxy | |
439 | service.setChannelTimer(fSelectedTrace.getParent().getParent().getName(), | |
440 | fSelectedTrace.getParent().getName(), | |
441 | fSelectedTrace.getName(), | |
442 | channelName, | |
443 | timer, | |
444 | new ILttControllerService.DoneSetChannelTimer() { | |
445 | ||
446 | @Override | |
447 | public void doneSetChannelTimer(IToken token, Exception error, Object str) { | |
448 | if (error != null) { | |
449 | // Notify with error | |
450 | error(error); | |
451 | return; | |
452 | } | |
453 | ||
454 | // Notify about success | |
455 | done(Boolean.valueOf(true)); | |
456 | } | |
457 | }); | |
458 | }}.get(TraceControlConstants.DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS); | |
459 | } catch (Exception e) { | |
460 | SystemMessageException sysExp; | |
461 | if (e instanceof SystemMessageException) { | |
462 | sysExp = (SystemMessageException)e; | |
463 | } else { | |
638eac44 | 464 | sysExp = new SystemMessageException(Activator.getDefault().getMessage(e)); |
e8d771d5 BH |
465 | } |
466 | SystemBasePlugin.logError(Messages.Lttng_Control_ErrorSetChannelTimer + " (" + //$NON-NLS-1$ | |
467 | Messages.Lttng_Resource_Trace + ": " + fSelectedTrace.getName() + ", " + //$NON-NLS-1$ //$NON-NLS-2$ | |
468 | Messages.Lttng_Resource_Channel + ": " + channelName + ")", sysExp); //$NON-NLS-1$ //$NON-NLS-2$ | |
469 | } | |
470 | } | |
471 | } |