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