| 1 | /********************************************************************** |
| 2 | * Copyright (c) 2012, 2013 Ericsson |
| 3 | * |
| 4 | * All rights reserved. This program and the accompanying materials are |
| 5 | * made available under the terms of the Eclipse Public License v1.0 which |
| 6 | * accompanies this distribution, and is available at |
| 7 | * http://www.eclipse.org/legal/epl-v10.html |
| 8 | * |
| 9 | * Contributors: |
| 10 | * Bernd Hufmann - Initial API and implementation |
| 11 | * Bernd Hufmann - Updated for support of LTTng Tools 2.1 |
| 12 | **********************************************************************/ |
| 13 | package org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl; |
| 14 | |
| 15 | import org.eclipse.core.commands.ExecutionException; |
| 16 | import org.eclipse.core.runtime.IProgressMonitor; |
| 17 | import org.eclipse.core.runtime.NullProgressMonitor; |
| 18 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.ISessionInfo; |
| 19 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent; |
| 20 | |
| 21 | /** |
| 22 | * <p> |
| 23 | * Implementation of the trace session group. |
| 24 | * </p> |
| 25 | * |
| 26 | * @author Bernd Hufmann |
| 27 | */ |
| 28 | public class TraceSessionGroup extends TraceControlComponent { |
| 29 | // ------------------------------------------------------------------------ |
| 30 | // Constants |
| 31 | // ------------------------------------------------------------------------ |
| 32 | /** |
| 33 | * Path to icon file for this component. |
| 34 | */ |
| 35 | public static final String TRACE_SESSIONS_ICON_FILE = "icons/obj16/sessions.gif"; //$NON-NLS-1$ |
| 36 | |
| 37 | // ------------------------------------------------------------------------ |
| 38 | // Attributes |
| 39 | // ------------------------------------------------------------------------ |
| 40 | |
| 41 | // ------------------------------------------------------------------------ |
| 42 | // Constructors |
| 43 | // ------------------------------------------------------------------------ |
| 44 | /** |
| 45 | * Constructor |
| 46 | * @param name - the name of the component. |
| 47 | * @param parent - the parent of this component. |
| 48 | */ |
| 49 | public TraceSessionGroup(String name, ITraceControlComponent parent) { |
| 50 | super(name, parent); |
| 51 | setImage(TRACE_SESSIONS_ICON_FILE); |
| 52 | } |
| 53 | |
| 54 | // ------------------------------------------------------------------------ |
| 55 | // Accessors |
| 56 | // ------------------------------------------------------------------------ |
| 57 | |
| 58 | /** |
| 59 | * @return the parent target node |
| 60 | */ |
| 61 | public TargetNodeComponent getTargetNode() { |
| 62 | return (TargetNodeComponent)getParent(); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Returns if node supports networks streaming or not |
| 67 | * @return <code>true</code> if node supports filtering else <code>false</code> |
| 68 | */ |
| 69 | public boolean isNetworkStreamingSupported() { |
| 70 | return getTargetNode().isNetworkStreamingSupported(); |
| 71 | } |
| 72 | /** |
| 73 | * Returns if node supports snapshots or not |
| 74 | * @return <code>true</code> if it supports snapshots else <code>false</code> |
| 75 | * |
| 76 | */ public boolean isSnapshotSupported() { |
| 77 | return getTargetNode().isSnapshotSupported(); |
| 78 | } |
| 79 | |
| 80 | // ------------------------------------------------------------------------ |
| 81 | // Operations |
| 82 | // ------------------------------------------------------------------------ |
| 83 | /** |
| 84 | * Retrieves the sessions information from the node. |
| 85 | * |
| 86 | * @throws ExecutionException |
| 87 | * If the command fails |
| 88 | */ |
| 89 | public void getSessionsFromNode() throws ExecutionException { |
| 90 | getSessionsFromNode(new NullProgressMonitor()); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Retrieves the sessions information from the node. |
| 95 | * |
| 96 | * @param monitor |
| 97 | * - a progress monitor |
| 98 | * @throws ExecutionException |
| 99 | * If the command fails |
| 100 | */ |
| 101 | public void getSessionsFromNode(IProgressMonitor monitor) |
| 102 | throws ExecutionException { |
| 103 | String[] sessionNames = getControlService().getSessionNames(monitor); |
| 104 | for (int i = 0; i < sessionNames.length; i++) { |
| 105 | TraceSessionComponent session = new TraceSessionComponent( |
| 106 | sessionNames[i], this); |
| 107 | addChild(session); |
| 108 | session.getConfigurationFromNode(monitor); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Creates a session with given session name and location. |
| 114 | * |
| 115 | * @param sessionName |
| 116 | * - a session name to create |
| 117 | * @param sessionPath |
| 118 | * - a path for storing the traces (use null for default) |
| 119 | * @param isSnapshot |
| 120 | * - true for snapshot session else false |
| 121 | * @param monitor |
| 122 | * - a progress monitor |
| 123 | * @throws ExecutionException |
| 124 | * If the command fails |
| 125 | */ |
| 126 | public void createSession(String sessionName, String sessionPath, boolean isSnapshot, IProgressMonitor monitor) throws ExecutionException { |
| 127 | ISessionInfo sessionInfo = getControlService().createSession(sessionName, sessionPath, isSnapshot, monitor); |
| 128 | |
| 129 | if (sessionInfo != null) { |
| 130 | TraceSessionComponent session = new TraceSessionComponent( |
| 131 | sessionInfo.getName(), TraceSessionGroup.this); |
| 132 | addChild(session); |
| 133 | session.getConfigurationFromNode(monitor); |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Creates a session with given session name and location. |
| 139 | * |
| 140 | * @param sessionName |
| 141 | * - a session name to create |
| 142 | * @param networkUrl |
| 143 | * - a network URL for common definition of data and control channel |
| 144 | * or null if separate definition of data and control channel |
| 145 | * @param controlUrl |
| 146 | * - a URL for control channel (networkUrl has to be null, dataUrl has to be set) |
| 147 | * @param dataUrl |
| 148 | * - a URL for data channel (networkUrl has to be null, controlUrl has to be set) |
| 149 | * @param isSnapshot |
| 150 | * - true for snapshot session else false |
| 151 | * @param monitor |
| 152 | * - a progress monitor |
| 153 | * @throws ExecutionException |
| 154 | * If the command fails |
| 155 | */ |
| 156 | public void createSession(String sessionName, String networkUrl, String controlUrl, String dataUrl, boolean isSnapshot, IProgressMonitor monitor) throws ExecutionException { |
| 157 | ISessionInfo sessionInfo = getControlService().createSession(sessionName, networkUrl, controlUrl, dataUrl, isSnapshot, monitor); |
| 158 | |
| 159 | if (sessionInfo != null) { |
| 160 | TraceSessionComponent session = new TraceSessionComponent(sessionInfo.getName(), TraceSessionGroup.this); |
| 161 | addChild(session); |
| 162 | session.getConfigurationFromNode(monitor); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Destroys a session with given session name. |
| 168 | * |
| 169 | * @param session |
| 170 | * - a session component to destroy |
| 171 | * @param monitor |
| 172 | * - a progress monitor |
| 173 | * @throws ExecutionException |
| 174 | * If the command fails |
| 175 | */ |
| 176 | public void destroySession(TraceSessionComponent session, |
| 177 | IProgressMonitor monitor) throws ExecutionException { |
| 178 | getControlService().destroySession(session.getName(), monitor); |
| 179 | session.removeAllChildren(); |
| 180 | removeChild(session); |
| 181 | } |
| 182 | } |