lttng.control: Add support for enabling syscall by name
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.control.ui / src / org / eclipse / tracecompass / internal / lttng2 / control / ui / views / handlers / EnableEventOnChannelHandler.java
1 /**********************************************************************
2 * Copyright (c) 2012, 2015 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 * Bernd Hufmann - Updated for support of LTTng Tools 2.1
12 **********************************************************************/
13 package org.eclipse.tracecompass.internal.lttng2.control.ui.views.handlers;
14
15 import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
16
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;
24 import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceDomainType;
25 import org.eclipse.tracecompass.internal.lttng2.control.core.model.ITraceLogLevel;
26 import org.eclipse.tracecompass.internal.lttng2.control.core.model.LogLevelType;
27 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.ControlView;
28 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceChannelComponent;
29 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceDomainComponent;
30 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent;
31 import org.eclipse.ui.IWorkbenchPage;
32
33 /**
34 * <p>
35 * Command handler implementation to enable events for a known channel.
36 * </p>
37 *
38 * @author Bernd Hufmann
39 */
40 public class EnableEventOnChannelHandler extends BaseEnableEventHandler {
41
42 // ------------------------------------------------------------------------
43 // Attributes
44 // ------------------------------------------------------------------------
45
46 // ------------------------------------------------------------------------
47 // Operations
48 // ------------------------------------------------------------------------
49
50 @Override
51 public void enableEvents(CommandParameter param, List<String> eventNames, TraceDomainType domain, String filterExression, List<String> excludedEvents, IProgressMonitor monitor) throws ExecutionException {
52 if (param instanceof ChannelCommandParameter) {
53 ((ChannelCommandParameter)param).getChannel().enableEvents(eventNames, filterExression, excludedEvents, monitor);
54 }
55 }
56
57 @Override
58 public void enableSyscalls(CommandParameter param, List<String> syscallNames, IProgressMonitor monitor) throws ExecutionException {
59 if (param instanceof ChannelCommandParameter) {
60 ((ChannelCommandParameter)param).getChannel().enableSyscalls(syscallNames, monitor);
61 }
62 }
63
64 @Override
65 public void enableProbe(CommandParameter param, String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException {
66 if (param instanceof ChannelCommandParameter) {
67 ((ChannelCommandParameter)param).getChannel().enableProbe(eventName, isFunction, probe, monitor);
68 }
69 }
70
71 @Override
72 public void enableLogLevel(CommandParameter param, List<String> eventNames, LogLevelType logLevelType, ITraceLogLevel level, String filterExression, TraceDomainType domain, IProgressMonitor monitor) throws ExecutionException {
73 if (param instanceof ChannelCommandParameter) {
74 ((ChannelCommandParameter)param).getChannel().enableLogLevel(eventNames, logLevelType, level, filterExression, domain, monitor);
75 }
76 }
77
78 @Override
79 public TraceDomainComponent getDomain(CommandParameter param) {
80 if (param instanceof ChannelCommandParameter) {
81 return (TraceDomainComponent) ((ChannelCommandParameter)param).getChannel().getParent();
82 }
83 return null;
84 }
85
86 @Override
87 public boolean isEnabled() {
88 // Get workbench page for the Control View
89 IWorkbenchPage page = getWorkbenchPage();
90 if (page == null) {
91 return false;
92 }
93
94 TraceChannelComponent channel = null;
95 TraceSessionComponent session = null;
96 ISelection selection = page.getSelection(ControlView.ID);
97 if (selection instanceof StructuredSelection) {
98 StructuredSelection structered = ((StructuredSelection) selection);
99 for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) {
100 Object element = iterator.next();
101 if (element instanceof TraceChannelComponent) {
102 // Add only if corresponding TraceSessionComponents is inactive and not destroyed
103 TraceChannelComponent tmpChannel = (TraceChannelComponent) element;
104 session = tmpChannel.getSession();
105 if (!session.isDestroyed()) {
106 channel = tmpChannel;
107 }
108 }
109 }
110 }
111
112 boolean isEnabled = (channel != null);
113 fLock.lock();
114 try {
115 fParam = null;
116 if(isEnabled) {
117 fParam = new ChannelCommandParameter(checkNotNull(session), checkNotNull(channel));
118 }
119 } finally {
120 fLock.unlock();
121 }
122 return isEnabled;
123 }
124 }
125
This page took 0.040255 seconds and 5 git commands to generate.