Commit | Line | Data |
---|---|---|
eb1bab5b BH |
1 | /********************************************************************** |
2 | * Copyright (c) 2012 Ericsson | |
3 | * | |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Bernd Hufmann - Initial API and implementation | |
11 | **********************************************************************/ | |
12 | package org.eclipse.linuxtools.lttng.ui.views.control.model.impl; | |
13 | ||
6503ae0f BH |
14 | import java.util.List; |
15 | ||
eb1bab5b BH |
16 | import org.eclipse.core.commands.ExecutionException; |
17 | import org.eclipse.core.runtime.IProgressMonitor; | |
18 | import org.eclipse.core.runtime.NullProgressMonitor; | |
19 | import org.eclipse.linuxtools.lttng.ui.LTTngUiPlugin; | |
20 | import org.eclipse.linuxtools.lttng.ui.views.control.Messages; | |
21 | import org.eclipse.linuxtools.lttng.ui.views.control.model.IDomainInfo; | |
22 | import org.eclipse.linuxtools.lttng.ui.views.control.model.ISessionInfo; | |
23 | import org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent; | |
ccc66d01 BH |
24 | import org.eclipse.linuxtools.lttng.ui.views.control.model.LogLevelType; |
25 | import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceLogLevel; | |
eb1bab5b | 26 | import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceSessionState; |
06b9339e | 27 | import org.eclipse.linuxtools.lttng.ui.views.control.property.TraceSessionPropertySource; |
eb1bab5b | 28 | import org.eclipse.swt.graphics.Image; |
06b9339e | 29 | import org.eclipse.ui.views.properties.IPropertySource; |
eb1bab5b BH |
30 | |
31 | /** | |
32 | * <b><u>TraceSessionComponent</u></b> | |
33 | * <p> | |
34 | * Implementation of the trace session component. | |
35 | * </p> | |
36 | */ | |
37 | public class TraceSessionComponent extends TraceControlComponent { | |
38 | ||
39 | // ------------------------------------------------------------------------ | |
40 | // Constants | |
41 | // ------------------------------------------------------------------------ | |
42 | /** | |
43 | * Path to icon file for this component (inactive state). | |
44 | */ | |
45 | public static final String TRACE_SESSION_ICON_FILE_INACTIVE = "icons/obj16/session_inactive.gif"; //$NON-NLS-1$ | |
46 | /** | |
47 | * Path to icon file for this component (active state). | |
48 | */ | |
49 | public static final String TRACE_SESSION_ICON_FILE_ACTIVE = "icons/obj16/session_active.gif"; //$NON-NLS-1$ | |
50 | /** | |
51 | * Path to icon file for this component (destroyed state). | |
52 | */ | |
53 | public static final String TRACE_SESSION_ICON_FILE_DESTROYED = "icons/obj16/session_destroyed.gif"; //$NON-NLS-1$ | |
54 | ||
55 | // ------------------------------------------------------------------------ | |
56 | // Attributes | |
57 | // ------------------------------------------------------------------------ | |
58 | /** | |
59 | * The session information. | |
60 | */ | |
61 | private ISessionInfo fSessionInfo = null; | |
62 | /** | |
63 | * A flag to indicate if session has been destroyed. | |
64 | */ | |
65 | private boolean fIsDestroyed = false; | |
66 | /** | |
67 | * The image to be displayed in state active. | |
68 | */ | |
69 | private Image fActiveImage = null; | |
70 | /** | |
71 | * The image to be displayed in state destroyed | |
72 | */ | |
73 | private Image fDestroyedImage = null; | |
74 | ||
75 | // ------------------------------------------------------------------------ | |
76 | // Constructors | |
77 | // ------------------------------------------------------------------------ | |
78 | /** | |
79 | * Constructor | |
80 | * @param name - the name of the component. | |
81 | * @param parent - the parent of this component. | |
82 | */ | |
83 | public TraceSessionComponent(String name, ITraceControlComponent parent) { | |
84 | super(name, parent); | |
85 | setImage(TRACE_SESSION_ICON_FILE_INACTIVE); | |
86 | setToolTip(Messages.TraceControl_SessionDisplayName); | |
87 | fSessionInfo = new SessionInfo(name); | |
88 | fActiveImage = LTTngUiPlugin.getDefault().loadIcon(TRACE_SESSION_ICON_FILE_ACTIVE); | |
89 | fDestroyedImage = LTTngUiPlugin.getDefault().loadIcon(TRACE_SESSION_ICON_FILE_DESTROYED); | |
90 | } | |
91 | ||
92 | // ------------------------------------------------------------------------ | |
93 | // Accessors | |
94 | // ------------------------------------------------------------------------ | |
95 | /* | |
96 | * (non-Javadoc) | |
97 | * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent#getImage() | |
98 | */ | |
99 | @Override | |
100 | public Image getImage() { | |
101 | if (fIsDestroyed) { | |
102 | return fDestroyedImage; | |
103 | } | |
104 | ||
105 | if (fSessionInfo.getSessionState() == TraceSessionState.INACTIVE) { | |
106 | return super.getImage(); | |
107 | } | |
108 | ||
109 | return fActiveImage; | |
110 | } | |
111 | ||
eb1bab5b BH |
112 | /** |
113 | * @return the whether the session is destroyed or not. | |
114 | */ | |
115 | public boolean isDestroyed() { | |
116 | return fIsDestroyed; | |
117 | } | |
bbb3538a | 118 | |
eb1bab5b BH |
119 | /** |
120 | * Sets the session destroyed state to the given value. | |
121 | * @param destroyed - value to set. | |
122 | */ | |
123 | public void setDestroyed(boolean destroyed) { | |
124 | fIsDestroyed = destroyed; | |
125 | } | |
bbb3538a | 126 | |
eb1bab5b BH |
127 | /** |
128 | * @return the session state state (active or inactive). | |
129 | */ | |
130 | public TraceSessionState getSessionState() { | |
131 | return fSessionInfo.getSessionState(); | |
132 | } | |
133 | ||
134 | /** | |
135 | * Sets the session state to the given value. | |
136 | * @param state - state to set. | |
137 | */ | |
138 | public void setSessionState(TraceSessionState state) { | |
139 | fSessionInfo.setSessionState(state); | |
140 | } | |
bbb3538a | 141 | |
eb1bab5b BH |
142 | /** |
143 | * Sets the event state to the value specified by the given name. | |
144 | * @param stateName - state to set. | |
145 | */ | |
146 | public void setSessionState(String stateName) { | |
147 | fSessionInfo.setSessionState(stateName); | |
148 | } | |
149 | ||
150 | /** | |
151 | * @return path string where session is located. | |
152 | */ | |
153 | public String getSessionPath() { | |
154 | return fSessionInfo.getSessionPath(); | |
155 | } | |
156 | ||
157 | /** | |
158 | * Sets the path string (where session is located) to the given value. | |
159 | * @param path - session path to set. | |
160 | */ | |
161 | public void setSessionPath(String sessionPath) { | |
162 | fSessionInfo.setSessionPath(sessionPath); | |
163 | } | |
164 | ||
06b9339e BH |
165 | /* |
166 | * (non-Javadoc) | |
167 | * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class) | |
168 | */ | |
169 | @SuppressWarnings("rawtypes") | |
170 | @Override | |
171 | public Object getAdapter(Class adapter) { | |
172 | if (adapter == IPropertySource.class) { | |
173 | return new TraceSessionPropertySource(this); | |
174 | } | |
175 | return null; | |
176 | } | |
bbb3538a | 177 | |
6503ae0f BH |
178 | /** |
179 | * @return all available domains of this session. | |
180 | */ | |
181 | public TraceDomainComponent[] getDomains() { | |
182 | List<ITraceControlComponent> sessions = getChildren(TraceDomainComponent.class); | |
183 | return (TraceDomainComponent[])sessions.toArray(new TraceDomainComponent[sessions.size()]); | |
184 | } | |
185 | ||
498704b3 BH |
186 | /** |
187 | * @return the parent target node | |
188 | */ | |
189 | public TargetNodeComponent getTargetNode() { | |
190 | return ((TraceSessionGroup)getParent()).getTargetNode(); | |
191 | } | |
192 | ||
eb1bab5b BH |
193 | // ------------------------------------------------------------------------ |
194 | // Operations | |
195 | // ------------------------------------------------------------------------ | |
196 | /** | |
197 | * Retrieves the session configuration from the node. | |
198 | * @throws ExecutionException | |
199 | */ | |
200 | public void getConfigurationFromNode() throws ExecutionException { | |
201 | getConfigurationFromNode(new NullProgressMonitor()); | |
202 | } | |
203 | ||
204 | /** | |
205 | * Retrieves the session configuration from the node. | |
206 | * @param monitor - a progress monitor | |
207 | * @throws ExecutionException | |
208 | */ | |
209 | public void getConfigurationFromNode(IProgressMonitor monitor) throws ExecutionException { | |
bbb3538a | 210 | removeAllChildren(); |
eb1bab5b BH |
211 | fSessionInfo = getControlService().getSession(getName(), monitor); |
212 | IDomainInfo[] domains = fSessionInfo.getDomains(); | |
213 | for (int i = 0; i < domains.length; i++) { | |
bbb3538a BH |
214 | TraceDomainComponent domainComponent = new TraceDomainComponent(domains[i].getName(), this); |
215 | addChild(domainComponent); | |
216 | domainComponent.setDomainInfo(domains[i]); | |
eb1bab5b BH |
217 | } |
218 | } | |
bbb3538a BH |
219 | |
220 | /** | |
221 | * Starts the session. | |
222 | * throws ExecutionExecption | |
223 | */ | |
224 | public void startSession() throws ExecutionException { | |
225 | startSession(new NullProgressMonitor()); | |
226 | } | |
227 | ||
228 | /** | |
229 | * Starts the session. | |
230 | * @param monitor - a progress monitor | |
231 | * throws ExecutionExecption | |
232 | */ | |
233 | public void startSession(IProgressMonitor monitor) throws ExecutionException { | |
234 | getControlService().startSession(getName(), monitor); | |
235 | } | |
236 | ||
237 | /** | |
238 | * Starts the session. | |
239 | * throws ExecutionExecption | |
240 | */ | |
241 | public void stopSession() throws ExecutionException { | |
242 | startSession(new NullProgressMonitor()); | |
243 | } | |
244 | ||
245 | /** | |
246 | * Starts the session. | |
247 | * @param monitor - a progress monitor | |
248 | * throws ExecutionExecption | |
249 | */ | |
250 | public void stopSession(IProgressMonitor monitor) throws ExecutionException { | |
251 | getControlService().stopSession(getName(), monitor); | |
252 | } | |
253 | ||
6503ae0f BH |
254 | /** |
255 | * Enables a list of events with no additional parameters. | |
256 | * @param eventNames - a list of event names to enabled. | |
257 | * @param isKernel - a flag for indicating kernel or UST. | |
258 | * @throws ExecutionException | |
259 | */ | |
260 | public void enableEvent(List<String> eventNames, boolean isKernel) throws ExecutionException { | |
498704b3 | 261 | enableEvents(eventNames, isKernel, new NullProgressMonitor()); |
6503ae0f BH |
262 | } |
263 | ||
264 | /** | |
265 | * Enables a list of events with no additional parameters. | |
266 | * @param eventNames - a list of event names to enabled. | |
267 | * @param isKernel - a flag for indicating kernel or UST. | |
268 | * @param monitor - a progress monitor | |
269 | * @throws ExecutionException | |
270 | */ | |
498704b3 BH |
271 | public void enableEvents(List<String> eventNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException { |
272 | getControlService().enableEvents(getName(), null, eventNames, isKernel, monitor); | |
273 | } | |
274 | ||
275 | /** | |
276 | * Enables all syscalls (for kernel domain) | |
277 | * @throws ExecutionException | |
278 | */ | |
279 | public void enableSyscalls() throws ExecutionException { | |
280 | enableSyscalls(new NullProgressMonitor()); | |
281 | } | |
282 | ||
283 | /** | |
284 | * Enables all syscalls (for kernel domain) | |
285 | * @param monitor - a progress monitor | |
286 | * @throws ExecutionException | |
287 | */ | |
288 | public void enableSyscalls(IProgressMonitor monitor) throws ExecutionException { | |
289 | getControlService().enableSyscalls(getName(), null, monitor); | |
290 | } | |
291 | ||
292 | /** | |
293 | * Enables a dynamic probe (for kernel domain) | |
294 | * @param eventName - event name for probe | |
d132bcc7 | 295 | * @param isFunction - true for dynamic function entry/return probe else false |
498704b3 BH |
296 | * @param probe - the actual probe |
297 | * @throws ExecutionException | |
298 | */ | |
d132bcc7 BH |
299 | public void enableProbe(String eventName, boolean isFunction, String probe) throws ExecutionException { |
300 | enableProbe(eventName, isFunction, probe, new NullProgressMonitor()); | |
498704b3 BH |
301 | } |
302 | ||
303 | /** | |
304 | * Enables a dynamic probe (for kernel domain) | |
305 | * @param eventName - event name for probe | |
d132bcc7 | 306 | * @param isFunction - true for dynamic function entry/return probe else false |
498704b3 BH |
307 | * @param probe - the actual probe |
308 | * @param monitor - a progress monitor | |
309 | * @throws ExecutionException | |
310 | */ | |
d132bcc7 BH |
311 | public void enableProbe(String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException { |
312 | getControlService().enableProbe(getName(), null, eventName, isFunction, probe, monitor); | |
6503ae0f | 313 | } |
ccc66d01 BH |
314 | |
315 | /** | |
316 | * Enables events using log level. | |
317 | * @param eventName - a event name | |
318 | * @param logLevelType - a log level type | |
319 | * @param level - a log level | |
320 | * @throws ExecutionException | |
321 | */ | |
322 | public void enableLogLevel(String eventName, LogLevelType logLevelType, TraceLogLevel level) throws ExecutionException { | |
323 | enableLogLevel(eventName, logLevelType, level, new NullProgressMonitor()); | |
324 | } | |
325 | ||
326 | /** | |
327 | * Enables events using log level. | |
328 | * @param eventName - a event name | |
329 | * @param logLevelType - a log level type | |
330 | * @param level - a log level | |
331 | * @param monitor - a progress monitor | |
332 | * @throws ExecutionException | |
333 | */ | |
334 | public void enableLogLevel(String eventName, LogLevelType logLevelType, TraceLogLevel level, IProgressMonitor monitor) throws ExecutionException { | |
335 | getControlService().enableLogLevel(getName(), null, eventName, logLevelType, level, monitor); | |
336 | } | |
eb1bab5b | 337 | } |