1 /**********************************************************************
2 * Copyright (c) 2012 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
;
14 import java
.util
.ArrayList
;
15 import java
.util
.List
;
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
.core
.control
.model
.IChannelInfo
;
21 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.IEventInfo
;
22 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.LogLevelType
;
23 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.TraceEnablement
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.TraceLogLevel
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.ChannelInfo
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.ProbeEventInfo
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.Activator
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.messages
.Messages
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.ITraceControlComponent
;
30 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.property
.TraceChannelPropertySource
;
31 import org
.eclipse
.swt
.graphics
.Image
;
32 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
37 * Implementation of the trace channel component.
40 * @author Bernd Hufmann
42 public class TraceChannelComponent
extends TraceControlComponent
{
43 // ------------------------------------------------------------------------
45 // ------------------------------------------------------------------------
47 * Path to icon file for this component (state enabled).
49 public static final String TRACE_CHANNEL_ICON_FILE_ENABLED
= "icons/obj16/channel.gif"; //$NON-NLS-1$
51 * Path to icon file for this component (state disabled).
53 public static final String TRACE_CHANNEL_ICON_FILE_DISABLED
= "icons/obj16/channel_disabled.gif"; //$NON-NLS-1$
55 // ------------------------------------------------------------------------
57 // ------------------------------------------------------------------------
59 * The channel information.
61 private IChannelInfo fChannelInfo
= null;
63 * The image to be displayed in disabled state.
65 private Image fDisabledImage
= null;
67 // ------------------------------------------------------------------------
69 // ------------------------------------------------------------------------
72 * @param name - the name of the component.
73 * @param parent - the parent of this component.
75 public TraceChannelComponent(String name
, ITraceControlComponent parent
) {
77 setImage(TRACE_CHANNEL_ICON_FILE_ENABLED
);
78 setToolTip(Messages
.TraceControl_ChannelDisplayName
);
79 fChannelInfo
= new ChannelInfo(name
);
80 fDisabledImage
= Activator
.getDefault().loadIcon(TRACE_CHANNEL_ICON_FILE_DISABLED
);
83 // ------------------------------------------------------------------------
85 // ------------------------------------------------------------------------
88 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getImage()
91 public Image
getImage() {
92 if (fChannelInfo
.getState() == TraceEnablement
.DISABLED
) {
93 return fDisabledImage
;
95 return super.getImage();
99 * Sets the channel information.
102 * The channel info to assign to this component
104 public void setChannelInfo(IChannelInfo channelInfo
) {
105 fChannelInfo
= channelInfo
;
106 IEventInfo
[] events
= fChannelInfo
.getEvents();
107 List
<ITraceControlComponent
> eventComponents
= new ArrayList
<ITraceControlComponent
>();
108 for (int i
= 0; i
< events
.length
; i
++) {
109 TraceEventComponent event
= null;
110 if (events
[i
].getClass() == ProbeEventInfo
.class) {
111 event
= new TraceProbeEventComponent(events
[i
].getName(), this);
113 event
= new TraceEventComponent(events
[i
].getName(), this);
116 eventComponents
.add(event
);
117 event
.setEventInfo(events
[i
]);
120 if (!eventComponents
.isEmpty()) {
121 setChildren(eventComponents
);
126 * @return the overwrite mode value.
128 public boolean isOverwriteMode() {
129 return fChannelInfo
.isOverwriteMode();
132 * Sets the overwrite mode value to the given mode.
133 * @param mode - mode to set.
135 public void setOverwriteMode(boolean mode
){
136 fChannelInfo
.setOverwriteMode(mode
);
139 * @return the sub-buffer size.
141 public long getSubBufferSize() {
142 return fChannelInfo
.getSubBufferSize();
145 * Sets the sub-buffer size to the given value.
146 * @param bufferSize - size to set to set.
148 public void setSubBufferSize(long bufferSize
) {
149 fChannelInfo
.setSubBufferSize(bufferSize
);
152 * @return the number of sub-buffers.
154 public int getNumberOfSubBuffers() {
155 return fChannelInfo
.getNumberOfSubBuffers();
158 * Sets the number of sub-buffers to the given value.
159 * @param numberOfSubBuffers - value to set.
161 public void setNumberOfSubBuffers(int numberOfSubBuffers
) {
162 fChannelInfo
.setNumberOfSubBuffers(numberOfSubBuffers
);
165 * @return the switch timer interval.
167 public long getSwitchTimer() {
168 return fChannelInfo
.getSwitchTimer();
171 * Sets the switch timer interval to the given value.
172 * @param timer - timer value to set.
174 public void setSwitchTimer(long timer
) {
175 fChannelInfo
.setSwitchTimer(timer
);
178 * @return the read timer interval.
180 public long getReadTimer() {
181 return fChannelInfo
.getReadTimer();
184 * Sets the read timer interval to the given value.
185 * @param timer - timer value to set..
187 public void setReadTimer(long timer
) {
188 fChannelInfo
.setReadTimer(timer
);
191 * @return the output type.
193 public String
getOutputType() {
194 return fChannelInfo
.getOutputType();
197 * Sets the output type to the given value.
198 * @param type - type to set.
200 public void setOutputType(String type
) {
201 fChannelInfo
.setOutputType(type
);
204 * @return the channel state (enabled or disabled).
206 public TraceEnablement
getState() {
207 return fChannelInfo
.getState();
210 * Sets the channel state (enablement) to the given value.
211 * @param state - state to set.
213 public void setState(TraceEnablement state
) {
214 fChannelInfo
.setState(state
);
217 * Sets the channel state (enablement) to the value specified by the given name.
218 * @param stateName - state to set.
220 public void setState(String stateName
) {
221 fChannelInfo
.setState(stateName
);
225 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class)
228 public Object
getAdapter(Class adapter
) {
229 if (adapter
== IPropertySource
.class) {
230 return new TraceChannelPropertySource(this);
236 * @return session name from parent
238 public String
getSessionName() {
239 return ((TraceDomainComponent
)getParent()).getSessionName();
243 * @return session from parent
245 public TraceSessionComponent
getSession() {
246 return ((TraceDomainComponent
)getParent()).getSession();
250 * @return if domain is kernel or UST
252 public boolean isKernel() {
253 return ((TraceDomainComponent
)getParent()).isKernel();
257 * @return the parent target node
259 public TargetNodeComponent
getTargetNode() {
260 return ((TraceDomainComponent
)getParent()).getTargetNode();
263 // ------------------------------------------------------------------------
265 // ------------------------------------------------------------------------
267 * Enables a list of events with no additional parameters.
270 * - a list of event names to enabled.
271 * @throws ExecutionException
272 * If the command fails
274 public void enableEvents(List
<String
> eventNames
) throws ExecutionException
{
275 enableEvents(eventNames
, new NullProgressMonitor());
279 * Enables a list of events with no additional parameters.
282 * - a list of event names to enabled.
284 * - a progress monitor
285 * @throws ExecutionException
286 * If the command fails
288 public void enableEvents(List
<String
> eventNames
, IProgressMonitor monitor
) throws ExecutionException
{
289 getControlService().enableEvents(getSessionName(), getName(), eventNames
, isKernel(), monitor
);
293 * Enables all syscalls (for kernel domain)
295 * @throws ExecutionException
296 * If the command fails
298 public void enableSyscalls() throws ExecutionException
{
299 enableSyscalls(new NullProgressMonitor());
303 * Enables all syscalls (for kernel domain)
306 * - a progress monitor
307 * @throws ExecutionException
308 * If the command fails
310 public void enableSyscalls(IProgressMonitor monitor
) throws ExecutionException
{
311 getControlService().enableSyscalls(getSessionName(), getName(), monitor
);
315 * Enables a dynamic probe (for kernel domain)
318 * - event name for probe
320 * - true for dynamic function entry/return probe else false
323 * @throws ExecutionException
324 * If the command fails
326 public void enableProbe(String eventName
, boolean isFunction
, String probe
)
327 throws ExecutionException
{
328 enableProbe(eventName
, isFunction
, probe
, new NullProgressMonitor());
332 * Enables a dynamic probe (for kernel domain)
335 * - event name for probe
337 * - true for dynamic function entry/return probe else false
341 * - a progress monitor
342 * @throws ExecutionException
343 * If the command fails
345 public void enableProbe(String eventName
, boolean isFunction
, String probe
,
346 IProgressMonitor monitor
) throws ExecutionException
{
347 getControlService().enableProbe(getSessionName(), getName(), eventName
, isFunction
, probe
, monitor
);
351 * Enables events using log level.
355 * @param logLevelType
359 * @throws ExecutionException
360 * If the command fails
362 public void enableLogLevel(String eventName
, LogLevelType logLevelType
,
363 TraceLogLevel level
) throws ExecutionException
{
364 enableLogLevel(eventName
, logLevelType
, level
, new NullProgressMonitor());
368 * Enables events using log level.
372 * @param logLevelType
377 * - a progress monitor
378 * @throws ExecutionException
379 * If the command fails
381 public void enableLogLevel(String eventName
, LogLevelType logLevelType
,
382 TraceLogLevel level
, IProgressMonitor monitor
)
383 throws ExecutionException
{
384 getControlService().enableLogLevel(getSessionName(), getName(), eventName
, logLevelType
, level
, monitor
);
388 * Enables a list of events with no additional parameters.
391 * - a list of event names to enabled.
392 * @throws ExecutionException
393 * If the command fails
395 public void disableEvent(List
<String
> eventNames
) throws ExecutionException
{
396 disableEvent(eventNames
, new NullProgressMonitor());
400 * Enables a list of events with no additional parameters.
403 * - a list of event names to enabled.
405 * - a progress monitor
406 * @throws ExecutionException
407 * If the command fails
409 public void disableEvent(List
<String
> eventNames
, IProgressMonitor monitor
)
410 throws ExecutionException
{
411 getControlService().disableEvent(getParent().getParent().getName(),
412 getName(), eventNames
, isKernel(), monitor
);
416 * Add contexts to given channels and or events
419 * - a list of contexts to add
420 * @throws ExecutionException
421 * If the command fails
423 public void addContexts(List
<String
> contexts
) throws ExecutionException
{
424 addContexts(contexts
, new NullProgressMonitor());
428 * Add contexts to given channels and or events
431 * - a list of contexts to add
433 * - a progress monitor
434 * @throws ExecutionException
435 * If the command fails
437 public void addContexts(List
<String
> contexts
, IProgressMonitor monitor
)
438 throws ExecutionException
{
439 getControlService().addContexts(getSessionName(), getName(), null,
440 isKernel(), contexts
, monitor
);