8ad26cf5cd0d117dc84643f3571af3063dcac9fa
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.control.ui / src / org / eclipse / linuxtools / internal / lttng2 / control / ui / views / model / impl / TraceChannelComponent.java
1 /**********************************************************************
2 * Copyright (c) 2012, 2014 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 * Bernd Hufmann - Updated for support of LTTng Tools 2.1
12 **********************************************************************/
13 package org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import org.eclipse.core.commands.ExecutionException;
19 import org.eclipse.core.runtime.IProgressMonitor;
20 import org.eclipse.linuxtools.internal.lttng2.control.core.model.IChannelInfo;
21 import org.eclipse.linuxtools.internal.lttng2.control.core.model.IEventInfo;
22 import org.eclipse.linuxtools.internal.lttng2.control.core.model.LogLevelType;
23 import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceEnablement;
24 import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceLogLevel;
25 import org.eclipse.linuxtools.internal.lttng2.control.core.model.impl.ChannelInfo;
26 import org.eclipse.linuxtools.internal.lttng2.control.core.model.impl.ProbeEventInfo;
27 import org.eclipse.linuxtools.internal.lttng2.control.ui.Activator;
28 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.messages.Messages;
29 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.ITraceControlComponent;
30 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.property.TraceChannelPropertySource;
31 import org.eclipse.swt.graphics.Image;
32 import org.eclipse.ui.views.properties.IPropertySource;
33
34
35 /**
36 * <p>
37 * Implementation of the trace channel component.
38 * </p>
39 *
40 * @author Bernd Hufmann
41 */
42 public class TraceChannelComponent extends TraceControlComponent {
43
44 // ------------------------------------------------------------------------
45 // Constants
46 // ------------------------------------------------------------------------
47
48 /**
49 * Path to icon file for this component (state enabled).
50 */
51 public static final String TRACE_CHANNEL_ICON_FILE_ENABLED = "icons/obj16/channel.gif"; //$NON-NLS-1$
52 /**
53 * Path to icon file for this component (state disabled).
54 */
55 public static final String TRACE_CHANNEL_ICON_FILE_DISABLED = "icons/obj16/channel_disabled.gif"; //$NON-NLS-1$
56
57 // ------------------------------------------------------------------------
58 // Attributes
59 // ------------------------------------------------------------------------
60
61 /**
62 * The channel information.
63 */
64 private IChannelInfo fChannelInfo = null;
65 /**
66 * The image to be displayed in disabled state.
67 */
68 private Image fDisabledImage = null;
69
70 // ------------------------------------------------------------------------
71 // Constructors
72 // ------------------------------------------------------------------------
73
74 /**
75 * Constructor
76 * @param name - the name of the component.
77 * @param parent - the parent of this component.
78 */
79 public TraceChannelComponent(String name, ITraceControlComponent parent) {
80 super(name, parent);
81 setImage(TRACE_CHANNEL_ICON_FILE_ENABLED);
82 setToolTip(Messages.TraceControl_ChannelDisplayName);
83 fChannelInfo = new ChannelInfo(name);
84 fDisabledImage = Activator.getDefault().loadIcon(TRACE_CHANNEL_ICON_FILE_DISABLED);
85 }
86
87 // ------------------------------------------------------------------------
88 // Accessors
89 // ------------------------------------------------------------------------
90
91 @Override
92 public Image getImage() {
93 if (fChannelInfo.getState() == TraceEnablement.DISABLED) {
94 return fDisabledImage;
95 }
96 return super.getImage();
97 }
98
99 /**
100 * Sets the channel information.
101 *
102 * @param channelInfo
103 * The channel info to assign to this component
104 */
105 public void setChannelInfo(IChannelInfo channelInfo) {
106 fChannelInfo = channelInfo;
107 IEventInfo[] events = fChannelInfo.getEvents();
108 List<ITraceControlComponent> eventComponents = new ArrayList<>();
109 for (int i = 0; i < events.length; i++) {
110 TraceEventComponent event = null;
111 if (events[i].getClass() == ProbeEventInfo.class) {
112 event = new TraceProbeEventComponent(events[i].getName(), this);
113 } else {
114 event = new TraceEventComponent(events[i].getName(), this);
115 }
116
117 eventComponents.add(event);
118 event.setEventInfo(events[i]);
119 }
120 if (!eventComponents.isEmpty()) {
121 setChildren(eventComponents);
122 }
123 }
124
125 /**
126 * @return the overwrite mode value.
127 */
128 public boolean isOverwriteMode() {
129 return fChannelInfo.isOverwriteMode();
130 }
131 /**
132 * Sets the overwrite mode value to the given mode.
133 * @param mode - mode to set.
134 */
135 public void setOverwriteMode(boolean mode){
136 fChannelInfo.setOverwriteMode(mode);
137 }
138 /**
139 * @return the sub-buffer size.
140 */
141 public long getSubBufferSize() {
142 return fChannelInfo.getSubBufferSize();
143 }
144 /**
145 * Sets the sub-buffer size to the given value.
146 * @param bufferSize - size to set to set.
147 */
148 public void setSubBufferSize(long bufferSize) {
149 fChannelInfo.setSubBufferSize(bufferSize);
150 }
151 /**
152 * @return the number of sub-buffers.
153 */
154 public int getNumberOfSubBuffers() {
155 return fChannelInfo.getNumberOfSubBuffers();
156 }
157 /**
158 * Sets the number of sub-buffers to the given value.
159 * @param numberOfSubBuffers - value to set.
160 */
161 public void setNumberOfSubBuffers(int numberOfSubBuffers) {
162 fChannelInfo.setNumberOfSubBuffers(numberOfSubBuffers);
163 }
164 /**
165 * @return the switch timer interval.
166 */
167 public long getSwitchTimer() {
168 return fChannelInfo.getSwitchTimer();
169 }
170 /**
171 * Sets the switch timer interval to the given value.
172 * @param timer - timer value to set.
173 */
174 public void setSwitchTimer(long timer) {
175 fChannelInfo.setSwitchTimer(timer);
176 }
177 /**
178 * @return the read timer interval.
179 */
180 public long getReadTimer() {
181 return fChannelInfo.getReadTimer();
182 }
183 /**
184 * Sets the read timer interval to the given value.
185 * @param timer - timer value to set..
186 */
187 public void setReadTimer(long timer) {
188 fChannelInfo.setReadTimer(timer);
189 }
190 /**
191 * @return the output type.
192 */
193 public String getOutputType() {
194 return fChannelInfo.getOutputType();
195 }
196 /**
197 * Sets the output type to the given value.
198 * @param type - type to set.
199 */
200 public void setOutputType(String type) {
201 fChannelInfo.setOutputType(type);
202 }
203 /**
204 * @return the channel state (enabled or disabled).
205 */
206 public TraceEnablement getState() {
207 return fChannelInfo.getState();
208 }
209 /**
210 * Sets the channel state (enablement) to the given value.
211 * @param state - state to set.
212 */
213 public void setState(TraceEnablement state) {
214 fChannelInfo.setState(state);
215 }
216 /**
217 * Sets the channel state (enablement) to the value specified by the given name.
218 * @param stateName - state to set.
219 */
220 public void setState(String stateName) {
221 fChannelInfo.setState(stateName);
222 }
223
224 @Override
225 public Object getAdapter(Class adapter) {
226 if (adapter == IPropertySource.class) {
227 return new TraceChannelPropertySource(this);
228 }
229 return null;
230 }
231
232 /**
233 * @return session name from parent
234 */
235 public String getSessionName() {
236 return ((TraceDomainComponent)getParent()).getSessionName();
237 }
238
239 /**
240 * @return session from parent
241 */
242 public TraceSessionComponent getSession() {
243 return ((TraceDomainComponent)getParent()).getSession();
244 }
245
246 /**
247 * @return if domain is kernel or UST
248 */
249 public boolean isKernel() {
250 return ((TraceDomainComponent)getParent()).isKernel();
251 }
252
253 /**
254 * @return the parent target node
255 */
256 public TargetNodeComponent getTargetNode() {
257 return ((TraceDomainComponent)getParent()).getTargetNode();
258 }
259
260 // ------------------------------------------------------------------------
261 // Operations
262 // ------------------------------------------------------------------------
263
264 /**
265 * Enables a list of events with no additional parameters.
266 *
267 * @param eventNames
268 * - a list of event names to enabled.
269 * @param monitor
270 * - a progress monitor
271 * @throws ExecutionException
272 * If the command fails
273 */
274 public void enableEvents(List<String> eventNames, IProgressMonitor monitor) throws ExecutionException {
275 enableEvents(eventNames, null, monitor);
276 }
277
278 /**
279 * Enables a list of events with no additional parameters.
280 *
281 * @param eventNames
282 * - a list of event names to enabled.
283 * @param filterExpression
284 * - a filter expression
285 * @param monitor
286 * - a progress monitor
287 * @throws ExecutionException
288 * If the command fails
289 */
290 public void enableEvents(List<String> eventNames, String filterExpression, IProgressMonitor monitor) throws ExecutionException {
291 getControlService().enableEvents(getSessionName(), getName(), eventNames, isKernel(), filterExpression, monitor);
292 }
293
294 /**
295 * Enables all syscalls (for kernel domain)
296 *
297 * @param monitor
298 * - a progress monitor
299 * @throws ExecutionException
300 * If the command fails
301 */
302 public void enableSyscalls(IProgressMonitor monitor) throws ExecutionException {
303 getControlService().enableSyscalls(getSessionName(), getName(), monitor);
304 }
305
306 /**
307 * Enables a dynamic probe (for kernel domain)
308 *
309 * @param eventName
310 * - event name for probe
311 * @param isFunction
312 * - true for dynamic function entry/return probe else false
313 * @param probe
314 * - the actual probe
315 * @param monitor
316 * - a progress monitor
317 * @throws ExecutionException
318 * If the command fails
319 */
320 public void enableProbe(String eventName, boolean isFunction, String probe,
321 IProgressMonitor monitor) throws ExecutionException {
322 getControlService().enableProbe(getSessionName(), getName(), eventName, isFunction, probe, monitor);
323 }
324
325 /**
326 * Enables events using log level.
327 *
328 * @param eventName
329 * - a event name
330 * @param logLevelType
331 * - a log level type
332 * @param level
333 * - a log level
334 * @param filterExpression
335 * - a filter expression
336 * @param monitor
337 * - a progress monitor
338 * @throws ExecutionException
339 * If the command fails
340 */
341 public void enableLogLevel(String eventName, LogLevelType logLevelType,
342 TraceLogLevel level, String filterExpression, IProgressMonitor monitor)
343 throws ExecutionException {
344 getControlService().enableLogLevel(getSessionName(), getName(), eventName, logLevelType, level, filterExpression, monitor);
345 }
346
347 /**
348 * Enables a list of events with no additional parameters.
349 *
350 * @param eventNames
351 * - a list of event names to enabled.
352 * @param monitor
353 * - a progress monitor
354 * @throws ExecutionException
355 * If the command fails
356 */
357 public void disableEvent(List<String> eventNames, IProgressMonitor monitor)
358 throws ExecutionException {
359 getControlService().disableEvent(getParent().getParent().getName(),
360 getName(), eventNames, isKernel(), monitor);
361 }
362
363 /**
364 * Add contexts to given channels and or events
365 *
366 * @param contexts
367 * - a list of contexts to add
368 * @param monitor
369 * - a progress monitor
370 * @throws ExecutionException
371 * If the command fails
372 */
373 public void addContexts(List<String> contexts, IProgressMonitor monitor)
374 throws ExecutionException {
375 getControlService().addContexts(getSessionName(), getName(), null,
376 isKernel(), contexts, monitor);
377 }
378 }
This page took 0.040143 seconds and 4 git commands to generate.