Commit | Line | Data |
---|---|---|
eb1bab5b BH |
1 | /********************************************************************** |
2 | * Copyright (c) 2012 Ericsson | |
cfdb727a | 3 | * |
eb1bab5b BH |
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 | |
cfdb727a AM |
8 | * |
9 | * Contributors: | |
eb1bab5b BH |
10 | * Bernd Hufmann - Initial API and implementation |
11 | **********************************************************************/ | |
115b4a01 | 12 | package org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl; |
eb1bab5b | 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; | |
9315aeee BH |
19 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.IChannelInfo; |
20 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.IDomainInfo; | |
21 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.ISessionInfo; | |
22 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.LogLevelType; | |
23 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceLogLevel; | |
24 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceSessionState; | |
25 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.SessionInfo; | |
115b4a01 | 26 | import org.eclipse.linuxtools.internal.lttng2.ui.Activator; |
9315aeee | 27 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.messages.Messages; |
115b4a01 | 28 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent; |
115b4a01 | 29 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.property.TraceSessionPropertySource; |
eb1bab5b | 30 | import org.eclipse.swt.graphics.Image; |
06b9339e | 31 | import org.eclipse.ui.views.properties.IPropertySource; |
eb1bab5b BH |
32 | |
33 | /** | |
eb1bab5b BH |
34 | * <p> |
35 | * Implementation of the trace session component. | |
36 | * </p> | |
cfdb727a | 37 | * |
dbd4432d | 38 | * @author Bernd Hufmann |
eb1bab5b BH |
39 | */ |
40 | public class TraceSessionComponent extends TraceControlComponent { | |
41 | ||
42 | // ------------------------------------------------------------------------ | |
43 | // Constants | |
44 | // ------------------------------------------------------------------------ | |
45 | /** | |
46 | * Path to icon file for this component (inactive state). | |
47 | */ | |
48 | public static final String TRACE_SESSION_ICON_FILE_INACTIVE = "icons/obj16/session_inactive.gif"; //$NON-NLS-1$ | |
49 | /** | |
50 | * Path to icon file for this component (active state). | |
51 | */ | |
52 | public static final String TRACE_SESSION_ICON_FILE_ACTIVE = "icons/obj16/session_active.gif"; //$NON-NLS-1$ | |
53 | /** | |
54 | * Path to icon file for this component (destroyed state). | |
55 | */ | |
56 | public static final String TRACE_SESSION_ICON_FILE_DESTROYED = "icons/obj16/session_destroyed.gif"; //$NON-NLS-1$ | |
57 | ||
58 | // ------------------------------------------------------------------------ | |
59 | // Attributes | |
60 | // ------------------------------------------------------------------------ | |
61 | /** | |
62 | * The session information. | |
63 | */ | |
64 | private ISessionInfo fSessionInfo = null; | |
65 | /** | |
66 | * A flag to indicate if session has been destroyed. | |
67 | */ | |
68 | private boolean fIsDestroyed = false; | |
69 | /** | |
70 | * The image to be displayed in state active. | |
71 | */ | |
72 | private Image fActiveImage = null; | |
73 | /** | |
74 | * The image to be displayed in state destroyed | |
75 | */ | |
76 | private Image fDestroyedImage = null; | |
77 | ||
78 | // ------------------------------------------------------------------------ | |
79 | // Constructors | |
80 | // ------------------------------------------------------------------------ | |
81 | /** | |
cfdb727a | 82 | * Constructor |
eb1bab5b BH |
83 | * @param name - the name of the component. |
84 | * @param parent - the parent of this component. | |
cfdb727a | 85 | */ |
eb1bab5b BH |
86 | public TraceSessionComponent(String name, ITraceControlComponent parent) { |
87 | super(name, parent); | |
88 | setImage(TRACE_SESSION_ICON_FILE_INACTIVE); | |
89 | setToolTip(Messages.TraceControl_SessionDisplayName); | |
90 | fSessionInfo = new SessionInfo(name); | |
31a6a4e4 BH |
91 | fActiveImage = Activator.getDefault().loadIcon(TRACE_SESSION_ICON_FILE_ACTIVE); |
92 | fDestroyedImage = Activator.getDefault().loadIcon(TRACE_SESSION_ICON_FILE_DESTROYED); | |
eb1bab5b BH |
93 | } |
94 | ||
95 | // ------------------------------------------------------------------------ | |
96 | // Accessors | |
97 | // ------------------------------------------------------------------------ | |
98 | /* | |
99 | * (non-Javadoc) | |
115b4a01 | 100 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getImage() |
eb1bab5b BH |
101 | */ |
102 | @Override | |
103 | public Image getImage() { | |
104 | if (fIsDestroyed) { | |
105 | return fDestroyedImage; | |
106 | } | |
107 | ||
108 | if (fSessionInfo.getSessionState() == TraceSessionState.INACTIVE) { | |
109 | return super.getImage(); | |
110 | } | |
cfdb727a | 111 | |
eb1bab5b BH |
112 | return fActiveImage; |
113 | } | |
114 | ||
eb1bab5b BH |
115 | /** |
116 | * @return the whether the session is destroyed or not. | |
117 | */ | |
118 | public boolean isDestroyed() { | |
119 | return fIsDestroyed; | |
120 | } | |
bbb3538a | 121 | |
eb1bab5b BH |
122 | /** |
123 | * Sets the session destroyed state to the given value. | |
124 | * @param destroyed - value to set. | |
125 | */ | |
126 | public void setDestroyed(boolean destroyed) { | |
127 | fIsDestroyed = destroyed; | |
128 | } | |
bbb3538a | 129 | |
eb1bab5b BH |
130 | /** |
131 | * @return the session state state (active or inactive). | |
132 | */ | |
133 | public TraceSessionState getSessionState() { | |
134 | return fSessionInfo.getSessionState(); | |
135 | } | |
136 | ||
137 | /** | |
138 | * Sets the session state to the given value. | |
139 | * @param state - state to set. | |
140 | */ | |
141 | public void setSessionState(TraceSessionState state) { | |
142 | fSessionInfo.setSessionState(state); | |
143 | } | |
bbb3538a | 144 | |
eb1bab5b BH |
145 | /** |
146 | * Sets the event state to the value specified by the given name. | |
147 | * @param stateName - state to set. | |
148 | */ | |
149 | public void setSessionState(String stateName) { | |
150 | fSessionInfo.setSessionState(stateName); | |
151 | } | |
152 | ||
153 | /** | |
154 | * @return path string where session is located. | |
155 | */ | |
156 | public String getSessionPath() { | |
157 | return fSessionInfo.getSessionPath(); | |
158 | } | |
159 | ||
160 | /** | |
161 | * Sets the path string (where session is located) to the given value. | |
cfdb727a | 162 | * @param sessionPath - session path to set. |
eb1bab5b BH |
163 | */ |
164 | public void setSessionPath(String sessionPath) { | |
165 | fSessionInfo.setSessionPath(sessionPath); | |
166 | } | |
167 | ||
06b9339e BH |
168 | /* |
169 | * (non-Javadoc) | |
115b4a01 | 170 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class) |
06b9339e | 171 | */ |
06b9339e BH |
172 | @Override |
173 | public Object getAdapter(Class adapter) { | |
174 | if (adapter == IPropertySource.class) { | |
175 | return new TraceSessionPropertySource(this); | |
176 | } | |
177 | return null; | |
cfdb727a | 178 | } |
bbb3538a | 179 | |
6503ae0f BH |
180 | /** |
181 | * @return all available domains of this session. | |
182 | */ | |
183 | public TraceDomainComponent[] getDomains() { | |
184 | List<ITraceControlComponent> sessions = getChildren(TraceDomainComponent.class); | |
cfdb727a | 185 | return sessions.toArray(new TraceDomainComponent[sessions.size()]); |
6503ae0f | 186 | } |
cfdb727a | 187 | |
498704b3 BH |
188 | /** |
189 | * @return the parent target node | |
190 | */ | |
191 | public TargetNodeComponent getTargetNode() { | |
192 | return ((TraceSessionGroup)getParent()).getTargetNode(); | |
193 | } | |
cfdb727a | 194 | |
eb1bab5b BH |
195 | // ------------------------------------------------------------------------ |
196 | // Operations | |
197 | // ------------------------------------------------------------------------ | |
cfdb727a | 198 | |
eb1bab5b | 199 | /** |
cfdb727a AM |
200 | * Retrieves the session configuration from the node. |
201 | * | |
eb1bab5b | 202 | * @throws ExecutionException |
cfdb727a | 203 | * If the command fails |
eb1bab5b BH |
204 | */ |
205 | public void getConfigurationFromNode() throws ExecutionException { | |
206 | getConfigurationFromNode(new NullProgressMonitor()); | |
207 | } | |
208 | ||
209 | /** | |
cfdb727a AM |
210 | * Retrieves the session configuration from the node. |
211 | * | |
212 | * @param monitor | |
213 | * - a progress monitor | |
eb1bab5b | 214 | * @throws ExecutionException |
cfdb727a | 215 | * If the command fails |
eb1bab5b | 216 | */ |
cfdb727a AM |
217 | public void getConfigurationFromNode(IProgressMonitor monitor) |
218 | throws ExecutionException { | |
bbb3538a | 219 | removeAllChildren(); |
eb1bab5b BH |
220 | fSessionInfo = getControlService().getSession(getName(), monitor); |
221 | IDomainInfo[] domains = fSessionInfo.getDomains(); | |
222 | for (int i = 0; i < domains.length; i++) { | |
cfdb727a AM |
223 | TraceDomainComponent domainComponent = new TraceDomainComponent( |
224 | domains[i].getName(), this); | |
bbb3538a BH |
225 | addChild(domainComponent); |
226 | domainComponent.setDomainInfo(domains[i]); | |
eb1bab5b BH |
227 | } |
228 | } | |
cfdb727a | 229 | |
bbb3538a | 230 | /** |
cfdb727a AM |
231 | * Starts the session. |
232 | * | |
233 | * @throws ExecutionException | |
234 | * If the command fails | |
bbb3538a BH |
235 | */ |
236 | public void startSession() throws ExecutionException { | |
237 | startSession(new NullProgressMonitor()); | |
238 | } | |
cfdb727a | 239 | |
bbb3538a BH |
240 | /** |
241 | * Starts the session. | |
cfdb727a AM |
242 | * |
243 | * @param monitor | |
244 | * - a progress monitor | |
245 | * @throws ExecutionException | |
246 | * If the command fails | |
bbb3538a | 247 | */ |
cfdb727a AM |
248 | public void startSession(IProgressMonitor monitor) |
249 | throws ExecutionException { | |
bbb3538a BH |
250 | getControlService().startSession(getName(), monitor); |
251 | } | |
cfdb727a | 252 | |
bbb3538a | 253 | /** |
cfdb727a AM |
254 | * Starts the session. |
255 | * | |
256 | * @throws ExecutionException | |
257 | * If the command fails | |
bbb3538a BH |
258 | */ |
259 | public void stopSession() throws ExecutionException { | |
260 | startSession(new NullProgressMonitor()); | |
261 | } | |
cfdb727a | 262 | |
bbb3538a BH |
263 | /** |
264 | * Starts the session. | |
cfdb727a AM |
265 | * |
266 | * @param monitor | |
267 | * - a progress monitor | |
268 | * @throws ExecutionException | |
269 | * If the command fails | |
bbb3538a BH |
270 | */ |
271 | public void stopSession(IProgressMonitor monitor) throws ExecutionException { | |
272 | getControlService().stopSession(getName(), monitor); | |
273 | } | |
274 | ||
c56972bb | 275 | /** |
cfdb727a AM |
276 | * Enables channels with given names which are part of this domain. If a |
277 | * given channel doesn't exists it creates a new channel with the given | |
278 | * parameters (or default values if given parameter is null). | |
279 | * | |
280 | * @param channelNames | |
281 | * - a list of channel names to enable on this domain | |
282 | * @param info | |
283 | * - channel information to set for the channel (use null for | |
284 | * default) | |
285 | * @param isKernel | |
286 | * - a flag for indicating kernel or UST. | |
c56972bb | 287 | * @throws ExecutionException |
cfdb727a | 288 | * If the command fails |
c56972bb | 289 | */ |
cfdb727a AM |
290 | public void enableChannels(List<String> channelNames, IChannelInfo info, |
291 | boolean isKernel) throws ExecutionException { | |
c56972bb BH |
292 | enableChannels(channelNames, info, isKernel, new NullProgressMonitor()); |
293 | } | |
294 | ||
295 | /** | |
cfdb727a AM |
296 | * Enables channels with given names which are part of this domain. If a |
297 | * given channel doesn't exists it creates a new channel with the given | |
298 | * parameters (or default values if given parameter is null). | |
299 | * | |
300 | * @param channelNames | |
301 | * - a list of channel names to enable on this domain | |
302 | * @param info | |
303 | * - channel information to set for the channel (use null for | |
304 | * default) | |
305 | * @param isKernel | |
306 | * - a flag for indicating kernel or UST. | |
307 | * @param monitor | |
308 | * - a progress monitor | |
c56972bb | 309 | * @throws ExecutionException |
cfdb727a | 310 | * If the command fails |
c56972bb | 311 | */ |
cfdb727a AM |
312 | public void enableChannels(List<String> channelNames, IChannelInfo info, |
313 | boolean isKernel, IProgressMonitor monitor) | |
314 | throws ExecutionException { | |
315 | getControlService().enableChannels(getName(), channelNames, isKernel, | |
316 | info, monitor); | |
c56972bb | 317 | } |
cfdb727a | 318 | |
6503ae0f BH |
319 | /** |
320 | * Enables a list of events with no additional parameters. | |
cfdb727a AM |
321 | * |
322 | * @param eventNames | |
323 | * - a list of event names to enabled. | |
324 | * @param isKernel | |
325 | * - a flag for indicating kernel or UST. | |
6503ae0f | 326 | * @throws ExecutionException |
cfdb727a | 327 | * If the command fails |
6503ae0f | 328 | */ |
cfdb727a AM |
329 | public void enableEvent(List<String> eventNames, boolean isKernel) |
330 | throws ExecutionException { | |
498704b3 | 331 | enableEvents(eventNames, isKernel, new NullProgressMonitor()); |
6503ae0f BH |
332 | } |
333 | ||
334 | /** | |
335 | * Enables a list of events with no additional parameters. | |
cfdb727a AM |
336 | * |
337 | * @param eventNames | |
338 | * - a list of event names to enabled. | |
339 | * @param isKernel | |
340 | * - a flag for indicating kernel or UST. | |
341 | * @param monitor | |
342 | * - a progress monitor | |
6503ae0f | 343 | * @throws ExecutionException |
cfdb727a | 344 | * If the command fails |
6503ae0f | 345 | */ |
cfdb727a AM |
346 | public void enableEvents(List<String> eventNames, boolean isKernel, |
347 | IProgressMonitor monitor) throws ExecutionException { | |
348 | getControlService().enableEvents(getName(), null, eventNames, isKernel, | |
349 | monitor); | |
498704b3 BH |
350 | } |
351 | ||
352 | /** | |
353 | * Enables all syscalls (for kernel domain) | |
cfdb727a | 354 | * |
498704b3 | 355 | * @throws ExecutionException |
cfdb727a | 356 | * If the command fails |
498704b3 BH |
357 | */ |
358 | public void enableSyscalls() throws ExecutionException { | |
359 | enableSyscalls(new NullProgressMonitor()); | |
360 | } | |
361 | ||
362 | /** | |
363 | * Enables all syscalls (for kernel domain) | |
cfdb727a AM |
364 | * |
365 | * @param monitor | |
366 | * - a progress monitor | |
498704b3 | 367 | * @throws ExecutionException |
cfdb727a | 368 | * If the command fails |
498704b3 | 369 | */ |
cfdb727a AM |
370 | public void enableSyscalls(IProgressMonitor monitor) |
371 | throws ExecutionException { | |
498704b3 BH |
372 | getControlService().enableSyscalls(getName(), null, monitor); |
373 | } | |
374 | ||
375 | /** | |
376 | * Enables a dynamic probe (for kernel domain) | |
cfdb727a AM |
377 | * |
378 | * @param eventName | |
379 | * - event name for probe | |
380 | * @param isFunction | |
381 | * - true for dynamic function entry/return probe else false | |
382 | * @param probe | |
383 | * - the actual probe | |
498704b3 | 384 | * @throws ExecutionException |
cfdb727a | 385 | * If the command fails |
498704b3 | 386 | */ |
cfdb727a AM |
387 | public void enableProbe(String eventName, boolean isFunction, String probe) |
388 | throws ExecutionException { | |
d132bcc7 | 389 | enableProbe(eventName, isFunction, probe, new NullProgressMonitor()); |
498704b3 | 390 | } |
cfdb727a | 391 | |
498704b3 BH |
392 | /** |
393 | * Enables a dynamic probe (for kernel domain) | |
cfdb727a AM |
394 | * |
395 | * @param eventName | |
396 | * - event name for probe | |
397 | * @param isFunction | |
398 | * - true for dynamic function entry/return probe else false | |
399 | * @param probe | |
400 | * - the actual probe | |
401 | * @param monitor | |
402 | * - a progress monitor | |
498704b3 | 403 | * @throws ExecutionException |
cfdb727a | 404 | * If the command fails |
498704b3 | 405 | */ |
cfdb727a AM |
406 | public void enableProbe(String eventName, boolean isFunction, String probe, |
407 | IProgressMonitor monitor) throws ExecutionException { | |
408 | getControlService().enableProbe(getName(), null, eventName, isFunction, | |
409 | probe, monitor); | |
6503ae0f | 410 | } |
cfdb727a | 411 | |
ccc66d01 BH |
412 | /** |
413 | * Enables events using log level. | |
cfdb727a AM |
414 | * |
415 | * @param eventName | |
416 | * - a event name | |
417 | * @param logLevelType | |
418 | * - a log level type | |
419 | * @param level | |
420 | * - a log level | |
ccc66d01 | 421 | * @throws ExecutionException |
cfdb727a | 422 | * If the command fails |
ccc66d01 | 423 | */ |
cfdb727a AM |
424 | public void enableLogLevel(String eventName, LogLevelType logLevelType, |
425 | TraceLogLevel level) throws ExecutionException { | |
426 | enableLogLevel(eventName, logLevelType, level, | |
427 | new NullProgressMonitor()); | |
ccc66d01 BH |
428 | } |
429 | ||
430 | /** | |
431 | * Enables events using log level. | |
cfdb727a AM |
432 | * |
433 | * @param eventName | |
434 | * - a event name | |
435 | * @param logLevelType | |
436 | * - a log level type | |
437 | * @param level | |
438 | * - a log level | |
439 | * @param monitor | |
440 | * - a progress monitor | |
ccc66d01 | 441 | * @throws ExecutionException |
cfdb727a | 442 | * If the command fails |
ccc66d01 | 443 | */ |
cfdb727a AM |
444 | public void enableLogLevel(String eventName, LogLevelType logLevelType, |
445 | TraceLogLevel level, IProgressMonitor monitor) | |
446 | throws ExecutionException { | |
447 | getControlService().enableLogLevel(getName(), null, eventName, | |
448 | logLevelType, level, monitor); | |
ccc66d01 | 449 | } |
cfdb727a | 450 | |
b793fbe1 BH |
451 | /** |
452 | * Gets all available contexts to be added to channels/events. | |
cfdb727a | 453 | * |
b793fbe1 | 454 | * @return the list of available contexts |
cfdb727a AM |
455 | * @throws ExecutionException |
456 | * If the command fails | |
b793fbe1 BH |
457 | */ |
458 | public List<String> getContextList() throws ExecutionException { | |
459 | return getContextList(new NullProgressMonitor()); | |
460 | } | |
461 | ||
462 | /** | |
463 | * Gets all available contexts to be added to channels/events. | |
cfdb727a | 464 | * |
b793fbe1 | 465 | * @param monitor |
cfdb727a | 466 | * The monitor that will indicate the progress |
b793fbe1 | 467 | * @return the list of available contexts |
cfdb727a AM |
468 | * @throws ExecutionException |
469 | * If the command fails | |
b793fbe1 | 470 | */ |
cfdb727a AM |
471 | public List<String> getContextList(IProgressMonitor monitor) |
472 | throws ExecutionException { | |
b793fbe1 BH |
473 | return getControlService().getContextList(monitor); |
474 | } | |
eb1bab5b | 475 | } |