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
public void setChannelInfo(IChannelInfo channelInfo) {
103
fChannelInfo = channelInfo;
104
IEventInfo[] events = fChannelInfo.getEvents();
105
List<ITraceControlComponent> eventComponents = new ArrayList<ITraceControlComponent>();
106
for (int i = 0; i < events.length; i++) {
107
TraceEventComponent event = null;
108
if (events[i].getClass() == ProbeEventInfo.class) {
109
event = new TraceProbeEventComponent(events[i].getName(), this);
111
event = new TraceEventComponent(events[i].getName(), this);
114
eventComponents.add(event);
115
event.setEventInfo(events[i]);
118
if (!eventComponents.isEmpty()) {
119
setChildren(eventComponents);
124
* @return the overwrite mode value.
126
public boolean isOverwriteMode() {
127
return fChannelInfo.isOverwriteMode();
130
* Sets the overwrite mode value to the given mode.
131
* @param mode - mode to set.
133
public void setOverwriteMode(boolean mode){
134
fChannelInfo.setOverwriteMode(mode);
137
* @return the sub-buffer size.
139
public long getSubBufferSize() {
140
return fChannelInfo.getSubBufferSize();
143
* Sets the sub-buffer size to the given value.
144
* @param bufferSize - size to set to set.
146
public void setSubBufferSize(long bufferSize) {
147
fChannelInfo.setSubBufferSize(bufferSize);
150
* @return the number of sub-buffers.
152
public int getNumberOfSubBuffers() {
153
return fChannelInfo.getNumberOfSubBuffers();
156
* Sets the number of sub-buffers to the given value.
157
* @param numberOfSubBuffers - value to set.
159
public void setNumberOfSubBuffers(int numberOfSubBuffers) {
160
fChannelInfo.setNumberOfSubBuffers(numberOfSubBuffers);
163
* @return the switch timer interval.
165
public long getSwitchTimer() {
166
return fChannelInfo.getSwitchTimer();
169
* Sets the switch timer interval to the given value.
170
* @param timer - timer value to set.
172
public void setSwitchTimer(long timer) {
173
fChannelInfo.setSwitchTimer(timer);
176
* @return the read timer interval.
178
public long getReadTimer() {
179
return fChannelInfo.getReadTimer();
182
* Sets the read timer interval to the given value.
183
* @param timer - timer value to set..
185
public void setReadTimer(long timer) {
186
fChannelInfo.setReadTimer(timer);
189
* @return the output type.
191
public String getOutputType() {
192
return fChannelInfo.getOutputType();
195
* Sets the output type to the given value.
196
* @param type - type to set.
198
public void setOutputType(String type) {
199
fChannelInfo.setOutputType(type);
202
* @return the channel state (enabled or disabled).
204
public TraceEnablement getState() {
205
return fChannelInfo.getState();
208
* Sets the channel state (enablement) to the given value.
209
* @param state - state to set.
211
public void setState(TraceEnablement state) {
212
fChannelInfo.setState(state);
215
* Sets the channel state (enablement) to the value specified by the given name.
216
* @param stateName - state to set.
218
public void setState(String stateName) {
219
fChannelInfo.setState(stateName);
223
* @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class)
225
@SuppressWarnings("rawtypes")
227
public Object getAdapter(Class adapter) {
228
if (adapter == IPropertySource.class) {
229
return new TraceChannelPropertySource(this);
235
* @return session name from parent
237
public String getSessionName() {
238
return ((TraceDomainComponent)getParent()).getSessionName();
242
* @return session from parent
244
public TraceSessionComponent getSession() {
245
return ((TraceDomainComponent)getParent()).getSession();
249
* @return if domain is kernel or UST
251
public boolean isKernel() {
252
return ((TraceDomainComponent)getParent()).isKernel();
256
* @return the parent target node
258
public TargetNodeComponent getTargetNode() {
259
return ((TraceDomainComponent)getParent()).getTargetNode();
262
// ------------------------------------------------------------------------
264
// ------------------------------------------------------------------------
266
* Enables a list of events with no additional parameters.
267
* @param eventNames - a list of event names to enabled.
268
* @throws ExecutionException
270
public void enableEvents(List<String> eventNames) throws ExecutionException {
271
enableEvents(eventNames, new NullProgressMonitor());
275
* Enables a list of events with no additional parameters.
276
* @param eventNames - a list of event names to enabled.
277
* @param monitor - a progress monitor
278
* @throws ExecutionException
280
public void enableEvents(List<String> eventNames, IProgressMonitor monitor) throws ExecutionException {
281
getControlService().enableEvents(getSessionName(), getName(), eventNames, isKernel(), monitor);
285
* Enables all syscalls (for kernel domain)
286
* @throws ExecutionException
288
public void enableSyscalls() throws ExecutionException {
289
enableSyscalls(new NullProgressMonitor());
293
* Enables all syscalls (for kernel domain)
294
* @param monitor - a progress monitor
295
* @throws ExecutionException
297
public void enableSyscalls(IProgressMonitor monitor) throws ExecutionException {
298
getControlService().enableSyscalls(getSessionName(), getName(), monitor);
302
* Enables a dynamic probe (for kernel domain)
303
* @param eventName - event name for probe
304
* @param isFunction - true for dynamic function entry/return probe else false
305
* @param probe - the actual probe
306
* @throws ExecutionException
308
public void enableProbe(String eventName, boolean isFunction, String probe) throws ExecutionException {
309
enableProbe(eventName, isFunction, probe, new NullProgressMonitor());
313
* Enables a dynamic probe (for kernel domain)
314
* @param eventName - event name for probe
315
* @param isFunction - true for dynamic function entry/return probe else false
316
* @param probe - the actual probe
317
* @param monitor - a progress monitor
318
* @throws ExecutionException
320
public void enableProbe(String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException {
321
getControlService().enableProbe(getSessionName(), getName(), eventName, isFunction, probe, monitor);
325
* Enables events using log level.
326
* @param eventName - a event name
327
* @param logLevelType - a log level type
328
* @param level - a log level
329
* @throws ExecutionException
331
public void enableLogLevel(String eventName, LogLevelType logLevelType, TraceLogLevel level) throws ExecutionException {
332
enableLogLevel(eventName, logLevelType, level, new NullProgressMonitor());
336
* Enables events using log level.
337
* @param eventName - a event name
338
* @param logLevelType - a log level type
339
* @param level - a log level
340
* @param monitor - a progress monitor
341
* @throws ExecutionException
343
public void enableLogLevel(String eventName, LogLevelType logLevelType, TraceLogLevel level, IProgressMonitor monitor) throws ExecutionException {
344
getControlService().enableLogLevel(getSessionName(), getName(), eventName, logLevelType, level, monitor);
348
* Enables a list of events with no additional parameters.
349
* @param eventNames - a list of event names to enabled.
350
* @throws ExecutionException
352
public void disableEvent(List<String> eventNames) throws ExecutionException {
353
disableEvent(eventNames, new NullProgressMonitor());
357
* Enables a list of events with no additional parameters.
358
* @param eventNames - a list of event names to enabled.
359
* @param monitor - a progress monitor
360
* @throws ExecutionException
362
public void disableEvent(List<String> eventNames, IProgressMonitor monitor) throws ExecutionException {
363
getControlService().disableEvent(getParent().getParent().getName(), getName(), eventNames, isKernel(), monitor);
367
* Add contexts to given channels and or events
368
* @param contexts - a list of contexts to add
369
* @throws ExecutionException
371
public void addContexts(List<String> contexts) throws ExecutionException {
372
addContexts(contexts, new NullProgressMonitor());
376
* Add contexts to given channels and or events
377
* @param contexts - a list of contexts to add
378
* @param monitor - a progress monitor
379
* @throws ExecutionException
381
public void addContexts(List<String> contexts, IProgressMonitor monitor) throws ExecutionException {
382
getControlService().addContexts(getSessionName(), getName(), null, isKernel(), contexts, monitor);