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