Commit | Line | Data |
---|---|---|
498704b3 | 1 | /********************************************************************** |
ba3a9bd2 | 2 | * Copyright (c) 2012, 2013 Ericsson |
cfdb727a | 3 | * |
498704b3 BH |
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 | |
cfdb727a AM |
8 | * |
9 | * Contributors: | |
498704b3 | 10 | * Bernd Hufmann - Initial API and implementation |
ba3a9bd2 | 11 | * Bernd Hufmann - Updated for support of LTTng Tools 2.1 |
498704b3 | 12 | **********************************************************************/ |
8e8c0226 | 13 | package org.eclipse.linuxtools.internal.lttng2.control.ui.views.handlers; |
498704b3 BH |
14 | |
15 | import java.util.Iterator; | |
16 | import java.util.List; | |
17 | ||
18 | import org.eclipse.core.commands.ExecutionException; | |
19 | import org.eclipse.core.runtime.IProgressMonitor; | |
20 | import org.eclipse.jface.viewers.ISelection; | |
21 | import org.eclipse.jface.viewers.StructuredSelection; | |
8e8c0226 AM |
22 | import org.eclipse.linuxtools.internal.lttng2.control.core.model.LogLevelType; |
23 | import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceLogLevel; | |
24 | import org.eclipse.linuxtools.internal.lttng2.control.ui.views.ControlView; | |
25 | import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceChannelComponent; | |
26 | import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceDomainComponent; | |
27 | import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent; | |
498704b3 BH |
28 | import org.eclipse.ui.IWorkbenchPage; |
29 | ||
30 | /** | |
498704b3 BH |
31 | * <p> |
32 | * Command handler implementation to enable events for a known channel. | |
33 | * </p> | |
cfdb727a | 34 | * |
dbd4432d | 35 | * @author Bernd Hufmann |
498704b3 BH |
36 | */ |
37 | public class EnableEventOnChannelHandler extends BaseEnableEventHandler { | |
38 | ||
39 | // ------------------------------------------------------------------------ | |
40 | // Attributes | |
41 | // ------------------------------------------------------------------------ | |
498704b3 BH |
42 | |
43 | // ------------------------------------------------------------------------ | |
44 | // Operations | |
45 | // ------------------------------------------------------------------------ | |
11252342 | 46 | |
498704b3 | 47 | @Override |
d4514365 | 48 | public void enableEvents(CommandParameter param, List<String> eventNames, boolean isKernel, String filterExression, IProgressMonitor monitor) throws ExecutionException { |
c56972bb | 49 | if (param instanceof ChannelCommandParameter) { |
d4514365 | 50 | ((ChannelCommandParameter)param).getChannel().enableEvents(eventNames, filterExression, monitor); |
c56972bb | 51 | } |
498704b3 BH |
52 | } |
53 | ||
498704b3 | 54 | @Override |
c56972bb BH |
55 | public void enableSyscalls(CommandParameter param, IProgressMonitor monitor) throws ExecutionException { |
56 | if (param instanceof ChannelCommandParameter) { | |
57 | ((ChannelCommandParameter)param).getChannel().enableSyscalls(monitor); | |
58 | } | |
498704b3 BH |
59 | } |
60 | ||
498704b3 | 61 | @Override |
c56972bb BH |
62 | public void enableProbe(CommandParameter param, String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException { |
63 | if (param instanceof ChannelCommandParameter) { | |
64 | ((ChannelCommandParameter)param).getChannel().enableProbe(eventName, isFunction, probe, monitor); | |
65 | } | |
498704b3 BH |
66 | } |
67 | ||
ccc66d01 | 68 | @Override |
d4514365 | 69 | public void enableLogLevel(CommandParameter param, String eventName, LogLevelType logLevelType, TraceLogLevel level, String filterExression, IProgressMonitor monitor) throws ExecutionException { |
c56972bb | 70 | if (param instanceof ChannelCommandParameter) { |
d4514365 | 71 | ((ChannelCommandParameter)param).getChannel().enableLogLevel(eventName, logLevelType, level, filterExression, monitor); |
c56972bb | 72 | } |
ccc66d01 BH |
73 | } |
74 | ||
ccc66d01 | 75 | @Override |
c56972bb BH |
76 | public TraceDomainComponent getDomain(CommandParameter param) { |
77 | if (param instanceof ChannelCommandParameter) { | |
78 | return (TraceDomainComponent) ((ChannelCommandParameter)param).getChannel().getParent(); | |
cfdb727a | 79 | } |
c56972bb | 80 | return null; |
ccc66d01 BH |
81 | } |
82 | ||
498704b3 BH |
83 | @Override |
84 | public boolean isEnabled() { | |
85 | // Get workbench page for the Control View | |
86 | IWorkbenchPage page = getWorkbenchPage(); | |
87 | if (page == null) { | |
88 | return false; | |
89 | } | |
90 | ||
c56972bb BH |
91 | TraceChannelComponent channel = null; |
92 | TraceSessionComponent session = null; | |
498704b3 BH |
93 | ISelection selection = page.getSelection(ControlView.ID); |
94 | if (selection instanceof StructuredSelection) { | |
95 | StructuredSelection structered = ((StructuredSelection) selection); | |
96 | for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) { | |
cfdb727a | 97 | Object element = iterator.next(); |
498704b3 | 98 | if (element instanceof TraceChannelComponent) { |
ccc66d01 | 99 | // Add only if corresponding TraceSessionComponents is inactive and not destroyed |
cfdb727a | 100 | TraceChannelComponent tmpChannel = (TraceChannelComponent) element; |
c56972bb | 101 | session = tmpChannel.getSession(); |
f455db37 | 102 | if(!session.isDestroyed()) { |
c56972bb | 103 | channel = tmpChannel; |
ccc66d01 | 104 | } |
498704b3 BH |
105 | } |
106 | } | |
107 | } | |
cfdb727a | 108 | |
c56972bb BH |
109 | boolean isEnabled = (channel != null); |
110 | fLock.lock(); | |
111 | try { | |
112 | fParam = null; | |
113 | if(isEnabled) { | |
114 | fParam = new ChannelCommandParameter(session, channel); | |
115 | } | |
116 | } finally { | |
117 | fLock.unlock(); | |
118 | } | |
119 | return isEnabled; | |
498704b3 | 120 | } |
498704b3 | 121 | } |
c56972bb | 122 |