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
.ui
.Activator
;
21 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.Messages
;
22 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.IChannelInfo
;
23 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.IEventInfo
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.ITraceControlComponent
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.LogLevelType
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.TraceEnablement
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.TraceLogLevel
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.property
.TraceChannelPropertySource
;
29 import org
.eclipse
.swt
.graphics
.Image
;
30 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
34 * <b><u>TraceChannelComponent</u></b>
36 * Implementation of the trace channel component.
39 public class TraceChannelComponent
extends TraceControlComponent
{
40 // ------------------------------------------------------------------------
42 // ------------------------------------------------------------------------
44 * Path to icon file for this component (state enabled).
46 public static final String TRACE_CHANNEL_ICON_FILE_ENABLED
= "icons/obj16/channel.gif"; //$NON-NLS-1$
48 * Path to icon file for this component (state disabled).
50 public static final String TRACE_CHANNEL_ICON_FILE_DISABLED
= "icons/obj16/channel_disabled.gif"; //$NON-NLS-1$
52 // ------------------------------------------------------------------------
54 // ------------------------------------------------------------------------
56 * The channel information.
58 private IChannelInfo fChannelInfo
= null;
60 * The image to be displayed in disabled state.
62 private Image fDisabledImage
= null;
64 // ------------------------------------------------------------------------
66 // ------------------------------------------------------------------------
69 * @param name - the name of the component.
70 * @param parent - the parent of this component.
72 public TraceChannelComponent(String name
, ITraceControlComponent parent
) {
74 setImage(TRACE_CHANNEL_ICON_FILE_ENABLED
);
75 setToolTip(Messages
.TraceControl_ChannelDisplayName
);
76 fChannelInfo
= new ChannelInfo(name
);
77 fDisabledImage
= Activator
.getDefault().loadIcon(TRACE_CHANNEL_ICON_FILE_DISABLED
);
80 // ------------------------------------------------------------------------
82 // ------------------------------------------------------------------------
85 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getImage()
88 public Image
getImage() {
89 if (fChannelInfo
.getState() == TraceEnablement
.DISABLED
) {
90 return fDisabledImage
;
92 return super.getImage();
96 * Sets the channel information.
99 public void setChannelInfo(IChannelInfo channelInfo
) {
100 fChannelInfo
= channelInfo
;
101 IEventInfo
[] events
= fChannelInfo
.getEvents();
102 List
<ITraceControlComponent
> eventComponents
= new ArrayList
<ITraceControlComponent
>();
103 for (int i
= 0; i
< events
.length
; i
++) {
104 TraceEventComponent event
= null;
105 if (events
[i
].getClass() == ProbeEventInfo
.class) {
106 event
= new TraceProbeEventComponent(events
[i
].getName(), this);
108 event
= new TraceEventComponent(events
[i
].getName(), this);
111 eventComponents
.add(event
);
112 event
.setEventInfo(events
[i
]);
115 if (!eventComponents
.isEmpty()) {
116 setChildren(eventComponents
);
121 * @return the overwrite mode value.
123 public boolean isOverwriteMode() {
124 return fChannelInfo
.isOverwriteMode();
127 * Sets the overwrite mode value to the given mode.
128 * @param mode - mode to set.
130 public void setOverwriteMode(boolean mode
){
131 fChannelInfo
.setOverwriteMode(mode
);
134 * @return the sub-buffer size.
136 public long getSubBufferSize() {
137 return fChannelInfo
.getSubBufferSize();
140 * Sets the sub-buffer size to the given value.
141 * @param bufferSize - size to set to set.
143 public void setSubBufferSize(long bufferSize
) {
144 fChannelInfo
.setSubBufferSize(bufferSize
);
147 * @return the number of sub-buffers.
149 public int getNumberOfSubBuffers() {
150 return fChannelInfo
.getNumberOfSubBuffers();
153 * Sets the number of sub-buffers to the given value.
154 * @param numberOfSubBuffers - value to set.
156 public void setNumberOfSubBuffers(int numberOfSubBuffers
) {
157 fChannelInfo
.setNumberOfSubBuffers(numberOfSubBuffers
);
160 * @return the switch timer interval.
162 public long getSwitchTimer() {
163 return fChannelInfo
.getSwitchTimer();
166 * Sets the switch timer interval to the given value.
167 * @param timer - timer value to set.
169 public void setSwitchTimer(long timer
) {
170 fChannelInfo
.setSwitchTimer(timer
);
173 * @return the read timer interval.
175 public long getReadTimer() {
176 return fChannelInfo
.getReadTimer();
179 * Sets the read timer interval to the given value.
180 * @param timer - timer value to set..
182 public void setReadTimer(long timer
) {
183 fChannelInfo
.setReadTimer(timer
);
186 * @return the output type.
188 public String
getOutputType() {
189 return fChannelInfo
.getOutputType();
192 * Sets the output type to the given value.
193 * @param type - type to set.
195 public void setOutputType(String type
) {
196 fChannelInfo
.setOutputType(type
);
199 * @return the channel state (enabled or disabled).
201 public TraceEnablement
getState() {
202 return fChannelInfo
.getState();
205 * Sets the channel state (enablement) to the given value.
206 * @param state - state to set.
208 public void setState(TraceEnablement state
) {
209 fChannelInfo
.setState(state
);
212 * Sets the channel state (enablement) to the value specified by the given name.
213 * @param stateName - state to set.
215 public void setState(String stateName
) {
216 fChannelInfo
.setState(stateName
);
220 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class)
222 @SuppressWarnings("rawtypes")
224 public Object
getAdapter(Class adapter
) {
225 if (adapter
== IPropertySource
.class) {
226 return new TraceChannelPropertySource(this);
232 * @return session name from parent
234 public String
getSessionName() {
235 return ((TraceDomainComponent
)getParent()).getSessionName();
239 * @return session from parent
241 public TraceSessionComponent
getSession() {
242 return ((TraceDomainComponent
)getParent()).getSession();
246 * @return if domain is kernel or UST
248 public boolean isKernel() {
249 return ((TraceDomainComponent
)getParent()).isKernel();
253 * @return the parent target node
255 public TargetNodeComponent
getTargetNode() {
256 return ((TraceDomainComponent
)getParent()).getTargetNode();
259 // ------------------------------------------------------------------------
261 // ------------------------------------------------------------------------
263 * Enables a list of events with no additional parameters.
264 * @param eventNames - a list of event names to enabled.
265 * @throws ExecutionException
267 public void enableEvents(List
<String
> eventNames
) throws ExecutionException
{
268 enableEvents(eventNames
, new NullProgressMonitor());
272 * Enables a list of events with no additional parameters.
273 * @param eventNames - a list of event names to enabled.
274 * @param monitor - a progress monitor
275 * @throws ExecutionException
277 public void enableEvents(List
<String
> eventNames
, IProgressMonitor monitor
) throws ExecutionException
{
278 getControlService().enableEvents(getSessionName(), getName(), eventNames
, isKernel(), monitor
);
282 * Enables all syscalls (for kernel domain)
283 * @throws ExecutionException
285 public void enableSyscalls() throws ExecutionException
{
286 enableSyscalls(new NullProgressMonitor());
290 * Enables all syscalls (for kernel domain)
291 * @param monitor - a progress monitor
292 * @throws ExecutionException
294 public void enableSyscalls(IProgressMonitor monitor
) throws ExecutionException
{
295 getControlService().enableSyscalls(getSessionName(), getName(), monitor
);
299 * Enables a dynamic probe (for kernel domain)
300 * @param eventName - event name for probe
301 * @param isFunction - true for dynamic function entry/return probe else false
302 * @param probe - the actual probe
303 * @throws ExecutionException
305 public void enableProbe(String eventName
, boolean isFunction
, String probe
) throws ExecutionException
{
306 enableProbe(eventName
, isFunction
, probe
, new NullProgressMonitor());
310 * Enables a dynamic probe (for kernel domain)
311 * @param eventName - event name for probe
312 * @param isFunction - true for dynamic function entry/return probe else false
313 * @param probe - the actual probe
314 * @param monitor - a progress monitor
315 * @throws ExecutionException
317 public void enableProbe(String eventName
, boolean isFunction
, String probe
, IProgressMonitor monitor
) throws ExecutionException
{
318 getControlService().enableProbe(getSessionName(), getName(), eventName
, isFunction
, probe
, monitor
);
322 * Enables events using log level.
323 * @param eventName - a event name
324 * @param logLevelType - a log level type
325 * @param level - a log level
326 * @throws ExecutionException
328 public void enableLogLevel(String eventName
, LogLevelType logLevelType
, TraceLogLevel level
) throws ExecutionException
{
329 enableLogLevel(eventName
, logLevelType
, level
, new NullProgressMonitor());
333 * Enables events using log level.
334 * @param eventName - a event name
335 * @param logLevelType - a log level type
336 * @param level - a log level
337 * @param monitor - a progress monitor
338 * @throws ExecutionException
340 public void enableLogLevel(String eventName
, LogLevelType logLevelType
, TraceLogLevel level
, IProgressMonitor monitor
) throws ExecutionException
{
341 getControlService().enableLogLevel(getSessionName(), getName(), eventName
, logLevelType
, level
, monitor
);
345 * Enables a list of events with no additional parameters.
346 * @param eventNames - a list of event names to enabled.
347 * @throws ExecutionException
349 public void disableEvent(List
<String
> eventNames
) throws ExecutionException
{
350 disableEvent(eventNames
, new NullProgressMonitor());
354 * Enables a list of events with no additional parameters.
355 * @param eventNames - a list of event names to enabled.
356 * @param monitor - a progress monitor
357 * @throws ExecutionException
359 public void disableEvent(List
<String
> eventNames
, IProgressMonitor monitor
) throws ExecutionException
{
360 getControlService().disableEvent(getParent().getParent().getName(), getName(), eventNames
, isKernel(), monitor
);
364 * Add contexts to given channels and or events
365 * @param contexts - a list of contexts to add
366 * @throws ExecutionException
368 public void addContexts(List
<String
> contexts
) throws ExecutionException
{
369 addContexts(contexts
, new NullProgressMonitor());
373 * Add contexts to given channels and or events
374 * @param contexts - a list of contexts to add
375 * @param monitor - a progress monitor
376 * @throws ExecutionException
378 public void addContexts(List
<String
> contexts
, IProgressMonitor monitor
) throws ExecutionException
{
379 getControlService().addContexts(getSessionName(), getName(), null, isKernel(), contexts
, monitor
);