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 / EnableEventOnSessionHandler.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 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;
22 import org.eclipse.tracecompass.common.core.NonNullUtils;
23 import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceDomainType;
24 import org.eclipse.tracecompass.internal.lttng2.control.core.model.ITraceLogLevel;
25 import org.eclipse.tracecompass.internal.lttng2.control.core.model.LogLevelType;
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;
30 import org.eclipse.ui.IWorkbenchPage;
31
32 /**
33 * <p>
34 * Command handler implementation to enable events for a known session and default channel 'channel0'
35 * (which will be created if doesn't exist).
36 * </p>
37 *
38 * @author Bernd Hufmann
39 */
40 public class EnableEventOnSessionHandler 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 filterExpression, List<String> excludedEvents, IProgressMonitor monitor) throws ExecutionException {
52 param.getSession().enableEvents(eventNames, domain, filterExpression, excludedEvents, monitor);
53 }
54
55 @Override
56 public void enableSyscalls(CommandParameter param, List<String> syscallNames, IProgressMonitor monitor) throws ExecutionException {
57 param.getSession().enableSyscalls(syscallNames, monitor);
58 }
59
60 @Override
61 public void enableProbe(CommandParameter param, String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException {
62 param.getSession().enableProbe(eventName, isFunction, probe, monitor);
63 }
64
65 @Override
66 public void enableLogLevel(CommandParameter param, List<String> eventNames, LogLevelType logLevelType, ITraceLogLevel level, String filterExpression, TraceDomainType domain, IProgressMonitor monitor) throws ExecutionException {
67 param.getSession().enableLogLevel(eventNames, logLevelType, level, filterExpression, domain, monitor);
68 }
69
70 @Override
71 public TraceDomainComponent getDomain(CommandParameter param) {
72 return null;
73 }
74
75 @Override
76 public boolean isEnabled() {
77 // Get workbench page for the Control View
78 IWorkbenchPage page = getWorkbenchPage();
79 if (page == null) {
80 return false;
81 }
82
83 TraceSessionComponent session = null;
84 // Check if one session is selected
85 ISelection selection = page.getSelection(ControlView.ID);
86 if (selection instanceof StructuredSelection) {
87 StructuredSelection structered = ((StructuredSelection) selection);
88 for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) {
89 Object element = iterator.next();
90 if (element instanceof TraceSessionComponent) {
91 // Add only if corresponding TraceSessionComponents is inactive and not destroyed
92 TraceSessionComponent tmpSession = (TraceSessionComponent) element;
93 if(tmpSession.getSessionState() == TraceSessionState.INACTIVE && !tmpSession.isDestroyed()) {
94 session = tmpSession;
95 }
96 }
97 }
98 }
99 boolean isEnabled = (session != null);
100 fLock.lock();
101 try {
102 fParam = null;
103 if(isEnabled) {
104 fParam = new CommandParameter(NonNullUtils.checkNotNull(session));
105 }
106 } finally {
107 fLock.unlock();
108 }
109 return isEnabled;
110 }
111 }
This page took 0.045545 seconds and 5 git commands to generate.