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