From b793fbe189d9901aaad63d3d58d024fd3bf5c23f Mon Sep 17 00:00:00 2001 From: Bernd Hufmann Date: Wed, 4 Apr 2012 14:12:59 -0400 Subject: [PATCH] Add support for LTTng 2.0 command add-context --- .../plugin.properties | 37 +- org.eclipse.linuxtools.lttng2.ui/plugin.xml | 145 ++++++- .../lttng2/ui/views/control/Messages.java | 7 + .../control/dialogs/AddContextDialog.java | 394 ++++++++++++++++++ .../control/dialogs/IAddContextDialog.java | 46 ++ .../dialogs/TraceControlDialogFactory.java | 23 + .../handlers/AddContextOnChannelHandler.java | 96 +++++ .../handlers/AddContextOnDomainHandler.java | 104 +++++ .../handlers/AddContextOnEventHandler.java | 96 +++++ .../handlers/BaseAddContextHandler.java | 136 ++++++ .../handlers/EventCommandParameter.java | 66 +++ .../ui/views/control/messages.properties | 8 + .../model/impl/TraceChannelComponent.java | 19 + .../model/impl/TraceDomainComponent.java | 18 + .../model/impl/TraceEventComponent.java | 31 ++ .../model/impl/TraceSessionComponent.java | 17 + .../control/service/ILttngControlService.java | 19 + .../control/service/LTTngControlService.java | 114 ++++- 18 files changed, 1334 insertions(+), 42 deletions(-) create mode 100644 org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/AddContextDialog.java create mode 100644 org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/IAddContextDialog.java create mode 100644 org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/AddContextOnChannelHandler.java create mode 100644 org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/AddContextOnDomainHandler.java create mode 100644 org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/AddContextOnEventHandler.java create mode 100644 org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/BaseAddContextHandler.java create mode 100644 org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/EventCommandParameter.java diff --git a/org.eclipse.linuxtools.lttng2.ui/plugin.properties b/org.eclipse.linuxtools.lttng2.ui/plugin.properties index 21f0793a20..231557ac67 100644 --- a/org.eclipse.linuxtools.lttng2.ui/plugin.properties +++ b/org.eclipse.linuxtools.lttng2.ui/plugin.properties @@ -62,37 +62,6 @@ commands.experiment.rename.description = Rename an LTTng Experiment commands.experiment.delete = Delete Experiment commands.experiment.delete.description = Delete an LTTng Experiment - -# trace control (RSE) properties -lttng.rse.subsystem.type.name=LTTng -lttng.rse.subsystem.type.description=LTTng TCF Subsystem -lttng.rse.subsystem.config.name = LTTng Tracing -lttng.rse.subsystem.config.description = LTTng Tracing Subsystem Configuration - -action.set.label = LTTng RSE action set -action.set.description = LTTng RSE action set - -menu.lttng.label = LTTng -action.stop.label = Stop -action.stop.tooltip = Stop the selected trace -action.pause.label = Pause -action.pause.tooltip = Pause tracing -action.start.label = Start -action.start.tooltip = Start tracing -action.newtrace.label = New Trace -action.newtrace.tooltip = Create a new trace -action.configuretrace.label = Configure Trace -action.configuretrace.tooltip = Configure the selected trace -action.browse.label = Browse Trace -action.browse.tooltip = Browse the trace folder of selected trace -action.configuremarkers.label = Configure Markers -action.configuremarkers.tooltip = Configure the markers of selected target -action.delete.label = Delete Trace -action.delete.tooltip = Delete the selected trace - -action.import.label = Import To Project -action.import.tooltip = Import selected trace to a project - # LTTng 2.0 trace control commands trace.control.rse.system.type.name=LTTng (v2.0 or later) trace.control.rse.system.type.description=LTTng Trace Control (v2.0 or later) @@ -112,7 +81,6 @@ commands.control.disconnect.description=Disconnect to Target Node commands.control.refresh=Refresh commands.control.refresh.description=Refresh Node Configuration - commands.control.delete=Delete commands.control.delete.description=Delete Target Node @@ -137,7 +105,6 @@ commands.control.start.description=Start Trace Session commands.control.stop=Stop commands.control.stop.description=Stop Trace Session -#commands.control.enable.event=Enable commands.control.enable.assign.description=Assign Event to Session and Channel and Enable Event commands.control.enable.event=Enable Event @@ -149,6 +116,8 @@ commands.control.enable.eventOnDomain.description=Enable Event on Default Channe commands.control.enable.eventOnSession=Enable Event (default channel) commands.control.enable.eventOnSession.description=Enable Event on Default Channel - commands.control.disable.event=Disable Event commands.control.disable.event.description=Disable Event + +commands.control.add.context=Add Context +commands.control.add.context.description=Add Context to Channel(s) and/or Event(s) diff --git a/org.eclipse.linuxtools.lttng2.ui/plugin.xml b/org.eclipse.linuxtools.lttng2.ui/plugin.xml index 135a71264f..e332ce4a8a 100644 --- a/org.eclipse.linuxtools.lttng2.ui/plugin.xml +++ b/org.eclipse.linuxtools.lttng2.ui/plugin.xml @@ -150,7 +150,28 @@ id="org.eclipse.linuxtools.internal.lttng2.ui.commands.control.enableEventOnSession" name="%commands.control.enable.eventOnSession"> - + + + + + + + + + + @@ -563,7 +584,6 @@ - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -884,6 +970,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + AddContextDialog + *

+ * Dialog box for collecting information about contexts to be added to channels/events. + *

+ */ +public class AddContextDialog extends Dialog implements IAddContextDialog { + + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + + /** + * The icon file for this dialog box. + */ + public static final String ADD_CONTEXT_ICON_FILE = "icons/elcl16/edit.gif"; //$NON-NLS-1$ + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + /** + * The dialog composite. + */ + private Composite fDialogComposite; + /** + * A tree viewer for displaying and selection of available contexts. + */ + private CheckboxTreeViewer fContextsViewer; + /** + * A Tree model for the checkbox tree viewer. + */ + private ContextModel fContextModel = new ContextModel(); + /** + * The contexts to add. + */ + private List fSelectedContexts = new ArrayList(); + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + /** + * Constructor + * @param shell - a shell for the display of the dialog + */ + public AddContextDialog(Shell shell) { + super(shell); + setShellStyle(SWT.RESIZE); + } + + // ------------------------------------------------------------------------ + // Accessors + // ------------------------------------------------------------------------ + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IAddContextDialog#setAvalibleContexts(java.util.List) + */ + @Override + public void setAvalibleContexts(List contexts) { + fContextModel.setAvalibleContexts(contexts); + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IAddContextDialog#getContexts() + */ + @Override + public List getContexts() { + List ret = new ArrayList(); + ret.addAll(fSelectedContexts); + return ret; + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + /* + * (non-Javadoc) + * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) + */ + @Override + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + newShell.setText(Messages.TraceControl_AddContextDialogTitle); + newShell.setImage(Activator.getDefault().loadIcon(ADD_CONTEXT_ICON_FILE)); + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) + */ + @Override + protected Control createDialogArea(Composite parent) { + + // Main dialog panel + fDialogComposite = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(1, true); + fDialogComposite.setLayout(layout); + fDialogComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); + + // Contexts list + Group contextGroup = new Group(fDialogComposite, SWT.SHADOW_NONE); + contextGroup.setText(Messages.TraceControl_AddContextAvailableContextsLabel); + layout = new GridLayout(1, true); + contextGroup.setLayout(layout); + contextGroup.setLayoutData(new GridData(GridData.FILL_BOTH)); + + fContextsViewer = new CheckboxTreeViewer(contextGroup, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); + fContextsViewer.getTree().setToolTipText(Messages.TraceControl_AddContextAvailableContextsTooltip); + + fContextsViewer.setContentProvider(new ContextsContentProvider()); + fContextsViewer.setLabelProvider(new ContextsLabelProvider()); + fContextsViewer.addCheckStateListener(new ContextCheckListener()); + fContextsViewer.setInput(fContextModel); + fContextsViewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH)); + + getShell().setMinimumSize(new Point(500, 650)); + + return fDialogComposite; + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) + */ + @Override + protected void createButtonsForButtonBar(Composite parent) { + createButton(parent, IDialogConstants.OK_ID, "&Ok", true); //$NON-NLS-1$ + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.dialogs.Dialog#okPressed() + */ + @Override + protected void okPressed() { + fSelectedContexts.clear(); + + Object[] checkedElements = fContextsViewer.getCheckedElements(); + for (int i = 0; i < checkedElements.length; i++) { + IContextModelComponent component = (IContextModelComponent)checkedElements[i]; + fSelectedContexts.add(component.getName()); + } + + // validation successful -> call super.okPressed() + super.okPressed(); + } + + // ------------------------------------------------------------------------ + // Helper classes and methods + // ------------------------------------------------------------------------ + /** + * Content provider for the contexts tree + */ + final public static class ContextsContentProvider implements ITreeContentProvider { + + @Override + public void dispose() { + } + + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + + @Override + public Object[] getElements(Object inputElement) { + return getChildren(inputElement); + } + + @Override + public Object[] getChildren(Object parentElement) { + if (parentElement instanceof IContextModelComponent) { + return ((IContextModelComponent)parentElement).getChildren(); + } + return null; + } + + @Override + public Object getParent(Object element) { + if (element instanceof IContextModelComponent) { + return ((IContextModelComponent)element).getParent(); + } + return null; + } + + @Override + public boolean hasChildren(Object element) { + if (element instanceof IContextModelComponent) { + return ((IContextModelComponent)element).hasChildren(); + } + return false; + } + } + + /** + * Label provider for the contexts tree + */ + final public static class ContextsLabelProvider extends ColumnLabelProvider { + @Override + public String getText(Object element) { + + if ((element != null) && (element instanceof IContextModelComponent)) { + return ((IContextModelComponent)element).getName(); + } + + return "";//$NON-NLS-1$ + } + } + + /** + * Check state listener for the contexts tree. + */ + final public class ContextCheckListener implements ICheckStateListener { + @Override + public void checkStateChanged(CheckStateChangedEvent event) { + if (event.getChecked()) { + if (event.getElement() instanceof AllContexts) { + fContextsViewer.setSubtreeChecked(event.getElement(), true); + } + } else { + if (event.getElement() instanceof AllContexts) { + fContextsViewer.setSubtreeChecked(event.getElement(), false); + } else { + IContextModelComponent component = (IContextModelComponent) event.getElement(); + fContextsViewer.setChecked(component.getParent(), false); + } + } + } + } + + /** + * Model for the context tree viewer (root component) + */ + public static class ContextModel implements IContextModelComponent { + + private AllContexts fAllContexts; + + public ContextModel() { + fAllContexts = new AllContexts(this); + } + + public void setAvalibleContexts(List contexts) { + fAllContexts.setAvalibleContexts(contexts); + } + + @Override + public String getName() { + return "root"; //$NON-NLS-1$ + } + + @Override + public Object getParent() { + return null; + } + + @Override + public Object[] getChildren() { + Object[] ret = new Object[1]; + ret[0] = fAllContexts; + return ret; + } + + @Override + public boolean hasChildren() { + return true; + } + } + + /** + * Model element (to select/deselect) all contexts) for the context tree viewer + */ + public static class AllContexts implements IContextModelComponent { + /** + * The available list of contexts. + */ + private List fAvailableContexts; + + private IContextModelComponent fParent; + + public AllContexts(IContextModelComponent parent) { + fParent = parent; + } + + public void setAvalibleContexts(List contexts) { + fAvailableContexts = new ArrayList(); + if (contexts != null) { + for (Iterator iterator = contexts.iterator(); iterator.hasNext();) { + String name = (String) iterator.next(); + fAvailableContexts.add(new Context(this, name)); + } + } + } + + @Override + public String getName() { + return Messages.TraceControl_AddContextAllLabel; + } + + @Override + public Object[] getChildren() { + return fAvailableContexts.toArray(); + } + + @Override + public Object getParent() { + return fParent; + } + + @Override + public boolean hasChildren() { + return true; + } + } + + /** + * Model element (the context) for the context tree viewer + */ + public static class Context implements IContextModelComponent { + + private String fContextName; + private IContextModelComponent fParent; + + public Context(IContextModelComponent parent, String name) { + fParent = parent; + fContextName = name; + } + + @Override + public String getName() { + return fContextName; + } + + @Override + public Object getParent() { + return fParent; + } + + @Override + public Object[] getChildren() { + return null; + } + + @Override + public boolean hasChildren() { + return false; + } + } + + /** + * Interface for the tree model used for the context tree viewer. + */ + public interface IContextModelComponent { + public String getName(); + public Object getParent(); + public Object[] getChildren(); + public boolean hasChildren(); + } +} diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/IAddContextDialog.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/IAddContextDialog.java new file mode 100644 index 0000000000..c8c0dd310f --- /dev/null +++ b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/IAddContextDialog.java @@ -0,0 +1,46 @@ +/********************************************************************** + * Copyright (c) 2012 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Bernd Hufmann - Initial API and implementation + **********************************************************************/ +package org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs; + +import java.util.List; + +/** + * IAddContextDialog + *

+ * Interface for providing information about contexts to be added to channels/events. + *

+ */ +public interface IAddContextDialog { + + // ------------------------------------------------------------------------ + // Accessors + // ------------------------------------------------------------------------ + + /** + * Sets the available contexts to choose from. + * @param contexts - a list of available contexts. + */ + public void setAvalibleContexts(List contexts); + + /** + * @return array of contexts to be added + */ + public List getContexts(); + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + /** + * @return returns the open return value + */ + int open(); +} diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/TraceControlDialogFactory.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/TraceControlDialogFactory.java index f8d5d8a720..3af2ce8d6a 100644 --- a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/TraceControlDialogFactory.java +++ b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/TraceControlDialogFactory.java @@ -43,6 +43,11 @@ final public class TraceControlDialogFactory { * The confirmation dialog implementation */ private IConfirmDialog fConfirmDialog; + + /** + * The add context dialog implementation + */ + private IAddContextDialog fAddContextDialog; // ------------------------------------------------------------------------ // Constructors @@ -175,6 +180,24 @@ final public class TraceControlDialogFactory { public void setConfirmDialog(IConfirmDialog confirmDialog) { fConfirmDialog = confirmDialog; } + + /** + * @return the add context dialog implementation + */ + public IAddContextDialog getAddContextDialog() { + if (fAddContextDialog == null) { + fAddContextDialog = new AddContextDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()); + } + return fAddContextDialog; + } + + /** + * Sets the add context dialog information + * @param addContextDialog + */ + public void setAddContextDialog(IAddContextDialog addContextDialog) { + fAddContextDialog = addContextDialog; + } } diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/AddContextOnChannelHandler.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/AddContextOnChannelHandler.java new file mode 100644 index 0000000000..0deea89562 --- /dev/null +++ b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/AddContextOnChannelHandler.java @@ -0,0 +1,96 @@ +/********************************************************************** + * Copyright (c) 2012 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Bernd Hufmann - Initial API and implementation + **********************************************************************/ +package org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers; + +import java.util.Iterator; +import java.util.List; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.linuxtools.internal.lttng2.ui.views.control.ControlView; +import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceSessionState; +import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceChannelComponent; +import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent; +import org.eclipse.ui.IWorkbenchPage; + +/** + * AddContextOnChannelHandler + *

+ * Command handler implementation to add contexts to a given channel and all of its events. + *

+ */ +public class AddContextOnChannelHandler extends BaseAddContextHandler { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseAddContextHandler#addContexts(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter, java.util.List, org.eclipse.core.runtime.IProgressMonitor) + */ + @Override + public void addContexts(CommandParameter param, List contextNames, IProgressMonitor monitor) throws ExecutionException { + if (param instanceof ChannelCommandParameter) { + TraceChannelComponent channel = ((ChannelCommandParameter)param).getChannel(); + channel.addContexts(contextNames, monitor); + } + } + + /* + * (non-Javadoc) + * @see org.eclipse.core.commands.AbstractHandler#isEnabled() + */ + @Override + public boolean isEnabled() { + // Get workbench page for the Control View + IWorkbenchPage page = getWorkbenchPage(); + if (page == null) { + return false; + } + + TraceChannelComponent channel = null; + TraceSessionComponent session = null; + ISelection selection = page.getSelection(ControlView.ID); + if (selection instanceof StructuredSelection) { + StructuredSelection structered = ((StructuredSelection) selection); + for (Iterator iterator = structered.iterator(); iterator.hasNext();) { + Object element = (Object) iterator.next(); + if (element instanceof TraceChannelComponent) { + // Add only if corresponding TraceSessionComponents is inactive and not destroyed + TraceChannelComponent tmpChannel = (TraceChannelComponent) element; + session = tmpChannel.getSession(); + if(session.getSessionState() == TraceSessionState.INACTIVE && !session.isDestroyed()) { + channel = tmpChannel; + } + } + } + } + + boolean isEnabled = (channel != null); + fLock.lock(); + try { + fParam = null; + if(isEnabled) { + fParam = new ChannelCommandParameter(session, channel); + } + } finally { + fLock.unlock(); + } + return isEnabled; + } +} diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/AddContextOnDomainHandler.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/AddContextOnDomainHandler.java new file mode 100644 index 0000000000..d5e6626d7c --- /dev/null +++ b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/AddContextOnDomainHandler.java @@ -0,0 +1,104 @@ +/********************************************************************** + * Copyright (c) 2012 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Bernd Hufmann - Initial API and implementation + **********************************************************************/ +package org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers; + +import java.util.Iterator; +import java.util.List; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.linuxtools.internal.lttng2.ui.views.control.ControlView; +import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceSessionState; +import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceDomainComponent; +import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent; +import org.eclipse.ui.IWorkbenchPage; + +/** + * AddContextOnDomainHandler + *

+ * Command handler implementation to add contexts to all channels and all events. + *

+ */ +public class AddContextOnDomainHandler extends BaseAddContextHandler { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseAddContextHandler#addContexts(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter, java.util.List, org.eclipse.core.runtime.IProgressMonitor) + */ + @Override + public void addContexts(CommandParameter param, List contextNames, IProgressMonitor monitor) throws ExecutionException { + if (param instanceof DomainCommandParameter) { + TraceDomainComponent domain = ((DomainCommandParameter)param).getDomain(); + domain.addContexts(contextNames, monitor); + } + } + + /* + * (non-Javadoc) + * @see org.eclipse.core.commands.AbstractHandler#isEnabled() + */ + @Override + public boolean isEnabled() { + + // Get workbench page for the Control View + IWorkbenchPage page = getWorkbenchPage(); + if (page == null) { + return false; + } + + TraceDomainComponent domain = null; + TraceSessionComponent session = null; + + // Check if one domain is selected + ISelection selection = page.getSelection(ControlView.ID); + if (selection instanceof StructuredSelection) { + StructuredSelection structered = ((StructuredSelection) selection); + for (Iterator iterator = structered.iterator(); iterator.hasNext();) { + Object element = (Object) iterator.next(); + if (element instanceof TraceDomainComponent) { + TraceDomainComponent tmpDomain = (TraceDomainComponent) element; + session = (TraceSessionComponent) tmpDomain.getParent(); + + // Add only TraceDomainComponent whose TraceSessionComponent parent is inactive and not destroyed + if ((session.getSessionState() == TraceSessionState.INACTIVE) && (!session.isDestroyed())) { + domain = tmpDomain; + } + } + } + } + + boolean isEnabled = domain != null; + + fLock.lock(); + try { + fParam = null; + if (isEnabled) { + fParam = new DomainCommandParameter(session, domain); + } + } finally { + fLock.unlock(); + } + + return isEnabled; + } + + +} diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/AddContextOnEventHandler.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/AddContextOnEventHandler.java new file mode 100644 index 0000000000..7611c8e1c5 --- /dev/null +++ b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/AddContextOnEventHandler.java @@ -0,0 +1,96 @@ +/********************************************************************** + * Copyright (c) 2012 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Bernd Hufmann - Initial API and implementation + **********************************************************************/ +package org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers; + +import java.util.Iterator; +import java.util.List; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.linuxtools.internal.lttng2.ui.views.control.ControlView; +import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceSessionState; +import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceEventComponent; +import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent; +import org.eclipse.ui.IWorkbenchPage; + +/** + * AddContextOnEventHandler + *

+ * Command handler implementation to add contexts to a given event. + *

+ */ +public class AddContextOnEventHandler extends BaseAddContextHandler { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseAddContextHandler#addContexts(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter, java.util.List, org.eclipse.core.runtime.IProgressMonitor) + */ + @Override + public void addContexts(CommandParameter param, List contextNames, IProgressMonitor monitor) throws ExecutionException { + if (param instanceof EventCommandParameter) { + TraceEventComponent event = ((EventCommandParameter)param).getEvent(); + event.addContexts(contextNames, monitor); + } + } + + /* + * (non-Javadoc) + * @see org.eclipse.core.commands.AbstractHandler#isEnabled() + */ + @Override + public boolean isEnabled() { + // Get workbench page for the Control View + IWorkbenchPage page = getWorkbenchPage(); + if (page == null) { + return false; + } + + TraceEventComponent event = null; + TraceSessionComponent session = null; + ISelection selection = page.getSelection(ControlView.ID); + if (selection instanceof StructuredSelection) { + StructuredSelection structered = ((StructuredSelection) selection); + for (Iterator iterator = structered.iterator(); iterator.hasNext();) { + Object element = (Object) iterator.next(); + if (element instanceof TraceEventComponent) { + // Add only if corresponding TraceSessionComponents is inactive and not destroyed + TraceEventComponent tmpEvent = (TraceEventComponent) element; + session = tmpEvent.getSession(); + if(session.getSessionState() == TraceSessionState.INACTIVE && !session.isDestroyed()) { + event = tmpEvent; + } + } + } + } + + boolean isEnabled = (event != null); + fLock.lock(); + try { + fParam = null; + if(isEnabled) { + fParam = new EventCommandParameter(session, event); + } + } finally { + fLock.unlock(); + } + return isEnabled; + } +} diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/BaseAddContextHandler.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/BaseAddContextHandler.java new file mode 100644 index 0000000000..339e0b5a08 --- /dev/null +++ b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/BaseAddContextHandler.java @@ -0,0 +1,136 @@ +/********************************************************************** + * Copyright (c) 2012 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Bernd Hufmann - Initial API and implementation + **********************************************************************/ +package org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers; + +import java.util.List; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.jface.window.Window; +import org.eclipse.linuxtools.internal.lttng2.ui.Activator; +import org.eclipse.linuxtools.internal.lttng2.ui.views.control.Messages; +import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IAddContextDialog; +import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.TraceControlDialogFactory; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.progress.UIJob; + +/** + * BaseAddContextHandler + *

+ * Base command handler implementation to add contexts. + *

+ */ +abstract public class BaseAddContextHandler extends BaseControlViewHandler { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + /** + * The command execution parameter. + */ + protected CommandParameter fParam = null; + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + /** + * Adds contexts to channel(s) and/or event(s) + * @param param - a parameter instance with data for the command execution + * @param contextNames - list contexts to add + * @param monitor - a progress monitor + * @throws ExecutionException + */ + abstract public void addContexts(CommandParameter param, List contextNames, IProgressMonitor monitor) throws ExecutionException; + + /* + * (non-Javadoc) + * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) + */ + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + + final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + + if (window == null) { + return false; + } + fLock.lock(); + try { + // Make a copy for thread safety + final CommandParameter param = fParam.clone(); + + UIJob getJob = new UIJob(Messages.TraceControl_GetContextJob) { + @Override + public IStatus runInUIThread(IProgressMonitor monitor) { + + try { + final List availableContexts = param.getSession().getContextList(monitor); + final IAddContextDialog dialog = TraceControlDialogFactory.getInstance().getAddContextDialog(); + dialog.setAvalibleContexts(availableContexts); + + if ((dialog.open() != Window.OK) || (dialog.getContexts().isEmpty())) { + return Status.OK_STATUS; + } + + Job addJob = new Job(Messages.TraceControl_AddContextJob) { + @Override + protected IStatus run(IProgressMonitor monitor) { + StringBuffer errorString = new StringBuffer(); + + try { + List contextNames = dialog.getContexts(); + addContexts(param, contextNames, monitor); + + } catch (ExecutionException e) { + errorString.append(e.toString()); + errorString.append('\n'); + } + + // get session configuration in all cases + try { + param.getSession().getConfigurationFromNode(monitor); + } catch (ExecutionException e) { + errorString.append(Messages.TraceControl_ListSessionFailure); + errorString.append(": "); //$NON-NLS-1$ + errorString.append(e.toString()); + } + + if (errorString.length() > 0) { + return new Status(Status.ERROR, Activator.PLUGIN_ID, errorString.toString()); + } + return Status.OK_STATUS; + } + }; + addJob.setUser(true); + addJob.schedule(); + } catch (ExecutionException e) { + return new Status(Status.ERROR, Activator.PLUGIN_ID, e.toString()); + } + + return Status.OK_STATUS; + } + }; + getJob.setUser(false); + getJob.schedule(); + + } finally { + fLock.unlock(); + } + return null; + } +} diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/EventCommandParameter.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/EventCommandParameter.java new file mode 100644 index 0000000000..82f4b9b2d3 --- /dev/null +++ b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/EventCommandParameter.java @@ -0,0 +1,66 @@ +/********************************************************************** + * Copyright (c) 2012 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Bernd Hufmann - Initial API and implementation + **********************************************************************/ +package org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers; + +import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceEventComponent; +import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent; + +/** + * Class containing parameter for a command execution. + */ +public class EventCommandParameter extends CommandParameter { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + private TraceEventComponent fEvent; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + /** + * Constructor + * @param session - a trace session component. + * @param event - a trace event component + */ + public EventCommandParameter(TraceSessionComponent session, TraceEventComponent event) { + super(session); + fEvent = event; + } + + // ------------------------------------------------------------------------ + // Accessors + // ------------------------------------------------------------------------ + + /** + * @return the trace event component + */ + public TraceEventComponent getEvent() { + return fEvent; + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + /* + * (non-Javadoc) + * @see java.lang.Object#clone() + */ + @Override + public EventCommandParameter clone() { + EventCommandParameter clone = (EventCommandParameter) super.clone(); + clone.fEvent = fEvent; + return clone; + } +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/messages.properties b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/messages.properties index 8dc114118f..3065622daa 100644 --- a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/messages.properties +++ b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/messages.properties @@ -31,6 +31,9 @@ TraceControl_EnableEventsJob=Enabling Events... TraceControl_EnableEventsFailure=Enable Events failed TraceControl_DisableEventsJob=Disabling Events... +TraceControl_GetContextJob=Getting Available Contexts... +TraceControl_AddContextJob=Adding Contexts... + # Dialogs TraceControl_NewDialogTitle=New Connection TraceControl_NewNodeExistingConnectionGroupName=Existing Connections @@ -105,6 +108,11 @@ TraceControl_InvalidWildcardError=The wild card name is invalid TraceControl_InvalidLogLevelEventNameError=The event name for log level is invalid TraceControl_InvalidLogLevel=No log level selected +TraceControl_AddContextDialogTitle=Add Contexts +TraceControl_AddContextAvailableContextsLabel=Contexts +TraceControl_AddContextAvailableContextsTooltip=Available Contexts +TraceControl_AddContextAllLabel=All Contexts + # Tree structure strings TraceControl_KernelDomainDisplayName=Kernel TraceControl_UstGlobalDomainDisplayName=UST global diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/model/impl/TraceChannelComponent.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/model/impl/TraceChannelComponent.java index 29d3ca7dc5..20f9909387 100644 --- a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/model/impl/TraceChannelComponent.java +++ b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/model/impl/TraceChannelComponent.java @@ -359,4 +359,23 @@ public class TraceChannelComponent extends TraceControlComponent { public void disableEvent(List eventNames, IProgressMonitor monitor) throws ExecutionException { getControlService().disableEvent(getParent().getParent().getName(), getName(), eventNames, isKernel(), monitor); } + + /** + * Add contexts to given channels and or events + * @param contexts - a list of contexts to add + * @throws ExecutionException + */ + public void addContexts(List contexts) throws ExecutionException { + addContexts(contexts, new NullProgressMonitor()); + } + + /** + * Add contexts to given channels and or events + * @param contexts - a list of contexts to add + * @param monitor - a progress monitor + * @throws ExecutionException + */ + public void addContexts(List contexts, IProgressMonitor monitor) throws ExecutionException { + getControlService().addContexts(getSessionName(), getName(), null, isKernel(), contexts, monitor); + } } diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/model/impl/TraceDomainComponent.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/model/impl/TraceDomainComponent.java index c88f90a83c..c8373395d2 100644 --- a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/model/impl/TraceDomainComponent.java +++ b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/model/impl/TraceDomainComponent.java @@ -271,4 +271,22 @@ public class TraceDomainComponent extends TraceControlComponent { getControlService().enableLogLevel(getSessionName(), null, eventName, logLevelType, level, monitor); } + /** + * Add contexts to given channels and or events + * @param contexts - a list of contexts to add + * @throws ExecutionException + */ + public void addContexts(List contexts) throws ExecutionException { + addContexts(contexts, new NullProgressMonitor()); + } + + /** + * Add contexts to given channels and or events + * @param contexts - a list of contexts to add + * @param monitor - a progress monitor + * @throws ExecutionException + */ + public void addContexts(List contexts, IProgressMonitor monitor) throws ExecutionException { + getControlService().addContexts(getSessionName(), null, null, isKernel(), contexts, monitor); + } } diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/model/impl/TraceEventComponent.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/model/impl/TraceEventComponent.java index f67b3cff0c..7c2f85a224 100644 --- a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/model/impl/TraceEventComponent.java +++ b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/model/impl/TraceEventComponent.java @@ -11,6 +11,11 @@ **********************************************************************/ package org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl; +import java.util.List; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.linuxtools.internal.lttng2.ui.Activator; import org.eclipse.linuxtools.internal.lttng2.ui.views.control.Messages; import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IEventInfo; @@ -182,6 +187,13 @@ public class TraceEventComponent extends TraceControlComponent { return ((TraceChannelComponent)getParent()).getSessionName(); } + /** + * @return session from parent + */ + public TraceSessionComponent getSession() { + return ((TraceChannelComponent)getParent()).getSession(); + } + /** * @return channel name from parent */ @@ -199,4 +211,23 @@ public class TraceEventComponent extends TraceControlComponent { // ------------------------------------------------------------------------ // Operations // ------------------------------------------------------------------------ + + /** + * Add contexts to given channels and or events + * @param contexts - a list of contexts to add + * @throws ExecutionException + */ + public void addContexts(List contexts) throws ExecutionException { + addContexts(contexts, new NullProgressMonitor()); + } + + /** + * Add contexts to given channels and or events + * @param contexts - a list of contexts to add + * @param monitor - a progress monitor + * @throws ExecutionException + */ + public void addContexts(List contexts, IProgressMonitor monitor) throws ExecutionException { + getControlService().addContexts(getSessionName(),getChannelName(), getName(), isKernel(), contexts, monitor); + } } diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/model/impl/TraceSessionComponent.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/model/impl/TraceSessionComponent.java index e8cffe2da5..f1d1476dd1 100644 --- a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/model/impl/TraceSessionComponent.java +++ b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/model/impl/TraceSessionComponent.java @@ -362,4 +362,21 @@ public class TraceSessionComponent extends TraceControlComponent { public void enableLogLevel(String eventName, LogLevelType logLevelType, TraceLogLevel level, IProgressMonitor monitor) throws ExecutionException { getControlService().enableLogLevel(getName(), null, eventName, logLevelType, level, monitor); } + + /** + * Gets all available contexts to be added to channels/events. + * @return the list of available contexts + */ + public List getContextList() throws ExecutionException { + return getContextList(new NullProgressMonitor()); + } + + /** + * Gets all available contexts to be added to channels/events. + * @param monitor + * @return the list of available contexts + */ + public List getContextList(IProgressMonitor monitor) throws ExecutionException { + return getControlService().getContextList(monitor); + } } diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/service/ILttngControlService.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/service/ILttngControlService.java index 2824c2f4b9..14a6410a32 100644 --- a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/service/ILttngControlService.java +++ b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/service/ILttngControlService.java @@ -178,5 +178,24 @@ public interface ILttngControlService { * @throws ExecutionException */ public void disableEvent(String sessionName, String channelName, List eventNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException; + + /** + * Gets all available context names to be added to channels/events. + * @param monitor + * @return the list of available contexts + */ + public List getContextList(IProgressMonitor monitor) throws ExecutionException; + + /** + * Add contexts to given channels and or events + * @param sessionName - a session name + * @param channelName - a channel name (null for all channels) + * @param eventName - a event name (null for all events) + * @param isKernel - a flag for indicating kernel or UST. + * @param contexts - a list of name of contexts to add + * @param monitor - a progress monitor + * @throws ExecutionException + */ + public void addContexts(String sessionName, String channelName, String eventName, boolean isKernel, List contexts, IProgressMonitor monitor) throws ExecutionException; } diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/service/LTTngControlService.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/service/LTTngControlService.java index ef08cae9d8..c471d2f03b 100644 --- a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/service/LTTngControlService.java +++ b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/service/LTTngControlService.java @@ -98,7 +98,11 @@ public class LTTngControlService implements ILttngControlService { * Command to disable a event. */ private final static String COMMAND_DISABLE_EVENT = CONTROL_COMMAND + " disable-event "; //$NON-NLS-1$ - + /** + * Command to add a context to channels and/or events + */ + private final static String COMMAND_ADD_CONTEXT = CONTROL_COMMAND + " add-context "; //$NON-NLS-1$ + // Command options constants /** * Command line option for output path. @@ -120,10 +124,18 @@ public class LTTngControlService implements ILttngControlService { * Command line option for specifying a channel. */ private final static String OPTION_CHANNEL = " -c "; //$NON-NLS-1$ + /** + * Command line option for specifying a event. + */ + private final static String OPTION_EVENT = " -e "; //$NON-NLS-1$ /** * Command line option for specifying all events. */ private final static String OPTION_ALL = " -a "; //$NON-NLS-1$ + /** + * Command line option for specifying a context. + */ + private final static String OPTION_CONTEXT_TYPE = " -t "; //$NON-NLS-1$ /** * Command line option for specifying tracepoint events. */ @@ -168,6 +180,10 @@ public class LTTngControlService implements ILttngControlService { * Optional command line option for configuring a channel's read timer interval. */ private final static String OPTION_READ_TIMER = " --read-timer "; //$NON-NLS-1$ + /** + * Command line option for printing the help of a specif command + */ + private final static String OPTION_HELP = " -h "; //$NON-NLS-1$ // Parsing constants /** @@ -284,6 +300,15 @@ public class LTTngControlService implements ILttngControlService { * Pattern to match for session command output for "session name not found". */ private final static Pattern SESSION_NOT_FOUND_ERROR_PATTERN = Pattern.compile("\\s*Error:\\s+Session\\s+name\\s+not\\s+found"); //$NON-NLS-1$ + /** + * Pattern to match introduction line of context list. + */ + private final static Pattern ADD_CONTEXT_HELP_CONTEXTS_INTRO = Pattern.compile("\\s*TYPE can\\s+be\\s+one\\s+of\\s+the\\s+strings\\s+below.*"); //$NON-NLS-1$ + + /** + * Pattern to match introduction line of context list. + */ + private final static Pattern ADD_CONTEXT_HELP_CONTEXTS_END_LINE = Pattern.compile("\\s*Example.*"); //$NON-NLS-1$ // ------------------------------------------------------------------------ // Attributes @@ -949,7 +974,91 @@ public class LTTngControlService implements ILttngControlService { throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$ } } - + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#getContexts(org.eclipse.core.runtime.IProgressMonitor) + */ + @Override + public List getContextList(IProgressMonitor monitor) throws ExecutionException { + + String command = COMMAND_ADD_CONTEXT + OPTION_HELP; + + ICommandResult result = fCommandShell.executeCommand(command, monitor); + + if (isError(result)) { + throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$ + } + + String[] output = result.getOutput(); + + List contexts = new ArrayList(0); + + int index = 0; + boolean inList = false; + while (index < output.length) { + String line = result.getOutput()[index]; + + Matcher startMatcher = ADD_CONTEXT_HELP_CONTEXTS_INTRO.matcher(line); + Matcher endMatcher = ADD_CONTEXT_HELP_CONTEXTS_END_LINE.matcher(line); + + if (startMatcher.matches()) { + inList = true; + } else if (endMatcher.matches()) { + break; + } else if (inList == true) { + String[] tmp = line.split(","); //$NON-NLS-1$ + for (int i = 0; i < tmp.length; i++) { + contexts.add(tmp[i].trim()); + } + } + index++; + } + return contexts; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#addContexts(java.lang.String, java.lang.String, java.lang.String, boolean, java.util.List, org.eclipse.core.runtime.IProgressMonitor) + */ + @Override + public void addContexts(String sessionName, String channelName, String eventName, boolean isKernel, List contextNames, IProgressMonitor monitor) throws ExecutionException { + + String newSessionName = formatParameter(sessionName); + StringBuffer command = new StringBuffer(COMMAND_ADD_CONTEXT); + + command.append(OPTION_SESSION); + command.append(newSessionName); + + if (channelName != null) { + command.append(OPTION_CHANNEL); + command.append(channelName); + } + + if (eventName != null) { + command.append(OPTION_EVENT); + command.append(eventName); + } + + if (isKernel) { + command.append(OPTION_KERNEL); + } else { + command.append(OPTION_UST); + } + + for (Iterator iterator = contextNames.iterator(); iterator.hasNext();) { + String context = (String) iterator.next(); + command.append(OPTION_CONTEXT_TYPE); + command.append(context); + } + + ICommandResult result = fCommandShell.executeCommand(command.toString(), monitor); + + if (isError(result)) { + throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$ + } + } + // ------------------------------------------------------------------------ // Helper methods // ------------------------------------------------------------------------ @@ -1238,5 +1347,4 @@ public class LTTngControlService implements ILttngControlService { } return null; } - } -- 2.34.1