From eb1bab5b3b7a59cfdd19c0d7a9600368ddfd7c4a Mon Sep 17 00:00:00 2001 From: Bernd Hufmann Date: Mon, 6 Feb 2012 13:01:28 -0500 Subject: [PATCH] First part of LTTng 2.0 support --- .../META-INF/MANIFEST.MF | 5 +- .../lttng/ui/tests/AllLTTngUITests.java | 3 + .../control/model/component/AllTests.java | 28 + .../model/component/ModelImplTestSetup.java | 43 ++ .../component/TraceControlComponentTest.java | 646 ++++++++++++++++++ .../component/TraceControlTestFacility.java | 127 ++++ .../component/TraceControlTreeModelTest.java | 596 ++++++++++++++++ .../ui/tests/control/model/impl/AllTests.java | 33 + .../control/model/impl/BaseEventInfoTest.java | 429 ++++++++++++ .../control/model/impl/ChannelInfoTest.java | 327 +++++++++ .../control/model/impl/DomainInfoTest.java | 203 ++++++ .../control/model/impl/EventInfoTest.java | 259 +++++++ .../control/model/impl/ListenerValidator.java | 94 +++ .../control/model/impl/ModelImplFactory.java | 171 +++++ .../control/model/impl/SessionInfoTest.java | 255 +++++++ .../control/model/impl/TraceInfoTest.java | 182 +++++ .../model/impl/UstProviderInfoTest.java | 229 +++++++ .../ui/tests/control/service/AllTests.java | 26 + .../service/LTTngControlServiceTest.java | 352 ++++++++++ .../stubs/service/CommandShellFactory.java | 47 ++ .../stubs/service/TestRemoteSystemProxy.java | 61 ++ .../shells/GetSessionGarbageShell.java | 20 + .../service/shells/LttngNotExistsShell.java | 17 + .../service/shells/NoSessionNamesShell.java | 17 + .../service/shells/NoUstProviderShell.java | 24 + .../service/shells/SessionNamesShell.java | 130 ++++ .../service/shells/SessionNotExistsShell.java | 20 + .../service/shells/TestCommandShell.java | 46 ++ .../META-INF/MANIFEST.MF | 7 + .../icons/elcl16/connect.gif | Bin 0 -> 189 bytes .../icons/elcl16/disconnect.gif | Bin 0 -> 151 bytes .../icons/elcl16/newconnection_wiz.gif | Bin 0 -> 202 bytes .../icons/elcl16/target_add.gif | Bin 0 -> 591 bytes .../icons/elcl16/target_delete.gif | Bin 0 -> 596 bytes .../icons/obj16/channel.gif | Bin 0 -> 200 bytes .../icons/obj16/channel_disabled.gif | Bin 0 -> 370 bytes .../icons/obj16/domain.gif | Bin 0 -> 616 bytes .../icons/obj16/event_disabled.gif | Bin 0 -> 130 bytes .../icons/obj16/event_enabled.gif | Bin 0 -> 183 bytes .../icons/obj16/node_obj.gif | Bin 0 -> 579 bytes .../icons/obj16/session_active.gif | Bin 0 -> 970 bytes .../icons/obj16/session_destroyed.gif | Bin 0 -> 697 bytes .../icons/obj16/session_inactive.gif | Bin 0 -> 1004 bytes .../icons/obj16/sessions.gif | Bin 0 -> 617 bytes .../icons/obj16/systemlttng2-live.gif | Bin 0 -> 882 bytes .../icons/obj16/systemlttng2.gif | Bin 0 -> 856 bytes .../icons/obj16/target_connected.gif | Bin 0 -> 374 bytes .../icons/obj16/target_disconnected.gif | Bin 0 -> 605 bytes .../plugin.properties | 26 +- org.eclipse.linuxtools.lttng.ui/plugin.xml | 183 +++++ .../linuxtools/lttng/ui/LTTngUiPlugin.java | 20 + .../lttng/ui/views/control/ControlView.java | 138 +++- .../lttng/ui/views/control/Messages.java | 72 ++ .../control/TraceControlContentProvider.java | 89 +++ .../control/TraceControlLabelProvider.java | 62 ++ .../control/dialogs/INewConnectionDialog.java | 42 ++ .../control/dialogs/NewConnectionDialog.java | 290 ++++++++ .../control/handlers/BaseNodeHandler.java | 133 ++++ .../control/handlers/ConnectHandler.java | 48 ++ .../views/control/handlers/DeleteHandler.java | 50 ++ .../control/handlers/DisconnectHandler.java | 48 ++ .../handlers/NewConnectionHandler.java | 202 ++++++ .../ui/views/control/messages.properties | 37 + .../views/control/model/IBaseEventInfo.java | 57 ++ .../ui/views/control/model/IChannelInfo.java | 113 +++ .../ui/views/control/model/IDomainInfo.java | 42 ++ .../ui/views/control/model/IEventInfo.java | 39 ++ .../ui/views/control/model/ISessionInfo.java | 67 ++ .../control/model/ITraceControlComponent.java | 188 +++++ ...ITraceControlComponentChangedListener.java | 41 ++ .../ui/views/control/model/ITraceInfo.java | 32 + .../views/control/model/IUstProviderInfo.java | 51 ++ .../views/control/model/TargetNodeState.java | 25 + .../views/control/model/TraceEnablement.java | 58 ++ .../views/control/model/TraceEventType.java | 34 + .../ui/views/control/model/TraceLogLevel.java | 75 ++ .../control/model/TraceSessionState.java | 58 ++ .../model/impl/BaseEventComponent.java | 117 ++++ .../control/model/impl/BaseEventInfo.java | 209 ++++++ .../views/control/model/impl/ChannelInfo.java | 381 +++++++++++ .../views/control/model/impl/DomainInfo.java | 160 +++++ .../views/control/model/impl/EventInfo.java | 138 ++++ .../model/impl/KernelProviderComponent.java | 75 ++ .../views/control/model/impl/SessionInfo.java | 232 +++++++ .../model/impl/TargetNodeComponent.java | 327 +++++++++ .../model/impl/TraceChannelComponent.java | 201 ++++++ .../model/impl/TraceControlComponent.java | 430 ++++++++++++ .../control/model/impl/TraceControlRoot.java | 41 ++ .../model/impl/TraceDomainComponent.java | 77 +++ .../model/impl/TraceEventComponent.java | 166 +++++ .../views/control/model/impl/TraceInfo.java | 120 ++++ .../model/impl/TraceProviderGroup.java | 95 +++ .../model/impl/TraceSessionComponent.java | 185 +++++ .../control/model/impl/TraceSessionGroup.java | 79 +++ .../model/impl/UstProviderComponent.java | 96 +++ .../control/model/impl/UstProviderInfo.java | 191 ++++++ .../property/TargetNodePropertySource.java | 131 ++++ .../control/remote/IRemoteSystemProxy.java | 103 +++ .../control/remote/RemoteSystemProxy.java | 184 +++++ .../views/control/service/CommandResult.java | 88 +++ .../views/control/service/CommandShell.java | 222 ++++++ .../views/control/service/ICommandResult.java | 43 ++ .../views/control/service/ICommandShell.java | 57 ++ .../control/service/ILttngControlService.java | 87 +++ .../control/service/LTTngControlService.java | 601 ++++++++++++++++ 105 files changed, 11538 insertions(+), 15 deletions(-) create mode 100644 org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/component/AllTests.java create mode 100644 org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/component/ModelImplTestSetup.java create mode 100644 org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/component/TraceControlComponentTest.java create mode 100644 org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/component/TraceControlTestFacility.java create mode 100644 org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/component/TraceControlTreeModelTest.java create mode 100644 org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/impl/AllTests.java create mode 100644 org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/impl/BaseEventInfoTest.java create mode 100644 org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/impl/ChannelInfoTest.java create mode 100644 org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/impl/DomainInfoTest.java create mode 100644 org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/impl/EventInfoTest.java create mode 100644 org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/impl/ListenerValidator.java create mode 100644 org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/impl/ModelImplFactory.java create mode 100644 org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/impl/SessionInfoTest.java create mode 100644 org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/impl/TraceInfoTest.java create mode 100644 org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/impl/UstProviderInfoTest.java create mode 100644 org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/service/AllTests.java create mode 100644 org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/service/LTTngControlServiceTest.java create mode 100644 org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/service/CommandShellFactory.java create mode 100644 org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/service/TestRemoteSystemProxy.java create mode 100644 org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/service/shells/GetSessionGarbageShell.java create mode 100644 org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/service/shells/LttngNotExistsShell.java create mode 100644 org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/service/shells/NoSessionNamesShell.java create mode 100644 org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/service/shells/NoUstProviderShell.java create mode 100644 org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/service/shells/SessionNamesShell.java create mode 100644 org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/service/shells/SessionNotExistsShell.java create mode 100644 org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/service/shells/TestCommandShell.java create mode 100644 org.eclipse.linuxtools.lttng.ui/icons/elcl16/connect.gif create mode 100644 org.eclipse.linuxtools.lttng.ui/icons/elcl16/disconnect.gif create mode 100644 org.eclipse.linuxtools.lttng.ui/icons/elcl16/newconnection_wiz.gif create mode 100644 org.eclipse.linuxtools.lttng.ui/icons/elcl16/target_add.gif create mode 100644 org.eclipse.linuxtools.lttng.ui/icons/elcl16/target_delete.gif create mode 100644 org.eclipse.linuxtools.lttng.ui/icons/obj16/channel.gif create mode 100644 org.eclipse.linuxtools.lttng.ui/icons/obj16/channel_disabled.gif create mode 100644 org.eclipse.linuxtools.lttng.ui/icons/obj16/domain.gif create mode 100644 org.eclipse.linuxtools.lttng.ui/icons/obj16/event_disabled.gif create mode 100644 org.eclipse.linuxtools.lttng.ui/icons/obj16/event_enabled.gif create mode 100755 org.eclipse.linuxtools.lttng.ui/icons/obj16/node_obj.gif create mode 100644 org.eclipse.linuxtools.lttng.ui/icons/obj16/session_active.gif create mode 100644 org.eclipse.linuxtools.lttng.ui/icons/obj16/session_destroyed.gif create mode 100644 org.eclipse.linuxtools.lttng.ui/icons/obj16/session_inactive.gif create mode 100644 org.eclipse.linuxtools.lttng.ui/icons/obj16/sessions.gif create mode 100755 org.eclipse.linuxtools.lttng.ui/icons/obj16/systemlttng2-live.gif create mode 100755 org.eclipse.linuxtools.lttng.ui/icons/obj16/systemlttng2.gif create mode 100644 org.eclipse.linuxtools.lttng.ui/icons/obj16/target_connected.gif create mode 100644 org.eclipse.linuxtools.lttng.ui/icons/obj16/target_disconnected.gif create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/Messages.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/TraceControlContentProvider.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/TraceControlLabelProvider.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/dialogs/INewConnectionDialog.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/dialogs/NewConnectionDialog.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/handlers/BaseNodeHandler.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/handlers/ConnectHandler.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/handlers/DeleteHandler.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/handlers/DisconnectHandler.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/handlers/NewConnectionHandler.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/messages.properties create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/IBaseEventInfo.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/IChannelInfo.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/IDomainInfo.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/IEventInfo.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/ISessionInfo.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/ITraceControlComponent.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/ITraceControlComponentChangedListener.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/ITraceInfo.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/IUstProviderInfo.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/TargetNodeState.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/TraceEnablement.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/TraceEventType.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/TraceLogLevel.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/TraceSessionState.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/BaseEventComponent.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/BaseEventInfo.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/ChannelInfo.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/DomainInfo.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/EventInfo.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/KernelProviderComponent.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/SessionInfo.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/TargetNodeComponent.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/TraceChannelComponent.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/TraceControlComponent.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/TraceControlRoot.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/TraceDomainComponent.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/TraceEventComponent.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/TraceInfo.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/TraceProviderGroup.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/TraceSessionComponent.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/TraceSessionGroup.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/UstProviderComponent.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/UstProviderInfo.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/property/TargetNodePropertySource.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/remote/IRemoteSystemProxy.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/remote/RemoteSystemProxy.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/service/CommandResult.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/service/CommandShell.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/service/ICommandResult.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/service/ICommandShell.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/service/ILttngControlService.java create mode 100644 org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/service/LTTngControlService.java diff --git a/org.eclipse.linuxtools.lttng.ui.tests/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.lttng.ui.tests/META-INF/MANIFEST.MF index 576cb63464..25984cc05b 100644 --- a/org.eclipse.linuxtools.lttng.ui.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.lttng.ui.tests/META-INF/MANIFEST.MF @@ -11,7 +11,10 @@ Require-Bundle: org.junit;bundle-version="3.8.2", org.eclipse.linuxtools.tmf.core;bundle-version="0.4.0", org.eclipse.ui;bundle-version="3.7.0", org.eclipse.core.resources;bundle-version="3.7.0", - org.eclipse.core.runtime;bundle-version="3.7.0" + org.eclipse.core.runtime;bundle-version="3.7.0", + org.eclipse.rse.core;bundle-version="3.2.0", + org.eclipse.rse.services;bundle-version="3.2.100", + org.eclipse.ui.views;bundle-version="3.6.0" Bundle-Localization: plugin Bundle-Activator: org.eclipse.linuxtools.lttng.ui.tests.LTTngUITestPlugin Bundle-ActivationPolicy: lazy diff --git a/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/AllLTTngUITests.java b/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/AllLTTngUITests.java index dcc3c10f25..9367895e1a 100644 --- a/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/AllLTTngUITests.java +++ b/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/AllLTTngUITests.java @@ -7,7 +7,10 @@ public class AllLTTngUITests { public static Test suite() { TestSuite suite = new TestSuite(AllLTTngUITests.class.getName()); //$JUnit-BEGIN$ + suite.addTest(org.eclipse.linuxtools.lttng.ui.tests.control.model.impl.AllTests.suite()); + suite.addTest(org.eclipse.linuxtools.lttng.ui.tests.control.service.AllTests.suite()); suite.addTest(org.eclipse.linuxtools.lttng.ui.tests.histogram.AllTests.suite()); + suite.addTest(org.eclipse.linuxtools.lttng.ui.tests.control.model.component.AllTests.suite()); //$JUnit-END$ return suite; } diff --git a/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/component/AllTests.java b/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/component/AllTests.java new file mode 100644 index 0000000000..af2b6a7193 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/component/AllTests.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2011 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.lttng.ui.tests.control.model.component; + +import junit.framework.Test; +import junit.framework.TestSuite; + +public class AllTests { + + public static Test suite() { + + TestSuite suite = new TestSuite(AllTests.class.getName()); + //$JUnit-BEGIN$ + suite.addTestSuite(TraceControlComponentTest.class); + suite.addTestSuite(TraceControlTreeModelTest.class); + //$JUnit-END$ + return new ModelImplTestSetup(suite); + } +} diff --git a/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/component/ModelImplTestSetup.java b/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/component/ModelImplTestSetup.java new file mode 100644 index 0000000000..cbd215e0f2 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/component/ModelImplTestSetup.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * 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.lttng.ui.tests.control.model.component; + +import junit.extensions.TestSetup; +import junit.framework.Test; + +/** + * Test setup class for one-time setUp() and tearDown() across test cases. + */ +public class ModelImplTestSetup extends TestSetup { + + public ModelImplTestSetup(Test test) { + super(test); + } + + /* + * (non-Javadoc) + * @see junit.extensions.TestSetup#setUp() + */ + @Override + protected void setUp() throws Exception { + TraceControlTestFacility.getInstance().init(); + } + + /* + * (non-Javadoc) + * @see junit.extensions.TestSetup#tearDown() + */ + @Override + protected void tearDown() throws Exception { + TraceControlTestFacility.getInstance().dispose(); + } +} diff --git a/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/component/TraceControlComponentTest.java b/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/component/TraceControlComponentTest.java new file mode 100644 index 0000000000..7b2fb70a3b --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/component/TraceControlComponentTest.java @@ -0,0 +1,646 @@ +/********************************************************************** + * 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.lttng.ui.tests.control.model.component; + +import java.util.LinkedList; +import java.util.List; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.eclipse.linuxtools.lttng.stubs.service.TestRemoteSystemProxy; +import org.eclipse.linuxtools.lttng.ui.tests.control.model.impl.ListenerValidator; +import org.eclipse.linuxtools.lttng.ui.views.control.ControlView; +import org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent; +import org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponentChangedListener; +import org.eclipse.linuxtools.lttng.ui.views.control.model.TargetNodeState; +import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent; +import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlRoot; +import org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService; +import org.eclipse.linuxtools.lttng.ui.views.control.service.LTTngControlService; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.PlatformUI; +import org.junit.After; +import org.junit.Before; + +/** + * The class TraceControlComponentTest contains tests for the class {@link TraceControlComponent}. + * + */ +@SuppressWarnings("nls") +public class TraceControlComponentTest extends TestCase { + + // ------------------------------------------------------------------------ + // Test data + // ------------------------------------------------------------------------ + + // ------------------------------------------------------------------------ + // Static methods + // ------------------------------------------------------------------------ + + /** + * Returns test setup used when executing test case stand-alone. + * @return Test setup class + */ + public static Test suite() { + return new ModelImplTestSetup(new TestSuite(TraceControlComponentTest.class)); + } + + // ------------------------------------------------------------------------ + // Housekeeping + // ------------------------------------------------------------------------ + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + */ + @Override + @Before + public void setUp() throws Exception { + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + */ + @Override + @After + public void tearDown() throws Exception { + } + + /** + * Run the TraceControlComponent(String) constructor test. + */ + public void testTraceControlComponent_1() + throws Exception { + + String name = "node"; + + TraceControlComponent result = new TraceControlComponent(name); + + assertNotNull(result); + assertEquals(name, result.getName()); + assertEquals(null, result.getParent()); + assertEquals(false, result.hasChildren()); + assertEquals(null, result.getImage()); + assertEquals(null, result.getControlService()); + assertEquals(null, result.getToolTip()); + } + + /** + * Run the TraceControlComponent(String,ITraceControlComponent) constructor test. + * + */ + public void testTraceControlComponent_2() + throws Exception { + String name = "node"; + + ITraceControlComponent parent = new TraceControlRoot(); + TraceControlComponent result = new TraceControlComponent(name, parent); + + assertNotNull(result); + assertEquals(name, result.getName()); + assertEquals(false, result.hasChildren()); + assertEquals(null, result.getImage()); + assertEquals(null, result.getControlService()); + assertEquals(null, result.getToolTip()); + } + + /** + * Run the void addChild(ITraceControlComponent) method test. + * + * @throws Exception + * + */ + public void testAddAndGetChild1() + throws Exception { + TraceControlComponent fixture = new TraceControlComponent("node", new TraceControlRoot()); + fixture.setToolTip("This is the test node"); + fixture.addChild(new TraceControlRoot()); + ITraceControlComponent component = new TraceControlRoot(); + fixture.addChild(component); + + ITraceControlComponent child = fixture.getChild(TraceControlRoot.TRACE_CONTROL_ROOT_NAME); + assertNotNull(child); + assertEquals(TraceControlRoot.TRACE_CONTROL_ROOT_NAME, child.getName()); + } + + /** + * Run the void addChild(ITraceControlComponent) method test. + * + * @throws Exception + * + */ + public void testAddAndGetChild2() + throws Exception { + TraceControlComponent fixture = new TraceControlComponent("", new TraceControlRoot()); + fixture.setToolTip(""); + ITraceControlComponent component = null; + + fixture.addChild(component); + assertFalse(fixture.hasChildren()); + } + + /** + * Run the void addComponentListener(ITraceControlComponentChangedListener) method test. + * + * @throws Exception + * + */ + + public void testAddComponentListener_1() + throws Exception { + TraceControlComponent fixture = new TraceControlComponent("", (ITraceControlComponent) null); + fixture.setToolTip(""); + + ListenerValidator validator = new ListenerValidator(); + fixture.addComponentListener(validator); + + TraceControlRoot root = new TraceControlRoot(); + fixture.addChild(root); + assertTrue(validator.isAddedCalled()); + + fixture.removeChild(root); + assertTrue(validator.isRemovedCalled()); + + fixture.fireCompenentChanged(fixture); + assertTrue(validator.isChangedCalled()); + } + + /** + * Run the boolean containsChild(String) method test. + * + * @throws Exception + * + */ + public void testContainsChild_1() + throws Exception { + TraceControlComponent fixture = new TraceControlComponent("", new TraceControlRoot()); + fixture.setToolTip(""); + fixture.addChild(new TraceControlRoot()); + String name = "node"; + + boolean result = fixture.containsChild(name); + + assertEquals(false, result); + } + + /** + * Run the boolean containsChild(String) method test. + * + * @throws Exception + * + */ + public void testContainsChild_2() + throws Exception { + TraceControlComponent fixture = new TraceControlComponent("name", new TraceControlRoot()); + fixture.setToolTip(""); + + boolean result = fixture.containsChild(TraceControlRoot.TRACE_CONTROL_ROOT_NAME); + + assertEquals(false, result); + } + + /** + * Run the void fireCompenentAdded(ITraceControlComponent,ITraceControlComponent) method test. + * Run the void fireCompenentRemoved(ITraceControlComponent,ITraceControlComponent) method test. + * Run the void fireCompenentChanged(ITraceControlComponent) method test + * + * @throws Exception + * + */ + + public void testFireCompenentUpdated() + throws Exception { + ITraceControlComponent parent = new TraceControlRoot(); + + TraceControlComponent fixture = new TraceControlComponent("node", parent); + fixture.setToolTip(""); + + ITraceControlComponent component = new TraceControlComponent("child"); + fixture.addChild(component); + + ListenerValidator validator = new ListenerValidator(); + fixture.addComponentListener(validator); + + fixture.fireCompenentAdded(parent, component); + assertTrue(validator.isAddedCalled()); + assertEquals(parent.getName(), validator.getSavedParent().getName()); + assertEquals(component.getName(), validator.getSavedChild().getName()); + + validator.initialize(); + + fixture.fireCompenentRemoved(parent, component); + assertTrue(validator.isRemovedCalled()); + assertEquals(parent.getName(), validator.getSavedParent().getName()); + assertEquals(component.getName(), validator.getSavedChild().getName()); + + validator.initialize(); + fixture.fireCompenentChanged(fixture); + assertTrue(validator.isChangedCalled()); + assertEquals(fixture.getName(), validator.getSavedComponent().getName()); + } + + /** + * Run the Object getAdapter(Class) method test. + * + * @throws Exception + * + */ + + public void testGetAdapter() + throws Exception { + TraceControlComponent fixture = new TraceControlComponent("", new TraceControlRoot()); + fixture.setToolTip(""); + fixture.addChild(new TraceControlRoot()); + Class adapter = Object.class; + + Object result = fixture.getAdapter(adapter); + + assertEquals(null, result); + } + + /** + * Run the ITraceControlComponent[] getChildren() method test. + * + * @throws Exception + * + */ + public void testGetChildren_1() + throws Exception { + TraceControlComponent fixture = new TraceControlComponent("", new TraceControlRoot()); + fixture.setToolTip(""); + fixture.addChild(new TraceControlRoot()); + + ITraceControlComponent[] result = fixture.getChildren(); + + assertNotNull(result); + assertEquals(1, result.length); + assertNotNull(result[0]); + assertEquals("trace_control_root", result[0].getName()); + assertEquals(null, result[0].getParent()); + assertEquals(false, result[0].hasChildren()); + assertEquals(null, result[0].getImage()); + assertEquals(null, result[0].getControlService()); + assertEquals(null, result[0].getToolTip()); + } + + /** + * Run the ILttngControlService getControlService()/setControlService() method test. + * + * @throws Exception + * + */ + public void testGetAndSetControlService_1() + throws Exception { + + TraceControlComponent parent = new TraceControlComponent("parent") { + ILttngControlService fService = null; + + @Override + public void setControlService(ILttngControlService service ) { + fService = service; + } + + @Override + public ILttngControlService getControlService() { + return fService; + } + }; + + TraceControlComponent fixture = new TraceControlComponent("", parent); + parent.addChild(fixture); + fixture.setToolTip(""); + TraceControlComponent child = new TraceControlComponent("child", fixture); + fixture.addChild(child); + + ILttngControlService result = fixture.getControlService(); + assertEquals(null, result); + + TestRemoteSystemProxy proxy = new TestRemoteSystemProxy(); + ILttngControlService service = new LTTngControlService(proxy.createCommandShell()); + fixture.setControlService(service); + result = fixture.getControlService(); + assertNotNull(service); + assertEquals(service, result); + + result = fixture.getChildren()[0].getControlService(); + assertNotNull(service); + assertEquals(service, result); + } + + /** + * Run the Image getImage() method test. + * + * @throws Exception + * + */ + public void testGetImage_1() + throws Exception { + TraceControlComponent fixture = new TraceControlComponent("", new TraceControlRoot()); + fixture.setToolTip(""); + fixture.addChild(new TraceControlRoot()); + + Image result = fixture.getImage(); + assertEquals(null, result); + + fixture.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER)); + assertNotNull(fixture.getImage()); + } + + /** + * Run the boolean hasChildren() method test. + * + * @throws Exception + * + */ + public void testHasChildren_1() + throws Exception { + TraceControlComponent fixture = new TraceControlComponent("", new TraceControlRoot()); + fixture.setToolTip(""); + fixture.addChild(new TraceControlRoot()); + + boolean result = fixture.hasChildren(); + + assertTrue(result); + } + + /** + * Run the boolean hasChildren() method test. + * + * @throws Exception + * + */ + public void testHasChildren_2() + throws Exception { + TraceControlComponent fixture = new TraceControlComponent("", new TraceControlRoot()); + fixture.setToolTip(""); + + boolean result = fixture.hasChildren(); + + assertFalse(result); + } + + /** + * Run the void removeAllChildren() method test. + * + * @throws Exception + * + */ + public void testRemoveAllChildren_2() + throws Exception { + TraceControlComponent fixture = new TraceControlComponent("", new TraceControlRoot()); + fixture.setToolTip(""); + + fixture.addChild(new TraceControlRoot()); + fixture.addChild(new TraceControlComponent("child")); + + fixture.removeAllChildren(); + assertFalse(fixture.hasChildren()); + } + + /** + * Run the void removeChild(ITraceControlComponent) method test. + * + * @throws Exception + * + */ + public void testRemoveChild_1() + throws Exception { + TraceControlComponent fixture = new TraceControlComponent("", new TraceControlRoot()); + fixture.setToolTip(""); + TraceControlComponent child = new TraceControlComponent("child", fixture); + + fixture.addChild(child); + fixture.removeChild(child); + assertFalse(fixture.hasChildren()); + } + + /** + * Run the void removeChild(ITraceControlComponent) method test. + * + * @throws Exception + * + */ + + public void testRemoveChild_2() + throws Exception { + TraceControlComponent fixture = new TraceControlComponent("", new TraceControlRoot()); + fixture.setToolTip(""); + fixture.addChild(new TraceControlRoot()); + ITraceControlComponent component = null; + + fixture.removeChild(component); + assertTrue(fixture.hasChildren()); + } + + /** + * Run the void removeComponentListener(ITraceControlComponentChangedListener) method test. + * + * @throws Exception + * + */ + public void testRemoveComponentListener_1() + throws Exception { + TraceControlComponent fixture = new TraceControlComponent("", (ITraceControlComponent) null); + fixture.setToolTip(""); + + ListenerValidator validator = new ListenerValidator(); + fixture.addComponentListener(validator); + + // Remove listener and check that validator is not called anymore + validator.initialize(); + fixture.removeComponentListener(validator); + TraceControlRoot root = new TraceControlRoot(); + fixture.addChild(root); + assertFalse(validator.isAddedCalled()); + + fixture.removeChild(root); + assertFalse(validator.isRemovedCalled()); + + fixture.fireCompenentChanged(fixture); + assertFalse(validator.isChangedCalled()); + } + + /** + * Run the void removeComponentListener(ITraceControlComponentChangedListener) method test. + * + * @throws Exception + * + */ + public void testRemoveComponentListener_2() + throws Exception { + TraceControlComponent fixture = new TraceControlComponent("", new TraceControlRoot()); + fixture.setToolTip(""); + fixture.addChild(new TraceControlRoot()); + ITraceControlComponentChangedListener listener = new ControlView(); + + fixture.removeComponentListener(listener); + + } + + /** + * Run the void setChildren(List)/ITraceControlComponent[] getChildren() method test. + * + * + * @throws Exception + * + */ + public void testGetAndSetChildren() + throws Exception { + TraceControlComponent fixture = new TraceControlComponent("", new TraceControlRoot()); + fixture.setToolTip(""); + List children = new LinkedList(); + children.add(new TraceControlComponent("child1")); + children.add(new TraceControlComponent("child2")); + + fixture.setChildren(children); + + ITraceControlComponent[] result = fixture.getChildren(); + assertEquals(2, result.length); + assertEquals("child1", result[0].getName()); + assertEquals("child2", result[1].getName()); + } + + /** + * Run the void String getName()/setName(String) method tests. + * + * @throws Exception + * + */ + public void testGetAndSetName() + throws Exception { + TraceControlComponent fixture = new TraceControlComponent("", new TraceControlRoot()); + fixture.setToolTip(""); + fixture.addChild(new TraceControlRoot()); + String name = "node"; + + fixture.setName(name); + assertEquals(name,fixture.getName()); + + } + + /** + * Run the void ITraceControlComponent getParent()/setParent(ITraceControlComponent) method tests. + * + * @throws Exception + * + */ + public void testGetAndSetParent() + throws Exception { + TraceControlComponent fixture = new TraceControlComponent("", new TraceControlRoot()); + fixture.setToolTip(""); + fixture.addChild(new TraceControlRoot()); + ITraceControlComponent parent = new TraceControlRoot(); + parent.addChild(fixture); + + fixture.setParent(parent); + ITraceControlComponent retrievedParent = fixture.getParent(); + assertNotNull(retrievedParent); + assertEquals(parent.getName(), retrievedParent.getName()); + assertEquals(TraceControlRoot.TRACE_CONTROL_ROOT_NAME, retrievedParent.getName()); + assertEquals(null, retrievedParent.getParent()); + assertEquals(true, retrievedParent.hasChildren()); + } + + /** + * Run the void TargetNodeState getTargetNodeState()/etTargetNodeState(TargetNodeState) method tests. + * + * @throws Exception + * + */ + public void testGetAndSetTargetNodeState_1() + throws Exception { + + TraceControlComponent parent = new TraceControlComponent("parent") { + private TargetNodeState fState; + + @Override + public void setTargetNodeState(TargetNodeState state ) { + fState = state; + } + + @Override + public TargetNodeState getTargetNodeState() { + return fState; + } + }; + + TraceControlComponent fixture = new TraceControlComponent("", parent); + parent.addChild(fixture); + + fixture.setToolTip(""); + TargetNodeState state = TargetNodeState.CONNECTED; + + fixture.setTargetNodeState(state); + TargetNodeState result = fixture.getTargetNodeState(); + + assertNotNull(result); + assertEquals(state, result); + // Check also parent + assertEquals(state, fixture.getParent().getTargetNodeState()); + assertEquals("CONNECTED", result.name()); + assertEquals("CONNECTED", result.toString()); + assertEquals(2, result.ordinal()); + + fixture.setTargetNodeState(TargetNodeState.DISCONNECTED); + result = fixture.getTargetNodeState(); + assertNotNull(result); + assertEquals("DISCONNECTED", result.name()); + assertEquals("DISCONNECTED", result.toString()); + assertEquals(0, result.ordinal()); + + state = TargetNodeState.CONNECTING; + + fixture.setTargetNodeState(state); + result = fixture.getTargetNodeState(); + assertNotNull(result); + assertEquals("CONNECTING", result.name()); + assertEquals("CONNECTING", result.toString()); + assertEquals(3, result.ordinal()); + + fixture.setTargetNodeState(TargetNodeState.DISCONNECTING); + result = fixture.getTargetNodeState(); + assertNotNull(result); + assertEquals("DISCONNECTING", result.name()); + assertEquals("DISCONNECTING", result.toString()); + assertEquals(1, result.ordinal()); + + } + + /** + * Run the void setToolTip(String) method test. + * + * @throws Exception + * + + */ + + public void testGetSndSetToolTip() + throws Exception { + TraceControlComponent fixture = new TraceControlComponent("", new TraceControlRoot()); + fixture.setToolTip("This is a tooltip"); + fixture.addChild(new TraceControlRoot()); + + String result = fixture.getToolTip(); + + assertEquals("This is a tooltip", result); + } +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/component/TraceControlTestFacility.java b/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/component/TraceControlTestFacility.java new file mode 100644 index 0000000000..9dc19ae41e --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/component/TraceControlTestFacility.java @@ -0,0 +1,127 @@ +/******************************************************************************* + * Copyright (c) 2011 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.lttng.ui.tests.control.model.component; + +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.linuxtools.lttng.ui.views.control.ControlView; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; + +/** + * Singleton class to facilitate the test cases. Creates UML2SD view and loader objects as well as provides + * utility methods for interacting with the loader/view. + */ +public class TraceControlTestFacility { + + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + + final static public int WAIT_FOR_JOBS_DELAY = 1000; + final static public int GUI_REFESH_DELAY = 500; + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + private static TraceControlTestFacility fInstance = null; + private ControlView fControlView = null; + private boolean fIsInitialized = false; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + private TraceControlTestFacility() { + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + public static TraceControlTestFacility getInstance() { + if (fInstance == null) { + fInstance = new TraceControlTestFacility(); + } + return fInstance; + } + + /** + * Initial the test facility. + */ + public void init() { + + if (!fIsInitialized) { + + IViewPart view; + try { + view = PlatformUI.getWorkbench() + .getActiveWorkbenchWindow() + .getActivePage() + .showView(ControlView.ID); + + } catch (PartInitException e) { + throw new RuntimeException(e); + } + + fControlView = (ControlView) view; + + delay(3000); + fIsInitialized = true; + } + } + + + public void dispose() { + if (fIsInitialized) { + waitForJobs(); + + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().hideView(fControlView); + fIsInitialized = false; + } + } + + public void delay(long waitTimeMillis) { + Display display = Display.getCurrent(); + if (display != null) { + long endTimeMillis = System.currentTimeMillis() + waitTimeMillis; + while(System.currentTimeMillis() < endTimeMillis) { + if (!display.readAndDispatch()) { + display.sleep(); + } + display.update(); + } + } else { + try { + Thread.sleep(waitTimeMillis); + } catch (InterruptedException e) { + // Ignored + } + } + } + + /** + * Waits for all Eclipse jobs to finish + */ + public void waitForJobs() { + while (!Job.getJobManager().isIdle()) { + delay(WAIT_FOR_JOBS_DELAY); + } + } + + + /** + * @return current control view + */ + public ControlView getControlView() { + return fControlView; + } +} diff --git a/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/component/TraceControlTreeModelTest.java b/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/component/TraceControlTreeModelTest.java new file mode 100644 index 0000000000..ee19a1346a --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/component/TraceControlTreeModelTest.java @@ -0,0 +1,596 @@ +/********************************************************************** + * 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.lttng.ui.tests.control.model.component; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.eclipse.linuxtools.lttng.stubs.service.TestRemoteSystemProxy; +import org.eclipse.linuxtools.lttng.ui.views.control.model.IChannelInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent; +import org.eclipse.linuxtools.lttng.ui.views.control.model.TargetNodeState; +import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceEnablement; +import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceEventType; +import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceLogLevel; +import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceSessionState; +import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.BaseEventComponent; +import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.KernelProviderComponent; +import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TargetNodeComponent; +import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceChannelComponent; +import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent; +import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceEventComponent; +import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceProviderGroup; +import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceSessionComponent; +import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceSessionGroup; +import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.UstProviderComponent; +import org.eclipse.linuxtools.lttng.ui.views.control.property.TargetNodePropertySource; +import org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService; +import org.eclipse.linuxtools.lttng.ui.views.control.service.LTTngControlService; +import org.eclipse.rse.core.model.Host; +import org.eclipse.rse.core.model.IHost; +import org.eclipse.rse.internal.core.model.SystemProfile; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.views.properties.IPropertySource; +import org.junit.After; +import org.junit.Before; + +/** + * The class TraceControlComponentTest contains tests for the class {@link TraceControlComponent}. + * + */ +@SuppressWarnings("nls") +public class TraceControlTreeModelTest extends TestCase { + + // ------------------------------------------------------------------------ + // Test data + // ------------------------------------------------------------------------ + + // ------------------------------------------------------------------------ + // Static methods + // ------------------------------------------------------------------------ + + /** + * Returns test setup used when executing test case stand-alone. + * @return Test setup class + */ + public static Test suite() { + return new ModelImplTestSetup(new TestSuite(TraceControlTreeModelTest.class)); + } + + // ------------------------------------------------------------------------ + // Housekeeping + // ------------------------------------------------------------------------ + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + */ + @Override + @Before + public void setUp() throws Exception { + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + */ + @Override + @After + public void tearDown() throws Exception { + } + + /** + * Run the TraceControlComponent. + */ + public void testTraceControlComponents() + throws Exception { + + TestRemoteSystemProxy proxy = new TestRemoteSystemProxy(); + + ITraceControlComponent root = TraceControlTestFacility.getInstance().getControlView().getTraceControlRoot(); + + @SuppressWarnings("restriction") + IHost host = new Host(new SystemProfile("myProfile", true)); + host.setHostName("127.0.0.1"); + + TargetNodeComponent node = new TargetNodeComponent("myNode", root, host, proxy); + + root.addChild(node); + node.connect(); + + TraceControlTestFacility.getInstance().waitForJobs(); + + // ------------------------------------------------------------------------ + // Verify Node Properties (adapter) + // ------------------------------------------------------------------------ + Object adapter = node.getAdapter(IPropertySource.class); + assertNotNull(adapter); + assertTrue(adapter instanceof TargetNodePropertySource); + + TargetNodePropertySource source = (TargetNodePropertySource)adapter; + + assertNull(source.getEditableValue()); + assertFalse(source.isPropertySet(TargetNodePropertySource.TARGET_NODE_NAME_PROPERTY_ID)); + assertNotNull(source.getPropertyDescriptors()); + + assertEquals("myNode", source.getPropertyValue(TargetNodePropertySource.TARGET_NODE_NAME_PROPERTY_ID)); + assertEquals("127.0.0.1", source.getPropertyValue(TargetNodePropertySource.TARGET_NODE_ADDRESS_PROPERTY_ID)); + assertNull(source.getPropertyValue("test")); + + adapter = node.getAdapter(IChannelInfo.class); + assertNull(adapter); + + // ------------------------------------------------------------------------ + // Verify Parameters of TargetNodeComponent + // ------------------------------------------------------------------------ + assertEquals("127.0.0.1", node.getHostName()); + assertEquals("127.0.0.1", node.getToolTip()); + Image connectedImage = node.getImage(); + assertNotNull(connectedImage); + assertEquals(TargetNodeState.CONNECTED, node.getTargetNodeState()); + assertNotNull(node.getControlService()); + ILttngControlService service = node.getControlService(); + assertTrue(service instanceof LTTngControlService); + node.setControlService(service); + assertTrue(node.getControlService() instanceof LTTngControlService); + + assertTrue(node.isPassiveCommunicationsListener()); + + // ------------------------------------------------------------------------ + // Verify Children of TargetNodeComponent + // ------------------------------------------------------------------------ + ITraceControlComponent[] groups = node.getChildren(); + assertNotNull(groups); + assertEquals(2, groups.length); + + assertTrue(groups[0] instanceof TraceProviderGroup); + assertTrue(groups[1] instanceof TraceSessionGroup); + + assertEquals("Provider", groups[0].getName()); + assertEquals("Sessions", groups[1].getName()); + + // ------------------------------------------------------------------------ + // Verify TraceProviderGroup + // ------------------------------------------------------------------------ + ITraceControlComponent[] providers = groups[0].getChildren(); + + assertNotNull(providers); + assertEquals(3, providers.length); + + // ------------------------------------------------------------------------ + // Verify UstProviderComponent + // ------------------------------------------------------------------------ + KernelProviderComponent kernelProvider = (KernelProviderComponent) providers[0]; + + // ------------------------------------------------------------------------ + // Verify event info (kernel provider) + // ------------------------------------------------------------------------ + ITraceControlComponent[] events = kernelProvider.getChildren(); + assertNotNull(events); + assertEquals(3, events.length); + + BaseEventComponent baseEventInfo = (BaseEventComponent) events[0]; + assertNotNull(baseEventInfo); + assertEquals("sched_kthread_stop", baseEventInfo.getName()); + assertEquals(TraceLogLevel.TRACE_EMERG, baseEventInfo.getLogLevel()); + assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType()); + + baseEventInfo = (BaseEventComponent) events[1]; + assertEquals("sched_kthread_stop_ret", baseEventInfo.getName()); + assertEquals(TraceLogLevel.TRACE_EMERG, baseEventInfo.getLogLevel()); + assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType()); + + baseEventInfo = (BaseEventComponent) events[2]; + assertEquals("sched_wakeup_new", baseEventInfo.getName()); + assertEquals(TraceLogLevel.TRACE_EMERG, baseEventInfo.getLogLevel()); + assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType()); + + // ------------------------------------------------------------------------ + // Verify UstProviderComponent + // ------------------------------------------------------------------------ + UstProviderComponent ustProvider = (UstProviderComponent) providers[1]; + assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello", ustProvider.getName()); + assertEquals(9379, ustProvider.getPid()); + + // ------------------------------------------------------------------------ + // Verify event info (UST provider) + // ------------------------------------------------------------------------ + events = ustProvider.getChildren(); + assertNotNull(events); + assertEquals(2, events.length); + + baseEventInfo = (BaseEventComponent) events[0]; + assertNotNull(baseEventInfo); + assertEquals("ust_tests_hello:tptest_sighandler", baseEventInfo.getName()); + assertEquals(TraceLogLevel.TRACE_MODULE, baseEventInfo.getLogLevel()); + assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType()); + + baseEventInfo = (BaseEventComponent) events[1]; + assertEquals("ust_tests_hello:tptest", baseEventInfo.getName()); + assertEquals(TraceLogLevel.TRACE_INFO, baseEventInfo.getLogLevel()); + assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType()); + + // ------------------------------------------------------------------------ + // Verify UstProviderComponent + // ------------------------------------------------------------------------ + ustProvider = (UstProviderComponent) providers[2]; + assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello", ustProvider.getName()); + assertEquals(4852, ustProvider.getPid()); + + // verify getters and setter + verifyUstProviderGettersSetters(ustProvider); + + // ------------------------------------------------------------------------ + // Verify event info (UST provider) + // ------------------------------------------------------------------------ + events = ustProvider.getChildren(); + assertNotNull(events); + assertEquals(2, events.length); + + baseEventInfo = (BaseEventComponent) events[0]; + assertNotNull(baseEventInfo); + assertEquals("ust_tests_hello:tptest_sighandler", baseEventInfo.getName()); + assertEquals(TraceLogLevel.TRACE_WARNING, baseEventInfo.getLogLevel()); + assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType()); + + baseEventInfo = (BaseEventComponent) events[1]; + assertEquals("ust_tests_hello:tptest", baseEventInfo.getName()); + assertEquals(TraceLogLevel.TRACE_FUNCTION, baseEventInfo.getLogLevel()); + assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType()); + + // verify getters and setters + verifyBaseEventGettersSetters(baseEventInfo); + + // ------------------------------------------------------------------------ + // Verify TraceSessionGroup + // ------------------------------------------------------------------------ + ITraceControlComponent[] sessions = groups[1].getChildren(); + assertNotNull(sessions); + assertEquals(2, sessions.length); + for (int i = 0; i < sessions.length; i++) { + assertTrue(sessions[i] instanceof TraceSessionComponent); + } + assertEquals("mysession1", sessions[0].getName()); + assertEquals("mysession", sessions[1].getName()); + + // ------------------------------------------------------------------------ + // Verify TraceSessionComponent + // ------------------------------------------------------------------------ + TraceSessionComponent session = (TraceSessionComponent)sessions[1]; + assertEquals("mysession", session.getName()); + assertEquals("/home/user/lttng-traces/mysession-20120129-084256", session.getSessionPath()); + assertEquals(TraceSessionState.ACTIVE, session.getSessionState()); + + // Verify setters and setters + verifySessionGetterSetters(session); + + ITraceControlComponent[] domains = session.getChildren(); + assertNotNull(domains); + assertEquals(2, domains.length); + + // ------------------------------------------------------------------------ + // Verify Kernel domain + // ------------------------------------------------------------------------ + assertEquals("Kernel", domains[0].getName()); + ITraceControlComponent[] channels = domains[0].getChildren(); + assertNotNull(channels); + assertEquals(2, channels.length); + + // ------------------------------------------------------------------------ + // Verify Kernel's channel0 + // ------------------------------------------------------------------------ + assertTrue(channels[0] instanceof TraceChannelComponent); + TraceChannelComponent channel = (TraceChannelComponent) channels[0]; + assertEquals("channel0", channel.getName()); + assertEquals(4, channel.getNumberOfSubBuffers()); + assertEquals("splice()", channel.getOutputType()); + assertEquals(false, channel.isOverwriteMode()); + assertEquals(200, channel.getReadTimer()); + assertEquals(TraceEnablement.ENABLED, channel.getState()); + assertEquals(262144, channel.getSubBufferSize()); + assertEquals(0, channel.getSwitchTimer()); + + // ------------------------------------------------------------------------ + // Verify event info (kernel, channel0) + // ------------------------------------------------------------------------ + ITraceControlComponent[] channel0Events = channel.getChildren(); + assertNotNull(channel0Events); + assertEquals(2, channel0Events.length); + assertTrue(channel0Events[0] instanceof TraceEventComponent); + assertTrue(channel0Events[1] instanceof TraceEventComponent); + + TraceEventComponent event = (TraceEventComponent) channel0Events[0]; + assertEquals("block_rq_remap", event.getName()); + assertEquals(TraceLogLevel.TRACE_EMERG, event.getLogLevel()); + assertEquals(TraceEventType.TRACEPOINT, event.getEventType()); + assertEquals(TraceEnablement.ENABLED, event.getState()); + + event = (TraceEventComponent) channel0Events[1]; + assertEquals("block_bio_remap", event.getName()); + assertEquals(TraceLogLevel.TRACE_EMERG, event.getLogLevel()); + assertEquals(TraceEventType.TRACEPOINT, event.getEventType()); + assertEquals(TraceEnablement.DISABLED, event.getState()); + + // ------------------------------------------------------------------------ + // Verify Kernel's channel1 + // ------------------------------------------------------------------------ + assertEquals("channel1", channels[1].getName()); + channel = (TraceChannelComponent) channels[1]; + assertEquals(4, channel.getNumberOfSubBuffers()); + assertEquals("splice()", channel.getOutputType()); + assertEquals(true, channel.isOverwriteMode()); + assertEquals(400, channel.getReadTimer()); + assertEquals(TraceEnablement.DISABLED, channel.getState()); + assertEquals(524288, channel.getSubBufferSize()); + assertEquals(100, channel.getSwitchTimer()); + + // ------------------------------------------------------------------------ + // Verify event info (kernel, channel1) + // ------------------------------------------------------------------------ + ITraceControlComponent[] channel1Events = channels[1].getChildren(); + assertEquals(0, channel1Events.length); + + // ------------------------------------------------------------------------ + // Verify domain UST global + // ------------------------------------------------------------------------ + assertEquals("UST global", domains[1].getName()); + + ITraceControlComponent[] ustChannels = domains[1].getChildren(); + + for (int i = 0; i < ustChannels.length; i++) { + assertTrue(ustChannels[i] instanceof TraceChannelComponent); + } + + // ------------------------------------------------------------------------ + // Verify UST global's mychannel1 + // ------------------------------------------------------------------------ + channel = (TraceChannelComponent) ustChannels[0]; + assertEquals("mychannel1", channel.getName()); + assertEquals(8, channel.getNumberOfSubBuffers()); + assertEquals("mmap()", channel.getOutputType()); + assertEquals(true, channel.isOverwriteMode()); + assertEquals(100, channel.getReadTimer()); + assertEquals(TraceEnablement.DISABLED, channel.getState()); + assertEquals(8192, channel.getSubBufferSize()); + assertEquals(200, channel.getSwitchTimer()); + + // verify getters and setters + verifyChannelGettersSetters(channel); + + // ------------------------------------------------------------------------ + // Verify event info (UST global, mychannel1) + // ------------------------------------------------------------------------ + ITraceControlComponent[] ustEvents = channel.getChildren(); + assertEquals(0, ustEvents.length); + + // ------------------------------------------------------------------------ + // Verify UST global's channel0 + // ------------------------------------------------------------------------ + channel = (TraceChannelComponent) ustChannels[1]; + assertEquals("channel0", channel.getName()); + assertEquals(4, channel.getNumberOfSubBuffers()); + assertEquals("mmap()", channel.getOutputType()); + assertEquals(false, channel.isOverwriteMode()); + assertEquals(200, channel.getReadTimer()); + assertEquals(TraceEnablement.ENABLED, channel.getState()); + assertEquals(4096, channel.getSubBufferSize()); + assertEquals(0, channel.getSwitchTimer()); + + // ------------------------------------------------------------------------ + // Verify event info (UST global, channel0) + // ------------------------------------------------------------------------ + ustEvents = channel.getChildren(); + assertEquals(2, ustEvents.length); + + event = (TraceEventComponent) ustEvents[0]; + assertEquals("ust_tests_hello:tptest_sighandler", event.getName()); + assertEquals(TraceLogLevel.TRACE_DEFAULT, event.getLogLevel()); + assertEquals(TraceEventType.TRACEPOINT, event.getEventType()); + assertEquals(TraceEnablement.DISABLED, event.getState()); + + event = (TraceEventComponent) ustEvents[1]; + assertEquals("*", ustEvents[1].getName()); + assertEquals(TraceLogLevel.TRACE_EMERG, event.getLogLevel()); + assertEquals(TraceEventType.TRACEPOINT, event.getEventType()); + assertEquals(TraceEnablement.ENABLED, event.getState()); + + // verify getters and setters + verifyEventGettersSetters(event); + + // disconnect + node.disconnect(); + assertEquals(TargetNodeState.DISCONNECTED, node.getTargetNodeState()); + assertNotNull(node.getImage()); + assertNotSame(connectedImage, node.getImage()); + } + + private void verifySessionGetterSetters(TraceSessionComponent session) { + // save original values + String name = session.getName(); + String origPath = session.getSessionPath(); + TraceSessionState origState = session.getSessionState(); + + // test cases + session.setName("newName"); + assertEquals("newName", session.getName()); + + session.setSessionPath("/home/user/tmp"); + assertEquals("/home/user/tmp", session.getSessionPath()); + + session.setSessionState(TraceSessionState.INACTIVE); + assertEquals(TraceSessionState.INACTIVE, session.getSessionState()); + Image inactiveImage = session.getImage(); + assertNotNull(inactiveImage); + + session.setSessionState("active"); + assertEquals(TraceSessionState.ACTIVE, session.getSessionState()); + + Image activeImage = session.getImage(); + assertNotNull(activeImage); + assertNotSame(activeImage, inactiveImage); + + + // restore original values + session.setName(name); + session.setSessionPath(origPath); + session.setSessionState(origState); + } + + private void verifyBaseEventGettersSetters(BaseEventComponent event) { + // save original values + String name = event.getName(); + TraceLogLevel level = event.getLogLevel(); + TraceEventType type = event.getEventType(); + + // test cases + event.setName("newName"); + assertEquals("newName", event.getName()); + + event.setLogLevel(TraceLogLevel.TRACE_INFO); + assertEquals(TraceLogLevel.TRACE_INFO, event.getLogLevel()); + event.setLogLevel("TRACE_ALERT1"); + assertEquals(TraceLogLevel.TRACE_ALERT, event.getLogLevel()); + + event.setEventType(TraceEventType.UNKNOWN); + assertEquals(TraceEventType.UNKNOWN, event.getEventType()); + event.setEventType("tracepoint"); + assertEquals(TraceEventType.TRACEPOINT, event.getEventType()); + + // restore original values + event.setName(name); + event.setLogLevel(level); + event.setEventType(type); + } + + private void verifyEventGettersSetters(TraceEventComponent event) { + // save original values + String name = event.getName(); + TraceLogLevel level = event.getLogLevel(); + TraceEventType type = event.getEventType(); + TraceEnablement state = event.getState(); + + // test cases + event.setName("newName"); + assertEquals("newName", event.getName()); + + event.setLogLevel(TraceLogLevel.TRACE_INFO); + assertEquals(TraceLogLevel.TRACE_INFO, event.getLogLevel()); + event.setLogLevel("TRACE_ALERT1"); + assertEquals(TraceLogLevel.TRACE_ALERT, event.getLogLevel()); + + event.setEventType(TraceEventType.UNKNOWN); + assertEquals(TraceEventType.UNKNOWN, event.getEventType()); + event.setEventType("tracepoint"); + assertEquals(TraceEventType.TRACEPOINT, event.getEventType()); + + event.setState("disabled"); + assertEquals(TraceEnablement.DISABLED, event.getState()); + + Image disabledImage = event.getImage(); + assertNotNull(disabledImage); + + event.setState(TraceEnablement.ENABLED); + assertEquals(TraceEnablement.ENABLED, event.getState()); + + Image enabledImage = event.getImage(); + assertNotNull(enabledImage); + assertNotSame(enabledImage, disabledImage); + + // restore original values + event.setName(name); + event.setLogLevel(level); + event.setEventType(type); + event.setState(state); + } + + private void verifyChannelGettersSetters(TraceChannelComponent channel) { + // save original values + String name = channel.getName(); + int nbSubBuffers = channel.getNumberOfSubBuffers(); + String type = channel.getOutputType(); + boolean mode = channel.isOverwriteMode(); + long readTimer = channel.getReadTimer(); + TraceEnablement state = channel.getState(); + long subBufferSize = channel.getSubBufferSize(); + long switchTimer = channel.getSwitchTimer(); + + // test cases + channel.setName("newName"); + assertEquals("newName", channel.getName()); + + channel.setNumberOfSubBuffers(2); + assertEquals(2, channel.getNumberOfSubBuffers()); + + channel.setOutputType("splice()"); + assertEquals("splice()", channel.getOutputType()); + + channel.setOverwriteMode(false); + assertEquals(false, channel.isOverwriteMode()); + + channel.setReadTimer(250); + assertEquals(250, channel.getReadTimer()); + + channel.setState("enabled"); + assertEquals(TraceEnablement.ENABLED, channel.getState()); + + Image enabledImage = channel.getImage(); + assertNotNull(enabledImage); + channel.setState(TraceEnablement.DISABLED); + assertEquals(TraceEnablement.DISABLED, channel.getState()); + + Image disabledImage = channel.getImage(); + assertNotNull(disabledImage); + assertNotSame(enabledImage, disabledImage); + + channel.setSubBufferSize(1024); + assertEquals(1024, channel.getSubBufferSize()); + + channel.setSwitchTimer(1000); + assertEquals(1000, channel.getSwitchTimer()); + + // restore original values + channel.setName(name); + channel.setNumberOfSubBuffers(nbSubBuffers); + channel.setOutputType(type); + channel.setOverwriteMode(mode); + channel.setReadTimer(readTimer); + channel.setState(state); + channel.setSubBufferSize(subBufferSize); + channel.setSwitchTimer(switchTimer); + } + + private void verifyUstProviderGettersSetters(UstProviderComponent ustProvider) { + // save original values + String name = ustProvider.getName(); + int pid = ustProvider.getPid(); + + // test cases + ustProvider.setName("newName"); + assertEquals("newName", ustProvider.getName()); + + ustProvider.setPid(9876); + assertEquals(9876, ustProvider.getPid()); + + // restore original values + ustProvider.setName(name); + ustProvider.setPid(pid); + } + + +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/impl/AllTests.java b/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/impl/AllTests.java new file mode 100644 index 0000000000..69d35da7ba --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/impl/AllTests.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2011 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.lttng.ui.tests.control.model.impl; + +import junit.framework.Test; +import junit.framework.TestSuite; + +public class AllTests { + + public static Test suite() { + + TestSuite suite = new TestSuite(AllTests.class.getName()); + //$JUnit-BEGIN$ + suite.addTestSuite(BaseEventInfoTest.class); + suite.addTestSuite(DomainInfoTest.class); + suite.addTestSuite(EventInfoTest.class); + suite.addTestSuite(ChannelInfoTest.class); + suite.addTestSuite(SessionInfoTest.class); + suite.addTestSuite(TraceInfoTest.class); + suite.addTestSuite(UstProviderInfoTest.class); + //$JUnit-END$ + return suite; + } +} diff --git a/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/impl/BaseEventInfoTest.java b/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/impl/BaseEventInfoTest.java new file mode 100644 index 0000000000..8b7855fc9e --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/impl/BaseEventInfoTest.java @@ -0,0 +1,429 @@ +/********************************************************************** + * 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.lttng.ui.tests.control.model.impl; + +import junit.framework.TestCase; + +import org.eclipse.linuxtools.lttng.ui.views.control.model.IBaseEventInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceEventType; +import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceLogLevel; +import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.BaseEventInfo; + +/** + * The class BaseEventInfoTest contains test for the class {@link BaseEventInfo}. + */ +@SuppressWarnings("nls") +public class BaseEventInfoTest extends TestCase { + + // ------------------------------------------------------------------------ + // Test data + // ------------------------------------------------------------------------ + private IBaseEventInfo fEventInfo1 = null; + private IBaseEventInfo fEventInfo2 = null; + + // ------------------------------------------------------------------------ + // Housekeeping + // ------------------------------------------------------------------------ + /** + * Perform pre-test initialization. + * + * @throws Exception if the initialization fails for some reason + * + */ + @Override + public void setUp() throws Exception { + super.setUp(); + ModelImplFactory factory = new ModelImplFactory(); + fEventInfo1 = factory.getBaseEventInfo1(); + fEventInfo2 = factory.getBaseEventInfo2(); + } + + /** + * Perform post-test clean-up. + * + * @throws Exception if the clean-up fails for some reason + * + */ + @Override + public void tearDown() throws Exception { + } + + // ------------------------------------------------------------------------ + // Tests + // ------------------------------------------------------------------------ + + /** + * Run the BaseEventInfo() constructor test. + * + */ + public void testBaseEventInfo() { + BaseEventInfo fixture = new BaseEventInfo("event"); + assertNotNull(fixture); + + TraceEventType result = fixture.getEventType(); + + assertEquals("event", fixture.getName()); + assertEquals("unknown", result.getInName()); + assertEquals("UNKNOWN", result.name()); + assertEquals("UNKNOWN", result.toString()); + assertEquals(1, result.ordinal()); + + TraceLogLevel level = fixture.getLogLevel(); + assertEquals("TRACE_DEFAULT13", level.getInName()); + assertEquals("TRACE_DEFAULT", level.name()); + assertEquals("TRACE_DEFAULT", level.toString()); + assertEquals(13, level.ordinal()); + } + + /** + * Test Copy Constructor + */ + public void testEventInfoCopy() { + BaseEventInfo info = new BaseEventInfo((BaseEventInfo)fEventInfo1); + + assertEquals(fEventInfo1.getName(), info.getName()); + assertEquals(fEventInfo1.getEventType(), info.getEventType()); + assertEquals(fEventInfo1.getLogLevel(), info.getLogLevel()); + } + + /** + * Test Copy Constructor + */ + public void testEventCopy2() { + try { + BaseEventInfo info = null; + new BaseEventInfo(info); + fail("null copy"); + } + catch (IllegalArgumentException e) { + // Success + } + } + + /** + * Run the TraceEventType getEventType() method test. + * + * @throws Exception + * + */ + public void testGetEventType_1() { + BaseEventInfo fixture = new BaseEventInfo("event"); + fixture.setEventType("unknown"); + + TraceEventType result = fixture.getEventType(); + + assertNotNull(result); + assertEquals("unknown", result.getInName()); + assertEquals("UNKNOWN", result.name()); + assertEquals("UNKNOWN", result.toString()); + assertEquals(1, result.ordinal()); + + fixture.setEventType(""); + result = fixture.getEventType(); + assertEquals("unknown", result.getInName()); + assertEquals("UNKNOWN", result.name()); + assertEquals("UNKNOWN", result.toString()); + assertEquals(1, result.ordinal()); + + fixture.setEventType("tracepoint"); + result = fixture.getEventType(); + assertNotNull(result); + assertEquals("tracepoint", result.getInName()); + assertEquals("TRACEPOINT", result.name()); + assertEquals("TRACEPOINT", result.toString()); + assertEquals(0, result.ordinal()); + } + + /** + * Run the void setEventType(TraceEventType) method test. + * + */ + public void testSetEventType_2() { + BaseEventInfo fixture = new BaseEventInfo("event"); + fixture.setEventType(TraceEventType.TRACEPOINT); + + TraceEventType result = fixture.getEventType(); + + assertNotNull(result); + assertEquals("tracepoint", result.getInName()); + assertEquals("TRACEPOINT", result.name()); + assertEquals("TRACEPOINT", result.toString()); + assertEquals(0, result.ordinal()); + + fixture.setEventType(TraceEventType.UNKNOWN); + result = fixture.getEventType(); + + assertNotNull(result); + assertEquals("unknown", result.getInName()); + assertEquals("UNKNOWN", result.name()); + assertEquals("UNKNOWN", result.toString()); + assertEquals(1, result.ordinal()); + } + + /** + * Run the void setLogLevel(TraceLogLevel) method test. + * Run the TraceLogLevel getLogLevel() method test + * + */ + public void testSetLogLevel1() { + BaseEventInfo fixture = new BaseEventInfo("event"); + fixture.setEventType(TraceEventType.TRACEPOINT); + fixture.setLogLevel(TraceLogLevel.TRACE_CRIT); + + // 2 set/get-operations are enough to test the method + TraceLogLevel result = fixture.getLogLevel(); + assertNotNull(result); + assertEquals("TRACE_CRIT2", result.getInName()); + assertEquals("TRACE_CRIT", result.name()); + assertEquals("TRACE_CRIT", result.toString()); + assertEquals(2, result.ordinal()); + + fixture.setLogLevel(TraceLogLevel.TRACE_FUNCTION); + + result = fixture.getLogLevel(); + assertNotNull(result); + assertEquals("TRACE_FUNCTION12", result.getInName()); + assertEquals("TRACE_FUNCTION", result.name()); + assertEquals("TRACE_FUNCTION", result.toString()); + assertEquals(12, result.ordinal()); + } + + /** + * Run the void setLogLevel(String) method test. + * Run the TraceLogLevel getLogLevel() method test + * + */ + public void testSetLogLevel2() { + BaseEventInfo fixture = new BaseEventInfo("event"); + fixture.setEventType(TraceEventType.TRACEPOINT); + fixture.setLogLevel("TRACE_EMERG0"); + + TraceLogLevel result = fixture.getLogLevel(); + assertNotNull(result); + assertEquals("TRACE_EMERG0", result.getInName()); + assertEquals("TRACE_EMERG", result.name()); + assertEquals(0, result.ordinal()); + + //------------------------ + fixture.setLogLevel("TRACE_ALERT1"); + + result = fixture.getLogLevel(); + assertNotNull(result); + assertEquals("TRACE_ALERT1", result.getInName()); + assertEquals("TRACE_ALERT", result.name()); + assertEquals(1, result.ordinal()); + + //------------------------ + fixture.setLogLevel("TRACE_CRIT2"); + + result = fixture.getLogLevel(); + assertNotNull(result); + assertEquals("TRACE_CRIT2", result.getInName()); + assertEquals("TRACE_CRIT", result.name()); + assertEquals(2, result.ordinal()); + + //------------------------ + fixture.setLogLevel("TRACE_ERR3"); + + result = fixture.getLogLevel(); + assertNotNull(result); + assertEquals("TRACE_ERR3", result.getInName()); + assertEquals("TRACE_ERR", result.name()); + assertEquals(3, result.ordinal()); + + //------------------------ + fixture.setLogLevel("TRACE_WARNING4"); + + result = fixture.getLogLevel(); + assertNotNull(result); + assertEquals("TRACE_WARNING4", result.getInName()); + assertEquals("TRACE_WARNING", result.name()); + assertEquals(4, result.ordinal()); + + //------------------------ + fixture.setLogLevel("TRACE_NOTICE5"); + + result = fixture.getLogLevel(); + assertNotNull(result); + assertEquals("TRACE_NOTICE5", result.getInName()); + assertEquals("TRACE_NOTICE", result.name()); + assertEquals(5, result.ordinal()); + + //------------------------ + fixture.setLogLevel("TRACE_INFO6"); + + result = fixture.getLogLevel(); + assertNotNull(result); + assertEquals("TRACE_INFO6", result.getInName()); + assertEquals("TRACE_INFO", result.name()); + assertEquals(6, result.ordinal()); + + //------------------------ + fixture.setLogLevel("TRACE_SYSTEM7"); + + result = fixture.getLogLevel(); + assertNotNull(result); + assertEquals("TRACE_SYSTEM7", result.getInName()); + assertEquals("TRACE_SYSTEM", result.name()); + assertEquals(7, result.ordinal()); + + //------------------------ + fixture.setLogLevel("TRACE_PROGRAM8"); + + result = fixture.getLogLevel(); + assertNotNull(result); + assertEquals("TRACE_PROGRAM8", result.getInName()); + assertEquals("TRACE_PROGRAM", result.name()); + assertEquals(8, result.ordinal()); + + //------------------------ + fixture.setLogLevel("TRACE_PROCESS9"); + + result = fixture.getLogLevel(); + assertNotNull(result); + assertEquals("TRACE_PROCESS9", result.getInName()); + assertEquals("TRACE_PROCESS", result.name()); + assertEquals(9, result.ordinal()); + + //------------------------ + fixture.setLogLevel("TRACE_MODULE10"); + + result = fixture.getLogLevel(); + assertNotNull(result); + assertEquals("TRACE_MODULE10", result.getInName()); + assertEquals("TRACE_MODULE", result.name()); + assertEquals(10, result.ordinal()); + + //------------------------ + fixture.setLogLevel("TRACE_UNIT11"); + + result = fixture.getLogLevel(); + assertNotNull(result); + assertEquals("TRACE_UNIT11", result.getInName()); + assertEquals("TRACE_UNIT", result.name()); + assertEquals(11, result.ordinal()); + + //------------------------ + fixture.setLogLevel("TRACE_FUNCTION12"); + + result = fixture.getLogLevel(); + assertNotNull(result); + assertEquals("TRACE_FUNCTION12", result.getInName()); + assertEquals("TRACE_FUNCTION", result.name()); + assertEquals(12, result.ordinal()); + + //------------------------ + fixture.setLogLevel("TRACE_DEFAULT13"); + + result = fixture.getLogLevel(); + assertNotNull(result); + assertEquals("TRACE_DEFAULT13", result.getInName()); + assertEquals("TRACE_DEFAULT", result.name()); + assertEquals(13, result.ordinal()); + + //------------------------ + fixture.setLogLevel("TRACE_VERBOSE14"); + + result = fixture.getLogLevel(); + assertNotNull(result); + assertEquals("TRACE_VERBOSE14", result.getInName()); + assertEquals("TRACE_VERBOSE", result.name()); + assertEquals(14, result.ordinal()); + + //------------------------ + fixture.setLogLevel("TRACE_DEBUG15"); + + result = fixture.getLogLevel(); + assertNotNull(result); + assertEquals("TRACE_DEBUG15", result.getInName()); + assertEquals("TRACE_DEBUG", result.name()); + assertEquals(15, result.ordinal()); + + fixture.setLogLevel("garbabe"); + + result = fixture.getLogLevel(); + assertNotNull(result); + assertEquals("TRACE_DEFAULT13", result.getInName()); + assertEquals("TRACE_DEFAULT", result.name()); + assertEquals(13, result.ordinal()); + } + + + /** + * Run the String toString() method test. + * + */ + public void testToString_1() { + BaseEventInfo fixture = new BaseEventInfo("event"); + fixture.setName("testName"); + fixture.setEventType(TraceEventType.TRACEPOINT); + fixture.setLogLevel(TraceLogLevel.TRACE_ERR); + + String result = fixture.toString(); + + // add additional test code here + assertEquals("[BaseEventInfo([TraceInfo(Name=testName)],type=TRACEPOINT,level=TRACE_ERR)]", result); + } + + // ------------------------------------------------------------------------ + // equals + // ------------------------------------------------------------------------ + + public void testEqualsReflexivity() { + assertTrue("equals", fEventInfo1.equals(fEventInfo1)); + assertTrue("equals", fEventInfo2.equals(fEventInfo2)); + + assertTrue("equals", !fEventInfo1.equals(fEventInfo2)); + assertTrue("equals", !fEventInfo2.equals(fEventInfo1)); + } + + public void testEqualsSymmetry() { + BaseEventInfo info1 = new BaseEventInfo((BaseEventInfo)fEventInfo1); + BaseEventInfo info2 = new BaseEventInfo((BaseEventInfo)fEventInfo2); + + assertTrue("equals", info1.equals(fEventInfo1)); + assertTrue("equals", fEventInfo1.equals(info1)); + + assertTrue("equals", info2.equals(fEventInfo2)); + assertTrue("equals", fEventInfo2.equals(info2)); + } + + public void testEqualsTransivity() { + BaseEventInfo info1 = new BaseEventInfo((BaseEventInfo)fEventInfo1); + BaseEventInfo info2 = new BaseEventInfo((BaseEventInfo)fEventInfo1); + BaseEventInfo info3 = new BaseEventInfo((BaseEventInfo)fEventInfo1); + + assertTrue("equals", info1.equals(info2)); + assertTrue("equals", info2.equals(info3)); + assertTrue("equals", info1.equals(info3)); + } + + public void testEqualsNull() { + assertTrue("equals", !fEventInfo1.equals(null)); + assertTrue("equals", !fEventInfo2.equals(null)); + } + + // ------------------------------------------------------------------------ + // hashCode + // ------------------------------------------------------------------------ + + public void testHashCode() { + BaseEventInfo info1 = new BaseEventInfo((BaseEventInfo)fEventInfo1); + BaseEventInfo info2 = new BaseEventInfo((BaseEventInfo)fEventInfo2); + + assertTrue("hashCode", fEventInfo1.hashCode() == info1.hashCode()); + assertTrue("hashCode", fEventInfo2.hashCode() == info2.hashCode()); + + assertTrue("hashCode", fEventInfo1.hashCode() != info2.hashCode()); + assertTrue("hashCode", fEventInfo2.hashCode() != info1.hashCode()); + } +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/impl/ChannelInfoTest.java b/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/impl/ChannelInfoTest.java new file mode 100644 index 0000000000..6a4020fb0e --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/impl/ChannelInfoTest.java @@ -0,0 +1,327 @@ +/********************************************************************** + * 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.lttng.ui.tests.control.model.impl; + +import java.util.LinkedList; +import java.util.List; + +import junit.framework.TestCase; + +import org.eclipse.linuxtools.lttng.ui.views.control.model.IChannelInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.IEventInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceEnablement; +import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.ChannelInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.EventInfo; + +/** + * The class ChannelInfoTest contains tests for the class {@link ChannelInfo}. + * + */ +@SuppressWarnings("nls") +public class ChannelInfoTest extends TestCase { + // ------------------------------------------------------------------------ + // Test data + // ------------------------------------------------------------------------ + private IChannelInfo fChannelInfo1 = null; + private IChannelInfo fChannelInfo2 = null; + + // ------------------------------------------------------------------------ + // Housekeeping + // ------------------------------------------------------------------------ + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + */ + @Override + public void setUp() { + ModelImplFactory factory = new ModelImplFactory(); + fChannelInfo1 = factory.getChannel1(); + fChannelInfo2 = factory.getChannel2(); + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + */ + @Override + public void tearDown() { + } + + // ------------------------------------------------------------------------ + // Tests + // ------------------------------------------------------------------------ + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + /** + * Run the ChannelInfo() constructor test. + * + */ + public void testChannelInfo() { + ChannelInfo result = new ChannelInfo("test"); + assertNotNull(result); + + assertEquals("test", result.getName()); + assertEquals(0, result.getNumberOfSubBuffers()); + assertEquals("", result.getOutputType()); + assertEquals(false, result.isOverwriteMode()); + assertEquals(0, result.getReadTimer()); + assertEquals("disabled", result.getState().getInName()); + assertEquals(0, result.getSubBufferSize()); + assertEquals(0, result.getSwitchTimer()); + } + + public void testChannelInfoCopy() { + ChannelInfo channelInfo = new ChannelInfo((ChannelInfo)fChannelInfo1); + + assertEquals(fChannelInfo1.getName(), channelInfo.getName()); + assertEquals(fChannelInfo1.getNumberOfSubBuffers(), channelInfo.getNumberOfSubBuffers()); + assertEquals(fChannelInfo1.getOutputType(), channelInfo.getOutputType()); + assertEquals(fChannelInfo1.isOverwriteMode(), channelInfo.isOverwriteMode()); + assertEquals(fChannelInfo1.getReadTimer(), channelInfo.getReadTimer()); + assertEquals(fChannelInfo1.getState(), channelInfo.getState()); + assertEquals(fChannelInfo1.getSwitchTimer(), channelInfo.getSwitchTimer()); + assertEquals(fChannelInfo1.getEvents().length, channelInfo.getEvents().length); + + IEventInfo[] orignalEvents = fChannelInfo1.getEvents(); + IEventInfo[] resultEvents = channelInfo.getEvents(); + for (int i = 0; i < orignalEvents.length; i++) { + assertEquals(orignalEvents[i], resultEvents[i]); + } + } + + public void testChannelCopy2() { + try { + ChannelInfo channel = null; + new ChannelInfo(channel); + fail("null copy"); + } + catch (IllegalArgumentException e) { + // Success + } + } + + /** + * Run the IEventInfo[] getEvents() method test. + * + */ + public void testAddAndGetEvents_1() { + ChannelInfo fixture = new ChannelInfo("test"); + fixture.setSwitchTimer(1L); + fixture.setOverwriteMode(true); + fixture.setReadTimer(1L); + fixture.setState(TraceEnablement.DISABLED); + fixture.setNumberOfSubBuffers(1); + fixture.setOutputType(""); + fixture.setSubBufferSize(1L); + + // add an event + IEventInfo event = new EventInfo("event"); + fixture.addEvent(event); + + // Verify the stored events + IEventInfo[] result = fixture.getEvents(); + + assertNotNull(result); + assertEquals(1, result.length); + assertNotNull(result[0]); + assertTrue(event.equals(result[0])); + } + + /** + * Run the long getNumberOfSubBuffers() method test. + * + */ + public void testGetAndSetters() { + ChannelInfo fixture = new ChannelInfo("test"); + fixture.setSwitchTimer(2L); + fixture.setOverwriteMode(true); + fixture.setReadTimer(3L); + fixture.setState(TraceEnablement.DISABLED); + fixture.setNumberOfSubBuffers(4); + fixture.setOutputType("splice()"); + fixture.setSubBufferSize(1L); + fixture.addEvent(new EventInfo("event")); + + long switchTimer = fixture.getSwitchTimer(); + assertEquals(2L, switchTimer); + + boolean mode = fixture.isOverwriteMode(); + assertTrue(mode); + + long readTimer = fixture.getReadTimer(); + assertEquals(3L, readTimer); + + TraceEnablement state = fixture.getState(); + assertEquals("disabled", state.getInName()); + + long numSubBuffers = fixture.getNumberOfSubBuffers(); + assertEquals(4, numSubBuffers); + + String outputType = fixture.getOutputType(); + assertEquals("splice()", outputType); + + long subBufferSize = fixture.getSubBufferSize(); + assertEquals(1L, subBufferSize); + + fixture.setSwitchTimer(5L); + fixture.setOverwriteMode(false); + fixture.setReadTimer(6L); + fixture.setState(TraceEnablement.ENABLED); + fixture.setNumberOfSubBuffers(7); + fixture.setOutputType("mmap()"); + fixture.setSubBufferSize(8L); + + switchTimer = fixture.getSwitchTimer(); + assertEquals(5L, switchTimer); + + mode = fixture.isOverwriteMode(); + assertFalse(mode); + + readTimer = fixture.getReadTimer(); + assertEquals(6L, readTimer); + + state = fixture.getState(); + assertEquals("enabled", state.getInName()); + + numSubBuffers = fixture.getNumberOfSubBuffers(); + assertEquals(7, numSubBuffers); + + outputType = fixture.getOutputType(); + assertEquals("mmap()", outputType); + + subBufferSize = fixture.getSubBufferSize(); + assertEquals(8L, subBufferSize); + } + + /** + * Run the void setEvents(List) method test. + * + */ + public void testSetEvents_1() { + ChannelInfo fixture = new ChannelInfo("test"); + fixture.setSwitchTimer(1L); + fixture.setOverwriteMode(true); + fixture.setReadTimer(1L); + fixture.setState(TraceEnablement.DISABLED); + fixture.setNumberOfSubBuffers(1); + fixture.setOutputType(""); + fixture.setSubBufferSize(1L); + List events = new LinkedList(); + + for (int i = 0; i < 2; i++) { + IEventInfo info = new EventInfo("event" + i); + info.setEventType("tracepoint"); + info.setState((i % 2 == 0 ? "enabled" : "disabled")); + events.add(info); + } + + fixture.setEvents(events); + + IEventInfo[] infos = fixture.getEvents(); + + assertEquals(events.size(), infos.length); + + for (int i = 0; i < infos.length; i++) { + assertEquals(events.get(i), infos[i]); + } + } + + public void testToString_1() { + ChannelInfo fixture = new ChannelInfo("channel"); + fixture.setSwitchTimer(1L); + fixture.setOverwriteMode(true); + fixture.setReadTimer(1L); + fixture.setState(TraceEnablement.DISABLED); + fixture.setNumberOfSubBuffers(1); + fixture.setOutputType("splice()"); + fixture.setSubBufferSize(1L); + + String result = fixture.toString(); + + // add additional test code here + assertEquals("[ChannelInfo([TraceInfo(Name=channel)],State=DISABLED,OverwriteMode=true,SubBuffersSize=1,NumberOfSubBuffers=1,SwitchTimer=1,ReadTimer=1,output=splice(),Events=None)]", result); + } + + /** + * Run the String toString() method test. + * + */ + public void testToString_2() { + String result = fChannelInfo1.toString(); + + // add additional test code here + assertEquals("[ChannelInfo([TraceInfo(Name=channel1)],State=DISABLED,OverwriteMode=true,SubBuffersSize=13,NumberOfSubBuffers=12,SwitchTimer=10,ReadTimer=11,output=splice(),Events=[EventInfo([BaseEventInfo([TraceInfo(Name=event1)],type=TRACEPOINT,level=TRACE_DEFAULT)],State=ENABLED)])]", result); + } + + // ------------------------------------------------------------------------ + // equals + // ------------------------------------------------------------------------ + + public void testEqualsReflexivity() { + assertTrue("equals", fChannelInfo1.equals(fChannelInfo1)); + assertTrue("equals", fChannelInfo2.equals(fChannelInfo2)); + + assertTrue("equals", !fChannelInfo1.equals(fChannelInfo2)); + assertTrue("equals", !fChannelInfo2.equals(fChannelInfo1)); + } + + public void testEqualsSymmetry() { + ChannelInfo event1 = new ChannelInfo((ChannelInfo)fChannelInfo1); + ChannelInfo event2 = new ChannelInfo((ChannelInfo)fChannelInfo2); + + assertTrue("equals", event1.equals(fChannelInfo1)); + assertTrue("equals", fChannelInfo1.equals(event1)); + + assertTrue("equals", event2.equals(fChannelInfo2)); + assertTrue("equals", fChannelInfo2.equals(event2)); + } + + public void testEqualsTransivity() { + ChannelInfo channel1 = new ChannelInfo((ChannelInfo)fChannelInfo1); + ChannelInfo channel2 = new ChannelInfo((ChannelInfo)fChannelInfo1); + ChannelInfo channel3 = new ChannelInfo((ChannelInfo)fChannelInfo1); + + assertTrue("equals", channel1.equals(channel2)); + assertTrue("equals", channel2.equals(channel3)); + assertTrue("equals", channel1.equals(channel3)); + } + + public void testEqualsNull() throws Exception { + assertTrue("equals", !fChannelInfo1.equals(null)); + assertTrue("equals", !fChannelInfo2.equals(null)); + } + + // ------------------------------------------------------------------------ + // hashCode + // ------------------------------------------------------------------------ + + public void testHashCode() { + ChannelInfo channel1 = new ChannelInfo((ChannelInfo)fChannelInfo1); + ChannelInfo channel2 = new ChannelInfo((ChannelInfo)fChannelInfo2); + + assertTrue("hashCode", fChannelInfo1.hashCode() == channel1.hashCode()); + assertTrue("hashCode", fChannelInfo2.hashCode() == channel2.hashCode()); + + assertTrue("hashCode", fChannelInfo1.hashCode() != channel2.hashCode()); + assertTrue("hashCode", fChannelInfo2.hashCode() != channel1.hashCode()); + } +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/impl/DomainInfoTest.java b/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/impl/DomainInfoTest.java new file mode 100644 index 0000000000..4ed31dc750 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/impl/DomainInfoTest.java @@ -0,0 +1,203 @@ +/********************************************************************** + * 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.lttng.ui.tests.control.model.impl; + +import java.util.LinkedList; +import java.util.List; + +import junit.framework.TestCase; + +import org.eclipse.linuxtools.lttng.ui.views.control.model.IChannelInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.IDomainInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.DomainInfo; + +/** + * The class ChannelInfoTest contains tests for the class {@link DomainInfo}. + * + */ +@SuppressWarnings("nls") +public class DomainInfoTest extends TestCase { + // ------------------------------------------------------------------------ + // Test data + // ------------------------------------------------------------------------ + private IDomainInfo fDomainInfo1 = null; + private IDomainInfo fDomainInfo2 = null; + private IChannelInfo fChannelInfo1 = null; + private IChannelInfo fChannelInfo2 = null; + + // ------------------------------------------------------------------------ + // Housekeeping + // ------------------------------------------------------------------------ + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + */ + @Override + public void setUp() { + // Get test instances from the factory + ModelImplFactory factory = new ModelImplFactory(); + fChannelInfo1 = factory.getChannel1(); + fChannelInfo2 = factory.getChannel2(); + fDomainInfo1 = factory.getDomainInfo1(); + fDomainInfo2 = factory.getDomainInfo2(); + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + */ + @Override + public void tearDown() { + } + + // ------------------------------------------------------------------------ + // Tests + // ------------------------------------------------------------------------ + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + /** + * Run the ChannelInfo() constructor test. + * + */ + public void testDomainInfo() { + DomainInfo result = new DomainInfo("test"); + assertNotNull(result); + + assertEquals("test", result.getName()); + assertEquals(0, result.getChannels().length); + } + + public void testDomainInfoCopy() { + DomainInfo channelInfo = new DomainInfo((DomainInfo)fDomainInfo1); + IChannelInfo[] orignalEvents = fDomainInfo1.getChannels(); + IChannelInfo[] resultEvents = channelInfo.getChannels(); + for (int i = 0; i < orignalEvents.length; i++) { + assertEquals(orignalEvents[i], resultEvents[i]); + } + } + + public void testDomainlCopy2() { + try { + DomainInfo domain = null; + new DomainInfo(domain); + fail("null copy"); + } + catch (IllegalArgumentException e) { + // Success + } + } + + /** + * Run the long getNumberOfSubBuffers() method test. + * + */ + public void testGetAndSetters() { + + // Note that addChannel() has been executed in setUp() + // check get method here + assertEquals(1, fDomainInfo1.getChannels().length); + assertNotNull(fDomainInfo1.getChannels()[0]); + assertEquals(fChannelInfo1, fDomainInfo1.getChannels()[0]); + + IDomainInfo domain = new DomainInfo("domain"); + List list = new LinkedList(); + list.add(fChannelInfo1); + list.add(fChannelInfo2); + domain.setChannels(list); + + IChannelInfo[] result = domain.getChannels(); + assertEquals(2, result.length); + assertEquals(fChannelInfo1, result[0]); + assertEquals(fChannelInfo2, result[1]); + } + + public void testToString_1() { + DomainInfo fixture = new DomainInfo("domain"); + + String result = fixture.toString(); + + assertEquals("[DomainInfo([TraceInfo(Name=domain)],Channels=None)]", result); + } + + /** + * Run the String toString() method test. + * + */ + public void testToString_2() { + String result = fDomainInfo1.toString(); + + assertEquals("[DomainInfo([TraceInfo(Name=test1)],Channels=[ChannelInfo([TraceInfo(Name=channel1)],State=DISABLED,OverwriteMode=true,SubBuffersSize=13,NumberOfSubBuffers=12,SwitchTimer=10,ReadTimer=11,output=splice(),Events=[EventInfo([BaseEventInfo([TraceInfo(Name=event1)],type=TRACEPOINT,level=TRACE_DEFAULT)],State=ENABLED)])])]", result); + } + + // ------------------------------------------------------------------------ + // equals + // ------------------------------------------------------------------------ + + public void testEqualsReflexivity() { + assertTrue("equals", fDomainInfo1.equals(fDomainInfo1)); + assertTrue("equals", fDomainInfo2.equals(fDomainInfo2)); + + assertTrue("equals", !fDomainInfo1.equals(fDomainInfo2)); + assertTrue("equals", !fDomainInfo2.equals(fDomainInfo1)); + } + + public void testEqualsSymmetry() { + DomainInfo event1 = new DomainInfo((DomainInfo)fDomainInfo1); + DomainInfo event2 = new DomainInfo((DomainInfo)fDomainInfo2); + + assertTrue("equals", event1.equals(fDomainInfo1)); + assertTrue("equals", fDomainInfo1.equals(event1)); + + assertTrue("equals", event2.equals(fDomainInfo2)); + assertTrue("equals", fDomainInfo2.equals(event2)); + } + + public void testEqualsTransivity() { + DomainInfo channel1 = new DomainInfo((DomainInfo)fDomainInfo1); + DomainInfo channel2 = new DomainInfo((DomainInfo)fDomainInfo1); + DomainInfo channel3 = new DomainInfo((DomainInfo)fDomainInfo1); + + assertTrue("equals", channel1.equals(channel2)); + assertTrue("equals", channel2.equals(channel3)); + assertTrue("equals", channel1.equals(channel3)); + } + + public void testEqualsNull() throws Exception { + assertTrue("equals", !fDomainInfo1.equals(null)); + assertTrue("equals", !fDomainInfo2.equals(null)); + } + + // ------------------------------------------------------------------------ + // hashCode + // ------------------------------------------------------------------------ + + public void testHashCode() { + DomainInfo channel1 = new DomainInfo((DomainInfo)fDomainInfo1); + DomainInfo channel2 = new DomainInfo((DomainInfo)fDomainInfo2); + + assertTrue("hashCode", fDomainInfo1.hashCode() == channel1.hashCode()); + assertTrue("hashCode", fDomainInfo2.hashCode() == channel2.hashCode()); + + assertTrue("hashCode", fDomainInfo1.hashCode() != channel2.hashCode()); + assertTrue("hashCode", fDomainInfo2.hashCode() != channel1.hashCode()); + } +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/impl/EventInfoTest.java b/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/impl/EventInfoTest.java new file mode 100644 index 0000000000..0ff9013b28 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/impl/EventInfoTest.java @@ -0,0 +1,259 @@ +/********************************************************************** + * 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.lttng.ui.tests.control.model.impl; + +import junit.framework.TestCase; + +import org.eclipse.linuxtools.lttng.ui.views.control.model.IEventInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceEnablement; +import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceEventType; +import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.BaseEventInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.EventInfo; + +/** + * The class BaseEventInfoTest contains test for the class {@link BaseEventInfo}. + */ +@SuppressWarnings("nls") +public class EventInfoTest extends TestCase { + + // ------------------------------------------------------------------------ + // Test data + // ------------------------------------------------------------------------ + private IEventInfo fEventInfo1 = null; + private IEventInfo fEventInfo2 = null; + + // ------------------------------------------------------------------------ + // Housekeeping + // ------------------------------------------------------------------------ + /** + * Perform pre-test initialization. + * + * @throws Exception if the initialization fails for some reason + * + */ + @Override + public void setUp() throws Exception { + ModelImplFactory factory = new ModelImplFactory(); + fEventInfo1 = factory.getEventInfo1(); + fEventInfo2 = factory.getEventInfo2(); + } + + /** + * Perform post-test clean-up. + * + * @throws Exception if the clean-up fails for some reason + * + */ + @Override + public void tearDown() throws Exception { + } + + // ------------------------------------------------------------------------ + // Tests + // ------------------------------------------------------------------------ + + /** + * Run the BaseEventInfo() constructor test. + * + */ + public void testBaseEventInfo() { + EventInfo fixture = new EventInfo("event"); + assertNotNull(fixture); + + TraceEventType result = fixture.getEventType(); + + assertEquals("event", fixture.getName()); + assertEquals("unknown", result.getInName()); + assertEquals("UNKNOWN", result.name()); + assertEquals("UNKNOWN", result.toString()); + assertEquals(1, result.ordinal()); + + TraceEnablement state = fixture.getState(); + assertEquals("disabled", state.getInName()); + assertEquals("DISABLED", state.name()); + assertEquals("DISABLED", state.toString()); + assertEquals(0, state.ordinal()); + + } + + /** + * Test Copy Constructor + */ + public void testEventInfoCopy() { + EventInfo info = new EventInfo((EventInfo)fEventInfo1); + + assertEquals(fEventInfo1.getName(), info.getName()); + assertEquals(fEventInfo1.getEventType(), info.getEventType()); + assertEquals(fEventInfo1.getState(), info.getState()); + } + + /** + * Test Copy Constructor + */ + public void testEventCopy2() { + try { + EventInfo info = null; + new EventInfo(info); + fail("null copy"); + } + catch (IllegalArgumentException e) { + // Success + } + } + + /** + * Getter/Setter tests + */ + public void testGetAndSetter() { + EventInfo fixture = new EventInfo("event"); + + fixture.setEventType(TraceEventType.TRACEPOINT); + TraceEventType result = fixture.getEventType(); + + // setEventType(TraceEventType type) + assertNotNull(result); + assertEquals("tracepoint", result.getInName()); + assertEquals("TRACEPOINT", result.name()); + assertEquals("TRACEPOINT", result.toString()); + assertEquals(0, result.ordinal()); + + fixture.setEventType(TraceEventType.UNKNOWN); + result = fixture.getEventType(); + assertEquals("unknown", result.getInName()); + assertEquals("UNKNOWN", result.name()); + assertEquals("UNKNOWN", result.toString()); + assertEquals(1, result.ordinal()); + + // setEventType(String typeName) + String typeName = ""; + fixture.setEventType(typeName); + result = fixture.getEventType(); + + assertEquals("unknown", result.getInName()); + assertEquals("UNKNOWN", result.name()); + assertEquals("UNKNOWN", result.toString()); + assertEquals(1, result.ordinal()); + + typeName = "unknown"; + + fixture.setEventType(typeName); + result = fixture.getEventType(); + + assertEquals("unknown", result.getInName()); + assertEquals("UNKNOWN", result.name()); + assertEquals("UNKNOWN", result.toString()); + assertEquals(1, result.ordinal()); + + // setState(String stateName) + fixture.setState("disabled"); + TraceEnablement state = fixture.getState(); + assertEquals("disabled", state.getInName()); + assertEquals("DISABLED", state.name()); + assertEquals("DISABLED", state.toString()); + assertEquals(0, state.ordinal()); + + fixture.setState("bla"); + state = fixture.getState(); + assertEquals("disabled", state.getInName()); + assertEquals("DISABLED", state.name()); + assertEquals("DISABLED", state.toString()); + assertEquals(0, state.ordinal()); + + fixture.setState("enabled"); + state = fixture.getState(); + assertEquals("enabled", state.getInName()); + assertEquals("ENABLED", state.name()); + assertEquals("ENABLED", state.toString()); + assertEquals(1, state.ordinal()); + + // setState(TraceEnablement state) + fixture.setState(TraceEnablement.DISABLED); + state = fixture.getState(); + assertEquals("disabled", state.getInName()); + assertEquals("DISABLED", state.name()); + assertEquals("DISABLED", state.toString()); + assertEquals(0, state.ordinal()); + + fixture.setState(TraceEnablement.ENABLED); + state = fixture.getState(); + assertEquals("enabled", state.getInName()); + assertEquals("ENABLED", state.name()); + assertEquals("ENABLED", state.toString()); + assertEquals(1, state.ordinal()); + } + + /** + * Run the String toString() method test. + */ + public void testToString_1() { + EventInfo fixture = new EventInfo("event"); + fixture.setName("testName"); + fixture.setEventType(TraceEventType.TRACEPOINT); + + String result = fixture.toString(); + + // add additional test code here + assertEquals("[EventInfo([BaseEventInfo([TraceInfo(Name=testName)],type=TRACEPOINT,level=TRACE_DEFAULT)],State=DISABLED)]", result); + } + + // ------------------------------------------------------------------------ + // equals + // ------------------------------------------------------------------------ + public void testEqualsReflexivity() { + assertTrue("equals", fEventInfo1.equals(fEventInfo1)); + assertTrue("equals", fEventInfo2.equals(fEventInfo2)); + + assertTrue("equals", !fEventInfo1.equals(fEventInfo2)); + assertTrue("equals", !fEventInfo2.equals(fEventInfo1)); + } + + public void testEqualsSymmetry() { + EventInfo info1 = new EventInfo((EventInfo)fEventInfo1); + EventInfo info2 = new EventInfo((EventInfo)fEventInfo2); + + assertTrue("equals", info1.equals(fEventInfo1)); + assertTrue("equals", fEventInfo1.equals(info1)); + + assertTrue("equals", info2.equals(fEventInfo2)); + assertTrue("equals", fEventInfo2.equals(info2)); + } + + public void testEqualsTransivity() { + EventInfo info1 = new EventInfo((EventInfo)fEventInfo1); + EventInfo info2 = new EventInfo((EventInfo)fEventInfo1); + EventInfo info3 = new EventInfo((EventInfo)fEventInfo1); + + assertTrue("equals", info1.equals(info2)); + assertTrue("equals", info2.equals(info3)); + assertTrue("equals", info1.equals(info3)); + } + + public void testEqualsNull() { + assertTrue("equals", !fEventInfo1.equals(null)); + assertTrue("equals", !fEventInfo2.equals(null)); + } + + // ------------------------------------------------------------------------ + // hashCode + // ------------------------------------------------------------------------ + + public void testHashCode() { + EventInfo info1 = new EventInfo((EventInfo)fEventInfo1); + EventInfo info2 = new EventInfo((EventInfo)fEventInfo2); + + assertTrue("hashCode", fEventInfo1.hashCode() == info1.hashCode()); + assertTrue("hashCode", fEventInfo2.hashCode() == info2.hashCode()); + + assertTrue("hashCode", fEventInfo1.hashCode() != info2.hashCode()); + assertTrue("hashCode", fEventInfo2.hashCode() != info1.hashCode()); + } +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/impl/ListenerValidator.java b/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/impl/ListenerValidator.java new file mode 100644 index 0000000000..3477eea27a --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/impl/ListenerValidator.java @@ -0,0 +1,94 @@ +/********************************************************************** + * 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.lttng.ui.tests.control.model.impl; + +import org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent; +import org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponentChangedListener; + +/** + * The class can be used to validate the listener interface. + * + */ +public class ListenerValidator implements ITraceControlComponentChangedListener { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + private boolean fisAddedCalled = false; + private boolean fisRemoveCalled = false; + private boolean fisChangedCalled = false; + + private ITraceControlComponent fParent = null; + private ITraceControlComponent fChild = null; + private ITraceControlComponent fChangedComponent = null; + + // ------------------------------------------------------------------------ + // Accessors + // ------------------------------------------------------------------------ + public boolean isAddedCalled() { + return fisAddedCalled; + } + + public boolean isRemovedCalled() { + return fisRemoveCalled; + } + + public boolean isChangedCalled() { + return fisChangedCalled; + } + + public ITraceControlComponent getSavedParent() { + return fParent; + } + + public ITraceControlComponent getSavedChild() { + return fChild; + } + + public ITraceControlComponent getSavedComponent() { + return fChangedComponent; + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + public void initialize() { + fisAddedCalled = false; + fisRemoveCalled = false; + fisChangedCalled = false; + fParent = null; + fChild = null; + fChangedComponent = null; + } + + @Override + public void componentAdded(ITraceControlComponent parent, ITraceControlComponent component) { + fisAddedCalled = true; + fParent = parent; + fChild = component; + } + + @Override + public void componentRemoved(ITraceControlComponent parent, ITraceControlComponent component) { + fisRemoveCalled = true; + fParent = parent; + fChild = component; + } + + @Override + public void componentChanged(ITraceControlComponent component) { + fisChangedCalled = true; + fParent = null; + fChangedComponent = component; + } + +} diff --git a/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/impl/ModelImplFactory.java b/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/impl/ModelImplFactory.java new file mode 100644 index 0000000000..fb34dc9363 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/impl/ModelImplFactory.java @@ -0,0 +1,171 @@ +/******************************************************************************* + * 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.lttng.ui.tests.control.model.impl; + +import org.eclipse.linuxtools.lttng.ui.views.control.model.IBaseEventInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.IChannelInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.IDomainInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.IEventInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.ISessionInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.IUstProviderInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceEnablement; +import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceEventType; +import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceLogLevel; +import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceSessionState; +import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.BaseEventInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.ChannelInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.DomainInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.EventInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.SessionInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.UstProviderInfo; + +/** + * Test facility to constants across test case + */ +@SuppressWarnings("nls") +public class ModelImplFactory { + + private ISessionInfo fSessionInfo1 = null; + private ISessionInfo fSessionInfo2 = null; + private IDomainInfo fDomainInfo1 = null; + private IDomainInfo fDomainInfo2 = null; + private IChannelInfo fChannelInfo1 = null; + private IChannelInfo fChannelInfo2 = null; + private IEventInfo fEventInfo1 = null; + private IEventInfo fEventInfo2 = null; + private IEventInfo fEventInfo3 = null; + private IBaseEventInfo fBaseEventInfo1 = null; + private IBaseEventInfo fBaseEventInfo2 = null; + private IUstProviderInfo fUstProviderInfo1 = null; + private IUstProviderInfo fUstProviderInfo2 = null; + + public ModelImplFactory() { + fBaseEventInfo1 = new BaseEventInfo("event1"); + fBaseEventInfo1.setEventType(TraceEventType.UNKNOWN); + fBaseEventInfo1.setLogLevel(TraceLogLevel.TRACE_ERR); + fBaseEventInfo2 = new BaseEventInfo("event2"); + fBaseEventInfo2.setEventType(TraceEventType.TRACEPOINT); + fBaseEventInfo1.setLogLevel(TraceLogLevel.TRACE_DEFAULT); + + fEventInfo1 = new EventInfo("event1"); + fEventInfo1.setEventType(TraceEventType.TRACEPOINT); + fEventInfo1.setState(TraceEnablement.ENABLED); + + fEventInfo2 = new EventInfo("event2"); + fEventInfo2.setEventType(TraceEventType.UNKNOWN); + fEventInfo2.setState(TraceEnablement.DISABLED); + + fEventInfo3 = new EventInfo("event3"); + fEventInfo3.setEventType(TraceEventType.TRACEPOINT); + fEventInfo3.setState(TraceEnablement.DISABLED); + + fUstProviderInfo1 = new UstProviderInfo("myUST1"); + fUstProviderInfo1.setPid(1234); + fUstProviderInfo1.addEvent(fBaseEventInfo1); + + fUstProviderInfo2 = new UstProviderInfo("myUST2"); + fUstProviderInfo2.setPid(2345); + fUstProviderInfo2.addEvent(fBaseEventInfo1); + fUstProviderInfo2.addEvent(fBaseEventInfo2); + + fChannelInfo1 = new ChannelInfo("channel1"); + fChannelInfo1.setSwitchTimer(10L); + fChannelInfo1.setOverwriteMode(true); + fChannelInfo1.setReadTimer(11L); + fChannelInfo1.setState(TraceEnablement.DISABLED); + fChannelInfo1.setNumberOfSubBuffers(12); + fChannelInfo1.setOutputType("splice()"); + fChannelInfo1.setSubBufferSize(13L); + fChannelInfo1.addEvent(fEventInfo1); + + fChannelInfo2 = new ChannelInfo("channel2"); + fChannelInfo2.setSwitchTimer(1L); + fChannelInfo2.setOverwriteMode(false); + fChannelInfo2.setReadTimer(2L); + fChannelInfo2.setState(TraceEnablement.ENABLED); + fChannelInfo2.setNumberOfSubBuffers(3); + fChannelInfo2.setOutputType("mmap()"); + fChannelInfo2.setSubBufferSize(4L); + fChannelInfo2.addEvent(fEventInfo2); + fChannelInfo2.addEvent(fEventInfo3); + + fDomainInfo1 = new DomainInfo("test1"); + fDomainInfo1.addChannel(fChannelInfo1); + + fDomainInfo2 = new DomainInfo("test2"); + fDomainInfo2.addChannel(fChannelInfo1); + fDomainInfo2.addChannel(fChannelInfo2); + + fSessionInfo1 = new SessionInfo("session1"); + fSessionInfo1.setSessionPath("/home/user"); + fSessionInfo1.setSessionState(TraceSessionState.ACTIVE); + fSessionInfo1.addDomain(fDomainInfo1); + + fSessionInfo2 = new SessionInfo("session2"); + fSessionInfo2.setSessionPath("/home/user1"); + fSessionInfo2.setSessionState(TraceSessionState.INACTIVE); + fSessionInfo2.addDomain(fDomainInfo1); + fSessionInfo2.addDomain(fDomainInfo2); + } + + public ISessionInfo getSessionInfo1() { + return fSessionInfo1; + } + + public ISessionInfo getSessionInfo2() { + return fSessionInfo2; + } + + public IDomainInfo getDomainInfo1() { + return fDomainInfo1; + } + + public IDomainInfo getDomainInfo2() { + return fDomainInfo2; + } + + public IChannelInfo getChannel1() { + return fChannelInfo1; + } + + public IChannelInfo getChannel2() { + return fChannelInfo2; + } + + public IEventInfo getEventInfo1() { + return fEventInfo1; + } + + public IEventInfo getEventInfo2() { + return fEventInfo2; + } + + public IEventInfo getEventInfo3() { + return fEventInfo3; + } + + public IBaseEventInfo getBaseEventInfo1() { + return fBaseEventInfo1; + } + + public IBaseEventInfo getBaseEventInfo2() { + return fBaseEventInfo2; + } + + public IUstProviderInfo getUstProviderInfo1() { + return fUstProviderInfo1; + } + + public IUstProviderInfo getUstProviderInfo2() { + return fUstProviderInfo2; + } +} diff --git a/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/impl/SessionInfoTest.java b/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/impl/SessionInfoTest.java new file mode 100644 index 0000000000..3d62d39cb7 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/impl/SessionInfoTest.java @@ -0,0 +1,255 @@ +/********************************************************************** + * 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.lttng.ui.tests.control.model.impl; + +import java.util.LinkedList; +import java.util.List; + +import junit.framework.TestCase; + +import org.eclipse.linuxtools.lttng.ui.views.control.model.IDomainInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.ISessionInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceSessionState; +import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.SessionInfo; + +/** + * The class ChannelInfoTest contains tests for the class {@link SessionInfo}. + * + */ +@SuppressWarnings("nls") +public class SessionInfoTest extends TestCase { + // ------------------------------------------------------------------------ + // Test data + // ------------------------------------------------------------------------ + private ISessionInfo fSessionInfo1 = null; + private ISessionInfo fSessionInfo2 = null; + + private IDomainInfo fDomainInfo1 = null; + private IDomainInfo fDomainInfo2 = null; + + // ------------------------------------------------------------------------ + // Housekeeping + // ------------------------------------------------------------------------ + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + */ + @Override + public void setUp() { + ModelImplFactory factory = new ModelImplFactory(); + fSessionInfo1 = factory.getSessionInfo1(); + fDomainInfo1 = factory.getDomainInfo1(); + fSessionInfo2 = factory.getSessionInfo2(); + fDomainInfo2 = factory.getDomainInfo2(); + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + */ + @Override + public void tearDown() { + } + + // ------------------------------------------------------------------------ + // Tests + // ------------------------------------------------------------------------ + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + /** + * Run the ChannelInfo() constructor test. + * + */ + public void testSessionInfo() { + ISessionInfo result = new SessionInfo("test"); + assertNotNull(result); + + assertEquals("test", result.getName()); + assertEquals("", result.getSessionPath()); + TraceSessionState state = result.getSessionState(); + assertEquals("inactive", state.getInName()); + assertEquals("INACTIVE", state.name()); + assertEquals("INACTIVE", state.toString()); + assertEquals(0, state.ordinal()); + assertEquals(0, result.getDomains().length); + } + + public void testSessionInfoCopy() { + SessionInfo sessionInfo = new SessionInfo((SessionInfo)fSessionInfo1); + + assertEquals(sessionInfo.getName(), fSessionInfo1.getName()); + assertEquals(sessionInfo.getSessionPath(), fSessionInfo1.getSessionPath()); + assertEquals(sessionInfo.getSessionState(), fSessionInfo1.getSessionState()); + + IDomainInfo[] orignalDomains = fSessionInfo1.getDomains(); + IDomainInfo[] resultDomains = sessionInfo.getDomains(); + for (int i = 0; i < orignalDomains.length; i++) { + assertEquals(orignalDomains[i], resultDomains[i]); + } + } + + public void testSessionCopy2() { + try { + SessionInfo session = null; + new SessionInfo(session); + fail("null copy"); + } + catch (IllegalArgumentException e) { + // Success + } + } + + /** + * Run the long getNumberOfSubBuffers() method test. + * + */ + public void testGetAndSetters() { + + // Note that addDomain() has been executed in setUp() + // check get method here + assertEquals(1, fSessionInfo1.getDomains().length); + assertNotNull(fSessionInfo1.getDomains()[0]); + assertEquals(fDomainInfo1, fSessionInfo1.getDomains()[0]); + + ISessionInfo session = new SessionInfo("session"); + List list = new LinkedList(); + list.add(fDomainInfo1); + list.add(fDomainInfo2); + session.setDomains(list); + + IDomainInfo[] result = session.getDomains(); + assertEquals(2, result.length); + assertEquals(fDomainInfo1, result[0]); + assertEquals(fDomainInfo2, result[1]); + + session.setSessionPath("/home/user"); + assertEquals("/home/user", session.getSessionPath()); + + session.setSessionState("active"); + TraceSessionState state = session.getSessionState(); + state = session.getSessionState(); + assertEquals("active", state.getInName()); + assertEquals("ACTIVE", state.name()); + assertEquals("ACTIVE", state.toString()); + assertEquals(1, state.ordinal()); + + session.setSessionState("inactive"); + state = session.getSessionState(); + assertEquals("inactive", state.getInName()); + assertEquals("INACTIVE", state.name()); + assertEquals("INACTIVE", state.toString()); + assertEquals(0, state.ordinal()); + + session.setSessionState("test"); + state = session.getSessionState(); + assertEquals("inactive", state.getInName()); + assertEquals("INACTIVE", state.name()); + assertEquals("INACTIVE", state.toString()); + assertEquals(0, state.ordinal()); + + session.setSessionState(TraceSessionState.ACTIVE); + state = session.getSessionState(); + assertEquals("active", state.getInName()); + assertEquals("ACTIVE", state.name()); + assertEquals("ACTIVE", state.toString()); + assertEquals(1, state.ordinal()); + + session.setSessionState(TraceSessionState.INACTIVE); + state = session.getSessionState(); + assertEquals("inactive", state.getInName()); + assertEquals("INACTIVE", state.name()); + assertEquals("INACTIVE", state.toString()); + assertEquals(0, state.ordinal()); + } + + public void testToString_1() { + ISessionInfo fixture = new SessionInfo("sessionName"); + + String result = fixture.toString(); + + // add additional test code here + assertEquals("[SessionInfo([TraceInfo(Name=sessionName)],State=INACTIVE,Domains=)]", result); + } + + /** + * Run the String toString() method test. + * + */ + public void testToString_2() { + String result = fSessionInfo1.toString(); + + // add additional test code here + assertEquals("[SessionInfo([TraceInfo(Name=session1)],State=ACTIVE,Domains=[DomainInfo([TraceInfo(Name=test1)],Channels=[ChannelInfo([TraceInfo(Name=channel1)],State=DISABLED,OverwriteMode=true,SubBuffersSize=13,NumberOfSubBuffers=12,SwitchTimer=10,ReadTimer=11,output=splice(),Events=[EventInfo([BaseEventInfo([TraceInfo(Name=event1)],type=TRACEPOINT,level=TRACE_DEFAULT)],State=ENABLED)])])])]", result); + } + + // ------------------------------------------------------------------------ + // equals + // ------------------------------------------------------------------------ + + public void testEqualsReflexivity() { + assertTrue("equals", fSessionInfo1.equals(fSessionInfo1)); + assertTrue("equals", fSessionInfo2.equals(fSessionInfo2)); + + assertTrue("equals", !fSessionInfo1.equals(fSessionInfo2)); + assertTrue("equals", !fSessionInfo2.equals(fSessionInfo1)); + } + + public void testEqualsSymmetry() { + SessionInfo event1 = new SessionInfo((SessionInfo)fSessionInfo1); + SessionInfo event2 = new SessionInfo((SessionInfo)fSessionInfo2); + + assertTrue("equals", event1.equals(fSessionInfo1)); + assertTrue("equals", fSessionInfo1.equals(event1)); + + assertTrue("equals", event2.equals(fSessionInfo2)); + assertTrue("equals", fSessionInfo2.equals(event2)); + } + + public void testEqualsTransivity() { + SessionInfo channel1 = new SessionInfo((SessionInfo)fSessionInfo1); + SessionInfo channel2 = new SessionInfo((SessionInfo)fSessionInfo1); + SessionInfo channel3 = new SessionInfo((SessionInfo)fSessionInfo1); + + assertTrue("equals", channel1.equals(channel2)); + assertTrue("equals", channel2.equals(channel3)); + assertTrue("equals", channel1.equals(channel3)); + } + + public void testEqualsNull() throws Exception { + assertTrue("equals", !fSessionInfo1.equals(null)); + assertTrue("equals", !fSessionInfo2.equals(null)); + } + + // ------------------------------------------------------------------------ + // hashCode + // ------------------------------------------------------------------------ + + public void testHashCode() { + SessionInfo channel1 = new SessionInfo((SessionInfo)fSessionInfo1); + SessionInfo channel2 = new SessionInfo((SessionInfo)fSessionInfo2); + + assertTrue("hashCode", fSessionInfo1.hashCode() == channel1.hashCode()); + assertTrue("hashCode", fSessionInfo2.hashCode() == channel2.hashCode()); + + assertTrue("hashCode", fSessionInfo1.hashCode() != channel2.hashCode()); + assertTrue("hashCode", fSessionInfo2.hashCode() != channel1.hashCode()); + }} \ No newline at end of file diff --git a/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/impl/TraceInfoTest.java b/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/impl/TraceInfoTest.java new file mode 100644 index 0000000000..a4b270286a --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/impl/TraceInfoTest.java @@ -0,0 +1,182 @@ +/********************************************************************** + * 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.lttng.ui.tests.control.model.impl; + +import junit.framework.TestCase; + +import org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceInfo; + +/** + * The class TraceInfoTest contains test for the class {@link TraceInfo}. + */ +@SuppressWarnings("nls") +public class TraceInfoTest extends TestCase { + + // ------------------------------------------------------------------------ + // Test data + // ------------------------------------------------------------------------ + private ITraceInfo fTraceInfo1 = null; + private ITraceInfo fTraceInfo2 = null; + + + // ------------------------------------------------------------------------ + // Housekeeping + // ------------------------------------------------------------------------ + /** + * Perform pre-test initialization. + * + * @throws Exception if the initialization fails for some reason + * + */ + @Override + public void setUp() throws Exception { + fTraceInfo1 = new TraceInfo("event1"); + fTraceInfo2 = new TraceInfo("event2"); + } + + /** + * Perform post-test clean-up. + * + * @throws Exception if the clean-up fails for some reason + * + */ + @Override + public void tearDown() throws Exception { + } + + // ------------------------------------------------------------------------ + // Tests + // ------------------------------------------------------------------------ + + /** + * Run the BaseEventInfo() constructor test. + * + */ + public void testTraceInfo() { + TraceInfo fixture = new TraceInfo("event"); + assertNotNull(fixture); + + assertEquals("event", fixture.getName()); + } + + /** + * Test Copy Constructor + */ + public void testTraceInfo2() { + try { + String name = null; + new TraceInfo(name); + fail("null name in custructor"); + } + catch (IllegalArgumentException e) { + // Success + } + } + + /** + * Test Copy Constructor + */ + public void testTraceInfoCopy() { + TraceInfo info = new TraceInfo((TraceInfo)fTraceInfo1); + + assertEquals(fTraceInfo1.getName(), info.getName()); + } + + /** + * Test Copy Constructor + */ + public void testTraceCopy2() { + try { + TraceInfo info = null; + new TraceInfo(info); + fail("null copy"); + } + catch (IllegalArgumentException e) { + // Success + } + } + + /** + * Run the void setEventType(String) method test. + * + */ + public void testSetName() { + TraceInfo fixture = new TraceInfo("event"); + fixture.setName("newName"); + assertEquals("newName", fixture.getName()); + } + + /** + * Run the String toString() method test. + * + */ + public void testToString_1() { + String result = fTraceInfo1.toString(); + + // add additional test code here + assertEquals("[TraceInfo(Name=event1)]", result); + } + + // ------------------------------------------------------------------------ + // equals + // ------------------------------------------------------------------------ + + public void testEqualsReflexivity() { + assertTrue("equals", fTraceInfo1.equals(fTraceInfo1)); + assertTrue("equals", fTraceInfo2.equals(fTraceInfo2)); + + assertTrue("equals", !fTraceInfo1.equals(fTraceInfo2)); + assertTrue("equals", !fTraceInfo2.equals(fTraceInfo1)); + } + + public void testEqualsSymmetry() { + TraceInfo info1 = new TraceInfo((TraceInfo)fTraceInfo1); + TraceInfo info2 = new TraceInfo((TraceInfo)fTraceInfo2); + + assertTrue("equals", info1.equals(fTraceInfo1)); + assertTrue("equals", fTraceInfo1.equals(info1)); + + assertTrue("equals", info2.equals(fTraceInfo2)); + assertTrue("equals", fTraceInfo2.equals(info2)); + } + + public void testEqualsTransivity() { + TraceInfo info1 = new TraceInfo((TraceInfo)fTraceInfo1); + TraceInfo info2 = new TraceInfo((TraceInfo)fTraceInfo1); + TraceInfo info3 = new TraceInfo((TraceInfo)fTraceInfo1); + + assertTrue("equals", info1.equals(info2)); + assertTrue("equals", info2.equals(info3)); + assertTrue("equals", info1.equals(info3)); + } + + public void testEqualsNull() { + assertTrue("equals", !fTraceInfo1.equals(null)); + assertTrue("equals", !fTraceInfo2.equals(null)); + } + + // ------------------------------------------------------------------------ + // hashCode + // ------------------------------------------------------------------------ + + public void testHashCode() { + TraceInfo info1 = new TraceInfo((TraceInfo)fTraceInfo1); + TraceInfo info2 = new TraceInfo((TraceInfo)fTraceInfo2); + + assertTrue("hashCode", fTraceInfo1.hashCode() == info1.hashCode()); + assertTrue("hashCode", fTraceInfo2.hashCode() == info2.hashCode()); + + assertTrue("hashCode", fTraceInfo1.hashCode() != info2.hashCode()); + assertTrue("hashCode", fTraceInfo2.hashCode() != info1.hashCode()); + } +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/impl/UstProviderInfoTest.java b/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/impl/UstProviderInfoTest.java new file mode 100644 index 0000000000..55f9787644 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/model/impl/UstProviderInfoTest.java @@ -0,0 +1,229 @@ +/********************************************************************** + * 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.lttng.ui.tests.control.model.impl; + +import java.util.LinkedList; +import java.util.List; + +import junit.framework.TestCase; + +import org.eclipse.linuxtools.lttng.ui.views.control.model.IBaseEventInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.IUstProviderInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.BaseEventInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.UstProviderInfo; + +/** + * The class ChannelInfoTest contains tests for the class {@link UstProviderInfo}. + * + */ +@SuppressWarnings("nls") +public class UstProviderInfoTest extends TestCase { + // ------------------------------------------------------------------------ + // Test data + // ------------------------------------------------------------------------ + private IUstProviderInfo fUstProviderInfo1 = null; + private IUstProviderInfo fUstProviderInfo2 = null; + + private IBaseEventInfo fEventInfo1 = null; + private IBaseEventInfo fEventInfo2 = null; + + // ------------------------------------------------------------------------ + // Housekeeping + // ------------------------------------------------------------------------ + + /** + * Perform pre-test initialization. + * + * @throws Exception + * if the initialization fails for some reason + * + */ + @Override + public void setUp() { + ModelImplFactory factory = new ModelImplFactory(); + fUstProviderInfo1 = factory.getUstProviderInfo1(); + fUstProviderInfo2 = factory.getUstProviderInfo2(); + fEventInfo1 = factory.getBaseEventInfo1(); + fEventInfo1 = factory.getBaseEventInfo2(); + } + + /** + * Perform post-test clean-up. + * + * @throws Exception + * if the clean-up fails for some reason + * + */ + @Override + public void tearDown() { + } + + // ------------------------------------------------------------------------ + // Tests + // ------------------------------------------------------------------------ + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + /** + * Run the UstProviderInfo() constructor test. + * + */ + public void testUstProviderInfo() { + IUstProviderInfo result = new UstProviderInfo("test"); + assertNotNull(result); + + assertEquals("test", result.getName()); + assertEquals(0, result.getPid()); + assertEquals(0, result.getEvents().length); + } + + public void testUstProviderInfoCopy() { + IUstProviderInfo providerInf = new UstProviderInfo((UstProviderInfo)fUstProviderInfo1); + + assertEquals(fUstProviderInfo1.getName(), providerInf.getName()); + assertEquals(fUstProviderInfo1.getPid(), providerInf.getPid()); + assertEquals(fUstProviderInfo1.getEvents().length, providerInf.getEvents().length); + + IBaseEventInfo[] orignalEvents = fUstProviderInfo1.getEvents(); + IBaseEventInfo[] resultEvents = providerInf.getEvents(); + for (int i = 0; i < orignalEvents.length; i++) { + assertEquals(orignalEvents[i], resultEvents[i]); + } + } + + public void testUstProviderCopy2() { + try { + UstProviderInfo providerInfo = null; + new UstProviderInfo(providerInfo); + fail("null copy"); + } + catch (IllegalArgumentException e) { + // Success + } + } + + /** + * Run the IEventInfo[] getEvents() method test. + * + */ + public void testGetAndSetters() { + IUstProviderInfo fixture = new UstProviderInfo("test"); + fixture.setPid(2468); + + // add an event + IBaseEventInfo event = new BaseEventInfo("event"); + fixture.addEvent(event); + + // Verify the stored events + IBaseEventInfo[] result = fixture.getEvents(); + + assertNotNull(result); + assertEquals(1, result.length); + assertNotNull(result[0]); + assertTrue(event.equals(result[0])); + + assertEquals(2468, fixture.getPid()); + } + + /** + * Run the void setEvents(List) method test. + * + */ + public void testSetEvents_1() { + UstProviderInfo fixture = new UstProviderInfo("test"); + fixture.setPid(2468); + List events = new LinkedList(); + events.add(fEventInfo1); + events.add(fEventInfo2); + fixture.setEvents(events); + + IBaseEventInfo[] infos = fixture.getEvents(); + + assertEquals(events.size(), infos.length); + + for (int i = 0; i < infos.length; i++) { + assertEquals(events.get(i), infos[i]); + } + } + + public void testToString_1() { + UstProviderInfo fixture = new UstProviderInfo("test"); + fixture.setPid(2468); + String result = fixture.toString(); + + assertEquals("[EventInfo([TraceInfo(Name=test)],PID=2468,Events=None)]", result); + } + + /** + * Run the String toString() method test. + * + */ + public void testToString_2() { + String result = fUstProviderInfo2.toString(); + assertEquals("[EventInfo([TraceInfo(Name=myUST2)],PID=2345,Events=[BaseEventInfo([TraceInfo(Name=event1)],type=UNKNOWN,level=TRACE_DEFAULT)][BaseEventInfo([TraceInfo(Name=event2)],type=TRACEPOINT,level=TRACE_DEFAULT)])]", result); + } + + // ------------------------------------------------------------------------ + // equals + // ------------------------------------------------------------------------ + + public void testEqualsReflexivity() { + assertTrue("equals", fUstProviderInfo1.equals(fUstProviderInfo1)); + assertTrue("equals", fUstProviderInfo2.equals(fUstProviderInfo2)); + + assertTrue("equals", !fUstProviderInfo1.equals(fUstProviderInfo2)); + assertTrue("equals", !fUstProviderInfo2.equals(fUstProviderInfo1)); + } + + public void testEqualsSymmetry() { + UstProviderInfo event1 = new UstProviderInfo((UstProviderInfo)fUstProviderInfo1); + UstProviderInfo event2 = new UstProviderInfo((UstProviderInfo)fUstProviderInfo2); + + assertTrue("equals", event1.equals(fUstProviderInfo1)); + assertTrue("equals", fUstProviderInfo1.equals(event1)); + + assertTrue("equals", event2.equals(fUstProviderInfo2)); + assertTrue("equals", fUstProviderInfo2.equals(event2)); + } + + public void testEqualsTransivity() { + UstProviderInfo UstProvider1 = new UstProviderInfo((UstProviderInfo)fUstProviderInfo1); + UstProviderInfo UstProvider2 = new UstProviderInfo((UstProviderInfo)fUstProviderInfo1); + UstProviderInfo UstProvider3 = new UstProviderInfo((UstProviderInfo)fUstProviderInfo1); + + assertTrue("equals", UstProvider1.equals(UstProvider2)); + assertTrue("equals", UstProvider2.equals(UstProvider3)); + assertTrue("equals", UstProvider1.equals(UstProvider3)); + } + + public void testEqualsNull() throws Exception { + assertTrue("equals", !fUstProviderInfo1.equals(null)); + assertTrue("equals", !fUstProviderInfo2.equals(null)); + } + + // ------------------------------------------------------------------------ + // hashCode + // ------------------------------------------------------------------------ + + public void testHashCode() { + UstProviderInfo UstProvider1 = new UstProviderInfo((UstProviderInfo)fUstProviderInfo1); + UstProviderInfo UstProvider2 = new UstProviderInfo((UstProviderInfo)fUstProviderInfo2); + + assertTrue("hashCode", fUstProviderInfo1.hashCode() == UstProvider1.hashCode()); + assertTrue("hashCode", fUstProviderInfo2.hashCode() == UstProvider2.hashCode()); + + assertTrue("hashCode", fUstProviderInfo1.hashCode() != UstProvider2.hashCode()); + assertTrue("hashCode", fUstProviderInfo2.hashCode() != UstProvider1.hashCode()); + } +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/service/AllTests.java b/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/service/AllTests.java new file mode 100644 index 0000000000..f8867947c2 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/service/AllTests.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2011 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.lttng.ui.tests.control.service; + +import junit.framework.Test; +import junit.framework.TestSuite; + +public class AllTests { + + public static Test suite() { + TestSuite suite = new TestSuite(AllTests.class.getName()); + //$JUnit-BEGIN$ + suite.addTestSuite(LTTngControlServiceTest.class); + //$JUnit-END$ + return suite; + } +} diff --git a/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/service/LTTngControlServiceTest.java b/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/service/LTTngControlServiceTest.java new file mode 100644 index 0000000000..1712657782 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui.tests/src/org/eclipse/linuxtools/lttng/ui/tests/control/service/LTTngControlServiceTest.java @@ -0,0 +1,352 @@ +/********************************************************************** + * 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.lttng.ui.tests.control.service; + +import java.util.List; + +import junit.framework.TestCase; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.linuxtools.lttng.stubs.service.CommandShellFactory; +import org.eclipse.linuxtools.lttng.ui.views.control.model.IBaseEventInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.IChannelInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.IDomainInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.IEventInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.ISessionInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.IUstProviderInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceEnablement; +import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceEventType; +import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceLogLevel; +import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceSessionState; +import org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService; +import org.eclipse.linuxtools.lttng.ui.views.control.service.LTTngControlService; +/** + * The class LTTngControlServiceTest contains test for the class {@link LTTngControlService}. + */ +@SuppressWarnings("nls") +public class LTTngControlServiceTest extends TestCase { + // ------------------------------------------------------------------------ + // Test data + // ------------------------------------------------------------------------ + private CommandShellFactory fShellFactory; + + // ------------------------------------------------------------------------ + // Static methods + // ------------------------------------------------------------------------ + + // ------------------------------------------------------------------------ + // Housekeeping + // ------------------------------------------------------------------------ + /** + * Perform pre-test initialization. + * + * @throws Exception if the initialization fails for some reason + * + */ + @Override + public void setUp() throws Exception { + super.setUp(); + fShellFactory = CommandShellFactory.getInstance(); + } + + /** + * Perform post-test clean-up. + * + * @throws Exception if the clean-up fails for some reason + * + */ + @Override + public void tearDown() throws Exception { + } + + // ------------------------------------------------------------------------ + // Test Cases + // ------------------------------------------------------------------------ + + public void testGetSessionNames() { + try { + ILttngControlService service = new LTTngControlService(fShellFactory.getShellForLttngNotExistsShell()); + service.getSessionNames(); + fail("No exeption thrown"); + + } catch (ExecutionException e) { + // success + } + } + + public void testGetSessionNames1() { + try { + ILttngControlService service = new LTTngControlService(fShellFactory.getShellForNoSessionNames()); + String[] result = service.getSessionNames(); + + assertNotNull(result); + assertEquals(0, result.length); + + } catch (ExecutionException e) { + fail(e.toString()); + } + } + + public void testGetSessionNames2() { + try { + ILttngControlService service = new LTTngControlService(fShellFactory.getShellForSessionNames()); + String[] result = service.getSessionNames(); + + assertNotNull(result); + assertEquals(2, result.length); + assertEquals("mysession1", result[0]); + assertEquals("mysession", result[1]); + + } catch (ExecutionException e) { + fail(e.toString()); + } + } + + public void testGetSessionNotExist() { + try { + ILttngControlService service = new LTTngControlService(fShellFactory.getShellForSessionNotExists()); + service.getSessionNames(); + fail("No exeption thrown"); + + } catch (ExecutionException e) { + // success + } + } + + public void testGetSessionNameGarbage() { + try { + ILttngControlService service = new LTTngControlService(fShellFactory.getShellForSessionGarbage()); + String[] result = service.getSessionNames(); + + assertNotNull(result); + assertEquals(0, result.length); + + } catch (ExecutionException e) { + fail(e.toString()); + } + } + + public void testGetSession1() { + try { + ILttngControlService service = new LTTngControlService(fShellFactory.getShellForSessionNames()); + ISessionInfo session = service.getSession("mysession"); + + // Verify Session + assertNotNull(session); + assertEquals("mysession", session.getName()); + assertEquals("/home/user/lttng-traces/mysession-20120129-084256", session.getSessionPath()); + assertEquals(TraceSessionState.ACTIVE, session.getSessionState()); + + IDomainInfo[] domains = session.getDomains(); + assertNotNull(domains); + assertEquals(2, domains.length); + + // Verify Kernel domain + assertEquals("Kernel", domains[0].getName()); + IChannelInfo[] channels = domains[0].getChannels(); + assertNotNull(channels); + assertEquals(2, channels.length); + + // Verify Kernel's channel0 + assertEquals("channel0", channels[0].getName()); + assertEquals(4, channels[0].getNumberOfSubBuffers()); + assertEquals("splice()", channels[0].getOutputType()); + assertEquals(false, channels[0].isOverwriteMode()); + assertEquals(200, channels[0].getReadTimer()); + assertEquals(TraceEnablement.ENABLED, channels[0].getState()); + assertEquals(262144, channels[0].getSubBufferSize()); + assertEquals(0, channels[0].getSwitchTimer()); + + // Verify event info + IEventInfo[] channel0Events = channels[0].getEvents(); + assertNotNull(channel0Events); + assertEquals(2, channel0Events.length); + assertEquals("block_rq_remap", channel0Events[0].getName()); + assertEquals(TraceLogLevel.TRACE_EMERG, channel0Events[0].getLogLevel()); + assertEquals(TraceEventType.TRACEPOINT, channel0Events[0].getEventType()); + assertEquals(TraceEnablement.ENABLED, channel0Events[0].getState()); + + assertEquals("block_bio_remap", channel0Events[1].getName()); + assertEquals(TraceLogLevel.TRACE_EMERG, channel0Events[1].getLogLevel()); + assertEquals(TraceEventType.TRACEPOINT, channel0Events[1].getEventType()); + assertEquals(TraceEnablement.DISABLED, channel0Events[1].getState()); + + // Verify Kernel's channel1 + assertEquals("channel1", channels[1].getName()); + assertEquals(4, channels[1].getNumberOfSubBuffers()); + assertEquals("splice()", channels[1].getOutputType()); + assertEquals(true, channels[1].isOverwriteMode()); + assertEquals(400, channels[1].getReadTimer()); + assertEquals(TraceEnablement.DISABLED, channels[1].getState()); + assertEquals(524288, channels[1].getSubBufferSize()); + assertEquals(100, channels[1].getSwitchTimer()); + + // Verify event info + IEventInfo[] channel1Events = channels[1].getEvents(); + assertEquals(0, channel1Events.length); + + // Verify domain UST global + assertEquals("UST global", domains[1].getName()); + + IChannelInfo[] ustChannels = domains[1].getChannels(); + + // Verify UST global's mychannel1 + assertEquals("mychannel1", ustChannels[0].getName()); + assertEquals(8, ustChannels[0].getNumberOfSubBuffers()); + assertEquals("mmap()", ustChannels[0].getOutputType()); + assertEquals(true, ustChannels[0].isOverwriteMode()); + assertEquals(100, ustChannels[0].getReadTimer()); + assertEquals(TraceEnablement.DISABLED, ustChannels[0].getState()); + assertEquals(8192, ustChannels[0].getSubBufferSize()); + assertEquals(200, ustChannels[0].getSwitchTimer()); + + // Verify event info + IEventInfo[] ustEvents = ustChannels[0].getEvents(); + assertEquals(0, ustEvents.length); + + // Verify UST global's channel0 + assertEquals("channel0", ustChannels[1].getName()); + assertEquals(4, ustChannels[1].getNumberOfSubBuffers()); + assertEquals("mmap()", ustChannels[1].getOutputType()); + assertEquals(false, ustChannels[1].isOverwriteMode()); + assertEquals(200, ustChannels[1].getReadTimer()); + assertEquals(TraceEnablement.ENABLED, ustChannels[1].getState()); + assertEquals(4096, ustChannels[1].getSubBufferSize()); + assertEquals(0, ustChannels[1].getSwitchTimer()); + + // Verify event info + ustEvents = ustChannels[1].getEvents(); + assertEquals(2, ustEvents.length); + + assertEquals("ust_tests_hello:tptest_sighandler", ustEvents[0].getName()); + assertEquals(TraceLogLevel.TRACE_DEFAULT, ustEvents[0].getLogLevel()); + assertEquals(TraceEventType.TRACEPOINT, ustEvents[0].getEventType()); + assertEquals(TraceEnablement.DISABLED, ustEvents[0].getState()); + + assertEquals("*", ustEvents[1].getName()); + assertEquals(TraceLogLevel.TRACE_EMERG, ustEvents[1].getLogLevel()); + assertEquals(TraceEventType.TRACEPOINT, ustEvents[1].getEventType()); + assertEquals(TraceEnablement.ENABLED, ustEvents[1].getState()); + + // next session (no detailed information available) + session = service.getSession("mysession1"); + assertNotNull(session); + assertEquals("mysession1", session.getName()); + assertEquals("/home/user/lttng-traces/mysession1-20120203-133225", session.getSessionPath()); + assertEquals(TraceSessionState.INACTIVE, session.getSessionState()); + + domains = session.getDomains(); + assertNotNull(domains); + assertEquals(0, domains.length); + } catch (ExecutionException e) { + fail(e.toString()); + } + } + + public void testGetKernelProvider() { + try { + ILttngControlService service = new LTTngControlService(fShellFactory.getShellForSessionNames()); + List events = service.getKernelProvider(); + + // Verify event info + assertNotNull(events); + assertEquals(3, events.size()); + + IBaseEventInfo baseEventInfo = (IBaseEventInfo) events.get(0); + assertNotNull(baseEventInfo); + assertEquals("sched_kthread_stop", baseEventInfo.getName()); + assertEquals(TraceLogLevel.TRACE_EMERG, baseEventInfo.getLogLevel()); + assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType()); + + baseEventInfo = (IBaseEventInfo) events.get(1); + assertEquals("sched_kthread_stop_ret", baseEventInfo.getName()); + assertEquals(TraceLogLevel.TRACE_EMERG, baseEventInfo.getLogLevel()); + assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType()); + + baseEventInfo = (IBaseEventInfo) events.get(2); + assertEquals("sched_wakeup_new", baseEventInfo.getName()); + assertEquals(TraceLogLevel.TRACE_EMERG, baseEventInfo.getLogLevel()); + assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType()); + + } catch (ExecutionException e) { + fail(e.toString()); + } + } + + public void testGetUstProvider() { + try { + ILttngControlService service = new LTTngControlService(fShellFactory.getShellForSessionNames()); + List providers = service.getUstProvider(); + + // Check all providers + assertNotNull(providers); + assertEquals(2, providers.size()); + + //Verify first provider + assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello", providers.get(0).getName()); + assertEquals(9379, providers.get(0).getPid()); + + // Verify event info + IBaseEventInfo[] events = providers.get(0).getEvents(); + assertNotNull(events); + assertEquals(2, events.length); + + IBaseEventInfo baseEventInfo = (IBaseEventInfo) events[0]; + assertNotNull(baseEventInfo); + assertEquals("ust_tests_hello:tptest_sighandler", baseEventInfo.getName()); + assertEquals(TraceLogLevel.TRACE_MODULE, baseEventInfo.getLogLevel()); + assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType()); + + baseEventInfo = (IBaseEventInfo) events[1]; + assertEquals("ust_tests_hello:tptest", baseEventInfo.getName()); + assertEquals(TraceLogLevel.TRACE_INFO, baseEventInfo.getLogLevel()); + assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType()); + + //Verify second provider + assertEquals("/home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello", providers.get(1).getName()); + assertEquals(4852, providers.get(1).getPid()); + + // Verify event info + events = providers.get(1).getEvents(); + assertNotNull(events); + assertEquals(2, events.length); + + baseEventInfo = (IBaseEventInfo) events[0]; + assertNotNull(baseEventInfo); + assertEquals("ust_tests_hello:tptest_sighandler", baseEventInfo.getName()); + assertEquals(TraceLogLevel.TRACE_WARNING, baseEventInfo.getLogLevel()); + assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType()); + + baseEventInfo = (IBaseEventInfo) events[1]; + assertEquals("ust_tests_hello:tptest", baseEventInfo.getName()); + assertEquals(TraceLogLevel.TRACE_FUNCTION, baseEventInfo.getLogLevel()); + assertEquals(TraceEventType.TRACEPOINT, baseEventInfo.getEventType()); + + } catch (ExecutionException e) { + fail(e.toString()); + } + } + + public void testUstProvider2() { + try { + ILttngControlService service = new LTTngControlService(fShellFactory.getShellForNoUstProvider()); + List providers = service.getUstProvider(); + + assertNotNull(providers); + assertEquals(0, providers.size()); + + } catch (ExecutionException e) { + fail(e.toString()); + } + } + +} diff --git a/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/service/CommandShellFactory.java b/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/service/CommandShellFactory.java new file mode 100644 index 0000000000..03679efec2 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/service/CommandShellFactory.java @@ -0,0 +1,47 @@ +package org.eclipse.linuxtools.lttng.stubs.service; + +import org.eclipse.linuxtools.lttng.stubs.service.shells.GetSessionGarbageShell; +import org.eclipse.linuxtools.lttng.stubs.service.shells.LttngNotExistsShell; +import org.eclipse.linuxtools.lttng.stubs.service.shells.NoSessionNamesShell; +import org.eclipse.linuxtools.lttng.stubs.service.shells.NoUstProviderShell; +import org.eclipse.linuxtools.lttng.stubs.service.shells.SessionNotExistsShell; +import org.eclipse.linuxtools.lttng.stubs.service.shells.SessionNamesShell; +import org.eclipse.linuxtools.lttng.ui.views.control.service.ICommandShell; + +public class CommandShellFactory { + + public static final int GET_SESSION_NAMES_COMMAND_SHELL = 0; + + private static CommandShellFactory fInstance = null; + + public static CommandShellFactory getInstance() { + if (fInstance == null) { + fInstance = new CommandShellFactory(); + } + return fInstance; + } + + public ICommandShell getShellForNoSessionNames() { + return new NoSessionNamesShell(); + } + + public ICommandShell getShellForSessionNames() { + return new SessionNamesShell(); + } + + public ICommandShell getShellForLttngNotExistsShell() { + return new LttngNotExistsShell(); + } + + public ICommandShell getShellForSessionNotExists() { + return new SessionNotExistsShell(); + } + + public ICommandShell getShellForSessionGarbage() { + return new GetSessionGarbageShell(); + } + + public ICommandShell getShellForNoUstProvider() { + return new NoUstProviderShell(); + } +} diff --git a/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/service/TestRemoteSystemProxy.java b/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/service/TestRemoteSystemProxy.java new file mode 100644 index 0000000000..92efecaf9a --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/service/TestRemoteSystemProxy.java @@ -0,0 +1,61 @@ +package org.eclipse.linuxtools.lttng.stubs.service; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.Status; +import org.eclipse.linuxtools.lttng.stubs.service.shells.TestCommandShell; +import org.eclipse.linuxtools.lttng.ui.views.control.remote.IRemoteSystemProxy; +import org.eclipse.linuxtools.lttng.ui.views.control.service.ICommandShell; +import org.eclipse.rse.core.model.IRSECallback; +import org.eclipse.rse.core.subsystems.ICommunicationsListener; +import org.eclipse.rse.core.subsystems.ISubSystem; +import org.eclipse.rse.services.shells.IShellService; +import org.eclipse.rse.services.terminals.ITerminalService; + +public class TestRemoteSystemProxy implements IRemoteSystemProxy { + + @Override + public IShellService getShellService() { + return null; + } + + @Override + public ITerminalService getTerminalService() { + return null; + } + + @Override + public ISubSystem getShellServiceSubSystem() { + return null; + } + + @Override + public ISubSystem getTerminalServiceSubSystem() { + return null; + } + + @Override + public void connect(IRSECallback callback) throws ExecutionException { + if (callback != null) { + callback.done(Status.OK_STATUS, null); + } + } + + @Override + public void disconnect() throws ExecutionException { + } + + @Override + public ICommandShell createCommandShell() throws ExecutionException { + ICommandShell shell = CommandShellFactory.getInstance().getShellForSessionNames(); + return shell; + } + + @Override + public void addCommunicationListener(ICommunicationsListener listener) { + } + + @Override + public void removeCommunicationListener(ICommunicationsListener listener) { + } + +} diff --git a/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/service/shells/GetSessionGarbageShell.java b/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/service/shells/GetSessionGarbageShell.java new file mode 100644 index 0000000000..478b4d5d60 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/service/shells/GetSessionGarbageShell.java @@ -0,0 +1,20 @@ +package org.eclipse.linuxtools.lttng.stubs.service.shells; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.linuxtools.lttng.ui.views.control.service.CommandResult; +import org.eclipse.linuxtools.lttng.ui.views.control.service.ICommandResult; + +public class GetSessionGarbageShell extends TestCommandShell { + @SuppressWarnings("nls") + @Override + public ICommandResult executeCommand(String command, IProgressMonitor monitor, boolean checkReturnValue) throws ExecutionException { + String[] output = new String[2]; + //Session test not found + //Error: Session name not found + output[0] = String.valueOf("asdfaereafsdcv 12333456434&*89**(())(^%$*"); + output[1] = String.valueOf("@#$%^&*()@#$%^&*()0834523094578kj;djkfs"); + return new CommandResult(0, output); + } +} + diff --git a/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/service/shells/LttngNotExistsShell.java b/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/service/shells/LttngNotExistsShell.java new file mode 100644 index 0000000000..66aa0fd0c9 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/service/shells/LttngNotExistsShell.java @@ -0,0 +1,17 @@ +package org.eclipse.linuxtools.lttng.stubs.service.shells; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.linuxtools.lttng.ui.views.control.service.CommandResult; +import org.eclipse.linuxtools.lttng.ui.views.control.service.ICommandResult; + +public class LttngNotExistsShell extends TestCommandShell { + + @SuppressWarnings("nls") + @Override + public ICommandResult executeCommand(String command, IProgressMonitor monitor, boolean checkReturnValue) throws ExecutionException { + String[] output = new String[1]; + output[0] = String.valueOf("Command not found"); + return new CommandResult(1, output); + } +} diff --git a/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/service/shells/NoSessionNamesShell.java b/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/service/shells/NoSessionNamesShell.java new file mode 100644 index 0000000000..de933f0ad8 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/service/shells/NoSessionNamesShell.java @@ -0,0 +1,17 @@ +package org.eclipse.linuxtools.lttng.stubs.service.shells; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.linuxtools.lttng.ui.views.control.service.CommandResult; +import org.eclipse.linuxtools.lttng.ui.views.control.service.ICommandResult; + +public class NoSessionNamesShell extends TestCommandShell { + + @SuppressWarnings("nls") + @Override + public ICommandResult executeCommand(String command, IProgressMonitor monitor, boolean checkReturnValue) throws ExecutionException { + String[] output = new String[1]; + output[0] = String.valueOf("Error: No Session found"); + return new CommandResult(1, output); + } +} diff --git a/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/service/shells/NoUstProviderShell.java b/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/service/shells/NoUstProviderShell.java new file mode 100644 index 0000000000..d02935a1dc --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/service/shells/NoUstProviderShell.java @@ -0,0 +1,24 @@ +package org.eclipse.linuxtools.lttng.stubs.service.shells; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.linuxtools.lttng.ui.views.control.service.CommandResult; +import org.eclipse.linuxtools.lttng.ui.views.control.service.ICommandResult; + +public class NoUstProviderShell extends TestCommandShell { + @SuppressWarnings("nls") + @Override + public ICommandResult executeCommand(String command, IProgressMonitor monitor, boolean checkReturnValue) throws ExecutionException { + String[] output = new String[4]; + //Session test not found + //Error: Session name not found + output[0] = String.valueOf("UST events:"); + output[1] = String.valueOf("-------------"); + output[2] = String.valueOf("None"); + output[3] = String.valueOf(""); + CommandResult result = new CommandResult(0, output); + result.setResult(0); + return result; + } +} + diff --git a/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/service/shells/SessionNamesShell.java b/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/service/shells/SessionNamesShell.java new file mode 100644 index 0000000000..e5a208d486 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/service/shells/SessionNamesShell.java @@ -0,0 +1,130 @@ +package org.eclipse.linuxtools.lttng.stubs.service.shells; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.linuxtools.lttng.ui.views.control.service.CommandResult; +import org.eclipse.linuxtools.lttng.ui.views.control.service.ICommandResult; + +public class SessionNamesShell extends TestCommandShell { + @SuppressWarnings("nls") + @Override + public ICommandResult executeCommand(String command, IProgressMonitor monitor, boolean checkReturnValue) throws ExecutionException { + if ("lttng list ".equals(command)) { + String[] output = new String[5]; + output[0] = String.valueOf("Available tracing sessions:"); + output[1] = String.valueOf(" 1) mysession1 (/home/user/lttng-traces/mysession1-20120123-083928) [inactive]"); + output[2] = String.valueOf(" 2) mysession (/home/user/lttng-traces/mysession-20120123-083318) [inactive]"); + output[3] = String.valueOf(""); + output[4] = String.valueOf(" Use lttng list for more details"); + // test constructor with null pointer parameter + CommandResult result = new CommandResult(0, null); + // test setOutput!!! + result.setOutput(output); + return result; + } else if ("lttng list mysession".equals(command)) { + List list = new ArrayList(); + list.add("Tracing session mysession: [active]"); + list.add(" Trace path: /home/user/lttng-traces/mysession-20120129-084256"); + list.add(""); + list.add("=== Domain: Kernel ==="); + list.add(""); + list.add("Channels:"); + list.add("-------------"); + list.add("- channel0: [enabled]"); + list.add(""); + list.add(" Attributes:"); + list.add(" overwrite mode: 0"); + list.add(" subbufers size: 262144"); + list.add(" number of subbufers: 4"); + list.add(" switch timer interval: 0"); + list.add(" read timer interval: 200"); + list.add(" output: splice()"); + list.add(""); + list.add(" Events:"); + list.add(" block_rq_remap (loglevel: TRACE_EMERG0) (type: tracepoint) [enabled]"); + list.add(" block_bio_remap (loglevel: TRACE_EMERG0) (type: tracepoint) [disabled]"); + list.add(""); + list.add("- channel1: [disabled]"); + list.add(""); + list.add(" Attributes:"); + list.add(" overwrite mode: 1"); + list.add(" subbufers size: 524288"); + list.add(" number of subbufers: 4"); + list.add(" switch timer interval: 100"); + list.add(" read timer interval: 400"); + list.add(" output: splice()"); + list.add(""); + list.add(" Events:"); + list.add(" None"); + list.add(""); + list.add("=== Domain: UST global ==="); + list.add(""); + list.add("Channels:"); + list.add("-------------"); + list.add("- mychannel1: [disabled]"); + list.add(""); + list.add(" Attributes:"); + list.add(" overwrite mode: 1"); + list.add(" subbufers size: 8192"); + list.add(" number of subbufers: 8"); + list.add(" switch timer interval: 200"); + list.add(" read timer interval: 100"); + list.add(" output: mmap()"); + list.add(""); + list.add(" Events:"); + list.add(" None"); + list.add(""); + list.add("- channel0: [enabled]"); + list.add(""); + list.add(" Attributes:"); + list.add(" overwrite mode: 0"); + list.add(" subbufers size: 4096"); + list.add(" number of subbufers: 4"); + list.add(" switch timer interval: 0"); + list.add(" read timer interval: 200"); + list.add(" output: mmap()"); + list.add(""); + list.add(" Events:"); + list.add(" ust_tests_hello:tptest_sighandler (loglevel: TRACE_DEFAULT13) (type: tracepoint) [disabled]"); + list.add(" * (loglevel: TRACE_EMERG0) (type: tracepoint) [enabled]"); + list.add(""); + return new CommandResult(0, list.toArray(new String[list.size()])); + } else if ("lttng list -u".equals(command)) { + List list = new ArrayList(); + list.add("UST events:"); + list.add("-------------"); + list.add(""); + list.add("PID: 9379 - Name: /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello"); + list.add(" ust_tests_hello:tptest_sighandler (loglevel: TRACE_MODULE10) (type: tracepoint)"); + list.add(" ust_tests_hello:tptest (loglevel: TRACE_INFO6) (type: tracepoint)"); + list.add(""); + list.add("PID: 4852 - Name: /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello"); + list.add(" ust_tests_hello:tptest_sighandler (loglevel: TRACE_WARNING4) (type: tracepoint)"); + list.add(" ust_tests_hello:tptest (loglevel: TRACE_FUNCTION12) (type: tracepoint)"); + list.add(""); + return new CommandResult(0, list.toArray(new String[list.size()])); + } else if ("lttng list -k".equals(command)) { + List list = new ArrayList(); + list.add("Kernel events:"); + list.add("-------------"); + list.add(" sched_kthread_stop (loglevel: TRACE_EMERG0) (type: tracepoint)"); + list.add(" sched_kthread_stop_ret (loglevel: TRACE_EMERG0) (type: tracepoint)"); + list.add(" sched_wakeup_new (loglevel: TRACE_EMERG0) (type: tracepoint)"); + list.add(""); + return new CommandResult(0, list.toArray(new String[list.size()])); + } else if ("lttng list mysession1".equals(command)) { + List list = new ArrayList(); + list.add("Tracing session mysession1: [inactive]"); + list.add(" Trace path: /home/user/lttng-traces/mysession1-20120203-133225"); + list.add(""); + return new CommandResult(0, list.toArray(new String[list.size()])); + } + + String[] output = new String[1]; + output[0] = String.valueOf("Command not found"); + return new CommandResult(1, output); + } +} diff --git a/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/service/shells/SessionNotExistsShell.java b/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/service/shells/SessionNotExistsShell.java new file mode 100644 index 0000000000..3aeac8307e --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/service/shells/SessionNotExistsShell.java @@ -0,0 +1,20 @@ +package org.eclipse.linuxtools.lttng.stubs.service.shells; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.linuxtools.lttng.ui.views.control.service.CommandResult; +import org.eclipse.linuxtools.lttng.ui.views.control.service.ICommandResult; + +public class SessionNotExistsShell extends TestCommandShell { + @SuppressWarnings("nls") + @Override + public ICommandResult executeCommand(String command, IProgressMonitor monitor, boolean checkReturnValue) throws ExecutionException { + String[] output = new String[2]; + //Session test not found + //Error: Session name not found + output[0] = String.valueOf("Session test not found"); + output[1] = String.valueOf("Error: Session name not found"); + return new CommandResult(1, output); + } +} + diff --git a/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/service/shells/TestCommandShell.java b/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/service/shells/TestCommandShell.java new file mode 100644 index 0000000000..9403ada45e --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui.tests/stubs/org/eclipse/linuxtools/lttng/stubs/service/shells/TestCommandShell.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.lttng.stubs.service.shells; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.linuxtools.lttng.ui.views.control.service.CommandResult; +import org.eclipse.linuxtools.lttng.ui.views.control.service.ICommandResult; +import org.eclipse.linuxtools.lttng.ui.views.control.service.ICommandShell; + +public class TestCommandShell implements ICommandShell { + + protected boolean fIsConnected = false; + + @Override + public void connect() throws ExecutionException { + fIsConnected = true; + } + + @Override + public void disconnect() { + fIsConnected = false; + } + + @Override + public ICommandResult executeCommand(String command, IProgressMonitor monitor) throws ExecutionException { + return executeCommand(command, monitor, true); + } + + @Override + public ICommandResult executeCommand(String command, IProgressMonitor monitor, boolean checkReturnValue) throws ExecutionException { + if (fIsConnected) { + + } + return new CommandResult(0, new String[0]); + } +} diff --git a/org.eclipse.linuxtools.lttng.ui/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.lttng.ui/META-INF/MANIFEST.MF index e3fe166072..3d600763e1 100644 --- a/org.eclipse.linuxtools.lttng.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.lttng.ui/META-INF/MANIFEST.MF @@ -35,6 +35,13 @@ Export-Package: org.eclipse.linuxtools.lttng.ui;x-friends:="org.eclipse.linuxtoo org.eclipse.linuxtools.lttng.ui.views;x-friends:="org.eclipse.linuxtools.lttng.ui.tests", org.eclipse.linuxtools.lttng.ui.views.common;x-friends:="org.eclipse.linuxtools.lttng.ui.tests", org.eclipse.linuxtools.lttng.ui.views.control;x-friends:="org.eclipse.linuxtools.lttng.ui.tests", + org.eclipse.linuxtools.lttng.ui.views.control.dialogs, + org.eclipse.linuxtools.lttng.ui.views.control.handlers, + org.eclipse.linuxtools.lttng.ui.views.control.model, + org.eclipse.linuxtools.lttng.ui.views.control.model.impl, + org.eclipse.linuxtools.lttng.ui.views.control.property, + org.eclipse.linuxtools.lttng.ui.views.control.remote, + org.eclipse.linuxtools.lttng.ui.views.control.service, org.eclipse.linuxtools.lttng.ui.views.controlflow;x-friends:="org.eclipse.linuxtools.lttng.ui.tests", org.eclipse.linuxtools.lttng.ui.views.controlflow.evProcessor;x-friends:="org.eclipse.linuxtools.lttng.ui.tests", org.eclipse.linuxtools.lttng.ui.views.controlflow.model;x-friends:="org.eclipse.linuxtools.lttng.ui.tests", diff --git a/org.eclipse.linuxtools.lttng.ui/icons/elcl16/connect.gif b/org.eclipse.linuxtools.lttng.ui/icons/elcl16/connect.gif new file mode 100644 index 0000000000000000000000000000000000000000..866ad33825010a87df311a4d9468dc73303f6935 GIT binary patch literal 189 zcmZ?wbhEHb6krfwc+A1TV9UVZ%D~XT5E&WCu$qBkKLf)(hF6cJ{^J0O|3saOQWHy3 zQxwWGOEMHfGEx=XJ$(Zh6o0ZXaxw5T=r8~Q$Z!Uhzz-)qSMRM*QsGnxT~OGP*c7aw z#LO;Y;Lypqo7bt&%e0zD*D2vRvs|BUi$;m{Kep4I6AnoIF}vt~a!Ss{v<-(=eGLfY Tuw=|SyxPZo<_;NQMh0sDv;9kC literal 0 HcmV?d00001 diff --git a/org.eclipse.linuxtools.lttng.ui/icons/elcl16/disconnect.gif b/org.eclipse.linuxtools.lttng.ui/icons/elcl16/disconnect.gif new file mode 100644 index 0000000000000000000000000000000000000000..ec8a8b01e4ac6338c51d70726903a0a1a0e7714b GIT binary patch literal 151 zcmV;I0BHY5Nk%w1VGsZi0J8u9$SE-JTW9e|Y;7TY>_Tf{9b{^RA@#C9czkYoF^!DwW7aP{h zTfKbFgF6>rJiWVO@$^Fn4?ceU`2YX^3`7IPpDc_F41x?gARQn(8CcyDRQggf=bi7A zTWMu?YT=e=$?6_`7oG?^G`Jo<_?k6{-|ga!D5Kc*jU}0@`M6pREy(Kr!Ia>5FhHQ; UpvO83?FT_SFYK5j!o*+=0L{Ws#sB~S literal 0 HcmV?d00001 diff --git a/org.eclipse.linuxtools.lttng.ui/icons/elcl16/target_add.gif b/org.eclipse.linuxtools.lttng.ui/icons/elcl16/target_add.gif new file mode 100644 index 0000000000000000000000000000000000000000..114b964325efa3c8e91b7691e981c9d207a78a2a GIT binary patch literal 591 zcmZ?wbhEHb6krfwIOfBkkijF@ylsCZ<{;c zYu*(1t&^0OPjy^A!)w=cwfL0{2`d{CS2m@rY}vTLBYRy>_WGV33!QQ|b`@@zP_VJL zU}Im=#tA!Dq}Oeq-LPX$)6Th5kFK6}boIsk&2!GJp9?}8=AGL(AA~k7JGXPixqYiI z>|b~B;JS;4He5Wk_S)Wc*Y<9_wtwTb1HbMzpL>1v-0N$9o-e-r`tje-=l^~=|LX7S zcmLnL|Ns8O{|{gOef|3H+voqEKmY&o<^Sh@f8YQ9`}^m=U*G?K|MCCFpZ|aU{{QoT z5Cg@ZEQ|~c^$a=;Kmdvp2KF@#^-aw!t!?cB?ezw-Y)ovH60V)CiXz&UZkD3FuDrZ0 z3d-(YOI56`t*op$n{fDW88?GJLfA`G1a~tQM+qCi8fqU*xPpUj2Rj{{M$}|KEN1|Kaoh&)@%l|MCCF_kZ92 z{QvX&?{9?+o@IyU{r&$ZcfQxro7>Oj#hnarKIv|E(%t@qyZv!n%j33I|NsAIpgU0f z$->CM5XqnevKbU74D1^lBAc39THD$?nuL@Uz(|56zj|^iB@(N-I z_4DLVeLyWj%H5mt`QAT}ljYXIKy<8 literal 0 HcmV?d00001 diff --git a/org.eclipse.linuxtools.lttng.ui/icons/obj16/channel.gif b/org.eclipse.linuxtools.lttng.ui/icons/obj16/channel.gif new file mode 100644 index 0000000000000000000000000000000000000000..e8efe69dc35230b3a17f5a852b2a89435bb28439 GIT binary patch literal 200 zcmZ?wbhEHb6krfwIKsfNe#QEgi&idQxO~}yWeaC7TrhjV%&9Y{O`bNPZ$fWRZ%2E_ zg$p+XG8`ldJPaBlDmD~!9BBCQ$JhCjOly9BEf8wsLGjOiWDjb~PR|O8ze^X4u8%TkD*%Q2e>Lk%5Ou1dGX=hyy^7n{{I4%72C5 z>*~UfzrUWp$-uxs#$vr*XH;2Vm^NT@^d?P_@BCuLJaR-Oy^G8_H#Ed)EGQn L{an^LB{Ts5xn!W@ literal 0 HcmV?d00001 diff --git a/org.eclipse.linuxtools.lttng.ui/icons/obj16/domain.gif b/org.eclipse.linuxtools.lttng.ui/icons/obj16/domain.gif new file mode 100644 index 0000000000000000000000000000000000000000..bb2d794614bfa38f0ec4179e4f1849a4d88cbf23 GIT binary patch literal 616 zcmZ?wbhEHb6krfwc*elcHf3GM)HOZRS6zSnrGM6n@ZJ-%cHf^eXQ^f7-tT|@|NQ&^ z>gWIOe*K>@f6>R^|G)nE|MKVmH^2UW`2GLOpZ~9a{eSoS|NGznKmYmv{qO&`zyE*x z`~U0T|G)nI|M~C#yhZaCEuFn$#q|H*rvCr2YVGPN8`n+Tx}k6H*3O-qdbY1A-MGAB z|F({b;>dmL3$N`>zP2yr;;!^F+p{{Vy^n3qYb^7fQ17v^-)_?c`&HeJi#nWVHM@OT z$M5-p^)ve<1ViWX3nW46iyEdLq>qgh|a0mYx?NJ;zsejPlZBCiftx`GBnC2rfknUIr043r7O!L7EsrkX(4f=JJYo0#EhL6R-Sse<>J%e zsr#a49V%XVX2PBu6Zc%7aqxEJtONi5|7Rc$DE?$&WMB|t&;cn2*~!3avOuLTC39ZJ zs&%PKEKZB87#1lsOy**LBHt8}a3I2ktx0x z&Ee^7-+ugw&hCuQ?@1|{@bKl2hcCZZOgj;k-H}-}HM4R`ar2y)?|;7i^sBsmetG-6 zhp&D-eD(d?kKfucbF`zTyA`jEs$XB!Ji81i+cCeaecppt-`{=y_4(T`&HN*pd51J} z_GxDC(#qPUnXy$XW2TFGm)QdVolFVqI2nAuuU)3u_fYe!En>zM!P+wZrZ ze|`J;=iATU=imPR|NlS3kOhiASr{1@92s;#J^;lD1N(vo$EN0%)@CKG&aQ4PrDkpJ ziIXOCYd7ogILw+on@6WvSH!_yj#18zSB{rYui1d#fs2!kg-O$ffnUGbP{2V$!}h=d zNdco~W6_OV9PF&jOcG)y&8Er@>VmQ|f wDSTFJQ?&f|@Ar?V97Y=y92r}jd=ySxc)-%)sP^Tz`^WhWt!+kJTr3RM0QlXhyZ`_I literal 0 HcmV?d00001 diff --git a/org.eclipse.linuxtools.lttng.ui/icons/obj16/session_active.gif b/org.eclipse.linuxtools.lttng.ui/icons/obj16/session_active.gif new file mode 100644 index 0000000000000000000000000000000000000000..57a42bca8473f9380d3afe72b5d0eda1b9523842 GIT binary patch literal 970 zcmW+#O-Phs5T2mJuC2SDZpSpFs}V6|>QbjDx&%p-(ZLFR4@LeUYSNDwkrs)Dq77zJ zW(FGJAvP%!QFD)jfj1nuM05+h3 zg=I{W<8e={HP*7VhQ*Mx3l(Ux5oTe6dx*lUkP%`b*h3zW ziEYFI{}2I(Pz^AMhDwY=2Z(_UXkd{`&b3kFu`%R=gg?-tVm3_36?UNlO+#!5IU;EU z09_bI&~S?=kq2aA8*xAr48tK*0}P_E30cqqVqgQB+=<*Y+Nkje7ekQn2U=82?&EN| z`uBEC|Aa1P|0-_Q589>fXXjS^INT9@hYraX?QY`haKJt^J_lS0;lUHA9?oul@IHEP zCbjcz%AILXrXp>xlUpW2x5hU$jwRh33FcRLdFQ+v!-4w2U~PY>vMW^G9WHK7K6xd4 zyvob3^p2K$dBtAiNT@lHeC=ttrZ3zyoYL?z<$64&^;Psjw^!Ba6}LpL^raTnMG7u^ zC#pSs`Wb5*H^3-mLIeH?k0{VX8r+g7?i{KOMAx6!eVZG;8W`U>`mQN$U+w3WqSK<}=vl^;)!X!^ELfMWjvrkL4Z literal 0 HcmV?d00001 diff --git a/org.eclipse.linuxtools.lttng.ui/icons/obj16/session_destroyed.gif b/org.eclipse.linuxtools.lttng.ui/icons/obj16/session_destroyed.gif new file mode 100644 index 0000000000000000000000000000000000000000..d9b6822e089ba73d9bc7233d1ea96cddbab3d166 GIT binary patch literal 697 zcmV;q0!ICbP)`hSy@Aiaxsm;G)+N&L2uctDiNV^AT^YR<^@kln80wF6x$SG^m=9x zxC}&m_nXBnXJXFg!r?pjJNKSL5C9P21;@w7TU%QL0|Uikac*vIa&i*>1tIN#2!t?= zBuU|L*z5ILt=6utu1F-Js;b-VZcPKC2G|BdWLe(X+41>&X0w@6YBU;sK3^mfDVNKw zX#mhLv3z^`rn}qWaCCNdBBH9Qlv0Di;B-2Vj*eQ>&w^|=yS~0IY;1g5S&?N~eSxAV zxm@o3;^Mp6SxJ(Zpv~oSg+if;iHV+`p3K;0)bdx-^s~IEFS-UaDa$ft=3|(B$G*#$wUM}u-R;c z5JV(|0KnDN)#}Qd+Oq zFD@=T9*@TF_ovh8hlht|v#BUbHk;jx#bSGVUp6;C1cP^XcdDvBJw0VI8JEj7Iy%}G zjYbUyLn@Ubgyi%2#Qy%bXq5SuhKD~cFN;oRu~-}*AD@|-0RV!C0C0VMEsA1rY3b|k zE_2NIYPI@#b@f+1Z@1f-&vtfj9LM$czMY;Psnzs)JtG^9#^vSZ@3S-e(9o;kTFKAP z&*ySE_6PNP{q*#d=lQ|G!RNmH-SCn;>*n_Mc7K2W&CLzZ^M1eo`Nmd95ddGKR4NIA fP%4%1e*pXe%>HE8Iq_uh00000NkvXXu0mjfrt3`R literal 0 HcmV?d00001 diff --git a/org.eclipse.linuxtools.lttng.ui/icons/obj16/session_inactive.gif b/org.eclipse.linuxtools.lttng.ui/icons/obj16/session_inactive.gif new file mode 100644 index 0000000000000000000000000000000000000000..13d3f5b5a52763b142216c370308c01502419839 GIT binary patch literal 1004 zcmV6ciK{6%`g178e&67#J8C85tTH8XFrM z92^`S9UUGX9v>ecARr(iAt53nA|oRsBqSsyB_$>%CMPE+C@3f?DJd!{Dl021EG#T7 zEiEoCE-x=HFfcGNF)=bSGBYzXG&D3dH8nOiHa9mnI5;>tIXOByIy*Z%JUl!-Jv}}? zK0iM{KtMo2K|w-7LPJACL_|bIMMXwNMn^|SNJvOYNl8jdN=r*iOiWBoO-)WtPESuy zP*6}&QBhJ-Qd3h?R8&+|RaI72R##V7SXfwDSy@_IT3cINTwGjTU0q&YUSD5dU|?Wj zVPRroVq;@tWMpJzWo2e&W@l$-XlQ6@X=!R|YHMq2Y;0_8ZEbFDZf|dIaBy&OadC2T za&vQYbaZreb#-=jc6WDoczAeud3kzzdV70&e0+R;eSLm@et&;|fPjF3fq{a8f`fyD zgoK2Jg@uNOhKGlTh=_=ZiHVAeii?YjjEszpjg5|uj*pLzkdTm(k&%*;l9Q8@l$4Z} zm6ev3mY0{8n3$NEnVFiJnwy)OoSdAUot>VZo}ZteprD|kp`oIpqNAguq@<*!rKP5( zrl+T;sHmu^si~@}s;jH3tgNi9t*x%EuCK4Ju&}VPv9YqUva_?Zw6wIfwY9dkwzs#p zxVX5vxw*Q!y1To(yu7@dCU$jHda z$;ryf%FD~k%*@Qq&CSlv&d<-!(9qD)(b3Y<($mw^)YR0~)z#M4*4Nk9*x1lt)=I7_<=;-L_>FMg~>g((4 z?Ck9A?d|UF?(gsK@bK{Q@$vHV^7Hfa^z`)g_4W4l_V@Sq`1ttw`T6?#`uqF){QUg= z{r&#_{{R2~EC2ui01yBW000Ql0RIUT=<73N9HGeSS!9NkLT!=gj3Py9)Tl&Hlu>+F1yZQbo5C=oC{WiG aN1rl{8AX~Ql|WxYwN@xiku=f)0RTIHhvRGj literal 0 HcmV?d00001 diff --git a/org.eclipse.linuxtools.lttng.ui/icons/obj16/sessions.gif b/org.eclipse.linuxtools.lttng.ui/icons/obj16/sessions.gif new file mode 100644 index 0000000000000000000000000000000000000000..c69588429f3e412e417487bd25df5bded371ff0f GIT binary patch literal 617 zcmchUxo;Ce7{xc>IE2##$03BnF^3)Oa0Dl|F_4XkuON$!6{E$~CKA$?3)PmBjgeNO znF>ugMUbXIXv?7+8Z>kxswr0#Xv!5Gm0AB2yzYHZPrpxk?QW}D+fQjJ?YE|}s?KeP zIWXjsLK^Z=NfoI`1QG!(sDu`wh%+pZk11i2hm42-a*70Y8FE+vh2%qQ2+jm!r&4;VAgTd5^(X*}U+M@^8%wF%cxi>0R z^vd}!<+s1Kt#t82V)yXfG)w1uc&|&EJDL2;?8biX{lR>}{H%XlcyrJw?HY|A{hzbV W)mQz-VgJvkY-w<8e9aY7TKykqrSHN3 literal 0 HcmV?d00001 diff --git a/org.eclipse.linuxtools.lttng.ui/icons/obj16/systemlttng2-live.gif b/org.eclipse.linuxtools.lttng.ui/icons/obj16/systemlttng2-live.gif new file mode 100755 index 0000000000000000000000000000000000000000..57c522db6c4f8bf2f1c800bee68f7421eb18df46 GIT binary patch literal 882 zcmb`Gv1`Rxj5*OML}?JaX4H>IXsZd)>&?H z>vpS;OtD_Co8Q}d zJb3br;J5!5ZWd-~R@y}7ZXV`oUgoW0xJ6i`MOn0Z(=Ed?Ez7bsT5c6qX;oHYYVFox zoz?|y0Sg)|hUsqYQG|QCmwRh1S%gP=lt+sN#SG8%EYB7xdMmurtGpVHjCzN6dY3m_ zVGS6hVF@j2ECw5Buo!L$Qch$mMk-}B3p7{L9sHbq8jy(qBlCDD;jzD0Zpc{ z1O1RdA*=y|G%RU_2aCZ58myLcDw7kH*)kG+tR<_;YJ5d5EGTAIHa_As2EdDUj7BY1 z;s-RD#tt|k7=^F~4AM+O3mz;68|c=F)J>V3XfB44=wmHejh9Tmj(e*(PAHqlRn$9- zmg~bijSf3>grQJKgS2ikcnEkv^Ez-P%tI5a4)iwbzhIN+c73w*=wx^Kak6!Ow4Cp* z4qpDa{pRoNe0BfI>yr<^w>PWL+lTjl-I#y+x!5}X_9EY%KK{D@?EB8yrM;(%TNgK{ aXN#L(mWOXQ7jm)xWWM+Q+U2WLyZaAPWPK0- literal 0 HcmV?d00001 diff --git a/org.eclipse.linuxtools.lttng.ui/icons/obj16/systemlttng2.gif b/org.eclipse.linuxtools.lttng.ui/icons/obj16/systemlttng2.gif new file mode 100755 index 0000000000000000000000000000000000000000..fd7b3117f2b11acc3980c249fbde3facfe51028c GIT binary patch literal 856 zcmZ?wbhEHb6krfw_|CxaW95d0eN$fdZvMOW%Kz~F+ZJxTn0n^R{15-H{r@%f|Gjz7 zA5ZxBV%GnM2fi=r-*EB#<@U}gb)6fIU;E8qv_K|!w_W}bxA-0go7n}On}mXQFoa+7 zYdn&>{HJihT-T1fmPMO|Q?_Q!JXNvkj{c+%|7idiM!{$ZP!Iw-Aibcxz`$Y4;K?E5 zv0=f%W)5Mkm=ggCtnDI7ZZ`WWnZa)V5xv%se*8^jg`f# zmc^@Wv5K(Pz@E;rpU$$e*1(+3ubs}XozAeI&ati5y{^{1vDUxN>(ZV@Bi@b|L*Vq@9_Wd^Z)br|M&R+`27F;`~Ca$|MMVd4E_K7ZJ$d2|Nj60 z00000A^8LW002DzEC2ui01yBW000J)z@BhOEE4+sHC*gZi2J61BYy8r+H literal 0 HcmV?d00001 diff --git a/org.eclipse.linuxtools.lttng.ui/icons/obj16/target_disconnected.gif b/org.eclipse.linuxtools.lttng.ui/icons/obj16/target_disconnected.gif new file mode 100644 index 0000000000000000000000000000000000000000..8591f40a1a1d8d7ca8295f548cb12edc6cdf1176 GIT binary patch literal 605 zcmV-j0;2tiP)ntmV~aMapznyUjAfDe`ZD$cmDnVZ_e?JuRnjNcTYk1Va>$@4?jMOv-JAM z_;>5|!zG(0IZn+i*)(y>^&|fn|0Y;^Km7Q7&BX%<4F~R@wNusq&-icK^<(QUAJmgo zo)=!HC#$mI@_}vFkNso(Yp1Gz;Qm>Jh6_(_=*z17Vfb_4_E}q1{qq-Ry4Gr*zc|xI zRsX>4vws-=>dUHJcya^b2l-~dGu880n3#R1mMsXccdgZAU|`sB%Nb`p$O?)-dH0%$ zfyqc#?a<>hzUFoiac)yXk+=v}NpX?52yRnDga!j?jf;=(urM$?su~}@ebGoiV|Vj) z1_lOBO?Bb;2yRnD;rIwnO?5=X*(wVR{y!f+ zi05a#oH*m_>GKF1!VMi|`6L$}-^%!($y?K=$1m?d_H?XC0})4!9x1Orf6QLpwd(xd z`){8A`}d!Lfq~!E5n{Y}eg?m*BYM(cU|?8(>CoZ(=g&U5_Tb%%T?ZJsO$|9U)j#gu r&+qE^`^C$TyY{1NKn6FR126>vM9JR19}MDe00000NkvXXu0mjf + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -460,6 +634,15 @@ name="org.eclipse.linuxtools.lttng.ui.tracecontrol.systemType" subsystemConfigurationIds="org.eclipse.linuxtools.lttng.ui.tracecontrol.subsystems.TraceSubSystemConfiguration;org.eclipse.tm.tcf.rse.Processes;org.eclipse.tm.tcf.rse.Shells;org.eclipse.tm.tcf.rse.Files;org.eclipse.tm.tcf.rse.Terminals"> + + diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/LTTngUiPlugin.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/LTTngUiPlugin.java index ec1f5835b8..88458a4459 100644 --- a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/LTTngUiPlugin.java +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/LTTngUiPlugin.java @@ -14,11 +14,13 @@ package org.eclipse.linuxtools.lttng.ui; +import java.net.URL; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; import org.eclipse.core.runtime.IAdapterManager; import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.linuxtools.lttng.core.tracecontrol.model.ProviderResource; import org.eclipse.linuxtools.lttng.core.tracecontrol.model.TargetResource; import org.eclipse.linuxtools.lttng.core.tracecontrol.model.TraceResource; @@ -27,6 +29,7 @@ import org.eclipse.linuxtools.lttng.ui.tracecontrol.Messages; import org.eclipse.rse.services.clientserver.messages.SimpleSystemMessage; import org.eclipse.rse.services.clientserver.messages.SystemMessage; import org.eclipse.rse.ui.SystemBasePlugin; +import org.eclipse.swt.graphics.Image; import org.osgi.framework.BundleContext; /** @@ -136,4 +139,21 @@ public class LTTngUiPlugin extends SystemBasePlugin { putImageInRegistry(ICON_ID_IMPORT_TRACE, path + "elcl16/import_trace.gif"); //$NON-NLS-1$ putImageInRegistry(ICON_ID_EDIT, path + "elcl16/edit.gif"); //$NON-NLS-1$ } + + /** + * Loads icon and puts it in the image registry + * + * @param url + * @return image + */ + public Image loadIcon(String url) { + Image icon = getImageRegistry().get(url); + if (icon == null) { + URL imageURL = getBundle().getEntry(url); + ImageDescriptor descriptor = ImageDescriptor.createFromURL(imageURL); + icon = descriptor.createImage(); + getImageRegistry().put(url, icon); + } + return icon; + } } diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/ControlView.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/ControlView.java index ced59acdb3..85570b2f80 100644 --- a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/ControlView.java +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/ControlView.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 Ericsson + * Copyright (c) 2009, 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 @@ -8,30 +8,73 @@ * * Contributors: * Francois Chouinard - Initial API and implementation + * Bernd Hufmann - Filled with content *******************************************************************************/ package org.eclipse.linuxtools.lttng.ui.views.control; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.viewers.ColumnViewerToolTipSupport; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent; +import org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponentChangedListener; +import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlRoot; +import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Menu; import org.eclipse.ui.part.ViewPart; /** * ControlView *

- * TODO: Implement me. Please. + * View implementation for Trace Control. + *

*/ -@Deprecated -public class ControlView extends ViewPart { +public class ControlView extends ViewPart implements ITraceControlComponentChangedListener { + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + /** + * View ID. + */ public static final String ID = "org.eclipse.linuxtools.lttng.ui.views.control"; //$NON-NLS-1$ + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + /** + * The tree viewer. + */ + private TreeViewer fTreeViewer = null; + + /** + * The trace control root node. This provides access to the whole model. + */ + private ITraceControlComponent fRoot = null; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + // ------------------------------------------------------------------------ + // Accessors + // ------------------------------------------------------------------------ + /** - * - */ - public ControlView() { - // TODO Auto-generated constructor stub + * @return returns the trace control tree node (model). + */ + public ITraceControlComponent getTraceControlRoot() { + return fRoot; } + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + /* * (non-Javadoc) * @@ -39,8 +82,22 @@ public class ControlView extends ViewPart { */ @Override public void createPartControl(Composite parent) { - // TODO Auto-generated method stub + // Create tree viewer + fTreeViewer = new TreeViewer(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL); + ColumnViewerToolTipSupport.enableFor(fTreeViewer); + + fTreeViewer.setContentProvider(new TraceControlContentProvider()); + fTreeViewer.setLabelProvider(new TraceControlLabelProvider()); + + // Create model root + fRoot = new TraceControlRoot(); + fRoot.addComponentListener(this); + fTreeViewer.setInput(fRoot); + // Create context menu for the tree viewer + createContextMenu(); + + getSite().setSelectionProvider(fTreeViewer); } /* @@ -50,8 +107,69 @@ public class ControlView extends ViewPart { */ @Override public void setFocus() { - // TODO Auto-generated method stub + fTreeViewer.getControl().setFocus(); + final ISelection sel = fTreeViewer.getSelection(); + if (sel == null) { + fTreeViewer.setSelection(new StructuredSelection(fRoot)); + fTreeViewer.setSelection(null); + return; + } + fTreeViewer.setSelection(sel); + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponentChangedListener#componentAdded(org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent, org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent) + */ + @Override + public void componentAdded(ITraceControlComponent parent, ITraceControlComponent component) { + componentChanged(component); + } + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponentChangedListener#componentRemoved(org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent, org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent) + */ + @Override + public void componentRemoved(ITraceControlComponent parent, ITraceControlComponent component) { + componentChanged(component); } + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponentChangedListener#componentChanged(org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent) + */ + @Override + public void componentChanged(ITraceControlComponent component) { + if (fTreeViewer.getTree().isDisposed()) { + return; + } + + fTreeViewer.getTree().getDisplay().asyncExec(new Runnable() { + @Override + public void run() { + if (fTreeViewer.getTree().isDisposed()) { + return; + } + fTreeViewer.refresh(); + // Change selection needed + final ISelection sel = fTreeViewer.getSelection(); + fTreeViewer.setSelection(null); + fTreeViewer.setSelection(sel); + } + }); + } + + // ------------------------------------------------------------------------ + // Helper methods + // ------------------------------------------------------------------------ + private void createContextMenu() { + // This is new code + // First we create a menu Manager + final MenuManager menuManager = new MenuManager(); + final Menu menu = menuManager.createContextMenu(fTreeViewer.getTree()); + // Set the MenuManager + fTreeViewer.getTree().setMenu(menu); + getSite().registerContextMenu(menuManager, fTreeViewer); + } } diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/Messages.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/Messages.java new file mode 100644 index 0000000000..220c58e84a --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/Messages.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2011 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.lttng.ui.views.control; + +import org.eclipse.osgi.util.NLS; + +/** + * Messages + *

+ * Messages file for the trace control package. + *

+ */ +final public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.linuxtools.lttng.ui.views.control.messages"; //$NON-NLS-1$ + + // Failures + public static String TraceControl_ConnectionFailure; + public static String TraceControl_DisconnectionFailure; + public static String TraceControl_ExecutionCancelled; + public static String TraceControl_ExecutionFailure; + public static String TraceControl_ExecutionTimeout; + public static String TraceControl_ShellNotConnected; + + public static String TraceControl_CommandShellError; + public static String TraceControl_CommandError; + + // Commands + public static String TraceControl_RetrieveNodeConfigurationJob; + public static String TraceControl_ListSessionFailure; + public static String TraceControl_EclipseCommandFailure; + public static String TraceControl_NewNodeCreationFailure; + + // Dialogs + public static String TraceControl_NewDialogTitle; + public static String TraceControl_NewNodeExistingConnetionsGroupName; + public static String TraceControl_NewNodeEditButtonName; + public static String TraceControl_NewNodeComboToolTip; + public static String TraceControl_NewNodeNameLabel; + public static String TraceControl_NewNodeNameTooltip; + public static String TraceControl_NewNodeAddressLabel; + public static String TraceControl_NewNodeAddressTooltip; + public static String TraceControl_AlreadyExistsError; + + // Tree structure strings + public static String TraceControl_KernelDomainDisplayName; + public static String TraceControl_UstGlobalDomainDisplayName; + public static String TraceControl_AllSessionsDisplayName; + public static String TraceControl_SessionDisplayName; + public static String TraceControl_DomainDisplayName; + public static String TraceControl_ChannelDisplayName; + public static String TraceControl_EventDisplayName; + public static String TraceControl_ProviderDisplayName; + public static String TraceControl_KernelProviderDisplayName; + + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/TraceControlContentProvider.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/TraceControlContentProvider.java new file mode 100644 index 0000000000..29b83e4100 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/TraceControlContentProvider.java @@ -0,0 +1,89 @@ +/********************************************************************** + * 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.lttng.ui.views.control; + +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent; + +/** + * TraceControlContentProvider + *

+ * Tree content provider implementation for trace control view. + *

+ */ +public class TraceControlContentProvider implements ITreeContentProvider { + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + /* + * (non-Javadoc) + * @see org.eclipse.jface.viewers.IContentProvider#dispose() + */ + @Override + public void dispose() { + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) + */ + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.viewers.ITreeContentProvider#getElements(java.lang.Object) + */ + @Override + public Object[] getElements(Object inputElement) { + return getChildren(inputElement); + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object) + */ + @Override + public Object[] getChildren(Object parentElement) { + + if (parentElement instanceof ITraceControlComponent) { + return ((ITraceControlComponent)parentElement).getChildren(); + } + return new Object[0]; + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object) + */ + @Override + public Object getParent(Object element) { + if (element instanceof ITraceControlComponent) { + return ((ITraceControlComponent)element).getParent(); + } + return null; + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object) + */ + @Override + public boolean hasChildren(Object element) { + if (element instanceof ITraceControlComponent) { + return ((ITraceControlComponent)element).hasChildren(); + } + return false; + } +} diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/TraceControlLabelProvider.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/TraceControlLabelProvider.java new file mode 100644 index 0000000000..c356cb857b --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/TraceControlLabelProvider.java @@ -0,0 +1,62 @@ +/********************************************************************** + * 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.lttng.ui.views.control; + +import org.eclipse.jface.viewers.ColumnLabelProvider; +import org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent; +import org.eclipse.swt.graphics.Image; + +/** + * TraceControlLabelProvider + *

+ * Label provider for trace control tree viewer. + *

+ */ +public class TraceControlLabelProvider extends ColumnLabelProvider { + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object) + */ + @Override + public Image getImage(Object element) { + if ((element != null) && (element instanceof ITraceControlComponent)) { + return ((ITraceControlComponent) element).getImage(); + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object) + */ + @Override + public String getText(Object element) { + if ((element != null) && (element instanceof ITraceControlComponent)) { + return ((ITraceControlComponent) element).getName(); + } + return "";//$NON-NLS-1$ + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.viewers.CellLabelProvider#getToolTipText(java.lang.Object) + */ + @Override + public String getToolTipText(Object element) { + if ((element != null) && (element instanceof ITraceControlComponent)) { + return ((ITraceControlComponent) element).getToolTip(); + } + return null; + } +} diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/dialogs/INewConnectionDialog.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/dialogs/INewConnectionDialog.java new file mode 100644 index 0000000000..5dc342b9a4 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/dialogs/INewConnectionDialog.java @@ -0,0 +1,42 @@ +/********************************************************************** + * 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.lttng.ui.views.control.dialogs; + +/** + * INewConnectionDialog + *

+ * Interface for connection information dialog. + *

+ */ +public interface INewConnectionDialog { + + // ------------------------------------------------------------------------ + // Accessors + // ------------------------------------------------------------------------ + /** + * @return returns the node name (alias). + */ + public String getNodeName(); + + /** + * @return returns the node address (IP address or DNS name) + */ + public String getNodeAddress(); + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + /** + * @return returns the open return value + */ + int open(); +} diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/dialogs/NewConnectionDialog.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/dialogs/NewConnectionDialog.java new file mode 100644 index 0000000000..03f92b0d5a --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/dialogs/NewConnectionDialog.java @@ -0,0 +1,290 @@ +/********************************************************************** + * 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.lttng.ui.views.control.dialogs; + +import java.util.Arrays; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.linuxtools.lttng.ui.LTTngUiPlugin; +import org.eclipse.linuxtools.lttng.ui.views.control.Messages; +import org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent; +import org.eclipse.rse.core.model.IHost; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +/** + * NewConnectionDialog + *

+ * Dialog box for connection information. + *

+ */ +public class NewConnectionDialog extends Dialog implements INewConnectionDialog { + + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + /** + * The icon file for this dialog box. + */ + public static final String TARGET_NEW_CONNECTION_ICON_FILE = "icons/elcl16/target_add.gif"; //$NON-NLS-1$ + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + /** + * The dialog composite. + */ + private Composite fDialogComposite = null; + /** + * The Group for the host combo box. + */ + private Group fComboGroup = null; + /** + * The Group for the text input. + */ + private Group fTextGroup = null; + /** + * The host combo box. + */ + private CCombo fExistingHostsCombo = null; + /** + * The check box button for enablling/disabling the text input. + */ + private Button fButton = null; + /** + * The text widget for the node name (alias) + */ + private Text fNodeNameText = null; + /** + * The text widget for the node address (IP or DNS name) + */ + private Text fNodeAddressText = null; + /** + * The parent where the new node should be added. + */ + private ITraceControlComponent fParent; + /** + * The node name (alias) string. + */ + private String fNodeName = null; + /** + * The node address (IP or DNS name) string. + */ + private String fNodeAddress = null; + + /** + * Input list of existing RSE hosts available for selection. + */ + private IHost[] fExistingHosts = new IHost[0]; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + public NewConnectionDialog(Shell shell, ITraceControlComponent parent, IHost[] hosts) { + super(shell); + fParent = parent; + if (hosts != null) { + fExistingHosts = Arrays.copyOf(hosts, hosts.length); + } + } + + // ------------------------------------------------------------------------ + // Accessors + // ------------------------------------------------------------------------ + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.INewConnectionDialog#getNodeName() + */ + @Override + public String getNodeName() { + return fNodeName; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.INewConnectionDialog#getNodeAddress() + */ + @Override + public String getNodeAddress() { + return fNodeAddress; + } + + // ------------------------------------------------------------------------ + // 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_NewDialogTitle); + newShell.setImage(LTTngUiPlugin.getDefault().loadIcon(TARGET_NEW_CONNECTION_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); + + // Existing connections group + fComboGroup = new Group(fDialogComposite, SWT.SHADOW_NONE); + fComboGroup.setText(Messages.TraceControl_NewNodeExistingConnetionsGroupName); + layout = new GridLayout(2, true); + fComboGroup.setLayout(layout); + GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL); + fComboGroup.setLayoutData(data); + + fExistingHostsCombo = new CCombo(fComboGroup, SWT.READ_ONLY); + fExistingHostsCombo.setToolTipText(Messages.TraceControl_NewNodeComboToolTip); + fExistingHostsCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false, 2, 1)); + + String items[] = new String[fExistingHosts.length]; + for (int i = 0; i < items.length; i++) { + items[i] = String.valueOf(fExistingHosts[i].getAliasName() + " - " + fExistingHosts[i].getHostName()); //$NON-NLS-1$ + } + + fExistingHostsCombo.setItems(items); + fExistingHostsCombo.setEnabled(fExistingHosts.length > 0); + + // Node information grop + fTextGroup = new Group(fDialogComposite, SWT.SHADOW_NONE); + layout = new GridLayout(2, true); + fTextGroup.setLayout(layout); + data = new GridData(GridData.HORIZONTAL_ALIGN_FILL); + fTextGroup.setLayoutData(data); + + fButton = new Button(fTextGroup, SWT.CHECK); + fButton.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false, 2, 1)); + fButton.setText(Messages.TraceControl_NewNodeEditButtonName); + fButton.setEnabled(fExistingHosts.length > 0); + + Label nodeNameLabel = new Label(fTextGroup, SWT.RIGHT); + nodeNameLabel.setText(Messages.TraceControl_NewNodeNameLabel); + fNodeNameText = new Text(fTextGroup, SWT.NONE); + fNodeNameText.setToolTipText(Messages.TraceControl_NewNodeNameTooltip); + fNodeNameText.setEnabled(fExistingHosts.length == 0); + + Label nodeAddressLabel = new Label(fTextGroup, SWT.RIGHT); + nodeAddressLabel.setText(Messages.TraceControl_NewNodeAddressLabel); + fNodeAddressText = new Text(fTextGroup, SWT.NONE); + fNodeAddressText.setToolTipText(Messages.TraceControl_NewNodeAddressTooltip); + fNodeAddressText.setEnabled(fExistingHosts.length == 0); + + fButton.addSelectionListener(new SelectionListener() { + @Override + public void widgetSelected(SelectionEvent e) { + if (fButton.getSelection()) { + fExistingHostsCombo.deselectAll(); + fExistingHostsCombo.setEnabled(false); + fNodeNameText.setEnabled(true); + fNodeAddressText.setEnabled(true); + } else { + fExistingHostsCombo.setEnabled(true); + fNodeNameText.setEnabled(false); + fNodeAddressText.setEnabled(false); + } + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + } + }); + + fExistingHostsCombo.addSelectionListener(new SelectionListener() { + @Override + public void widgetSelected(SelectionEvent e) { + int index = fExistingHostsCombo.getSelectionIndex(); + fNodeNameText.setText(fExistingHosts[index].getAliasName()); + fNodeAddressText.setText(fExistingHosts[index].getHostName()); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + } + }); + + // layout widgets + data = new GridData(GridData.HORIZONTAL_ALIGN_FILL); + fNodeAddressText.setText("666.666.666.666"); //$NON-NLS-1$ + Point minSize = fNodeAddressText.computeSize(SWT.DEFAULT, SWT.DEFAULT, true); + data.widthHint = minSize.x + 5; + + fNodeNameText.setLayoutData(data); + fNodeAddressText.setLayoutData(data); + + fNodeAddressText.setText(""); //$NON-NLS-1$ + + 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() { + // Validate input data + fNodeName = fNodeNameText.getText(); + fNodeAddress = fNodeAddressText.getText(); + + if (!"".equals(fNodeAddress)) { //$NON-NLS-1$ + // If no node name is specified use the node address as name + if ("".equals(fNodeName)) { //$NON-NLS-1$ + fNodeName = fNodeAddress; + } + // Check if node with name already exists in parent + if(fParent.containsChild(fNodeName)) { + MessageDialog.openError(getShell(), + Messages.TraceControl_NewDialogTitle, + Messages.TraceControl_AlreadyExistsError + " (" + fNodeName + ")"); //$NON-NLS-1$//$NON-NLS-2$ + return; + } + } + else { + return; + } + // validation successful -> call super.okPressed() + super.okPressed(); + } +} diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/handlers/BaseNodeHandler.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/handlers/BaseNodeHandler.java new file mode 100644 index 0000000000..14881d1662 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/handlers/BaseNodeHandler.java @@ -0,0 +1,133 @@ +/********************************************************************** + * 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.lttng.ui.views.control.handlers; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.IHandler; +import org.eclipse.core.commands.IHandlerListener; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.linuxtools.lttng.ui.views.control.ControlView; +import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TargetNodeComponent; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; + +/** + * BaseNodeHandler + *

+ * Command handler implementation to delete a target host. + *

+ */ +abstract public class BaseNodeHandler implements IHandler { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + /** + * The target node component the command is to be executed on. + */ + protected TargetNodeComponent fTargetNode = null; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + // ------------------------------------------------------------------------ + // Accessors + // ------------------------------------------------------------------------ + public TargetNodeComponent getTargetNode() { + return fTargetNode; + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + /* + * (non-Javadoc) + * @see org.eclipse.core.commands.IHandler#dispose() + */ + @Override + public void dispose() { + } + + /* + * (non-Javadoc) + * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) + */ + @Override + abstract public Object execute(ExecutionEvent event) throws ExecutionException; + + /* + * (non-Javadoc) + * @see org.eclipse.core.commands.IHandler#isEnabled() + */ + @Override + public boolean isEnabled() { + fTargetNode = null; + + // Check if we are closing down + IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + if (window == null) { + return false; + } + + // Check if we are in the Project View + IWorkbenchPage page = window.getActivePage(); + if (page == null) { + return false; + } + + IWorkbenchPart part = page.getActivePart(); + if (!(part instanceof ControlView)) { + return false; + } + + // Check if a project is selected + ISelection selection = page.getSelection(ControlView.ID); + if (selection instanceof StructuredSelection) { + Object element = ((StructuredSelection) selection).getFirstElement(); + fTargetNode = (element instanceof TargetNodeComponent) ? (TargetNodeComponent) element : null; + } + return fTargetNode != null; + } + + /* + * (non-Javadoc) + * @see org.eclipse.core.commands.IHandler#isHandled() + */ + @Override + public boolean isHandled() { + return true; + } + + // ------------------------------------------------------------------------ + // IHandlerListener + // ------------------------------------------------------------------------ + /* + * (non-Javadoc) + * @see org.eclipse.core.commands.IHandler#addHandlerListener(org.eclipse.core.commands.IHandlerListener) + */ + @Override + public void addHandlerListener(IHandlerListener handlerListener) { + } + + /* + * (non-Javadoc) + * @see org.eclipse.core.commands.IHandler#removeHandlerListener(org.eclipse.core.commands.IHandlerListener) + */ + @Override + public void removeHandlerListener(IHandlerListener handlerListener) { + } +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/handlers/ConnectHandler.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/handlers/ConnectHandler.java new file mode 100644 index 0000000000..dfdc86c79b --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/handlers/ConnectHandler.java @@ -0,0 +1,48 @@ +/********************************************************************** + * 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.lttng.ui.views.control.handlers; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.linuxtools.lttng.ui.views.control.model.TargetNodeState; + +/** + * ConnectHandler + *

+ * Command handler implementation to connect to a target host. + *

+ */ +public class ConnectHandler extends BaseNodeHandler { + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.handlers.BaseNodeHandler#execute(org.eclipse.core.commands.ExecutionEvent) + */ + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + fTargetNode.connect(); + return null; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.handlers.BaseNodeHandler#isEnabled() + */ + @Override + public boolean isEnabled() { + return (super.isEnabled() && (fTargetNode.getTargetNodeState() == TargetNodeState.DISCONNECTED)); + } +} diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/handlers/DeleteHandler.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/handlers/DeleteHandler.java new file mode 100644 index 0000000000..631ac77f8b --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/handlers/DeleteHandler.java @@ -0,0 +1,50 @@ +/********************************************************************** + * 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.lttng.ui.views.control.handlers; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent; +import org.eclipse.linuxtools.lttng.ui.views.control.model.TargetNodeState; + +/** + * DeleteHandler + *

+ * Command handler implementation to delete a target host. + *

+ */ +public class DeleteHandler extends BaseNodeHandler { + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.handlers.BaseNodeHandler#execute(org.eclipse.core.commands.ExecutionEvent) + */ + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + ITraceControlComponent root = fTargetNode.getParent(); + fTargetNode.removeAllChildren(); + root.removeChild(fTargetNode); + return null; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.handlers.BaseNodeHandler#isEnabled() + */ + @Override + public boolean isEnabled() { + return (super.isEnabled() && (fTargetNode.getTargetNodeState() == TargetNodeState.DISCONNECTED)); + } +} diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/handlers/DisconnectHandler.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/handlers/DisconnectHandler.java new file mode 100644 index 0000000000..0c1c19f76f --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/handlers/DisconnectHandler.java @@ -0,0 +1,48 @@ +/********************************************************************** + * 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.lttng.ui.views.control.handlers; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.linuxtools.lttng.ui.views.control.model.TargetNodeState; + +/** + * DisconnectHandler + *

+ * Command handler implementation to disconnect from a target host. + *

+ */ +public class DisconnectHandler extends BaseNodeHandler { + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.handlers.BaseNodeHandler#execute(org.eclipse.core.commands.ExecutionEvent) + */ + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + fTargetNode.disconnect(); + return null; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.handlers.BaseNodeHandler#isEnabled() + */ + @Override + public boolean isEnabled() { + return super.isEnabled() && (fTargetNode.getTargetNodeState() == TargetNodeState.CONNECTED); + } +} diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/handlers/NewConnectionHandler.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/handlers/NewConnectionHandler.java new file mode 100644 index 0000000000..47891e1480 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/handlers/NewConnectionHandler.java @@ -0,0 +1,202 @@ +/********************************************************************** + * 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.lttng.ui.views.control.handlers; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.IHandler; +import org.eclipse.core.commands.IHandlerListener; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.window.Window; +import org.eclipse.linuxtools.lttng.ui.views.control.ControlView; +import org.eclipse.linuxtools.lttng.ui.views.control.Messages; +import org.eclipse.linuxtools.lttng.ui.views.control.dialogs.INewConnectionDialog; +import org.eclipse.linuxtools.lttng.ui.views.control.dialogs.NewConnectionDialog; +import org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent; +import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TargetNodeComponent; +import org.eclipse.rse.core.IRSESystemType; +import org.eclipse.rse.core.RSECorePlugin; +import org.eclipse.rse.core.model.IHost; +import org.eclipse.rse.core.model.ISystemRegistry; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; + +/** + * NewConnectionHandler + *

+ * Command handler for creation new connection for trace control. + *

+ */ +public class NewConnectionHandler implements IHandler { + + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + /** + * The trace control system type defined for LTTng version 2.0 and later. + */ + public final static String TRACE_CONTROL_SYSTEM_TYPE = "org.eclipse.linuxtools.lttng.ui.control.systemType"; //$NON-NLS-1$ + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + /** + * The parent trace control component the new node will be added to. + */ + private ITraceControlComponent fParent = null; + + /* + * (non-Javadoc) + * @see org.eclipse.core.commands.IHandler#dispose() + */ + @Override + public void dispose() { + } + + /* + * (non-Javadoc) + * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) + */ + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + assert (fParent != null); + + IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + if (window == null) { + return false; + } + + ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry(); + + // get system type definition for LTTng 2.x connection + IRSESystemType sysType = RSECorePlugin.getTheCoreRegistry().getSystemTypeById(TRACE_CONTROL_SYSTEM_TYPE); + + // get all hosts for this system type + IHost[] hosts = registry.getHostsBySystemType(sysType); + + // Open dialog box for the node name and address + INewConnectionDialog dialog = new NewConnectionDialog(window.getShell(), fParent, hosts); + + if (dialog.open() == Window.OK) { + + String hostName = dialog.getNodeName(); + String hostAddress = dialog.getNodeAddress(); + +// String hostName = "hallo"; +// String hostAddress = "142.133.166.54"; +// String hostName = "ha"; +// String hostAddress = "192.168.0.196"; + // get the singleton RSE registry + IHost host = null; + + for (int i = 0; i < hosts.length; i++) { + if (hosts[i].getAliasName().equals(hostName)) { + host = hosts[i]; + break; + } + } + + if (host == null) { + // if there's no host then we will create it + try { + + // create the host object as an SSH Only connection + host = registry.createHost( + sysType, //System Type Name + hostName, //Connection name + hostAddress, //IP Address + "Connection to Host"); //description //$NON-NLS-1$ + } + catch (Exception e) { + MessageDialog.openError(window.getShell(), + Messages.TraceControl_EclipseCommandFailure, + Messages.TraceControl_NewNodeCreationFailure + " (" + hostName + ", " + hostAddress + ")" + ":\n" + e.toString()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + return null; + } + } + + if (host != null) { + // successful creation of host + TargetNodeComponent node = null; + if (!fParent.containsChild(hostName)) { + node = new TargetNodeComponent(hostName, fParent, host); + fParent.addChild(node); + } + else { + node = (TargetNodeComponent)fParent.getChild(hostName); + } + + node.connect(); + } + } + return null; + } + + /* + * (non-Javadoc) + * @see org.eclipse.core.commands.IHandler#isEnabled() + */ + @Override + public boolean isEnabled() { + fParent = null; + + // Check if we are closing down + IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + if (window == null) { + return false; + } + + // Check if we are in the Project View + IWorkbenchPage page = window.getActivePage(); + if (page == null) return false; + IWorkbenchPart part = page.getActivePart(); + if (!(part instanceof ControlView)) { + return false; + } + + fParent = ((ControlView) part).getTraceControlRoot(); + + return (fParent != null); + } + + /* + * (non-Javadoc) + * @see org.eclipse.core.commands.IHandler#isHandled() + */ + @Override + public boolean isHandled() { + // TODO Auto-generated method stub + return true; + } + + // ------------------------------------------------------------------------ + // IHandlerListener + // ------------------------------------------------------------------------ + + /* + * (non-Javadoc) + * @see org.eclipse.core.commands.IHandler#addHandlerListener(org.eclipse.core.commands.IHandlerListener) + */ + @Override + public void addHandlerListener(IHandlerListener handlerListener) { + } + + /* + * (non-Javadoc) + * @see org.eclipse.core.commands.IHandler#removeHandlerListener(org.eclipse.core.commands.IHandlerListener) + */ + @Override + public void removeHandlerListener(IHandlerListener handlerListener) { + } +} diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/messages.properties b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/messages.properties new file mode 100644 index 0000000000..2fbf6d9d80 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/messages.properties @@ -0,0 +1,37 @@ +TraceControl_ConnectionFailure=Connecting to host failed +TraceControl_DisconnectionFailure=Disconnection to host failed +TraceControl_ExecutionCancelled=Command Execution cancelled +TraceControl_ExecutionFailure=Command Execution failed +TraceControl_ExecutionTimeout=Command Execution timed-out +TraceControl_ShellNotConnected=Command shell not connected +TraceControl_CommandShellError=Could not create HostShellProcessAdapter +TraceControl_CommandError=Command failed! Command: + +# Commands +TraceControl_ListSessionFailure=List sessions failed +TraceControl_RetrieveNodeConfigurationJob=Retrieving Target Node Configuration ... +TraceControl_EclipseCommandFailure=Command failed +TraceControl_NewNodeCreationFailure=Creation of new connection failed + + +# Dialogs +TraceControl_NewDialogTitle=New Connection +TraceControl_NewNodeExistingConnetionsGroupName=Existing Connections +TraceControl_NewNodeEditButtonName=Edit host information +TraceControl_NewNodeComboToolTip=List of existing connections (host name - host address +TraceControl_NewNodeNameLabel=Node Name +TraceControl_NewNodeNameTooltip=Alias to be displayed for node to connect to. +TraceControl_NewNodeAddressLabel=Node Address +TraceControl_NewNodeAddressTooltip=IP Address or DNS name of node to connect to. +TraceControl_AlreadyExistsError=Node name already exists in Control View + +# Tree structure strings +TraceControl_KernelDomainDisplayName=Kernel +TraceControl_UstGlobalDomainDisplayName=UST global +TraceControl_AllSessionsDisplayName=Sessions +TraceControl_SessionDisplayName=Session +TraceControl_DomainDisplayName=Domain +TraceControl_ChannelDisplayName=Channel +TraceControl_EventDisplayName=Event +TraceControl_ProviderDisplayName=Provider +TraceControl_KernelProviderDisplayName=Kernel diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/IBaseEventInfo.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/IBaseEventInfo.java new file mode 100644 index 0000000000..4c106d816a --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/IBaseEventInfo.java @@ -0,0 +1,57 @@ +/********************************************************************** + * 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.lttng.ui.views.control.model; + +/** + * IBaseEventInfo + *

+ * Interface for retrieval of basic trace event information. + *

+ */ +public interface IBaseEventInfo extends ITraceInfo { + + /** + * @return the trace event type + */ + public TraceEventType getEventType(); + + /** + * Sets the trace event type to the given type + * @param type - type to set + */ + public void setEventType(TraceEventType type); + + /** + * Sets the trace event type to the type specified by the given name. + * @param typeName - event type name + */ + public void setEventType(String typeName); + + /** + * @return the trace event log level + */ + public TraceLogLevel getLogLevel(); + + /** + * Sets the trace event log level to the given level + * @param level - event log level to set + */ + public void setLogLevel(TraceLogLevel level); + + /** + * Sets the trace event log level to the level specified by the given name. + * @param levelName - event log level name + */ + public void setLogLevel(String levelName); + + +} diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/IChannelInfo.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/IChannelInfo.java new file mode 100644 index 0000000000..7de4092a34 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/IChannelInfo.java @@ -0,0 +1,113 @@ +/********************************************************************** + * 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.lttng.ui.views.control.model; + +import java.util.List; + +/** + * IChannelInfo + *

+ * Interface for retrieval of trace channel information. + *

+ */ +public interface IChannelInfo extends ITraceInfo { + + /** + * @return the overwrite mode value. + */ + public boolean isOverwriteMode(); + /** + * Sets the overwrite mode value to the given mode. + * @param mode - mode to set. + */ + public void setOverwriteMode(boolean mode); + + /** + * @return the sub-buffer size. + */ + public long getSubBufferSize(); + /** + * Sets the sub-buffer size to the given value. + * @param bufferSize - size to set to set. + */ + public void setSubBufferSize(long bufferSize); + + /** + * @return the number of sub-buffers. + */ + public int getNumberOfSubBuffers(); + /** + * Sets the number of sub-buffers to the given value. + * @param numberOfSubBuffers - value to set. + */ + public void setNumberOfSubBuffers(int numberOfSubBuffers); + + /** + * @return the switch timer interval. + */ + public long getSwitchTimer(); + /** + * Sets the switch timer interval to the given value. + * @param timer - timer value to set. + */ + public void setSwitchTimer(long timer); + + /** + * @return the read timer interval. + */ + public long getReadTimer(); + /** + * Sets the read timer interval to the given value. + * @param timer - timer value to set.. + */ + public void setReadTimer(long timer); + + /** + * @return the output type. + */ + public String getOutputType(); + /** + * Sets the output type to the given value. + * @param type - type to set. + */ + public void setOutputType(String type); + + /** + * @return the channel state (enabled or disabled). + */ + public TraceEnablement getState(); + /** + * Sets the channel state (enablement) to the given value. + * @param state - state to set. + */ + public void setState(TraceEnablement state); + /** + * Sets the channel state (enablement) to the value specified by the given name. + * @param stateName - state to set. + */ + public void setState(String stateName); + + /** + * @return all event information as array. + */ + public IEventInfo[] getEvents(); + /** + * Sets the event information specified by given list. + * @param events - all event information to set. + */ + public void setEvents(List events); + /** + * Adds a single event information. + * @param event - event information to add. + */ + public void addEvent(IEventInfo event); +} diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/IDomainInfo.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/IDomainInfo.java new file mode 100644 index 0000000000..9056c57963 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/IDomainInfo.java @@ -0,0 +1,42 @@ +/********************************************************************** + * 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.lttng.ui.views.control.model; + +import java.util.List; + +/** + * IDomainInfo + *

+ * Interface for retrieval of trace domain information. + *

+ */ + +public interface IDomainInfo extends ITraceInfo { + + /** + * @return information about all channels + */ + public IChannelInfo[] getChannels(); + + /** + * Sets the channel information specified by given list. + * @param channels - all channel information to set. + */ + public void setChannels(List channels); + + /** + * Adds a single channel information. + * @param channel - channel information to add. + */ + public void addChannel(IChannelInfo channel); + +} diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/IEventInfo.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/IEventInfo.java new file mode 100644 index 0000000000..8d81292fe7 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/IEventInfo.java @@ -0,0 +1,39 @@ +/********************************************************************** + * 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.lttng.ui.views.control.model; + +/** + * IEventInfo + *

+ * Interface for retrieval of trace event information. + *

+ */ +public interface IEventInfo extends IBaseEventInfo { + + /** + * @return the event state (enabled or disabled). + */ + public TraceEnablement getState(); + + /** + * Sets the event state (enablement) to the given value. + * @param state - state to set. + */ + public void setState(TraceEnablement state); + + /** + * Sets the event state (enablement) to the value specified by the given name. + * @param stateName - state to set. + */ + public void setState(String stateName); + +} diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/ISessionInfo.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/ISessionInfo.java new file mode 100644 index 0000000000..fb02ca9a33 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/ISessionInfo.java @@ -0,0 +1,67 @@ +/********************************************************************** + * 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.lttng.ui.views.control.model; + +import java.util.List; + +/** + * ISessionInfo + *

+ * Interface for retrieval of trace session information. + *

+ */ +public interface ISessionInfo extends ITraceInfo { + + /** + * @return the session state state (active or inactive). + */ + public TraceSessionState getSessionState(); + /** + * Sets the session state to the given value. + * @param state - state to set. + */ + public void setSessionState(TraceSessionState state); + + /** + * Sets the event state to the value specified by the given name. + * @param stateName - state to set. + */ + public void setSessionState(String stateName); + + /** + * @return path string where session is located. + */ + public String getSessionPath(); + + /** + * Sets the path string (where session is located) to the given value. + * @param path - session path to set. + */ + public void setSessionPath(String path); + + /** + * @return all domain information as array. + */ + public IDomainInfo[] getDomains(); + + /** + * Sets all domain information specified by given list. + * @param domains - all domain information to set. + */ + public void setDomains(List domains); + + /** + * Adds a single domain information. + * @param domain - domain information to add. + */ + public void addDomain(IDomainInfo domainInfo); +} diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/ITraceControlComponent.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/ITraceControlComponent.java new file mode 100644 index 0000000000..f876506d03 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/ITraceControlComponent.java @@ -0,0 +1,188 @@ +/********************************************************************** + * 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.lttng.ui.views.control.model; + +import java.util.List; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService; +import org.eclipse.swt.graphics.Image; + +/** + * ITraceControlComponent + *

+ * Interface for trace control components that can be displayed in the + * trace control tree viewer. + *

+ */ +public interface ITraceControlComponent extends IAdaptable { + + // ------------------------------------------------------------------------ + // Accessors + // ------------------------------------------------------------------------ + + /** + * @return the name of the component + */ + public String getName(); + + /** + * Sets the name of the component to the given value. + * @param name - name to set + */ + public void setName(String name); + + /** + * @return the image representing the component. + */ + public Image getImage(); + /** + * Sets the image path of the component. + * @param path - path to the image location + */ + public void setImage(String path); + /** + * Sets the image the component. + * @param image - image to the image location + */ + public void setImage(Image image); + /** + * @return tool tip with information about the component. + */ + public String getToolTip(); + + /** + * Sets the tool tip with information about the component. + * @param toolTip - the tool tip to set. + */ + public void setToolTip(String toolTip); + + /** + * @return the node's connection state + */ + public TargetNodeState getTargetNodeState(); + /** + * Sets the node's connection state. + * @param state - the state to set + */ + public void setTargetNodeState(TargetNodeState state); + + /** + * @return returns the parent component. + */ + public ITraceControlComponent getParent(); + + /** + * Sets the parent component. + * @param parent - the parent to set. + */ + public void setParent(ITraceControlComponent parent); + + /** + * @return the children components + */ + public ITraceControlComponent[] getChildren(); + + /** + * Sets the children components. + * @param children - the children to set. + */ + public void setChildren(List children); + + /** + * Returns the child component with given name. + * @param name - name of child to find. + * @return child component or null. + */ + public ITraceControlComponent getChild(String name); + + /** + * @return the LTTng control service implementation. + */ + public ILttngControlService getControlService(); + + /** + * Sets the LTTng control service implementation. + * @param service - the service to set. + */ + public void setControlService(ILttngControlService service); + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + /** + * Dispose any resource. + */ + public void dispose(); + + /** + * Adds a child component. + * @param component - child to add. + */ + public void addChild(ITraceControlComponent component); + + /** + * Removes the given child component. + * @param component - the child to remove. + */ + public void removeChild(ITraceControlComponent component); + + /** + * Removes all children. + */ + public void removeAllChildren(); + + /** + * Checks if child with given name exists. + * @param name - child name to search for. + * @return - true if exists else false. + */ + public boolean containsChild(String name); + + /** + * Checks for children. + * @return true if one or more children exist else false + */ + public boolean hasChildren(); + + /** + * Adds a component listener for notification of component changes. + * @param listener - listener interface implementation to add. + */ + public void addComponentListener(ITraceControlComponentChangedListener listener); + + /** + * Removes a component listener for notification of component changes. + * @param listener - listener interface implementation to remove. + */ + public void removeComponentListener(ITraceControlComponentChangedListener listener); + + /** + * Notifies listeners about the addition of a child. + * @param parent - the parent where the child was added. + * @param component - the child that was added. + */ + public void fireCompenentAdded(ITraceControlComponent parent, ITraceControlComponent component); + + /** + * Notifies listeners about the removal of a child. + * @param parent - the parent where the child was removed. + * @param component - the child that was removed. + */ + public void fireCompenentRemoved(ITraceControlComponent parent, ITraceControlComponent component); + + /** + * Notifies listeners about the change of a component. + * @param component - the component that was changed. + */ + public void fireCompenentChanged(ITraceControlComponent component); +} diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/ITraceControlComponentChangedListener.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/ITraceControlComponentChangedListener.java new file mode 100644 index 0000000000..809b1113a7 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/ITraceControlComponentChangedListener.java @@ -0,0 +1,41 @@ +/********************************************************************** + * 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.lttng.ui.views.control.model; + +/** + * ITraceControlComponentChangedListener + *

+ * Listener interface a class can implement to be notified about changes + * of components + *

+ */ +public interface ITraceControlComponentChangedListener { + /** + * Interface for notifications about the addition of a component. + * @param parent - the parent where the child was added. + * @param component - the child that was added. + */ + public void componentAdded(ITraceControlComponent parent, ITraceControlComponent component); + + /** + * Interface for notifications about the removal of a child. + * @param parent - the parent where the child was removed. + * @param component - the child that was removed. + */ + public void componentRemoved(ITraceControlComponent parent, ITraceControlComponent component); + /** + * NInterface for notifications about the change of a component. + * @param component - the component that was changed. + */ + public void componentChanged(ITraceControlComponent component); +} + diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/ITraceInfo.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/ITraceInfo.java new file mode 100644 index 0000000000..f03d6da92f --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/ITraceInfo.java @@ -0,0 +1,32 @@ +/********************************************************************** + * 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.lttng.ui.views.control.model; + +/** + * ITraceInfo + *

+ * Interface for retrieve trace comon information. + *

+ */ + +public interface ITraceInfo { + /** + * @return the name of the information element. + */ + public String getName(); + + /** + * Sets the name of the information element. + * @param name + */ + public void setName(String name); +} diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/IUstProviderInfo.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/IUstProviderInfo.java new file mode 100644 index 0000000000..8f8e69b55f --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/IUstProviderInfo.java @@ -0,0 +1,51 @@ +/********************************************************************** + * 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.lttng.ui.views.control.model; + +import java.util.List; + +/** + * IUstProviderInfo + *

+ * Interface for retrieval of UST provider information. + *

+ */ +public interface IUstProviderInfo extends ITraceInfo { + + /** + * @return the process ID of the UST provider. + */ + public int getPid(); + + /** + * Sets the process ID of the UST provider to the given value. + * @param pid - process ID to set + */ + public void setPid(int pid); + + /** + * @return all event information as array. + */ + public IBaseEventInfo[] getEvents(); + + /** + * Sets the event information specified by given list. + * @param events - all event information to set. + */ + public void setEvents(List events); + + /** + * Adds a single event information. + * @param event - event information to add. + */ + public void addEvent(IBaseEventInfo event); +} diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/TargetNodeState.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/TargetNodeState.java new file mode 100644 index 0000000000..856eb10810 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/TargetNodeState.java @@ -0,0 +1,25 @@ +/********************************************************************** + * 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.lttng.ui.views.control.model; + +/** + * TargetNodeState + *

+ * Enumeration for the node connection state. + *

+ */ +public enum TargetNodeState { + DISCONNECTED, + DISCONNECTING, + CONNECTED, + CONNECTING; +} diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/TraceEnablement.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/TraceEnablement.java new file mode 100644 index 0000000000..4073b66d4a --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/TraceEnablement.java @@ -0,0 +1,58 @@ +/********************************************************************** + * 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.lttng.ui.views.control.model; + +/** + * TraceEnablement + *

+ * Enumeration for enabled/disabled states. + *

+ */ +public enum TraceEnablement { + + // ------------------------------------------------------------------------ + // Enum definition + // ------------------------------------------------------------------------ + DISABLED("disabled"), //$NON-NLS-1$ + ENABLED("enabled"); //$NON-NLS-1$ + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + /** + * Name of enum + */ + private final String fInName; + + // ------------------------------------------------------------------------ + // Constuctors + // ------------------------------------------------------------------------ + + /** + * Private constructor + * @param name the name of state + */ + private TraceEnablement(String name) { + fInName = name; + } + + // ------------------------------------------------------------------------ + // Accessors + // ------------------------------------------------------------------------ + /** + * @return state name + */ + public String getInName() { + return fInName; + } +}; + diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/TraceEventType.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/TraceEventType.java new file mode 100644 index 0000000000..7139342e44 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/TraceEventType.java @@ -0,0 +1,34 @@ +/********************************************************************** + * 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.lttng.ui.views.control.model; + +/** + * TraceEventType + *

+ * Trace event type enumeration. + *

+ */ +public enum TraceEventType { + TRACEPOINT("tracepoint"), //$NON-NLS-1$ + UNKNOWN("unknown"); //$NON-NLS-1$ + + private final String fInName; + + private TraceEventType(String name) { + fInName = name; + } + + public String getInName() { + return fInName; + } +}; + diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/TraceLogLevel.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/TraceLogLevel.java new file mode 100644 index 0000000000..4c6e27d9fc --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/TraceLogLevel.java @@ -0,0 +1,75 @@ +/********************************************************************** + * 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.lttng.ui.views.control.model; + +/** + * TraceLogLevels + *

+ * Log Level state enumeration. + *

+ */ +@SuppressWarnings("nls") +public enum TraceLogLevel { + + // ------------------------------------------------------------------------ + // Enum definition + // ------------------------------------------------------------------------ + TRACE_EMERG("TRACE_EMERG0"), + TRACE_ALERT("TRACE_ALERT1"), + TRACE_CRIT("TRACE_CRIT2"), + TRACE_ERR("TRACE_ERR3"), + TRACE_WARNING("TRACE_WARNING4"), + TRACE_NOTICE("TRACE_NOTICE5"), + TRACE_INFO("TRACE_INFO6"), + TRACE_SYSTEM("TRACE_SYSTEM7"), + TRACE_PROGRAM("TRACE_PROGRAM8"), + TRACE_PROCESS("TRACE_PROCESS9"), + TRACE_MODULE("TRACE_MODULE10"), + TRACE_UNIT("TRACE_UNIT11"), + TRACE_FUNCTION("TRACE_FUNCTION12"), + TRACE_DEFAULT("TRACE_DEFAULT13"), + TRACE_VERBOSE("TRACE_VERBOSE14"), + TRACE_DEBUG("TRACE_DEBUG15"); + + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + /** + * Name of enum. + */ + private final String fInName; + + // ------------------------------------------------------------------------ + // Constuctors + // ------------------------------------------------------------------------ + + /** + * Private constructor + * @param name the name of state + */ + private TraceLogLevel(String name) { + fInName = name; + } + + // ------------------------------------------------------------------------ + // Accessors + // ------------------------------------------------------------------------ + /** + * @return state name + */ + public String getInName() { + return fInName; + } +}; + + diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/TraceSessionState.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/TraceSessionState.java new file mode 100644 index 0000000000..cfc4bb0dd9 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/TraceSessionState.java @@ -0,0 +1,58 @@ +/********************************************************************** + * 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.lttng.ui.views.control.model; + +/** + * TraceSessionState + *

+ * Session state enumeration. + *

+ */ +public enum TraceSessionState { + + // ------------------------------------------------------------------------ + // Enum definition + // ------------------------------------------------------------------------ + INACTIVE("inactive"), //$NON-NLS-1$ + ACTIVE("active"); //$NON-NLS-1$ + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + /** + * Name of enum. + */ + private final String fInName; + + // ------------------------------------------------------------------------ + // Constuctors + // ------------------------------------------------------------------------ + + /** + * Private constructor + * @param name the name of state + */ + private TraceSessionState(String name) { + fInName = name; + } + + // ------------------------------------------------------------------------ + // Accessors + // ------------------------------------------------------------------------ + /** + * @return state name + */ + public String getInName() { + return fInName; + } +}; + diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/BaseEventComponent.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/BaseEventComponent.java new file mode 100644 index 0000000000..14fc9dac13 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/BaseEventComponent.java @@ -0,0 +1,117 @@ +/********************************************************************** + * 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.lttng.ui.views.control.model.impl; + +import org.eclipse.linuxtools.lttng.ui.views.control.model.IBaseEventInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent; +import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceEventType; +import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceLogLevel; + +/** + * BaseEventComponent + *

+ * Implementation of the base trace event component. + *

+ */ +public class BaseEventComponent extends TraceControlComponent { + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + /** + * Path to icon file for this component. + */ + public static final String TRACE_EVENT_ICON_FILE_ENABLED = "icons/obj16/event_enabled.gif"; //$NON-NLS-1$ + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + /** + * The Event information implementation. + */ + private IBaseEventInfo fEventInfo; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + /** + * Constructor + * @param name - the name of the component. + * @param parent - the parent of this component. + */ + public BaseEventComponent(String name, ITraceControlComponent parent) { + super(name, parent); + setImage(TRACE_EVENT_ICON_FILE_ENABLED); + fEventInfo = new EventInfo(name); + } + + // ------------------------------------------------------------------------ + // Accessors + // ------------------------------------------------------------------------ + /** + * Sets the event information. + * @param eventInfo - the event info to set. + */ + public void setEventInfo(IBaseEventInfo eventInfo) { + fEventInfo = eventInfo; + } + + /** + * @return the event type. + */ + public TraceEventType getEventType() { + return fEventInfo.getEventType(); + } + + /** + * Sets the event type to the given value. + * @param type - type to set. + */ + public void setEventType(TraceEventType type) { + fEventInfo.setEventType(type); + } + + /** + * Sets the event type to the value specified by the give name. + * @param typeName - the type name. + */ + public void setEventType(String typeName) { + fEventInfo.setEventType(typeName); + } + + /** + * @return the trace event log level + */ + public TraceLogLevel getLogLevel() { + return fEventInfo.getLogLevel(); + } + + /** + * Sets the trace event log level to the given level + * @param level - event log level to set + */ + public void setLogLevel(TraceLogLevel level) { + fEventInfo.setLogLevel(level); + } + + /** + * Sets the trace event log level to the level specified by the given name. + * @param levelName - event log level name + */ + public void setLogLevel(String levelName) { + fEventInfo.setLogLevel(levelName); + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ +} diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/BaseEventInfo.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/BaseEventInfo.java new file mode 100644 index 0000000000..26cebc8972 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/BaseEventInfo.java @@ -0,0 +1,209 @@ +/********************************************************************** + * 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.lttng.ui.views.control.model.impl; + +import org.eclipse.linuxtools.lttng.ui.views.control.model.IBaseEventInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceEventType; +import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceLogLevel; + +/** +* BaseEventInfo +*

+* Implementation of the basic trace event interface (IEventInfo) to store event +* related data. +*

+*/ +public class BaseEventInfo extends TraceInfo implements IBaseEventInfo { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + /** + * The trace event type. + */ + private TraceEventType fEventType = TraceEventType.UNKNOWN; + /** + * The trace log level. + */ + private TraceLogLevel fLogLevel = TraceLogLevel.TRACE_DEFAULT; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + /** + * Constructor + * @param name - name of base event + */ + public BaseEventInfo(String name) { + super(name); + } + + /** + * Copy constructor + * @param other - the instance to copy + */ + public BaseEventInfo(BaseEventInfo other) { + super(other); + fEventType = other.fEventType; + } + + // ------------------------------------------------------------------------ + // Accessors + // ------------------------------------------------------------------------ + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IBaseEventInfo#getEventType() + */ + @Override + public TraceEventType getEventType() { + return fEventType; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IBaseEventInfo#setEventType(org.eclipse.linuxtools.lttng.ui.views.control.model.TraceEventType) + */ + @Override + public void setEventType(TraceEventType type) { + fEventType = type; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IBaseEventInfo#setEventType(java.lang.String) + */ + @Override + public void setEventType(String typeName) { + if(TraceEventType.TRACEPOINT.getInName().equals(typeName)) { + fEventType = TraceEventType.TRACEPOINT; + } else { + fEventType = TraceEventType.UNKNOWN; + } + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IBaseEventInfo#getLogLevel() + */ + @Override + public TraceLogLevel getLogLevel() { + return fLogLevel; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IBaseEventInfo#setLogLevel(org.eclipse.linuxtools.lttng.ui.views.control.model.TraceLogLevel) + */ + @Override + public void setLogLevel(TraceLogLevel level) { + fLogLevel = level; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IBaseEventInfo#setLogLevel(java.lang.String) + */ + @Override + public void setLogLevel(String levelName) { + if(TraceLogLevel.TRACE_EMERG.getInName().equals(levelName)) { + fLogLevel = TraceLogLevel.TRACE_EMERG; + } else if(TraceLogLevel.TRACE_ALERT.getInName().equals(levelName)) { + fLogLevel = TraceLogLevel.TRACE_ALERT; + } else if(TraceLogLevel.TRACE_CRIT.getInName().equals(levelName)) { + fLogLevel = TraceLogLevel.TRACE_CRIT; + } else if(TraceLogLevel.TRACE_ERR.getInName().equals(levelName)) { + fLogLevel = TraceLogLevel.TRACE_ERR; + } else if(TraceLogLevel.TRACE_WARNING.getInName().equals(levelName)) { + fLogLevel = TraceLogLevel.TRACE_WARNING; + } else if(TraceLogLevel.TRACE_NOTICE.getInName().equals(levelName)) { + fLogLevel = TraceLogLevel.TRACE_NOTICE; + } else if(TraceLogLevel.TRACE_INFO.getInName().equals(levelName)) { + fLogLevel = TraceLogLevel.TRACE_INFO; + } else if(TraceLogLevel.TRACE_SYSTEM.getInName().equals(levelName)) { + fLogLevel = TraceLogLevel.TRACE_SYSTEM; + } else if(TraceLogLevel.TRACE_PROGRAM.getInName().equals(levelName)) { + fLogLevel = TraceLogLevel.TRACE_PROGRAM; + } else if(TraceLogLevel.TRACE_PROCESS.getInName().equals(levelName)) { + fLogLevel = TraceLogLevel.TRACE_PROCESS; + } else if(TraceLogLevel.TRACE_MODULE.getInName().equals(levelName)) { + fLogLevel = TraceLogLevel.TRACE_MODULE; + } else if(TraceLogLevel.TRACE_UNIT.getInName().equals(levelName)) { + fLogLevel = TraceLogLevel.TRACE_UNIT; + } else if(TraceLogLevel.TRACE_FUNCTION.getInName().equals(levelName)) { + fLogLevel = TraceLogLevel.TRACE_FUNCTION; + } else if(TraceLogLevel.TRACE_DEFAULT.getInName().equals(levelName)) { + fLogLevel = TraceLogLevel.TRACE_DEFAULT; + } else if(TraceLogLevel.TRACE_VERBOSE.getInName().equals(levelName)) { + fLogLevel = TraceLogLevel.TRACE_VERBOSE; + } else if(TraceLogLevel.TRACE_DEBUG.getInName().equals(levelName)) { + fLogLevel = TraceLogLevel.TRACE_DEBUG; + } else { + fLogLevel = TraceLogLevel.TRACE_DEFAULT; + } + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceInfo#hashCode() + */ + @Override + public int hashCode() { + int result = 17; + result = 37 * result + super.hashCode(); + result = 37 * result + fEventType.ordinal(); + result = 37 * result + fLogLevel.ordinal(); + return result; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceInfo#equals(java.lang.Object) + */ + @Override + public boolean equals(Object other) { + if (!(other instanceof BaseEventInfo)) { + return false; + } + + BaseEventInfo otherInfo = (BaseEventInfo) other; + if (!super.equals(otherInfo)) { + return false; + } + + if (fEventType.ordinal() != otherInfo.fEventType.ordinal()) { + return false; + } + + if (fLogLevel.ordinal() != otherInfo.fLogLevel.ordinal()) { + return false; + } + return true; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceInfo#toString() + */ + @SuppressWarnings("nls") + @Override + public String toString() { + StringBuffer output = new StringBuffer(); + output.append("[BaseEventInfo("); + output.append(super.toString()); + output.append(",type="); + output.append(fEventType); + output.append(",level="); + output.append(fLogLevel); + output.append(")]"); + return output.toString(); + } +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/ChannelInfo.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/ChannelInfo.java new file mode 100644 index 0000000000..468952971d --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/ChannelInfo.java @@ -0,0 +1,381 @@ +/********************************************************************** + * 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.lttng.ui.views.control.model.impl; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.linuxtools.lttng.ui.views.control.model.IChannelInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.IEventInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceEnablement; + +/** + * ChannelInfo + *

+ * Implementation of the trace channel interface (IChannelInfo) to store channel + * related data. + *

+ */ +public class ChannelInfo extends TraceInfo implements IChannelInfo { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + /** + * The overwrite mode of the channel. + */ + private boolean fOverwriteMode; + /** + * The sub-buffer size of the channel. + */ + private long fSubBufferSize; + /** + * The number of sub-buffers of the channel. + */ + private int fNumberOfSubBuffers; + /** + * The switch timer interval of the channel. + */ + private long fSwitchTimer; + /** + * The read timer interval of the channel. + */ + private long fReadTimer; + /** + * The Output type of the channel. + */ + private String fOutputType = ""; //$NON-NLS-1$ + /** + * The channel enable state. + */ + private TraceEnablement fState = TraceEnablement.DISABLED; + /** + * The events information of the channel. + */ + private List fEvents = new ArrayList(); + + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + /** + * Constructor + * @param name - name channel + */ + public ChannelInfo(String name) { + super(name); + } + + /** + * Copy constructor + * @param other - the instance to copy + */ + public ChannelInfo(ChannelInfo other) { + super(other); + fOverwriteMode = other.fOverwriteMode; + fSubBufferSize = other.fSubBufferSize; + fNumberOfSubBuffers = other.fNumberOfSubBuffers; + fSwitchTimer = other.fSwitchTimer; + fReadTimer = other.fReadTimer; + fOutputType = (other.fOutputType == null ? null : String.valueOf(other.fOutputType)); + fState = other.fState; + for (Iterator iterator = other.fEvents.iterator(); iterator.hasNext();) { + IEventInfo event = iterator.next(); + if (event instanceof EventInfo) { + fEvents.add(new EventInfo((EventInfo)event)); + } else { + fEvents.add(event); + } + } + } + + // ------------------------------------------------------------------------ + // Accessors + // ------------------------------------------------------------------------ + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IChannelInfo#getOverwriteMode() + */ + @Override + public boolean isOverwriteMode() { + return fOverwriteMode; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IChannelInfo#setOverwriteMode(boolean) + */ + @Override + public void setOverwriteMode(boolean mode) { + fOverwriteMode = mode; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IChannelInfo#getSubBufferSize() + */ + @Override + public long getSubBufferSize() { + return fSubBufferSize; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IChannelInfo#setSubBufferSize(long) + */ + @Override + public void setSubBufferSize(long bufferSize) { + fSubBufferSize = bufferSize; + + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IChannelInfo#getNumberOfSubBuffers() + */ + @Override + public int getNumberOfSubBuffers() { + return fNumberOfSubBuffers; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IChannelInfo#setNumberOfSubBuffers(int) + */ + @Override + public void setNumberOfSubBuffers(int numberOfSubBuffers) { + fNumberOfSubBuffers = numberOfSubBuffers; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IChannelInfo#getSwitchTimer() + */ + @Override + public long getSwitchTimer() { + return fSwitchTimer; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IChannelInfo#setSwitchTimer(long) + */ + @Override + public void setSwitchTimer(long timer) { + fSwitchTimer = timer; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IChannelInfo#getReadTimer() + */ + @Override + public long getReadTimer() { + return fReadTimer; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IChannelInfo#setReadTimer(long) + */ + @Override + public void setReadTimer(long timer) { + fReadTimer = timer; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IChannelInfo#getOutputType() + */ + @Override + public String getOutputType() { + return fOutputType; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IChannelInfo#setOutputType(java.lang.String) + */ + @Override + public void setOutputType(String type) { + fOutputType = type; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IChannelInfo#getState() + */ + @Override + public TraceEnablement getState() { + return fState; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IChannelInfo#setState(org.eclipse.linuxtools.lttng.ui.views.control.model.TraceEnablement) + */ + @Override + public void setState(TraceEnablement state) { + fState = state; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IChannelInfo#setState(java.lang.String) + */ + @Override + public void setState(String stateName) { + fState = TraceEnablement.ENABLED; + if (TraceEnablement.DISABLED.getInName().equals(stateName)) { + fState = TraceEnablement.DISABLED; + } else if (TraceEnablement.ENABLED.getInName().equals(stateName)) { + fState = TraceEnablement.ENABLED; + } + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IChannelInfo#getEvents() + */ + @Override + public IEventInfo[] getEvents() { + return fEvents.toArray(new IEventInfo[fEvents.size()]); + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IChannelInfo#setEvents(java.util.List) + */ + @Override + public void setEvents(List events) { + for (Iterator iterator = events.iterator(); iterator.hasNext();) { + IEventInfo eventInfo = (IEventInfo) iterator.next(); + fEvents.add(eventInfo); + } + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IChannelInfo#addEvent(org.eclipse.linuxtools.lttng.ui.views.control.model.IEventInfo) + */ + @Override + public void addEvent(IEventInfo channel) { + fEvents.add(channel); + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceInfo#hashCode() + */ + @Override + public int hashCode() { + int result = 17; + result = 37 * result + super.hashCode(); + result = 37 * result + Boolean.valueOf(fOverwriteMode).hashCode(); + result = 37 * result + Long.valueOf(fSubBufferSize).hashCode(); + result = 37 * result + fNumberOfSubBuffers; + result = 37 * result + Long.valueOf(fSwitchTimer).hashCode(); + result = 37 * result + Long.valueOf(fReadTimer).hashCode(); + result = 37 * result + (fOutputType != null ? fOutputType.hashCode() : 0); + result = 37 * result + fState.ordinal(); + for (Iterator iterator = fEvents.iterator(); iterator.hasNext();) { + IEventInfo event = (IEventInfo) iterator.next(); + result = 37 * result + event.hashCode(); + } + return result; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceInfo#equals(java.lang.Object) + */ + @Override + public boolean equals(Object other) { + if (!(other instanceof ChannelInfo)) { + return false; + } + + ChannelInfo otherInfo = (ChannelInfo) other; + if (!super.equals(otherInfo)) { + return false; + } + + if (fOverwriteMode != otherInfo.fOverwriteMode) { + return false; + } + if (fSubBufferSize != otherInfo.fSubBufferSize) { + return false; + } + if (fNumberOfSubBuffers != otherInfo.fNumberOfSubBuffers) { + return false; + } + if (fSwitchTimer != otherInfo.fSwitchTimer) { + return false; + } + if (fReadTimer != otherInfo.fReadTimer) { + return false; + } + if (fState.ordinal() != otherInfo.fState.ordinal()) { + return false; + } + if (!fOutputType.equals(otherInfo.fOutputType)) { + return false; + } + if (fEvents.size() != otherInfo.fEvents.size()) { + return false; + } + for (int i = 0; i < fEvents.size(); i++) { + if (!fEvents.get(i).equals(otherInfo.fEvents.get(i))) { + return false; + } + } + return true; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceInfo#toString() + */ + @SuppressWarnings("nls") + @Override + public String toString() { + StringBuffer output = new StringBuffer(); + output.append("[ChannelInfo("); + output.append(super.toString()); + output.append(",State="); + output.append(fState); + output.append(",OverwriteMode="); + output.append(fOverwriteMode); + output.append(",SubBuffersSize="); + output.append(fSubBufferSize); + output.append(",NumberOfSubBuffers="); + output.append(fNumberOfSubBuffers); + output.append(",SwitchTimer="); + output.append(fSwitchTimer); + output.append(",ReadTimer="); + output.append(fReadTimer); + output.append(",output="); + output.append(fOutputType); + output.append(",Events="); + if (fEvents.isEmpty()) { + output.append("None"); + } else { + for (Iterator iterator = fEvents.iterator(); iterator.hasNext();) { + IEventInfo event = (IEventInfo) iterator.next(); + output.append(event.toString()); + } + } + output.append(")]"); + return output.toString(); + } +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/DomainInfo.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/DomainInfo.java new file mode 100644 index 0000000000..1269b85ff5 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/DomainInfo.java @@ -0,0 +1,160 @@ +/********************************************************************** + * 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.lttng.ui.views.control.model.impl; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.linuxtools.lttng.ui.views.control.model.IChannelInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.IDomainInfo; + +/** + * DomainInfo + *

+ * Implementation of the trace domain interface (IDomainInfo) to store domain + * related data. + *

+ */ +public class DomainInfo extends TraceInfo implements IDomainInfo { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + /** + * The channels information of the domain. + */ + private List fChannels = new ArrayList(); + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + /** + * Constructor + * @param name - name of domain + */ + public DomainInfo(String name) { + super(name); + } + + /** + * Copy constructor + * @param other - the instance to copy + */ + public DomainInfo(DomainInfo other) { + super(other); + for (int i = 0; i < other.fChannels.size(); i++) { + if (other.fChannels.get(i) instanceof ChannelInfo) { + fChannels.add(new ChannelInfo((ChannelInfo)other.fChannels.get(i))); + } else { + fChannels.add(other.fChannels.get(i)); + } + } + } + + // ------------------------------------------------------------------------ + // Accessors + // ------------------------------------------------------------------------ + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IDomainInfo#getChannels() + */ + @Override + public IChannelInfo[] getChannels() { + return fChannels.toArray(new IChannelInfo[fChannels.size()]); + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IDomainInfo#setChannels(java.util.List) + */ + @Override + public void setChannels(List channels) { + for (Iterator iterator = channels.iterator(); iterator.hasNext();) { + IChannelInfo channelInfo = (IChannelInfo) iterator.next(); + fChannels.add(channelInfo); + } + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IDomainInfo#addChannel(org.eclipse.linuxtools.lttng.ui.views.control.model.IChannelInfo) + */ + @Override + public void addChannel(IChannelInfo channel) { + fChannels.add(channel); + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceInfo#hashCode() + */ + @Override + public int hashCode() { + int result = 17; + result = 37 * result + super.hashCode(); + for (Iterator iterator = fChannels.iterator(); iterator.hasNext();) { + IChannelInfo channel = (IChannelInfo) iterator.next(); + result = 37 * result + channel.hashCode(); + } + return result; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceInfo#equals(java.lang.Object) + */ + @Override + public boolean equals(Object other) { + if (!(other instanceof DomainInfo)) { + return false; + } + + DomainInfo otherInfo = (DomainInfo) other; + if (!super.equals(otherInfo)) { + return false; + } + + if (fChannels.size() != otherInfo.fChannels.size()) { + return false; + } + for (int i = 0; i < fChannels.size(); i++) { + if (!fChannels.get(i).equals(otherInfo.fChannels.get(i))) { + return false; + } + } + return true; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceInfo#toString() + */ + @SuppressWarnings("nls") + @Override + public String toString() { + StringBuffer output = new StringBuffer(); + output.append("[DomainInfo("); + output.append(super.toString()); + output.append(",Channels="); + if (fChannels.isEmpty()) { + output.append("None"); + } else { + for (Iterator iterator = fChannels.iterator(); iterator.hasNext();) { + IChannelInfo channel = (IChannelInfo) iterator.next(); + output.append(channel.toString()); + } + } + output.append(")]"); + return output.toString(); + } +} diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/EventInfo.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/EventInfo.java new file mode 100644 index 0000000000..9ecb0b1b65 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/EventInfo.java @@ -0,0 +1,138 @@ +/********************************************************************** + * 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.lttng.ui.views.control.model.impl; + +import org.eclipse.linuxtools.lttng.ui.views.control.model.IEventInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceEnablement; + +/** +* EventInfo +*

+* Implementation of the trace event interface (IEventInfo) to store event +* related data. +*

+*/ +public class EventInfo extends BaseEventInfo implements IEventInfo { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + /** + * The enable state of the event. + */ + private TraceEnablement fState = TraceEnablement.DISABLED; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + /** + * Constructor + * @param name - name of event + */ + public EventInfo(String name) { + super(name); + } + + /** + * Copy constructor + * @param other - the instance to copy + */ + public EventInfo(EventInfo other) { + super(other); + fState = other.fState; + } + + // ------------------------------------------------------------------------ + // Accessors + // ------------------------------------------------------------------------ + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IEventInfo#getState() + */ + @Override + public TraceEnablement getState() { + return fState; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IEventInfo#setState(org.eclipse.linuxtools.lttng.ui.views.control.model.TraceEnablement) + */ + @Override + public void setState(TraceEnablement state) { + fState = state; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IEventInfo#setState(java.lang.String) + */ + @Override + public void setState(String stateName) { + fState = TraceEnablement.DISABLED; + if (TraceEnablement.DISABLED.getInName().equals(stateName)) { + fState = TraceEnablement.DISABLED; + } else if (TraceEnablement.ENABLED.getInName().equals(stateName)) { + fState = TraceEnablement.ENABLED; + } + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.BaseEventInfo#hashCode() + */ + @Override + public int hashCode() { + int result = 17; + result = 37 * result + super.hashCode(); + result = 37 * result + fState.ordinal(); + return result; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.BaseEventInfo#equals(java.lang.Object) + */ + @Override + public boolean equals(Object other) { + if (!(other instanceof EventInfo)) { + return false; + } + + EventInfo otherInfo = (EventInfo) other; + if (!super.equals(otherInfo)) { + return false; + } + + if (fState.ordinal() != otherInfo.fState.ordinal()) { + return false; + } + return true; + } + + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.BaseEventInfo#toString() + */ + @SuppressWarnings("nls") + @Override + public String toString() { + StringBuffer output = new StringBuffer(); + output.append("[EventInfo("); + output.append(super.toString()); + output.append(",State="); + output.append(fState); + output.append(")]"); + return output.toString(); + } +} diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/KernelProviderComponent.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/KernelProviderComponent.java new file mode 100644 index 0000000000..bb3e809226 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/KernelProviderComponent.java @@ -0,0 +1,75 @@ +/********************************************************************** + * 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.lttng.ui.views.control.model.impl; + +import java.util.Iterator; +import java.util.List; + +import org.eclipse.linuxtools.lttng.ui.views.control.model.IBaseEventInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent; + +/** + * KernelProviderComponent + *

+ * TODO + *

+ */ +public class KernelProviderComponent extends TraceControlComponent { + + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + /** + * Path to icon file for this component. + */ + public static final String KERNEL_PROVIDER_ICON_FILE = "icons/obj16/targets.gif"; //$NON-NLS-1$ + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + /** + * Constructor + * @param name - the name of the component. + * @param parent - the parent of this component. + */ + public KernelProviderComponent(String name, ITraceControlComponent parent) { + super(name, parent); + setImage(KERNEL_PROVIDER_ICON_FILE); + } + + // ------------------------------------------------------------------------ + // Accessors + // ------------------------------------------------------------------------ + /** + * Sets the events information for this component. + * @param eventInfos - events information to set. + */ + public void setEventInfo(List eventInfos) { + for (Iterator iterator = eventInfos.iterator(); iterator.hasNext();) { + IBaseEventInfo baseEventInfo = (IBaseEventInfo) iterator.next(); + BaseEventComponent component = new BaseEventComponent(baseEventInfo.getName(), this); + component.setEventInfo(baseEventInfo); + addChild(component); + } + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + +} diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/SessionInfo.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/SessionInfo.java new file mode 100644 index 0000000000..ac6464762f --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/SessionInfo.java @@ -0,0 +1,232 @@ +/********************************************************************** + * 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.lttng.ui.views.control.model.impl; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.linuxtools.lttng.ui.views.control.model.IDomainInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.ISessionInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceSessionState; + +/** + * SessionInfo + *

+ * Implementation of the trace session interface (ISessionInfo) to store session + * related data. + *

+ */ +public class SessionInfo extends TraceInfo implements ISessionInfo { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + /** + * The trace session state. + */ + private TraceSessionState fState = TraceSessionState.INACTIVE; + /** + * The trace session path for storing traces. + */ + private String fSessionPath = ""; //$NON-NLS-1$ + /** + * The domains information of this session. + */ + private List fDomains = new ArrayList(); + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + /** + * Constructor + * @param name - name of base event + */ + public SessionInfo(String name) { + super(name); + } + + /** + * Copy constructor + * @param other - the instance to copy + */ + public SessionInfo(SessionInfo other) { + super(other); + fState = other.fState; + fSessionPath = other.fSessionPath; + + for (Iterator iterator = other.fDomains.iterator(); iterator.hasNext();) { + IDomainInfo domain = iterator.next(); + if (domain instanceof DomainInfo) { + fDomains.add(new DomainInfo((DomainInfo)domain)); + } else { + fDomains.add(domain); + } + } + } + + // ------------------------------------------------------------------------ + // Accessors + // ------------------------------------------------------------------------ + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ISessionInfo#getSessionState() + */ + @Override + public TraceSessionState getSessionState() { + return fState; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ISessionInfo#setSessionState(org.eclipse.linuxtools.lttng.ui.views.control.model.TraceSessionState) + */ + @Override + public void setSessionState(TraceSessionState state) { + fState = state; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ISessionInfo#setSessionState(java.lang.String) + */ + @Override + public void setSessionState(String stateName) { + if (TraceSessionState.INACTIVE.getInName().equals(stateName)) { + fState = TraceSessionState.INACTIVE; + } else if (TraceSessionState.ACTIVE.getInName().equals(stateName)) { + fState = TraceSessionState.ACTIVE; + } + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ISessionInfo#getSessionPath() + */ + @Override + public String getSessionPath() { + return fSessionPath; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ISessionInfo#setSessionPath(java.lang.String) + */ + @Override + public void setSessionPath(String path) { + fSessionPath = path; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ISessionInfo#getDomains() + */ + @Override + public IDomainInfo[] getDomains() { + return fDomains.toArray(new IDomainInfo[fDomains.size()]); + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ISessionInfo#setDomains(java.util.List) + */ + @Override + public void setDomains(List domains) { + for (Iterator iterator = domains.iterator(); iterator.hasNext();) { + IDomainInfo domainInfo = (IDomainInfo) iterator.next(); + fDomains.add(domainInfo); + } + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ISessionInfo#addDomain(org.eclipse.linuxtools.lttng.ui.views.control.model.IDomainInfo) + */ + @Override + public void addDomain(IDomainInfo domainInfo) { + fDomains.add(domainInfo); + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceInfo#hashCode() + */ + @Override + public int hashCode() { + int result = 17; + result = 37 * result + super.hashCode(); + result = 37 * result + fSessionPath.hashCode(); + result = 37 * result + fState.hashCode(); + for (Iterator iterator = fDomains.iterator(); iterator.hasNext();) { + IDomainInfo domain = (IDomainInfo) iterator.next(); + result = 37 * result + domain.hashCode(); + } + return result; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceInfo#equals(java.lang.Object) + */ + @Override + public boolean equals(Object other) { + if (!(other instanceof SessionInfo)) { + return false; + } + SessionInfo otherInfo = (SessionInfo) other; + if (!super.equals(otherInfo)) { + return false; + } + + if (!fSessionPath.equals(otherInfo.fSessionPath)) { + return false; + } + + if (fState.ordinal() != otherInfo.fState.ordinal()) { + return false; + } + + if (fDomains.size() != otherInfo.fDomains.size()) { + return false; + } + for (int i = 0; i < fDomains.size(); i++) { + if (!fDomains.get(i).equals(otherInfo.fDomains.get(i))) { + return false; + } + } + return true; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceInfo#toString() + */ + @SuppressWarnings("nls") + @Override + public String toString() { + StringBuffer output = new StringBuffer(); + output.append("[SessionInfo("); + output.append(super.toString()); + output.append(",State="); + output.append(fState); + output.append(",Domains="); + for (Iterator iterator = fDomains.iterator(); iterator.hasNext();) { + IDomainInfo channel = (IDomainInfo) iterator.next(); + output.append(channel.toString()); + } + output.append(")]"); + return output.toString(); + } +} diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/TargetNodeComponent.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/TargetNodeComponent.java new file mode 100644 index 0000000000..d0758dbb40 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/TargetNodeComponent.java @@ -0,0 +1,327 @@ +/********************************************************************** + * 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.lttng.ui.views.control.model.impl; + +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.linuxtools.lttng.ui.LTTngUiPlugin; +import org.eclipse.linuxtools.lttng.ui.views.control.Messages; +import org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent; +import org.eclipse.linuxtools.lttng.ui.views.control.model.TargetNodeState; +import org.eclipse.linuxtools.lttng.ui.views.control.property.TargetNodePropertySource; +import org.eclipse.linuxtools.lttng.ui.views.control.remote.IRemoteSystemProxy; +import org.eclipse.linuxtools.lttng.ui.views.control.remote.RemoteSystemProxy; +import org.eclipse.linuxtools.lttng.ui.views.control.service.ICommandShell; +import org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService; +import org.eclipse.linuxtools.lttng.ui.views.control.service.LTTngControlService; +import org.eclipse.rse.core.model.IHost; +import org.eclipse.rse.core.model.IRSECallback; +import org.eclipse.rse.core.subsystems.CommunicationsEvent; +import org.eclipse.rse.core.subsystems.ICommunicationsListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.views.properties.IPropertySource; + +/** + * TargetNodeComponent + *

+ * Implementation of the trace node component. + *

+ */ +public class TargetNodeComponent extends TraceControlComponent implements ICommunicationsListener { + + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + /** + * Path to icon file for this component (state connected). + */ + public static final String TARGET_NODE_CONNECTED_ICON_FILE = "icons/obj16/target_connected.gif"; //$NON-NLS-1$ + /** + * Path to icon file for this component (state disconnected). + */ + public static final String TARGET_NODE_DISCONNECTED_ICON_FILE = "icons/obj16/target_disconnected.gif"; //$NON-NLS-1$ + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + /** + * The node connection state. + */ + private TargetNodeState fState = TargetNodeState.DISCONNECTED; + /** + * The image to be displayed in state disconnected. + */ + private Image fDisconnectedImage = null; + /** + * The connection implementation. + */ + private IHost fHost = null; + /** + * The remote proxy implementation. + */ + private IRemoteSystemProxy fRemoteProxy = null; + /** + * The control service for LTTng specific commands. + */ + private ILttngControlService fService = null; + /** + * The command shell for issuing commands. + */ + private ICommandShell fShell = null; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + /** + * Constructor + * @param name - the name of the component + * @param parent - the parent of the component + * @param host - the host connection implementation + * @param proxy - the remote proxy implementation + */ + public TargetNodeComponent(String name, ITraceControlComponent parent, IHost host, IRemoteSystemProxy proxy) { + super(name, parent); + setImage(TARGET_NODE_CONNECTED_ICON_FILE); + fDisconnectedImage = LTTngUiPlugin.getDefault().loadIcon(TARGET_NODE_DISCONNECTED_ICON_FILE); + fHost = host; + fRemoteProxy = proxy; + setToolTip(fHost.getHostName()); + } + + /** + * Constructor (using default proxy) + * @param name - the name of the component + * @param parent - the parent of the component + * @param host - the host connection implementation + */ + public TargetNodeComponent(String name, ITraceControlComponent parent, IHost host) { + this(name, parent, host, new RemoteSystemProxy(host)); + } + + // ------------------------------------------------------------------------ + // Accessors + // ------------------------------------------------------------------------ + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent#getImage() + */ + @Override + public Image getImage() { + if (fState == TargetNodeState.CONNECTED) { + return super.getImage(); + } + return fDisconnectedImage; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent#getTargetNodeState() + */ + @Override + public TargetNodeState getTargetNodeState() { + return fState; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent#setTargetNodeState(org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent.TargetNodeState) + */ + @Override + public void setTargetNodeState(TargetNodeState state) { + fState = state; + fireCompenentChanged(TargetNodeComponent.this); + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent#getControlService() + */ + @Override + public ILttngControlService getControlService() { + return fService; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent#setControlService(org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService) + */ + @Override + public void setControlService(ILttngControlService service) { + fService = (ILttngControlService)service; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class) + */ + @SuppressWarnings("rawtypes") + @Override + public Object getAdapter(Class adapter) { + if (adapter == IPropertySource.class) { + return new TargetNodePropertySource(this); + } + return null; + } + + public String getHostName() { + return fHost.getHostName(); + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + /* + * @see org.eclipse.rse.core.subsystems.ICommunicationsListener#communicationsStateChange(org.eclipse.rse.core.subsystems.CommunicationsEvent) + */ + @Override + public void communicationsStateChange(CommunicationsEvent e) { + if (e.getState() == CommunicationsEvent.AFTER_DISCONNECT || + e.getState() == CommunicationsEvent.CONNECTION_ERROR) { + handleDisconnected(); + } if ((e.getState() == CommunicationsEvent.AFTER_CONNECT) && (fState != TargetNodeState.CONNECTING)) { + handleConnected(); + } + } + + /* (non-Javadoc) + * @see org.eclipse.rse.core.subsystems.ICommunicationsListener#isPassiveCommunicationsListener() + */ + @Override + public boolean isPassiveCommunicationsListener() { + return true; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.TraceControlComponent#dispose() + */ + @Override + public void dispose() { + fRemoteProxy.removeCommunicationListener(this); + } + + /** + * Method to connect this node component to the remote target node. + */ + public void connect() { + if (fState == TargetNodeState.DISCONNECTED) { + try { + setTargetNodeState(TargetNodeState.CONNECTING); + fRemoteProxy.connect(new IRSECallback() { + @Override + public void done(IStatus status, Object result) { + // Note: result might be null! + if(status.isOK()) { + handleConnected(); + } + } + }); + } catch (Exception e) { + setTargetNodeState(TargetNodeState.DISCONNECTED); + LTTngUiPlugin.logError(Messages.TraceControl_ConnectionFailure + " (" + getName() + ").", e); //$NON-NLS-1$ //$NON-NLS-2$ + } + } + } + + /** + * Method to disconnect this node component to the remote target node. + */ + public void disconnect() { + if (fState == TargetNodeState.CONNECTED) { + try { + setTargetNodeState(TargetNodeState.DISCONNECTING); + fRemoteProxy.disconnect(); + } catch (Exception e) { + LTTngUiPlugin.logError(Messages.TraceControl_DisconnectionFailure + getName(), e); + } finally { + handleDisconnected(); + } + } + } + + /** + * Retrieves the trace configuration from the target node and populates the information + * in the tree model. The execution is done in a own job. + * + * @throws ExecutionException + */ + public void getConfigurationFromNode() throws ExecutionException { + Job job = new Job(Messages.TraceControl_RetrieveNodeConfigurationJob) { + @Override + protected IStatus run(IProgressMonitor monitor) { + + try { + // Get provider information from node + TraceProviderGroup providerGroup = new TraceProviderGroup(Messages.TraceControl_ProviderDisplayName, TargetNodeComponent.this); + addChild(providerGroup); + providerGroup.getProviderFromNode(monitor); + + // Get session information from node + TraceSessionGroup sessionGroup = new TraceSessionGroup(Messages.TraceControl_AllSessionsDisplayName, TargetNodeComponent.this); + addChild(sessionGroup); + sessionGroup.getSessionsFromNode(monitor); + } catch (ExecutionException e) { + removeAllChildren(); + return new Status(Status.ERROR, LTTngUiPlugin.PLUGIN_ID, e.toString()); + } + + return Status.OK_STATUS; + } + }; + job.setUser(true); + job.schedule(); + + } + + // ------------------------------------------------------------------------ + // Helper function + // ------------------------------------------------------------------------ + /** + * @return returns the control service for LTTng specific commands. + * @throws ExecutionException + */ + private ILttngControlService createControlService() throws ExecutionException { + if (fShell == null) { + fShell = fRemoteProxy.createCommandShell(); + fRemoteProxy.addCommunicationListener(this); + } + fService = new LTTngControlService(fShell); + return fService; + } + + /** + * Handles the connected event. + */ + private void handleConnected() { + setTargetNodeState(TargetNodeState.CONNECTED); + try { + createControlService(); + getConfigurationFromNode(); + } catch (ExecutionException e) { + LTTngUiPlugin.logError(Messages.TraceControl_ListSessionFailure, e); + } + } + + /** + * Handles the disconnected event. + */ + private void handleDisconnected() { + removeAllChildren(); + setTargetNodeState(TargetNodeState.DISCONNECTED); + fShell = null; + fService = null; + } +} diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/TraceChannelComponent.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/TraceChannelComponent.java new file mode 100644 index 0000000000..ec037c6e09 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/TraceChannelComponent.java @@ -0,0 +1,201 @@ +/********************************************************************** + * 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.lttng.ui.views.control.model.impl; + +import org.eclipse.linuxtools.lttng.ui.LTTngUiPlugin; +import org.eclipse.linuxtools.lttng.ui.views.control.Messages; +import org.eclipse.linuxtools.lttng.ui.views.control.model.IChannelInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.IEventInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent; +import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceEnablement; +import org.eclipse.swt.graphics.Image; + + +/** + * TraceChannelComponent + *

+ * Implementation of the trace channel component. + *

+ */ +public class TraceChannelComponent extends TraceControlComponent { + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + /** + * Path to icon file for this component (state enabled). + */ + public static final String TRACE_CHANNEL_ICON_FILE_ENABLED = "icons/obj16/channel.gif"; //$NON-NLS-1$ + /** + * Path to icon file for this component (state disabled). + */ + public static final String TRACE_CHANNEL_ICON_FILE_DISABLED = "icons/obj16/channel_disabled.gif"; //$NON-NLS-1$ + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + /** + * The channel information. + */ + private IChannelInfo fChannelInfo = null; + /** + * The image to be displayed in disabled state. + */ + private Image fDisabledImage = null; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + /** + * Constructor + * @param name - the name of the component. + * @param parent - the parent of this component. + */ + public TraceChannelComponent(String name, ITraceControlComponent parent) { + super(name, parent); + setImage(TRACE_CHANNEL_ICON_FILE_ENABLED); + setToolTip(Messages.TraceControl_ChannelDisplayName); + fChannelInfo = new ChannelInfo(name); + fDisabledImage = LTTngUiPlugin.getDefault().loadIcon(TRACE_CHANNEL_ICON_FILE_DISABLED); + } + + // ------------------------------------------------------------------------ + // Accessors + // ------------------------------------------------------------------------ + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent#getImage() + */ + @Override + public Image getImage() { + if (fChannelInfo.getState() == TraceEnablement.DISABLED) { + return fDisabledImage; + } + return super.getImage(); + } + + /** + * Sets the channel information. + * @param channelInfo + */ + public void setChannelInfo(IChannelInfo channelInfo) { + fChannelInfo = channelInfo; + IEventInfo[] events = fChannelInfo.getEvents(); + for (int i = 0; i < events.length; i++) { + TraceEventComponent event = new TraceEventComponent(events[i].getName(), this); + event.setEventInfo(events[i]); + addChild(event); + } + } + + /** + * @return the overwrite mode value. + */ + public boolean isOverwriteMode() { + return fChannelInfo.isOverwriteMode(); + } + /** + * Sets the overwrite mode value to the given mode. + * @param mode - mode to set. + */ + public void setOverwriteMode(boolean mode){ + fChannelInfo.setOverwriteMode(mode); + } + /** + * @return the sub-buffer size. + */ + public long getSubBufferSize() { + return fChannelInfo.getSubBufferSize(); + } + /** + * Sets the sub-buffer size to the given value. + * @param bufferSize - size to set to set. + */ + public void setSubBufferSize(long bufferSize) { + fChannelInfo.setSubBufferSize(bufferSize); + } + /** + * @return the number of sub-buffers. + */ + public int getNumberOfSubBuffers() { + return fChannelInfo.getNumberOfSubBuffers(); + } + /** + * Sets the number of sub-buffers to the given value. + * @param numberOfSubBuffers - value to set. + */ + public void setNumberOfSubBuffers(int numberOfSubBuffers) { + fChannelInfo.setNumberOfSubBuffers(numberOfSubBuffers); + } + /** + * @return the switch timer interval. + */ + public long getSwitchTimer() { + return fChannelInfo.getSwitchTimer(); + } + /** + * Sets the switch timer interval to the given value. + * @param timer - timer value to set. + */ + public void setSwitchTimer(long timer) { + fChannelInfo.setSwitchTimer(timer); + } + /** + * @return the read timer interval. + */ + public long getReadTimer() { + return fChannelInfo.getReadTimer(); + } + /** + * Sets the read timer interval to the given value. + * @param timer - timer value to set.. + */ + public void setReadTimer(long timer) { + fChannelInfo.setReadTimer(timer); + } + /** + * @return the output type. + */ + public String getOutputType() { + return fChannelInfo.getOutputType(); + } + /** + * Sets the output type to the given value. + * @param type - type to set. + */ + public void setOutputType(String type) { + fChannelInfo.setOutputType(type); + } + /** + * @return the channel state (enabled or disabled). + */ + public TraceEnablement getState() { + return fChannelInfo.getState(); + } + /** + * Sets the channel state (enablement) to the given value. + * @param state - state to set. + */ + public void setState(TraceEnablement state) { + fChannelInfo.setState(state); + } + /** + * Sets the channel state (enablement) to the value specified by the given name. + * @param stateName - state to set. + */ + public void setState(String stateName) { + fChannelInfo.setState(stateName); + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ +} diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/TraceControlComponent.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/TraceControlComponent.java new file mode 100644 index 0000000000..b8b728924c --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/TraceControlComponent.java @@ -0,0 +1,430 @@ +/********************************************************************** + * 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.lttng.ui.views.control.model.impl; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.core.runtime.ListenerList; +import org.eclipse.linuxtools.lttng.ui.LTTngUiPlugin; +import org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent; +import org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponentChangedListener; +import org.eclipse.linuxtools.lttng.ui.views.control.model.TargetNodeState; +import org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService; +import org.eclipse.swt.graphics.Image; + +/** + * TraceControlComponent + *

+ * Base implementation for trace control component. + *

+ */ +public class TraceControlComponent implements ITraceControlComponent { + + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + /** + * The nambe of the component + */ + private String fName = ""; //$NON-NLS-1$ + /** + * The image to be displayed for the component. + */ + private Image fImage = null; + /** + * The tool tip to be displayed for the component. + */ + private String fToolTip = null; + /** + * The parent component. + */ + private ITraceControlComponent fParent = null; + /** + * The list if children components. + */ + private List fChildren = new ArrayList(); + + /** + * The list of listeners to be notfied about changes. + */ + private ListenerList fListeners = new ListenerList(); + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + /** + * Constructor + * @param name - the name of the component. + */ + public TraceControlComponent(String name) { + this(name, null); + } + + /** + * Constructor + * @param name - the name of the component. + * @param parent - the parent component. + */ + public TraceControlComponent(String name, ITraceControlComponent parent) { + fName = name; + fParent = parent; + } + + // ------------------------------------------------------------------------ + // Accessors + // ------------------------------------------------------------------------ + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent#getName() + */ + @Override + public String getName() { + return fName; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent#setName(java.lang.String) + */ + @Override + public void setName(String name) { + fName = name; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent#getImage() + */ + @Override + public Image getImage() { + return fImage; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent#setImage(java.lang.String) + */ + @Override + public void setImage(String path) { + fImage = LTTngUiPlugin.getDefault().loadIcon(path); + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent#setImage(org.eclipse.swt.graphics.Image) + */ + @Override + public void setImage(Image image) { + fImage = image; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent#getToolTip() + */ + @Override + public String getToolTip() { + return fToolTip; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent#setToolTip(java.lang.String) + */ + @Override + public void setToolTip(String toolTip) { + fToolTip = toolTip; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent#getTargetNodeState() + */ + @Override + public TargetNodeState getTargetNodeState() { + if (getParent() != null) { + return getParent().getTargetNodeState(); + } + return TargetNodeState.DISCONNECTED; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent#setTargetNodeState(org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent.TargetNodeState) + */ + @Override + public void setTargetNodeState(TargetNodeState state) { + if (getParent() != null) { + getParent().setTargetNodeState(state); + } + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent#getControlService() + */ + @Override + public ILttngControlService getControlService() { + if (getParent() != null) { + return getParent().getControlService(); + } + return null; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent#setControlService(org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService) + */ + @Override + public void setControlService(ILttngControlService service) { + if (getParent() != null) { + getParent().setControlService(service); + } + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent#getParent() + */ + @Override + public ITraceControlComponent getParent() { + return fParent; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent#setParent(org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent) + */ + @Override + public void setParent(ITraceControlComponent parent) { + fParent = parent; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent#getChildren() + */ + @Override + public ITraceControlComponent[] getChildren() { + return (ITraceControlComponent [])fChildren.toArray(new TraceControlComponent[fChildren.size()]); + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent#setChildren(java.util.List) + */ + @Override + public void setChildren(List children) { + for (Iterator iterator = children.iterator(); iterator.hasNext();) { + ITraceControlComponent traceControlComponent = (ITraceControlComponent) iterator.next(); + fChildren.add(traceControlComponent); + } + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent#getChild(java.lang.String) + */ + @Override + public ITraceControlComponent getChild(String name) { + ITraceControlComponent child = null; + for (int i = 0; i < fChildren.size(); i++) { + if (fChildren.get(i).getName().equals(name)) { + child = fChildren.get(i); + break; + } + } + return child; + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent#dispose() + */ + @Override + public void dispose() { + // default implementation + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent#addChild(org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent) + */ + @Override + public void addChild(ITraceControlComponent component) { + if (component != null) { + fChildren.add(component); + } + fireCompenentAdded(this, component); + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent#removeChild(org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent) + */ + @Override + public void removeChild(ITraceControlComponent component) { + if (component != null) { + fChildren.remove(component); + component.dispose(); + } + fireCompenentRemoved(this, component); + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent#removeAllChildren() + */ + @Override + public void removeAllChildren() { + for (Iterator iterator = fChildren.iterator(); iterator.hasNext();) { + ITraceControlComponent child = (ITraceControlComponent) iterator.next(); + child.removeAllChildren(); + } + fChildren.clear(); +// fireCompenentChanged(this); + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent#containsChild(java.lang.String) + */ + @Override + public boolean containsChild(String name) { + boolean retValue = false; + for (int i = 0; i < fChildren.size(); i++) { + if (fChildren.get(i).getName().equals(name)) { + retValue = true; + break; + } + } + return retValue; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent#hasChildren() + */ + @Override + public boolean hasChildren() { + return !fChildren.isEmpty(); + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent#addComponentListener(org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponentChangedListener) + */ + @Override + public void addComponentListener(ITraceControlComponentChangedListener listener) { + if (fParent != null) + fParent.addComponentListener(listener); + else { + fListeners.add(listener); + } + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent#removeComponentListener(org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponentChangedListener) + */ + @Override + public void removeComponentListener(ITraceControlComponentChangedListener listener) { + if (fParent != null) + fParent.removeComponentListener(listener); + else { + fListeners.remove(listener); + } + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent#fireCompenentAdded(org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent, org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent) + */ + @Override + public void fireCompenentAdded(ITraceControlComponent parent, ITraceControlComponent component) { + if (component == null) { + return; + } + + if (fParent != null) { + fParent.fireCompenentAdded(parent, component); + } else { + Object[] listeners = fListeners.getListeners(); + for (int i = 0; i < listeners.length; i++) { + ITraceControlComponentChangedListener listener = (ITraceControlComponentChangedListener) listeners[i]; + listener.componentAdded(parent, component); + } + } + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent#fireCompenentRemoved(org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent, org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent) + */ + @Override + public void fireCompenentRemoved(ITraceControlComponent parent, ITraceControlComponent component) { + if (component == null) { + return; + } + + if (fParent != null) { + fParent.fireCompenentRemoved(parent, component); + } else { + Object[] listeners = fListeners.getListeners(); + for (int i = 0; i < listeners.length; i++) { + ITraceControlComponentChangedListener listener = (ITraceControlComponentChangedListener) listeners[i]; + listener.componentRemoved(parent, component); + } + } + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent#fireCompenentChanged(org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent) + */ + @Override + public void fireCompenentChanged(ITraceControlComponent component) { + if (component == null) { + return; + } + + if (fParent != null) { + fParent.fireCompenentChanged(component); + } else { + Object[] listeners = fListeners.getListeners(); + for (int i = 0; i < listeners.length; i++) { + ITraceControlComponentChangedListener listener = (ITraceControlComponentChangedListener) listeners[i]; + listener.componentChanged(component); + } + } + } + + /* + * (non-Javadoc) + * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) + */ + @SuppressWarnings("rawtypes") + @Override + public Object getAdapter(Class adapter) { + return null; + } +} diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/TraceControlRoot.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/TraceControlRoot.java new file mode 100644 index 0000000000..cf2337402e --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/TraceControlRoot.java @@ -0,0 +1,41 @@ +/********************************************************************** + * 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.lttng.ui.views.control.model.impl; + + +/** + * TraceControlRoot + *

+ * Root element in trace control tree. + *

+ */ +public class TraceControlRoot extends TraceControlComponent { + + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + /** + * The name of the root component + */ + public final static String TRACE_CONTROL_ROOT_NAME = "trace_control_root"; //$NON-NLS-1$ + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + /** + * Default constructor + */ + public TraceControlRoot() { + super(TRACE_CONTROL_ROOT_NAME); + } + +} diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/TraceDomainComponent.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/TraceDomainComponent.java new file mode 100644 index 0000000000..36ed3400cf --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/TraceDomainComponent.java @@ -0,0 +1,77 @@ +/********************************************************************** + * 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.lttng.ui.views.control.model.impl; + +import org.eclipse.linuxtools.lttng.ui.views.control.Messages; +import org.eclipse.linuxtools.lttng.ui.views.control.model.IChannelInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.IDomainInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent; + +/** + * TraceDomainComponent + *

+ * Implementation of the trace domain component. + *

+ */ +public class TraceDomainComponent extends TraceControlComponent { + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + /** + * Path to icon file for this component. + */ + public static final String TRACE_DOMAIN_ICON_FILE = "icons/obj16/domain.gif"; //$NON-NLS-1$ + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + /** + * The domain information. + */ + private IDomainInfo fDomainInfo = null; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + /** + * Constructor + * @param name - the name of the component. + * @param parent - the parent of this component. + */ + public TraceDomainComponent(String name, ITraceControlComponent parent) { + super(name, parent); + setImage(TRACE_DOMAIN_ICON_FILE); + setToolTip(Messages.TraceControl_DomainDisplayName); + fDomainInfo = new DomainInfo(name); + } + + // ------------------------------------------------------------------------ + // Accessors + // ------------------------------------------------------------------------ + /** + * Sets the domain information. + * @param domainInfo - the domain information to set. + */ + public void setDomainInfo(IDomainInfo domainInfo) { + fDomainInfo = domainInfo; + IChannelInfo[] channels = fDomainInfo.getChannels(); + for (int i = 0; i < channels.length; i++) { + TraceChannelComponent channel = new TraceChannelComponent(channels[i].getName(), this); + channel.setChannelInfo(channels[i]); + addChild(channel); + } + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ +} diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/TraceEventComponent.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/TraceEventComponent.java new file mode 100644 index 0000000000..49c00d4f5c --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/TraceEventComponent.java @@ -0,0 +1,166 @@ +/********************************************************************** + * 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.lttng.ui.views.control.model.impl; + +import org.eclipse.linuxtools.lttng.ui.LTTngUiPlugin; +import org.eclipse.linuxtools.lttng.ui.views.control.Messages; +import org.eclipse.linuxtools.lttng.ui.views.control.model.IEventInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent; +import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceEnablement; +import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceEventType; +import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceLogLevel; +import org.eclipse.swt.graphics.Image; + + +/** + * TraceChannelComponent + *

+ * Implementation of the trace channel component. + *

+ */ +public class TraceEventComponent extends TraceControlComponent { + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + /** + * Path to icon file for this component (enabled state). + */ + public static final String TRACE_EVENT_ICON_FILE_ENABLED = "icons/obj16/event_enabled.gif"; //$NON-NLS-1$ + /** + * Path to icon file for this component (disabled state). + */ + public static final String TRACE_EVENT_ICON_FILE_DISABLED = "icons/obj16/event_disabled.gif"; //$NON-NLS-1$ + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + /** + * The event information. + */ + private IEventInfo fEventInfo = null; + /** + * The image to be displayed when in disabled state. + */ + private Image fDisabledImage = null; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + /** + * Constructor + * @param name - the name of the component. + * @param parent - the parent of this component. + */ + public TraceEventComponent(String name, ITraceControlComponent parent) { + super(name, parent); + setImage(TRACE_EVENT_ICON_FILE_ENABLED); + setToolTip(Messages.TraceControl_EventDisplayName); + fEventInfo = new EventInfo(name); + fDisabledImage = LTTngUiPlugin.getDefault().loadIcon(TRACE_EVENT_ICON_FILE_DISABLED); + } + + // ------------------------------------------------------------------------ + // Accessors + // ------------------------------------------------------------------------ + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent#getImage() + */ + @Override + public Image getImage() { + if (fEventInfo.getState() == TraceEnablement.DISABLED) { + return fDisabledImage; + } + return super.getImage(); + } + + /** + * Sets the event information. + * @param eventInfo - the event information to set. + */ + public void setEventInfo(IEventInfo eventInfo) { + fEventInfo = eventInfo; + } + + /** + * @return the trace event type + */ + public TraceEventType getEventType() { + return fEventInfo.getEventType(); + } + + /** + * Sets the trace event type to the given type + * @param type - type to set + */ + public void setEventType(TraceEventType type) { + fEventInfo.setEventType(type); + } + + /** + * Sets the trace event type to the type specified by the given name. + * @param type - event type name + */ + public void setEventType(String typeName) { + fEventInfo.setEventType(typeName); + } + + /** + * @return the event state (enabled or disabled). + */ + public TraceEnablement getState() { + return fEventInfo.getState(); + } + + /** + * Sets the event state (enablement) to the given value. + * @param state - state to set. + */ + public void setState(TraceEnablement state) { + fEventInfo.setState(state); + } + + /** + * Sets the event state (enablement) to the value specified by the given name. + * @param stateName - state to set. + */ + public void setState(String stateName) { + fEventInfo.setState(stateName); + } + + /** + * @return the trace event log level + */ + public TraceLogLevel getLogLevel() { + return fEventInfo.getLogLevel(); + } + + /** + * Sets the trace event log level to the given level + * @param level - event log level to set + */ + public void setLogLevel(TraceLogLevel level) { + fEventInfo.setLogLevel(level); + } + + /** + * Sets the trace event log level to the level specified by the given name. + * @param levelName - event log level name + */ + public void setLogLevel(String levelName) { + fEventInfo.setLogLevel(levelName); + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ +} diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/TraceInfo.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/TraceInfo.java new file mode 100644 index 0000000000..5ae5e2e0f0 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/TraceInfo.java @@ -0,0 +1,120 @@ +/********************************************************************** + * 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.lttng.ui.views.control.model.impl; + +import org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceInfo; + +/** + * TraceInfo + *

+ * Implementation of the base trace information interface (ITraceInfo) to + * store common data. + *

+ */ +public class TraceInfo implements ITraceInfo { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + /** + * The name of the element. + */ + private String fName = null; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + /** + * Constructor + * @param name - name of trace element + */ + public TraceInfo(String name) { + if (name == null) { + throw new IllegalArgumentException(); + } + fName = name; + } + + /** + * Copy constructor + * @param other - the instance to copy + */ + public TraceInfo(TraceInfo other) { + if (other == null) { + throw new IllegalArgumentException(); + } else { + fName = String.valueOf(other.fName); + } + } + + // ------------------------------------------------------------------------ + // Accessors + // ------------------------------------------------------------------------ + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceInfo#getName() + */ + @Override + public String getName() { + return fName; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceInfo#setName(java.lang.String) + */ + @Override + public void setName(String name) { + fName = name; + } + + /* + * (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + if (fName == null) { + return 17; + } + return fName.hashCode(); + } + + /* + * (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TraceInfo)) { + return false; + } + + TraceInfo otherInfo = (TraceInfo) other; + return fName.equals(otherInfo.fName); + } + + /* + * (non-Javadoc) + * @see java.lang.Object#toString() + */ + @SuppressWarnings("nls") + @Override + public String toString() { + StringBuffer output = new StringBuffer(); + output.append("[TraceInfo("); + output.append("Name="); + output.append(getName()); + output.append(")]"); + return output.toString(); + } +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/TraceProviderGroup.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/TraceProviderGroup.java new file mode 100644 index 0000000000..b81272857b --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/TraceProviderGroup.java @@ -0,0 +1,95 @@ +/********************************************************************** + * 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.lttng.ui.views.control.model.impl; + +import java.util.Iterator; +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.lttng.ui.views.control.Messages; +import org.eclipse.linuxtools.lttng.ui.views.control.model.IBaseEventInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent; +import org.eclipse.linuxtools.lttng.ui.views.control.model.IUstProviderInfo; + +/** + * TraceProviderGroup + *

+ * Implementation of the trace provider group. + *

+ */ +public class TraceProviderGroup extends TraceControlComponent { + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + /** + * Path to icon file for this component. + */ + public static final String TRACE_PROVIDERS_ICON_FILE = "icons/obj16/providers.gif"; //$NON-NLS-1$ + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + /** + * Constructor + * @param name - the name of the component. + * @param parent - the parent of this component. + */ + public TraceProviderGroup(String name, ITraceControlComponent parent) { + super(name, parent); + setImage(TRACE_PROVIDERS_ICON_FILE); + } + + // ------------------------------------------------------------------------ + // Accessors + // ------------------------------------------------------------------------ + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + /** + * Gets the provider information from the target node. + * @throws ExecutionException + */ + public void getProviderFromNode() throws ExecutionException { + getProviderFromNode(new NullProgressMonitor()); + } + + /** + * Gets the provider information from the target node. + * @param monitor - a progress monitor + * @throws ExecutionException + */ + public void getProviderFromNode(IProgressMonitor monitor) throws ExecutionException { + + List eventInfos = getControlService().getKernelProvider(monitor); + KernelProviderComponent component = new KernelProviderComponent(Messages.TraceControl_KernelProviderDisplayName, this); + addChild(component); + component.setEventInfo(eventInfos); + + List allProviders = getControlService().getUstProvider(monitor); + + for (Iterator iterator = allProviders.iterator(); iterator.hasNext();) { + IUstProviderInfo ustProviderInfo = (IUstProviderInfo) iterator.next(); + UstProviderComponent ustComponent = new UstProviderComponent(ustProviderInfo.getName(), this); + addChild(ustComponent); + ustComponent.setUstProvider(ustProviderInfo); + } + } +} + diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/TraceSessionComponent.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/TraceSessionComponent.java new file mode 100644 index 0000000000..4376cce749 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/TraceSessionComponent.java @@ -0,0 +1,185 @@ +/********************************************************************** + * 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.lttng.ui.views.control.model.impl; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.linuxtools.lttng.ui.LTTngUiPlugin; +import org.eclipse.linuxtools.lttng.ui.views.control.Messages; +import org.eclipse.linuxtools.lttng.ui.views.control.model.IDomainInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.ISessionInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent; +import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceSessionState; +import org.eclipse.swt.graphics.Image; + +/** + * TraceSessionComponent + *

+ * Implementation of the trace session component. + *

+ */ +public class TraceSessionComponent extends TraceControlComponent { + + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + /** + * Path to icon file for this component (inactive state). + */ + public static final String TRACE_SESSION_ICON_FILE_INACTIVE = "icons/obj16/session_inactive.gif"; //$NON-NLS-1$ + /** + * Path to icon file for this component (active state). + */ + public static final String TRACE_SESSION_ICON_FILE_ACTIVE = "icons/obj16/session_active.gif"; //$NON-NLS-1$ + /** + * Path to icon file for this component (destroyed state). + */ + public static final String TRACE_SESSION_ICON_FILE_DESTROYED = "icons/obj16/session_destroyed.gif"; //$NON-NLS-1$ + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + /** + * The session information. + */ + private ISessionInfo fSessionInfo = null; + /** + * A flag to indicate if session has been destroyed. + */ + private boolean fIsDestroyed = false; + /** + * The image to be displayed in state active. + */ + private Image fActiveImage = null; + /** + * The image to be displayed in state destroyed + */ + private Image fDestroyedImage = null; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + /** + * Constructor + * @param name - the name of the component. + * @param parent - the parent of this component. + */ + public TraceSessionComponent(String name, ITraceControlComponent parent) { + super(name, parent); + setImage(TRACE_SESSION_ICON_FILE_INACTIVE); + setToolTip(Messages.TraceControl_SessionDisplayName); + fSessionInfo = new SessionInfo(name); + fActiveImage = LTTngUiPlugin.getDefault().loadIcon(TRACE_SESSION_ICON_FILE_ACTIVE); + fDestroyedImage = LTTngUiPlugin.getDefault().loadIcon(TRACE_SESSION_ICON_FILE_DESTROYED); + } + + // ------------------------------------------------------------------------ + // Accessors + // ------------------------------------------------------------------------ + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent#getImage() + */ + @Override + public Image getImage() { + if (fIsDestroyed) { + return fDestroyedImage; + } + + if (fSessionInfo.getSessionState() == TraceSessionState.INACTIVE) { + return super.getImage(); + } + + return fActiveImage; + } + + + /** + * @return the whether the session is destroyed or not. + */ + public boolean isDestroyed() { + return fIsDestroyed; + } + + /** + * Sets the session destroyed state to the given value. + * @param destroyed - value to set. + */ + public void setDestroyed(boolean destroyed) { + fIsDestroyed = destroyed; + } + + /** + * @return the session state state (active or inactive). + */ + public TraceSessionState getSessionState() { + return fSessionInfo.getSessionState(); + } + + /** + * Sets the session state to the given value. + * @param state - state to set. + */ + public void setSessionState(TraceSessionState state) { + fSessionInfo.setSessionState(state); + } + + /** + * Sets the event state to the value specified by the given name. + * @param stateName - state to set. + */ + public void setSessionState(String stateName) { + fSessionInfo.setSessionState(stateName); + } + + /** + * @return path string where session is located. + */ + public String getSessionPath() { + return fSessionInfo.getSessionPath(); + } + + /** + * Sets the path string (where session is located) to the given value. + * @param path - session path to set. + */ + public void setSessionPath(String sessionPath) { + fSessionInfo.setSessionPath(sessionPath); + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + /** + * Retrieves the session configuration from the node. + * @throws ExecutionException + */ + public void getConfigurationFromNode() throws ExecutionException { + getConfigurationFromNode(new NullProgressMonitor()); + } + + /** + * Retrieves the session configuration from the node. + * @param monitor - a progress monitor + * @throws ExecutionException + */ + public void getConfigurationFromNode(IProgressMonitor monitor) throws ExecutionException { + fSessionInfo = getControlService().getSession(getName(), monitor); + IDomainInfo[] domains = fSessionInfo.getDomains(); + for (int i = 0; i < domains.length; i++) { + TraceDomainComponent domainComponenent = new TraceDomainComponent(domains[i].getName(), this); + addChild(domainComponenent); + domainComponenent.setDomainInfo(domains[i]); + } + } +} diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/TraceSessionGroup.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/TraceSessionGroup.java new file mode 100644 index 0000000000..105f76a738 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/TraceSessionGroup.java @@ -0,0 +1,79 @@ +/********************************************************************** + * 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.lttng.ui.views.control.model.impl; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent; + +/** + * TraceSessionGroup + *

+ * Implementation of the trace session group. + *

+ */ +public class TraceSessionGroup extends TraceControlComponent { + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + /** + * Path to icon file for this component. + */ + public static final String TRACE_SESSIONS_ICON_FILE = "icons/obj16/sessions.gif"; //$NON-NLS-1$ + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + /** + * Constructor + * @param name - the name of the component. + * @param parent - the parent of this component. + */ + public TraceSessionGroup(String name, ITraceControlComponent parent) { + super(name, parent); + setImage(TRACE_SESSIONS_ICON_FILE); + } + + // ------------------------------------------------------------------------ + // Accessors + // ------------------------------------------------------------------------ + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + /** + * Retrieves the sessions information from the node. + * @throws ExecutionException + */ + public void getSessionsFromNode() throws ExecutionException { + getSessionsFromNode(new NullProgressMonitor()); + } + + /** + * Retrieves the sessions information from the node. + * @param monitor - a progress monitor + * @throws ExecutionException + */ + public void getSessionsFromNode(IProgressMonitor monitor) throws ExecutionException { + String[] sessionNames = getControlService().getSessionNames(monitor); + for (int i = 0; i < sessionNames.length; i++) { + TraceSessionComponent session = new TraceSessionComponent(sessionNames[i], this); + addChild(session); + session.getConfigurationFromNode(monitor); + } + } +} diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/UstProviderComponent.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/UstProviderComponent.java new file mode 100644 index 0000000000..102edae67c --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/UstProviderComponent.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.lttng.ui.views.control.model.impl; + +import org.eclipse.linuxtools.lttng.ui.views.control.model.IBaseEventInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent; +import org.eclipse.linuxtools.lttng.ui.views.control.model.IUstProviderInfo; + +/** + * UstProviderComponent + *

+ * Implementation of the UST provider component. + *

+ */ +public class UstProviderComponent extends TraceControlComponent { + + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + /** + * Path to icon file for this component. + */ + public static final String USTL_PROVIDER_ICON_FILE = "icons/obj16/targets.gif"; //$NON-NLS-1$ + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + /** + * The UST provider information. + */ + private IUstProviderInfo fProviderInfo = null; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + /** + * Constructor + * @param name - the name of the component. + * @param parent - the parent of this component. + */ + public UstProviderComponent(String name, ITraceControlComponent parent) { + super(name, parent); + setImage(USTL_PROVIDER_ICON_FILE); + fProviderInfo = new UstProviderInfo(name); + } + + // ------------------------------------------------------------------------ + // Accessors + // ------------------------------------------------------------------------ + /** + * Sets the UST provider information to the given value. + * @param providerInfo - the provider information to set + */ + public void setUstProvider(IUstProviderInfo providerInfo) { + fProviderInfo = providerInfo; + IBaseEventInfo[] events = providerInfo.getEvents(); + for (int i = 0; i < events.length; i++) { + BaseEventComponent component = new BaseEventComponent(events[i].getName(), this); + component.setEventInfo(events[i]); + addChild(component); + } + setToolTip("PID=" + fProviderInfo.getPid()); //$NON-NLS-1$ + } + + /** + * @return the process ID of the UST provider. + */ + public int getPid() { + return fProviderInfo.getPid(); + } + + /** + * Sets the process ID of the UST provider to the given value. + * @param pid - process ID to set + */ + public void setPid(int pid) { + fProviderInfo.setPid(pid); + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + +} + + diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/UstProviderInfo.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/UstProviderInfo.java new file mode 100644 index 0000000000..537d734117 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/model/impl/UstProviderInfo.java @@ -0,0 +1,191 @@ +/********************************************************************** + * 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.lttng.ui.views.control.model.impl; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.linuxtools.lttng.ui.views.control.model.IBaseEventInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.IUstProviderInfo; + +/** + * UstProviderInfo + *

+ * Implementation of the Ust Provider interface (IUstProviderInfo) to store UST + * provider related data. + *

+ */ +public class UstProviderInfo extends TraceInfo implements IUstProviderInfo { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + /** + * The process ID of the UST provider. + */ + private int fPid = 0; + /** + * List of event information. + */ + private List fEvents = new ArrayList(); + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + /** + * Constructor + * @param name - name of UST provider + */ + public UstProviderInfo(String name) { + super(name); + } + + /** + * Copy constructor + * @param other - the instance to copy + */ + public UstProviderInfo(UstProviderInfo other) { + super(other); + fPid = other.fPid; + for (Iterator iterator = other.fEvents.iterator(); iterator.hasNext();) { + IBaseEventInfo event = iterator.next(); + if (event instanceof BaseEventInfo) { + fEvents.add(new BaseEventInfo((BaseEventInfo)event)); + } else { + fEvents.add(event); + } + } + } + + // ------------------------------------------------------------------------ + // Accessors + // ------------------------------------------------------------------------ + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IUstProviderInfo#getPid() + */ + @Override + public int getPid() { + return fPid; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IUstProviderInfo#setPid(int) + */ + @Override + public void setPid(int pid) { + fPid = pid; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IUstProviderInfo#getEvents() + */ + @Override + public IBaseEventInfo[] getEvents() { + return fEvents.toArray(new IBaseEventInfo[fEvents.size()]); + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IUstProviderInfo#setEvents(java.util.List) + */ + @Override + public void setEvents(List events) { + for (Iterator iterator = events.iterator(); iterator.hasNext();) { + IBaseEventInfo eventInfo = (IBaseEventInfo) iterator.next(); + fEvents.add(eventInfo); + } + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.IUstProviderInfo#addEvent(org.eclipse.linuxtools.lttng.ui.views.control.model.IBaseEventInfo) + */ + @Override + public void addEvent(IBaseEventInfo event) { + fEvents.add(event); + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceInfo#hashCode() + */ + @Override + public int hashCode() { + int result = 17; + result = 37 * result + super.hashCode(); + for (Iterator iterator = fEvents.iterator(); iterator.hasNext();) { + IBaseEventInfo event = (IBaseEventInfo) iterator.next(); + result = 37 * result + event.hashCode(); + } + return result; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceInfo#equals(java.lang.Object) + */ + @Override + public boolean equals(Object other) { + if (!(other instanceof UstProviderInfo)) { + return false; + } + + UstProviderInfo otherUstInfo = (UstProviderInfo) other; + if (!super.equals(otherUstInfo)) { + return false; + } + + if (fEvents.size() != otherUstInfo.fEvents.size()) { + return false; + } + for (int i = 0; i < fEvents.size(); i++) { + if (!fEvents.get(i).equals(otherUstInfo.fEvents.get(i))) { + return false; + } + } + return true; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceInfo#toString() + */ + @SuppressWarnings("nls") + @Override + public String toString() { + StringBuffer output = new StringBuffer(); + output.append("[EventInfo("); + output.append(super.toString()); + output.append(",PID="); + output.append(fPid); + output.append(",Events="); + if (fEvents.isEmpty()) { + output.append("None"); + } else { + for (Iterator iterator = fEvents.iterator(); iterator.hasNext();) { + IBaseEventInfo event = (IBaseEventInfo) iterator.next(); + output.append(event.toString()); + } + } + output.append(")]"); + return output.toString(); + } +} diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/property/TargetNodePropertySource.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/property/TargetNodePropertySource.java new file mode 100644 index 0000000000..1a785b6969 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/property/TargetNodePropertySource.java @@ -0,0 +1,131 @@ +/********************************************************************** + * 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.lttng.ui.views.control.property; + +import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TargetNodeComponent; +import org.eclipse.ui.views.properties.IPropertyDescriptor; +import org.eclipse.ui.views.properties.IPropertySource; +import org.eclipse.ui.views.properties.TextPropertyDescriptor; + +/** + * TargetNodePropertySource + *

+ * Property source implementation for the target node component. + *

+ */ +public class TargetNodePropertySource implements IPropertySource { + + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + /** + * The node name property ID. + */ + public static final String TARGET_NODE_NAME_PROPERTY_ID = "target.node.name"; //$NON-NLS-1$ + /** + * The node address property ID. + */ + public static final String TARGET_NODE_ADDRESS_PROPERTY_ID = "target.node.address"; //$NON-NLS-1$ + /** + * The node name property name. + */ + public static final String TARGET_NODE_NAME_PROPERTY_NAME = "Name"; //$NON-NLS-1$ + /** + * The node address property name. + */ + public static final String TARGET_NODE_ADDRESS_PROPERTY_NAME = "Address"; //$NON-NLS-1$ + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + /** + * The node component which this property source is for. + */ + final private TargetNodeComponent fTargetNode; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + /** + * Constructor + * @param component - the node component + */ + public TargetNodePropertySource(TargetNodeComponent component) { + fTargetNode = component; + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + /* + * (non-Javadoc) + * @see org.eclipse.ui.views.properties.IPropertySource#getEditableValue() + */ + @Override + public Object getEditableValue() { + return null; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors() + */ + @Override + public IPropertyDescriptor[] getPropertyDescriptors() { + return new IPropertyDescriptor[] { + new TextPropertyDescriptor(TARGET_NODE_NAME_PROPERTY_ID, TARGET_NODE_NAME_PROPERTY_NAME), + new TextPropertyDescriptor(TARGET_NODE_ADDRESS_PROPERTY_ID, TARGET_NODE_ADDRESS_PROPERTY_NAME), + }; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object) + */ + @Override + public Object getPropertyValue(Object id) { + if(TARGET_NODE_NAME_PROPERTY_ID.equals(id)) { + return fTargetNode.getName(); + } + if (TARGET_NODE_ADDRESS_PROPERTY_ID.equals(id)) { + return fTargetNode.getHostName(); + } + return null; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.views.properties.IPropertySource#isPropertySet(java.lang.Object) + */ + @Override + public boolean isPropertySet(Object id) { + return false; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.views.properties.IPropertySource#resetPropertyValue(java.lang.Object) + */ + @Override + public void resetPropertyValue(Object id) { + + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object) + */ + @Override + public void setPropertyValue(Object id, Object value) { + } + +} diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/remote/IRemoteSystemProxy.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/remote/IRemoteSystemProxy.java new file mode 100644 index 0000000000..97e941e38e --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/remote/IRemoteSystemProxy.java @@ -0,0 +1,103 @@ +/********************************************************************** + * 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.lttng.ui.views.control.remote; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.linuxtools.lttng.ui.views.control.service.ICommandShell; +import org.eclipse.rse.core.model.IRSECallback; +import org.eclipse.rse.core.subsystems.ICommunicationsListener; +import org.eclipse.rse.core.subsystems.ISubSystem; +import org.eclipse.rse.services.shells.IShellService; +import org.eclipse.rse.services.terminals.ITerminalService; + +/** + * IRemoteSystemProxy + *

+ * Remote System Proxy interface. + *

+ */ +public interface IRemoteSystemProxy { + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + /** + * Find the first shell service associated with the host. + * + * @return shell service object, or null if not found. + */ + public IShellService getShellService(); + + /** + * Find the first terminal service associated with the host. + * + * @return shell service object, or null if not found. + */ + public ITerminalService getTerminalService(); + + /** + * Find the first IShellServiceSubSystem service associated with the host. + * + * @return shell service subsystem, or null if not found. + */ + public ISubSystem getShellServiceSubSystem(); + + /** + * Find the first ITerminalServiceSubSystem service associated with the host. + * + * @param host the connection + * @return shell service subsystem, or null if not found. + */ + public ISubSystem getTerminalServiceSubSystem(); + + /** + * Connects the shell service sub system. + * + * @param callback - call-back method being called when connection was finished + * @throws Exception + */ + public void connect(IRSECallback callback) throws ExecutionException; + + /** + * Disconnects from the shell service sub system. + * + * @throws Exception + */ + public void disconnect() throws ExecutionException; + + /** + * Creates a command shell. + * + * @return the command shell implementation + * @throws Exception + */ + public ICommandShell createCommandShell() throws ExecutionException; + + /** + * Method to add a communication listener to the connector service defined for + * the given connection. + * + * @param listener - listener to add + * @throws Exception + */ + public void addCommunicationListener(ICommunicationsListener listener); + + /** + * Method to remove a communication listener from the connector service defined for + * the given connection. + * + * @param listener - listener to remove + * @throws Exception + */ + public void removeCommunicationListener(ICommunicationsListener listener); + +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/remote/RemoteSystemProxy.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/remote/RemoteSystemProxy.java new file mode 100644 index 0000000000..9d47cbfe89 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/remote/RemoteSystemProxy.java @@ -0,0 +1,184 @@ +/********************************************************************** + * 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.lttng.ui.views.control.remote; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.Status; +import org.eclipse.linuxtools.lttng.ui.views.control.service.CommandShell; +import org.eclipse.linuxtools.lttng.ui.views.control.service.ICommandShell; +import org.eclipse.rse.core.model.IHost; +import org.eclipse.rse.core.model.IRSECallback; +import org.eclipse.rse.core.subsystems.ICommunicationsListener; +import org.eclipse.rse.core.subsystems.IConnectorService; +import org.eclipse.rse.core.subsystems.ISubSystem; +import org.eclipse.rse.services.IService; +import org.eclipse.rse.services.shells.IShellService; +import org.eclipse.rse.services.terminals.ITerminalService; + +/** + * RemoteSystemProxy + *

+ * RemoteSystemProxy implementation. + *

+ */ +public class RemoteSystemProxy implements IRemoteSystemProxy { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + private IHost fHost; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + public RemoteSystemProxy(IHost host) { + fHost = host; + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + /* (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.util.IRemoteSystemProxy#getShellService(org.eclipse.rse.core.model.IHost) + */ + @Override + public IShellService getShellService() { + ISubSystem ss = getShellServiceSubSystem(); + if (ss != null) { + return (IShellService)ss.getSubSystemConfiguration().getService(fHost).getAdapter(IShellService.class); + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.util.IRemoteSystemProxy#getTerminalService() + */ + @Override + public ITerminalService getTerminalService() { + ISubSystem ss = getTerminalServiceSubSystem(); + if (ss != null) { + return (ITerminalService)ss.getSubSystemConfiguration().getService(fHost).getAdapter(ITerminalService.class); + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.util.IRemoteSystemProxy#getShellServiceSubSystem() + */ + @Override + public ISubSystem getShellServiceSubSystem() { + if (fHost == null) { + return null; + } + ISubSystem[] subSystems = fHost.getSubSystems(); + IShellService ssvc = null; + for (int i = 0; subSystems != null && i < subSystems.length; i++) { + IService svc = subSystems[i].getSubSystemConfiguration().getService(fHost); + if (svc!=null) { + ssvc = (IShellService)svc.getAdapter(IShellService.class); + if (ssvc != null) { + return subSystems[i]; + } + } + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.util.IRemoteSystemProxy#getTerminalServiceSubSystem() + */ + @Override + public ISubSystem getTerminalServiceSubSystem() { + if (fHost == null) { + return null; + } + ISubSystem[] subSystems = fHost.getSubSystems(); + ITerminalService ssvc = null; + for (int i = 0; subSystems != null && i < subSystems.length; i++) { + IService svc = subSystems[i].getSubSystemConfiguration().getService(fHost); + if (svc!=null) { + ssvc = (ITerminalService)svc.getAdapter(ITerminalService.class); + if (ssvc != null) { + return subSystems[i]; + } + } + } + return null; + } + + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.util.IRemoteSystemProxy#connect(org.eclipse.rse.core.model.IRSECallback) + */ + @Override + public void connect(IRSECallback callback) throws ExecutionException { + ISubSystem shellSubSystem = getShellServiceSubSystem(); + if (shellSubSystem != null) { + if (!shellSubSystem.isConnected()) { + try { + shellSubSystem.connect(false, callback); + } catch (Exception e) { + throw new ExecutionException(e.toString(), e); + } + } else { + callback.done(Status.OK_STATUS, null); + } + } + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.util.IRemoteSystemProxy#disconnect() + */ + @Override + public void disconnect() throws ExecutionException { + ISubSystem shellSubSystem = getShellServiceSubSystem(); + if (shellSubSystem != null) { + try { + shellSubSystem.disconnect(); + } catch (Exception e) { + throw new ExecutionException(e.toString(), e); + } + } + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.util.IRemoteSystemProxy#createCommandShell() + */ + @Override + public ICommandShell createCommandShell() throws ExecutionException { + ICommandShell shell = new CommandShell(this); + shell.connect(); + return shell; + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.util.IRemoteSystemProxy#addCommunicationListener(org.eclipse.rse.core.subsystems.ICommunicationsListener) + */ + @Override + public void addCommunicationListener(ICommunicationsListener listener) { + IConnectorService[] css = fHost.getConnectorServices(); + for (IConnectorService cs : css) { + cs.addCommunicationsListener(listener); + } + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.util.IRemoteSystemProxy#removeCommunicationListener(org.eclipse.rse.core.subsystems.ICommunicationsListener) + */ + @Override + public void removeCommunicationListener(ICommunicationsListener listener) { + IConnectorService[] css = fHost.getConnectorServices(); + for (IConnectorService cs : css) { + cs.removeCommunicationsListener(listener); + } + } +} diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/service/CommandResult.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/service/CommandResult.java new file mode 100644 index 0000000000..4ba1070c5e --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/service/CommandResult.java @@ -0,0 +1,88 @@ +/********************************************************************** + * 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.lttng.ui.views.control.service; + +import java.util.Arrays; + +/** + * CommandResult + *

+ * Class containing command result of remote command execution. + *

+ */ +public class CommandResult implements ICommandResult { + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + /** + * The result of the command. 0 if successful else > 0 + */ + private int fResult; + + /** + * The output as String array. + */ + private String[] fOutput = new String[0]; + + // ------------------------------------------------------------------------ + // Constructor + // ------------------------------------------------------------------------ + public CommandResult(int result, String[] output) { + fResult = result; + if (output != null) { + fOutput = Arrays.copyOf(output, output.length); + } + } + + // ------------------------------------------------------------------------ + // Accessor + // ------------------------------------------------------------------------ + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ICommandResult#getResult() + */ + @Override + public int getResult() { + return fResult; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ICommandResult#setResult(int) + */ + @Override + public void setResult(int result) { + fResult = result; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ICommandResult#getOutput() + */ + @Override + public String[] getOutput() { + return Arrays.copyOf(fOutput, fOutput.length); + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ICommandResult#setOutput(java.lang.String[]) + */ + @Override + public void setOutput(String[] output) { + fOutput = new String[0]; + if (output != null) { + fOutput = Arrays.copyOf(output, output.length); + } + } +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/service/CommandShell.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/service/CommandShell.java new file mode 100644 index 0000000000..eb26530315 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/service/CommandShell.java @@ -0,0 +1,222 @@ +/********************************************************************** + * 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: + * Patrick Tasse - Initial API and implementation + * Bernd Hufmann - Updated using Executor Framework + **********************************************************************/ +package org.eclipse.linuxtools.lttng.ui.views.control.service; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.concurrent.Callable; +import java.util.concurrent.CancellationException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.FutureTask; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.linuxtools.lttng.ui.views.control.Messages; +import org.eclipse.linuxtools.lttng.ui.views.control.remote.IRemoteSystemProxy; +import org.eclipse.rse.services.shells.HostShellProcessAdapter; +import org.eclipse.rse.services.shells.IHostShell; +import org.eclipse.rse.services.shells.IShellService; + +/** + * CommandShell + *

+ * Implementation of remote command execution using RSE's shell service. + *

+ */ +public class CommandShell implements ICommandShell { + + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + + // string to be echo'ed when running command in shell, used to indicate that the command has finished running + public final static String DONE_MARKUP_STRING = "--RSE:donedonedone:--"; //$NON-NLS-1$ + + //command delimiter for shell + public final static String CMD_DELIMITER = "\n"; //$NON-NLS-1$ + + public final static String SHELL_ECHO_CMD = " echo "; //$NON-NLS-1$ + + private final static int DEFAULT_TIMEOUT_VALUE = 15000; // in milliseconds + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + private IRemoteSystemProxy fProxy = null; + private IHostShell fHostShell = null; + private BufferedReader fBufferReader = null; + private ExecutorService fExecutor = Executors.newFixedThreadPool(1); + private boolean fIsConnected = false; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + public CommandShell(IRemoteSystemProxy proxy) { + fProxy = proxy; + } + + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ICommandShell#connect() + */ + @Override + public void connect() throws ExecutionException { + IShellService shellService = fProxy.getShellService(); + Process p = null; + try { + fHostShell = shellService.launchShell("", new String[0], new NullProgressMonitor()); //$NON-NLS-1$ + p = new HostShellProcessAdapter(fHostShell); + } catch (Exception e) { + throw new ExecutionException(Messages.TraceControl_CommandShellError, e); + } + fBufferReader = new BufferedReader(new InputStreamReader(p.getInputStream())); + fIsConnected = true; + + // Flush Login messages + executeCommand(" ", new NullProgressMonitor(), false); //$NON-NLS-1$ + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ICommandShell#disconnect() + */ + @Override + public void disconnect() { + fIsConnected = false; + try { + fBufferReader.close(); + } catch (IOException e) { + // ignore + } + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ICommandShell#executeCommand(java.lang.String, org.eclipse.core.runtime.IProgressMonitor) + */ + @Override + public ICommandResult executeCommand(String command, IProgressMonitor monitor) throws ExecutionException { + return executeCommand(command, monitor, true); + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ICommandShell#executeCommand(java.lang.String, org.eclipse.core.runtime.IProgressMonitor, boolean) + */ + @Override + public ICommandResult executeCommand(final String command, final IProgressMonitor monitor, final boolean checkReturnValue) throws ExecutionException { + if (fIsConnected) { + FutureTask future = new FutureTask(new Callable() { + @Override + public CommandResult call() throws IOException, CancellationException { + final ArrayList result = new ArrayList(); + int returnValue = 0; + + synchronized (fHostShell) { + fHostShell.writeToShell(formatShellCommand(command)); + String nextLine; + while ((nextLine = fBufferReader.readLine()) != null) { + + if (monitor.isCanceled()) { + flushInput(); + throw new CancellationException(); + } + + if (nextLine.contains(DONE_MARKUP_STRING) && nextLine.contains(SHELL_ECHO_CMD)) { + break; + } + } + + while ((nextLine = fBufferReader.readLine()) != null) { + // check if job was cancelled + if (monitor.isCanceled()) { + flushInput(); + throw new CancellationException(); + } + + if (!nextLine.contains(DONE_MARKUP_STRING)) { + result.add(nextLine); + } else { + if (checkReturnValue) { + returnValue = Integer.valueOf(nextLine.substring(DONE_MARKUP_STRING.length()+1)); + } + break; + } + } + + flushInput(); + } + return new CommandResult(returnValue, result.toArray(new String[result.size()])); + } + }); + + fExecutor.execute(future); + + try { + return future.get(DEFAULT_TIMEOUT_VALUE, TimeUnit.MILLISECONDS); + } catch (java.util.concurrent.ExecutionException ex) { + throw new ExecutionException(Messages.TraceControl_ExecutionFailure, ex); + } catch (InterruptedException ex) { + throw new ExecutionException(Messages.TraceControl_ExecutionCancelled, ex); + } catch (TimeoutException ex) { + throw new ExecutionException(Messages.TraceControl_ExecutionTimeout, ex); + } + } + throw new ExecutionException(Messages.TraceControl_ShellNotConnected, null); + } + + // ------------------------------------------------------------------------ + // Helper methods + // ------------------------------------------------------------------------ + /** + * Flushes the buffer reader + * @throws IOException + */ + private void flushInput() throws IOException { + char[] cbuf = new char[1]; + while (fBufferReader.ready()) { + if (fBufferReader.read(cbuf, 0, 1) == -1) { + break; + } + } + } + + /** + * format the command to be sent into the shell command with the done markup string. + * The done markup string is needed so we can tell that end of output has been reached. + * + * @param cmd + * @return formatted command string + */ + private String formatShellCommand(String cmd) { + if (cmd == null || cmd.equals("")) //$NON-NLS-1$ + return cmd; + StringBuffer formattedCommand = new StringBuffer(); +// formattedCommand.append(cmd).append(CMD_DELIMITER); + formattedCommand.append(cmd).append("\\\r;"); //$NON-NLS-1$ + formattedCommand.append(SHELL_ECHO_CMD).append(DONE_MARKUP_STRING); + formattedCommand.append(" $?"); //$NON-NLS-1$ + formattedCommand.append(CMD_DELIMITER); + return formattedCommand.toString(); + } + +} diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/service/ICommandResult.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/service/ICommandResult.java new file mode 100644 index 0000000000..729bedf5a5 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/service/ICommandResult.java @@ -0,0 +1,43 @@ +/********************************************************************** + * 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.lttng.ui.views.control.service; + +/** + * IommandResult + *

+ * Interface for providing command execution result. + *

+ */ +public interface ICommandResult { + /** + * The result of the command. + * @return 0 if successful else >0 + */ + public int getResult() ; + + /** + * Sets the command result value. + * @param result + */ + public void setResult(int result); + + /** + * @return returns the command output. + */ + public String[] getOutput(); + + /** + * Sets the command output. + * @param output + */ + public void setOutput(String[] output); +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/service/ICommandShell.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/service/ICommandShell.java new file mode 100644 index 0000000000..bdea09bdc9 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/service/ICommandShell.java @@ -0,0 +1,57 @@ +/********************************************************************** + * 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.lttng.ui.views.control.service; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IProgressMonitor; + +/** + * ICommandShell + *

+ * Interface for a command shell implementation + *

+ */ +public interface ICommandShell { + + /** + * Method to connect the command shell. + * @throws ExecutionException + */ + public void connect() throws ExecutionException; + + /** + * Method to disconnect the command shell. + */ + public void disconnect(); + + /** + * Method to execute a command on the command shell. + * + * @param command - the command to executed + * @param monitor - a progress monitor + * @return the command result + * @throws ExecutionException + */ + public ICommandResult executeCommand(String command, IProgressMonitor monitor) throws ExecutionException; + + /** + * Method to execute a command on the command shell. + * + * @param command - the command to executed + * @param monitor - a progress monitor + * @param checkReturnValue - flag to indicate that the command result should be checked. If false the command result will be always 0. + * @return the command result + * @throws ExecutionException + */ + public ICommandResult executeCommand(final String command, final IProgressMonitor monitor, final boolean checkReturnValue) throws ExecutionException; + +} diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/service/ILttngControlService.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/service/ILttngControlService.java new file mode 100644 index 0000000000..572c357434 --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/service/ILttngControlService.java @@ -0,0 +1,87 @@ +/********************************************************************** + * 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.lttng.ui.views.control.service; + +import java.util.List; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.linuxtools.lttng.ui.views.control.model.IBaseEventInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.ISessionInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.IUstProviderInfo; + + +/** ILttngControlService +*

+* Interface for LTTng trace control command service. +*

+*/ +public interface ILttngControlService { + /** + * Retrieves the existing sessions names from the node. + * @return an array with session names. + * @throws ExecutionException + */ + public String[] getSessionNames() throws ExecutionException; + /** + * Retrieves the existing sessions names from the node. + * @param monitor - a progress monitor + * @return an array with session names. + * @throws ExecutionException + */ + public String[] getSessionNames(IProgressMonitor monitor) throws ExecutionException; + + /** + * Retrieves the session information with the given name the node. + * @param sessionName - the session name + * @return session information + * @throws ExecutionException + */ + public ISessionInfo getSession(String sessionName) throws ExecutionException; + + /** + * Retrieves the session information with the given name the node. + * @param sessionName - the session name + * @param monitor - a progress monitor + * @return session information + * @throws ExecutionException + */ + public ISessionInfo getSession(String sessionName, IProgressMonitor monitor) throws ExecutionException; + + /** + * Retrieves the kernel provider information (i.e. the kernel events) + * @return the list of existing kernel events. + * @throws ExecutionException + */ + public List getKernelProvider() throws ExecutionException; + /** + * Retrieves the kernel provider information (i.e. the kernel events) + * @param monitor - a progress monitor + * @return the list of existing kernel events. + * @throws ExecutionException + */ + public List getKernelProvider(IProgressMonitor monitor) throws ExecutionException; + + /** + * Retrieves the UST provider information from the node. + * @return - the UST provider information. + * @throws ExecutionException + */ + public List getUstProvider() throws ExecutionException; + /** + * Retrieves the UST provider information from the node. + * @param monitor - a progress monitor + * @return - the UST provider information. + * @throws ExecutionException + */ + public List getUstProvider(IProgressMonitor monitor) throws ExecutionException; +} diff --git a/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/service/LTTngControlService.java b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/service/LTTngControlService.java new file mode 100644 index 0000000000..597cbb7acc --- /dev/null +++ b/org.eclipse.linuxtools.lttng.ui/src/org/eclipse/linuxtools/lttng/ui/views/control/service/LTTngControlService.java @@ -0,0 +1,601 @@ +/********************************************************************** + * 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.lttng.ui.views.control.service; + +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.linuxtools.lttng.ui.views.control.Messages; +import org.eclipse.linuxtools.lttng.ui.views.control.model.IBaseEventInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.IChannelInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.IDomainInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.IEventInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.ISessionInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.IUstProviderInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.BaseEventInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.ChannelInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.DomainInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.EventInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.SessionInfo; +import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.UstProviderInfo; +/** + * LTTngControlService + *

+ * Service for sending LTTng trace control commands to remote host. + *

+ */ +public class LTTngControlService implements ILttngControlService { + // ------------------------------------------------------------------------ + // Constants + // ------------------------------------------------------------------------ + // Command constants + /** + * The lttng tools command. + */ + private final static String CONTROL_COMMAND = "lttng"; //$NON-NLS-1$ + /** + * Command: lttng list. + */ + private final static String COMMAND_LIST = CONTROL_COMMAND + " list "; //$NON-NLS-1$ + /** + * Command to list kernel tracer information. + */ + private final static String COMMAND_LIST_KERNEL = COMMAND_LIST + "-k"; //$NON-NLS-1$ + /** + * Command to list user space trace information. + */ + private final static String COMMAND_LIST_UST = COMMAND_LIST + "-u"; //$NON-NLS-1$ + + // Parsing constants + /** + * Pattern to match for error output + */ + private final static String ERROR_PATTERN = "\\s*Error\\:.*"; //$NON-NLS-1$ + /** + * Pattern to match for session information (lttng list) + */ + private final static String SESSION_PATTERN = "\\s+(\\d+)\\)\\s+(.*)\\s+\\((.*)\\)\\s+\\[(active|inactive)\\].*"; //$NON-NLS-1$ + /** + * Pattern to match for session information (lttng list ) + */ + private final static String TRACE_SESSION_PATTERN = "\\s*Tracing\\s+session\\s+(.*)\\:\\s+\\[(active|inactive)\\].*"; //$NON-NLS-1$ + /** + * Pattern to match for session path information (lttng list ) + */ + private final static String TRACE_SESSION_PATH_PATTERN = "\\s*Trace\\s+path\\:\\s+(.*)"; //$NON-NLS-1$ + /** + * Pattern to match for kernel domain information (lttng list ) + */ + private final static String DOMAIN_KERNEL_PATTERN = "=== Domain: Kernel ==="; //$NON-NLS-1$ + /** + * Pattern to match for ust domain information (lttng list ) + */ + private final static String DOMAIN_UST_GLOBAL_PATTERN = "=== Domain: UST global ==="; //$NON-NLS-1$ + /** + * Pattern to match for channels section (lttng list ) + */ + private final static String CHANNELS_SECTION_PATTERN = "\\s*Channels\\:"; //$NON-NLS-1$ + /** + * Pattern to match for channel information (lttng list ) + */ + private final static String CHANNEL_PATTERN = "\\s*-\\s+(.*)\\:\\s+\\[(enabled|disabled)\\]"; //$NON-NLS-1$ + /** + * Pattern to match for events section information (lttng list ) + */ + private final static String EVENT_SECTION_PATTERN = "\\s*Events\\:"; //$NON-NLS-1$ + /** + * Pattern to match for event information (no enabled events) (lttng list ) + */ +// private final static String EVENT_NONE_PATTERN = "\\s+None"; //$NON-NLS-1$ + /** + * Pattern to match for event information (lttng list ) + */ + private final static String EVENT_PATTERN = "\\s+(.*)\\s+\\(loglevel:\\s+(.*)\\)\\s+\\(type:\\s+(.*)\\)\\s+\\[(enabled|disabled)\\].*"; //$NON-NLS-1$ + /** + * Pattern to match for channel (overwite mode) information (lttng list ) + */ + private final static String OVERWRITE_MODE_ATTRIBUTE = "\\s+overwrite\\s+mode\\:.*"; //$NON-NLS-1$ + /** + * Pattern to match indicating false for overwrite mode + */ + private final static String OVERWRITE_MODE_ATTRIBUTE_FALSE = "0"; //$NON-NLS-1$ + /** + * Pattern to match for channel (sub-buffer size) information (lttng list ) + */ + private final static String SUBBUFFER_SIZE_ATTRIBUTE = "\\s+subbufers\\s+size\\:.*"; //$NON-NLS-1$ + /** + * Pattern to match for channel (number of sub-buffers) information (lttng list ) + */ + private final static String NUM_SUBBUFFERS_ATTRIBUTE = "\\s+number\\s+of\\s+subbufers\\:.*"; //$NON-NLS-1$ + /** + * Pattern to match for channel (switch timer) information (lttng list ) + */ + private final static String SWITCH_TIMER_ATTRIBUTE = "\\s+switch\\s+timer\\s+interval\\:.*"; //$NON-NLS-1$ + /** + * Pattern to match for channel (read timer) information (lttng list ) + */ + private final static String READ_TIMER_ATTRIBUTE = "\\s+read\\s+timer\\s+interval\\:.*"; //$NON-NLS-1$ + /** + * Pattern to match for channel (output type) information (lttng list ) + */ + private final static String OUTPUT_ATTRIBUTE = "\\s+output\\:.*"; //$NON-NLS-1$ + /** + * Pattern to match for provider information (lttng list -k/-u) + */ + private final static String PROVIDER_EVENT_PATTERN = "\\s*(.*)\\s+\\(loglevel:\\s+(.*)\\)\\s+\\(type:\\s+(.*)\\)"; //$NON-NLS-1$ + /** + * Pattern to match for UST provider information (lttng list -u) + */ + private final static String UST_PROVIDER_PATTERN = "\\s*PID\\:\\s+(\\d+)\\s+-\\s+Name\\:\\s+(.*)"; //$NON-NLS-1$ + + // ------------------------------------------------------------------------ + // Attributes + // ------------------------------------------------------------------------ + /** + * The command shell implementation + */ + private ICommandShell fCommandShell = null; + + // ------------------------------------------------------------------------ + // Constructors + // ------------------------------------------------------------------------ + + /** + * Constructor + * @param shell - the command shell implementation to use + */ + public LTTngControlService(ICommandShell shell) { + fCommandShell = shell; + } + // ------------------------------------------------------------------------ + // Operations + // ------------------------------------------------------------------------ + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#getSessionNames() + */ + @Override + public String[] getSessionNames() throws ExecutionException { + return getSessionNames(new NullProgressMonitor()); + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#getSessionNames(org.eclipse.core.runtime.IProgressMonitor) + */ + @Override + public String[] getSessionNames(IProgressMonitor monitor) throws ExecutionException { + + String command = COMMAND_LIST; + ICommandResult result = fCommandShell.executeCommand(command, monitor); + + if (isError(result)) { + // TODO: no session available shouldn't be an error! + if (result.getOutput().length > 0 && result.getOutput()[0].matches(ERROR_PATTERN)) { + // no sessions available + return new String[0]; + } + throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$ + } + + // Output: + // Available tracing sessions: + // 1) mysession1 (/home/user/lttng-traces/mysession1-20120123-083928) [inactive] + // 2) mysession (/home/user/lttng-traces/mysession-20120123-083318) [inactive] + // + // Use lttng list for more details + + ArrayList retArray = new ArrayList(); + int index = 0; + while (index < result.getOutput().length) { + String line = result.getOutput()[index]; + try { + Pattern pattern = Pattern.compile(SESSION_PATTERN); + Matcher matcher = pattern.matcher(line); + if (matcher.matches()) { + retArray.add(matcher.group(2).trim()); + } + } catch (PatternSyntaxException e) { + } + index++; + } + return retArray.toArray(new String[retArray.size()]); + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#getSession(java.lang.String) + */ + @Override + public ISessionInfo getSession(String sessionName) throws ExecutionException { + return getSession(sessionName, new NullProgressMonitor()); + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#getSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor) + */ + @Override + public ISessionInfo getSession(String sessionName, IProgressMonitor monitor) throws ExecutionException { + String command = COMMAND_LIST + sessionName; + 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$ + } + + int index = 0; + + // Output: + // Tracing session mysession2: [inactive] + // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330 + ISessionInfo sessionInfo = new SessionInfo(sessionName); + + try { + while (index < result.getOutput().length) { + // Tracing session mysession2: [inactive] + // Trace path: /home/eedbhu/lttng-traces/mysession2-20120123-110330 + // + // === Domain: Kernel === + // + String line = result.getOutput()[index]; + if (line.matches(TRACE_SESSION_PATTERN)) { + Pattern pattern = Pattern.compile(TRACE_SESSION_PATTERN); + Matcher matcher = pattern.matcher(line); + if (matcher.matches()) { + sessionInfo.setSessionState(matcher.group(2)); + } + index++; + } else if (line.matches(TRACE_SESSION_PATH_PATTERN)) { + Pattern pattern = Pattern.compile(TRACE_SESSION_PATH_PATTERN); + Matcher matcher = pattern.matcher(line); + if (matcher.matches()) { + sessionInfo.setSessionPath(matcher.group(1).trim()); + } + index++; + } + else if (line.matches(DOMAIN_KERNEL_PATTERN)) { + // Create Domain + IDomainInfo domainInfo = new DomainInfo(Messages.TraceControl_KernelDomainDisplayName); + sessionInfo.addDomain(domainInfo); + + // in domain kernel + ArrayList channels = new ArrayList(); + index = parseDomain(result.getOutput(), index, channels); + + // set channels + domainInfo.setChannels(channels); + + } else if (line.contains(DOMAIN_UST_GLOBAL_PATTERN)) { + IDomainInfo domainInfo = new DomainInfo(Messages.TraceControl_UstGlobalDomainDisplayName); + sessionInfo.addDomain(domainInfo); + + // in domain kernel + ArrayList channels = new ArrayList(); + index = parseDomain(result.getOutput(), index, channels); + + // set channels + domainInfo.setChannels(channels); + } else { + index++; + } + } + } catch (PatternSyntaxException e) { + throw new ExecutionException("Invalid regular expression", e); //$NON-NLS-1$ + } + return sessionInfo; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#getKernelProvider() + */ + @Override + public List getKernelProvider() throws ExecutionException { + return getKernelProvider(new NullProgressMonitor()); + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#getKernelProvider(org.eclipse.core.runtime.IProgressMonitor) + */ + @Override + public List getKernelProvider(IProgressMonitor monitor) throws ExecutionException { + String command = COMMAND_LIST_KERNEL; + 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$ + } + +// Kernel events: +// ------------- +// sched_kthread_stop (type: tracepoint) + List events = new ArrayList(); + getProviderEventInfo(result.getOutput(), 0, events); + return events; + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#getUstProvider() + */ + @Override + public List getUstProvider() throws ExecutionException { + return getUstProvider(new NullProgressMonitor()); + } + + /* + * (non-Javadoc) + * @see org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService#getUstProvider(org.eclipse.core.runtime.IProgressMonitor) + */ + @Override + public List getUstProvider(IProgressMonitor monitor) throws ExecutionException { + String command = COMMAND_LIST_UST; + 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$ + } + +// UST events: +// ------------- +// +// PID: 3635 - Name: /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello +// ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type: tracepoint) +// ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint) +// +// PID: 6459 - Name: /home/user/git/lttng-ust/tests/hello.cxx/.libs/lt-hello +// ust_tests_hello:tptest_sighandler (loglevel: TRACE_EMERG0) (type: tracepoint) +// ust_tests_hello:tptest (loglevel: TRACE_EMERG0) (type: tracepoint) + + List allProviders = new ArrayList(); + IUstProviderInfo provider = null; + + int index = 0; + while (index < result.getOutput().length) { + String line = result.getOutput()[index]; + if (line.matches(UST_PROVIDER_PATTERN)) { + Pattern pattern = Pattern.compile(UST_PROVIDER_PATTERN); + + Matcher matcher = pattern.matcher(line); + + if (matcher.matches()) { + + provider = new UstProviderInfo(matcher.group(2).trim()); + provider.setPid(Integer.valueOf(matcher.group(1).trim())); + List events = new ArrayList(); + index = getProviderEventInfo(result.getOutput(), ++index, events); + provider.setEvents(events); + allProviders.add(provider); + } + + } else { + index++; + } + + } + return allProviders; + } + + // ------------------------------------------------------------------------ + // Helper methods + // ------------------------------------------------------------------------ + /** + * Checks if command result is an error result. + * @param result - the command result to check + * @return true if error else false + */ + private boolean isError(ICommandResult result) { + if ((result.getResult()) != 0 || (result.getOutput().length < 1 || result.getOutput()[0].matches(ERROR_PATTERN))) { + return true; + } + return false; + } + + /** + * Formats the output string as single string. + * @param output - output array + * @return - the formatted output + */ + private String formatOutput(String[] output) { + if (output == null || output.length == 0) { + return ""; //$NON-NLS-1$ + } + + StringBuffer ret = new StringBuffer(); + for (int i = 0; i < output.length; i++) { + ret.append(output[i] + "\n"); //$NON-NLS-1$ + } + return ret.toString(); + } + + /** + * Parses the domain information. + * + * @param output - a command output array + * @param currentIndex - current index in command output array + * @param channels - list for returning channel information + * @return the new current index in command output array + * @throws PatternSyntaxException + */ + private int parseDomain(String[] output, int currentIndex, List channels) throws PatternSyntaxException { + int index = currentIndex; + +// Channels: +// ------------- +// - channnel1: [enabled] +// +// Attributes: +// overwrite mode: 0 +// subbufers size: 262144 +// number of subbufers: 4 +// switch timer interval: 0 +// read timer interval: 200 +// output: splice() + + while (index < output.length) { + String line = output[index]; + if (line.matches(CHANNELS_SECTION_PATTERN)) { + IChannelInfo channelInfo = null; + while (index < output.length) { + String subLine = output[index]; + if (subLine.matches(CHANNEL_PATTERN)) { + + Pattern pattern = Pattern.compile(CHANNEL_PATTERN); + Matcher matcher = pattern.matcher(subLine); + channelInfo = new ChannelInfo(""); //$NON-NLS-1$ + if (matcher.matches()) { + // get channel name + channelInfo.setName(matcher.group(1)); + + // get channel enablement + channelInfo.setState(matcher.group(2)); + + // add channel + channels.add(channelInfo); + } + } else if (subLine.matches(OVERWRITE_MODE_ATTRIBUTE)) { + String value = getAttributeValue(subLine); + channelInfo.setOverwriteMode(!OVERWRITE_MODE_ATTRIBUTE_FALSE.equals(value)); + } else if (subLine.matches(SUBBUFFER_SIZE_ATTRIBUTE)) { + channelInfo.setSubBufferSize(Long.valueOf(getAttributeValue(subLine))); + + } else if (subLine.matches(NUM_SUBBUFFERS_ATTRIBUTE)) { + channelInfo.setNumberOfSubBuffers(Integer.valueOf(getAttributeValue(subLine))); + + } else if (subLine.matches(SWITCH_TIMER_ATTRIBUTE)) { + channelInfo.setSwitchTimer(Long.valueOf(getAttributeValue(subLine))); + + } else if (subLine.matches(READ_TIMER_ATTRIBUTE)) { + channelInfo.setReadTimer(Long.valueOf(getAttributeValue(subLine))); + + } else if (subLine.matches(OUTPUT_ATTRIBUTE)) { + channelInfo.setOutputType(getAttributeValue(subLine)); + + } else if (subLine.matches(EVENT_SECTION_PATTERN)) { + List events = new ArrayList(); + index = parseEvents(output, index, events); + channelInfo.setEvents(events); + // we want to stay at the current index to be able to exit the domain + continue; + } + else if (subLine.matches(DOMAIN_KERNEL_PATTERN)) { + return index; + + } else if (subLine.contains(DOMAIN_UST_GLOBAL_PATTERN)) { + return index; + } + index++; + } + } + index++; + } + return index; + } + + /** + * Parses the event information within a domain. + * + * @param output - a command output array + * @param currentIndex - current index in command output array + * @param events - list for returning event information + * @return the new current index in command output array + * @throws PatternSyntaxException + */ + private int parseEvents(String[] output, int currentIndex, List events) throws PatternSyntaxException { + int index = currentIndex; + + while (index < output.length) { + String line = output[index]; + if (line.matches(CHANNEL_PATTERN)) { + // end of channel + return index; + } else if (line.matches(DOMAIN_KERNEL_PATTERN)) { + // end of domain + return index; + } else if (line.contains(DOMAIN_UST_GLOBAL_PATTERN)) { + // end of domain + return index; + } else if (line.matches(EVENT_PATTERN)) { + Pattern pattern = Pattern.compile(EVENT_PATTERN); + + Matcher matcher = pattern.matcher(line); + + if (matcher.matches()) { + IEventInfo eventInfo = new EventInfo(matcher.group(1).trim()); + eventInfo.setLogLevel(matcher.group(2).trim()); + eventInfo.setEventType(matcher.group(3).trim()); + eventInfo.setState(matcher.group(4)); + events.add(eventInfo); + } + } +// else if (line.matches(EVENT_NONE_PATTERN)) { + // do nothing +// } else + index++; + } + + return index; + } + + /** + * Parses a line with attributes: : + * + * @param line - attribute line to parse + * @return the attribute value as string + * @throws PatternSyntaxException + */ + private String getAttributeValue(String line) { + String[] temp = line.split("\\: "); //$NON-NLS-1$ + return temp[1]; + } + + /** + * Parses the event information within a provider. + * + * @param output - a command output array + * @param currentIndex - current index in command output array + * @param events - list for returning event information + * @return the new current index in command output array + */ + private int getProviderEventInfo(String[] output, int currentIndex, List events) { + int index = currentIndex; + while (index < output.length) { + String line = output[index]; + if (line.matches(PROVIDER_EVENT_PATTERN)) { + // sched_kthread_stop (loglevel: TRACE_EMERG0) (type: tracepoint) + Pattern pattern = Pattern.compile(PROVIDER_EVENT_PATTERN); + + Matcher matcher = pattern.matcher(line); + + if (matcher.matches()) { + IBaseEventInfo eventInfo = new BaseEventInfo(matcher.group(1).trim()); + eventInfo.setLogLevel(matcher.group(2).trim()); + eventInfo.setEventType(matcher.group(3).trim()); + events.add(eventInfo); + } + } else if (line.matches(UST_PROVIDER_PATTERN)) { + return index; + } + index++; + } + return index; + } + +} -- 2.34.1