lttng.control: add possibility to run a list of lttng commands
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.control.ui / src / org / eclipse / linuxtools / internal / lttng2 / control / ui / views / model / impl / TraceSessionGroup.java
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.control.ui.views.model.impl;
14
15 import java.util.List;
16
17 import org.eclipse.core.commands.ExecutionException;
18 import org.eclipse.core.runtime.IProgressMonitor;
19 import org.eclipse.core.runtime.NullProgressMonitor;
20 import org.eclipse.linuxtools.internal.lttng2.control.core.model.ISessionInfo;
21 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.ITraceControlComponent;
22
23 /**
24 * <p>
25 * Implementation of the trace session group.
26 * </p>
27 *
28 * @author Bernd Hufmann
29 */
30 public class TraceSessionGroup extends TraceControlComponent {
31 // ------------------------------------------------------------------------
32 // Constants
33 // ------------------------------------------------------------------------
34 /**
35 * Path to icon file for this component.
36 */
37 public static final String TRACE_SESSIONS_ICON_FILE = "icons/obj16/sessions.gif"; //$NON-NLS-1$
38
39 // ------------------------------------------------------------------------
40 // Attributes
41 // ------------------------------------------------------------------------
42
43 // ------------------------------------------------------------------------
44 // Constructors
45 // ------------------------------------------------------------------------
46 /**
47 * Constructor
48 * @param name - the name of the component.
49 * @param parent - the parent of this component.
50 */
51 public TraceSessionGroup(String name, ITraceControlComponent parent) {
52 super(name, parent);
53 setImage(TRACE_SESSIONS_ICON_FILE);
54 }
55
56 // ------------------------------------------------------------------------
57 // Accessors
58 // ------------------------------------------------------------------------
59
60 /**
61 * @return the parent target node
62 */
63 public TargetNodeComponent getTargetNode() {
64 return (TargetNodeComponent)getParent();
65 }
66
67 /**
68 * Returns if node supports networks streaming or not
69 * @return <code>true</code> if node supports filtering else <code>false</code>
70 */
71 public boolean isNetworkStreamingSupported() {
72 return getTargetNode().isNetworkStreamingSupported();
73 }
74 /**
75 * Returns if node supports snapshots or not
76 * @return <code>true</code> if it supports snapshots else <code>false</code>
77 *
78 */ public boolean isSnapshotSupported() {
79 return getTargetNode().isSnapshotSupported();
80 }
81
82 // ------------------------------------------------------------------------
83 // Operations
84 // ------------------------------------------------------------------------
85 /**
86 * Retrieves the sessions information from the node.
87 *
88 * @throws ExecutionException
89 * If the command fails
90 */
91 public void getSessionsFromNode() throws ExecutionException {
92 getSessionsFromNode(new NullProgressMonitor());
93 }
94
95 /**
96 * Retrieves the sessions information from the node.
97 *
98 * @param monitor
99 * - a progress monitor
100 * @throws ExecutionException
101 * If the command fails
102 */
103 public void getSessionsFromNode(IProgressMonitor monitor)
104 throws ExecutionException {
105 String[] sessionNames = getControlService().getSessionNames(monitor);
106 for (int i = 0; i < sessionNames.length; i++) {
107 TraceSessionComponent session = new TraceSessionComponent(
108 sessionNames[i], this);
109 addChild(session);
110 session.getConfigurationFromNode(monitor);
111 }
112 }
113
114 /**
115 * Creates a session with given session name and location.
116 *
117 * @param sessionInf
118 * the session information used to create the session
119 *
120 * @param monitor
121 * - a progress monitor
122 * @throws ExecutionException
123 * If the command fails
124 */
125 public void createSession(ISessionInfo sessionInf, IProgressMonitor monitor) throws ExecutionException {
126 ISessionInfo sessionInfo = getControlService().createSession(sessionInf, monitor);
127
128 if (sessionInfo != null) {
129 TraceSessionComponent session = new TraceSessionComponent(sessionInfo.getName(), TraceSessionGroup.this);
130 addChild(session);
131 session.getConfigurationFromNode(monitor);
132 }
133 }
134
135 /**
136 * Command to execute a list of commands
137 * @param monitor
138 * - a progress monitor
139 * @param commands
140 * - a list of commands to execute
141 * @throws ExecutionException
142 * If the command fails
143 */
144 public void executeCommands(IProgressMonitor monitor, List<String> commands) throws ExecutionException {
145 getControlService().runCommands(monitor, commands);
146 getTargetNode().refresh();
147 }
148
149 /**
150 * Destroys a session with given session name.
151 *
152 * @param session
153 * - a session component to destroy
154 * @param monitor
155 * - a progress monitor
156 * @throws ExecutionException
157 * If the command fails
158 */
159 public void destroySession(TraceSessionComponent session,
160 IProgressMonitor monitor) throws ExecutionException {
161 getControlService().destroySession(session.getName(), monitor);
162 session.removeAllChildren();
163 removeChild(session);
164 }
165 }
This page took 0.038358 seconds and 5 git commands to generate.