lttng.ust: Replace timestamp.getValue() with toNanos()
[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.LogLevelType;
25 import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceLogLevel;
26 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.ControlView;
27 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceChannelComponent;
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 channel.
35 * </p>
36 *
37 * @author Bernd Hufmann
38 */
39 public class EnableEventOnChannelHandler extends BaseEnableEventHandler {
40
41 // ------------------------------------------------------------------------
42 // Attributes
43 // ------------------------------------------------------------------------
44
45 // ------------------------------------------------------------------------
46 // Operations
47 // ------------------------------------------------------------------------
48
49 @Override
50 public void enableEvents(CommandParameter param, List<String> eventNames, boolean isKernel, String filterExression, List<String> excludedEvents, IProgressMonitor monitor) throws ExecutionException {
51 if (param instanceof ChannelCommandParameter) {
52 ((ChannelCommandParameter)param).getChannel().enableEvents(eventNames, filterExression, excludedEvents, monitor);
53 }
54 }
55
56 @Override
57 public void enableSyscalls(CommandParameter param, IProgressMonitor monitor) throws ExecutionException {
58 if (param instanceof ChannelCommandParameter) {
59 ((ChannelCommandParameter)param).getChannel().enableSyscalls(monitor);
60 }
61 }
62
63 @Override
64 public void enableProbe(CommandParameter param, String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException {
65 if (param instanceof ChannelCommandParameter) {
66 ((ChannelCommandParameter)param).getChannel().enableProbe(eventName, isFunction, probe, monitor);
67 }
68 }
69
70 @Override
71 public void enableLogLevel(CommandParameter param, String eventName, LogLevelType logLevelType, TraceLogLevel level, String filterExression, IProgressMonitor monitor) throws ExecutionException {
72 if (param instanceof ChannelCommandParameter) {
73 ((ChannelCommandParameter)param).getChannel().enableLogLevel(eventName, logLevelType, level, filterExression, monitor);
74 }
75 }
76
77 @Override
78 public TraceDomainComponent getDomain(CommandParameter param) {
79 if (param instanceof ChannelCommandParameter) {
80 return (TraceDomainComponent) ((ChannelCommandParameter)param).getChannel().getParent();
81 }
82 return null;
83 }
84
85 @Override
86 public boolean isEnabled() {
87 // Get workbench page for the Control View
88 IWorkbenchPage page = getWorkbenchPage();
89 if (page == null) {
90 return false;
91 }
92
93 TraceChannelComponent channel = null;
94 TraceSessionComponent session = null;
95 ISelection selection = page.getSelection(ControlView.ID);
96 if (selection instanceof StructuredSelection) {
97 StructuredSelection structered = ((StructuredSelection) selection);
98 for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) {
99 Object element = iterator.next();
100 if (element instanceof TraceChannelComponent) {
101 // Add only if corresponding TraceSessionComponents is inactive and not destroyed
102 TraceChannelComponent tmpChannel = (TraceChannelComponent) element;
103 session = tmpChannel.getSession();
104 if(!session.isDestroyed()) {
105 channel = tmpChannel;
106 }
107 }
108 }
109 }
110
111 boolean isEnabled = (channel != null);
112 fLock.lock();
113 try {
114 fParam = null;
115 if(isEnabled) {
116 fParam = new ChannelCommandParameter(checkNotNull(session), checkNotNull(channel));
117 }
118 } finally {
119 fLock.unlock();
120 }
121 return isEnabled;
122 }
123 }
124
This page took 0.039614 seconds and 5 git commands to generate.