Update file headers in LTTng Control feature
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / model / impl / TraceChannelComponent.java
1 /**********************************************************************
2 * Copyright (c) 2012, 2013 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.ui.views.control.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.core.runtime.NullProgressMonitor;
21 import org.eclipse.linuxtools.internal.lttng2.core.control.model.IChannelInfo;
22 import org.eclipse.linuxtools.internal.lttng2.core.control.model.IEventInfo;
23 import org.eclipse.linuxtools.internal.lttng2.core.control.model.LogLevelType;
24 import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEnablement;
25 import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceLogLevel;
26 import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.ChannelInfo;
27 import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.ProbeEventInfo;
28 import org.eclipse.linuxtools.internal.lttng2.ui.Activator;
29 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.messages.Messages;
30 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent;
31 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.property.TraceChannelPropertySource;
32 import org.eclipse.swt.graphics.Image;
33 import org.eclipse.ui.views.properties.IPropertySource;
34
35
36 /**
37 * <p>
38 * Implementation of the trace channel component.
39 * </p>
40 *
41 * @author Bernd Hufmann
42 */
43 public class TraceChannelComponent extends TraceControlComponent {
44 // ------------------------------------------------------------------------
45 // Constants
46 // ------------------------------------------------------------------------
47 /**
48 * Path to icon file for this component (state enabled).
49 */
50 public static final String TRACE_CHANNEL_ICON_FILE_ENABLED = "icons/obj16/channel.gif"; //$NON-NLS-1$
51 /**
52 * Path to icon file for this component (state disabled).
53 */
54 public static final String TRACE_CHANNEL_ICON_FILE_DISABLED = "icons/obj16/channel_disabled.gif"; //$NON-NLS-1$
55
56 // ------------------------------------------------------------------------
57 // Attributes
58 // ------------------------------------------------------------------------
59 /**
60 * The channel information.
61 */
62 private IChannelInfo fChannelInfo = null;
63 /**
64 * The image to be displayed in disabled state.
65 */
66 private Image fDisabledImage = null;
67
68 // ------------------------------------------------------------------------
69 // Constructors
70 // ------------------------------------------------------------------------
71 /**
72 * Constructor
73 * @param name - the name of the component.
74 * @param parent - the parent of this component.
75 */
76 public TraceChannelComponent(String name, ITraceControlComponent parent) {
77 super(name, parent);
78 setImage(TRACE_CHANNEL_ICON_FILE_ENABLED);
79 setToolTip(Messages.TraceControl_ChannelDisplayName);
80 fChannelInfo = new ChannelInfo(name);
81 fDisabledImage = Activator.getDefault().loadIcon(TRACE_CHANNEL_ICON_FILE_DISABLED);
82 }
83
84 // ------------------------------------------------------------------------
85 // Accessors
86 // ------------------------------------------------------------------------
87 /*
88 * (non-Javadoc)
89 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getImage()
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<ITraceControlComponent>();
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 // addChild(event);
120 }
121 if (!eventComponents.isEmpty()) {
122 setChildren(eventComponents);
123 }
124 }
125
126 /**
127 * @return the overwrite mode value.
128 */
129 public boolean isOverwriteMode() {
130 return fChannelInfo.isOverwriteMode();
131 }
132 /**
133 * Sets the overwrite mode value to the given mode.
134 * @param mode - mode to set.
135 */
136 public void setOverwriteMode(boolean mode){
137 fChannelInfo.setOverwriteMode(mode);
138 }
139 /**
140 * @return the sub-buffer size.
141 */
142 public long getSubBufferSize() {
143 return fChannelInfo.getSubBufferSize();
144 }
145 /**
146 * Sets the sub-buffer size to the given value.
147 * @param bufferSize - size to set to set.
148 */
149 public void setSubBufferSize(long bufferSize) {
150 fChannelInfo.setSubBufferSize(bufferSize);
151 }
152 /**
153 * @return the number of sub-buffers.
154 */
155 public int getNumberOfSubBuffers() {
156 return fChannelInfo.getNumberOfSubBuffers();
157 }
158 /**
159 * Sets the number of sub-buffers to the given value.
160 * @param numberOfSubBuffers - value to set.
161 */
162 public void setNumberOfSubBuffers(int numberOfSubBuffers) {
163 fChannelInfo.setNumberOfSubBuffers(numberOfSubBuffers);
164 }
165 /**
166 * @return the switch timer interval.
167 */
168 public long getSwitchTimer() {
169 return fChannelInfo.getSwitchTimer();
170 }
171 /**
172 * Sets the switch timer interval to the given value.
173 * @param timer - timer value to set.
174 */
175 public void setSwitchTimer(long timer) {
176 fChannelInfo.setSwitchTimer(timer);
177 }
178 /**
179 * @return the read timer interval.
180 */
181 public long getReadTimer() {
182 return fChannelInfo.getReadTimer();
183 }
184 /**
185 * Sets the read timer interval to the given value.
186 * @param timer - timer value to set..
187 */
188 public void setReadTimer(long timer) {
189 fChannelInfo.setReadTimer(timer);
190 }
191 /**
192 * @return the output type.
193 */
194 public String getOutputType() {
195 return fChannelInfo.getOutputType();
196 }
197 /**
198 * Sets the output type to the given value.
199 * @param type - type to set.
200 */
201 public void setOutputType(String type) {
202 fChannelInfo.setOutputType(type);
203 }
204 /**
205 * @return the channel state (enabled or disabled).
206 */
207 public TraceEnablement getState() {
208 return fChannelInfo.getState();
209 }
210 /**
211 * Sets the channel state (enablement) to the given value.
212 * @param state - state to set.
213 */
214 public void setState(TraceEnablement state) {
215 fChannelInfo.setState(state);
216 }
217 /**
218 * Sets the channel state (enablement) to the value specified by the given name.
219 * @param stateName - state to set.
220 */
221 public void setState(String stateName) {
222 fChannelInfo.setState(stateName);
223 }
224 /*
225 * (non-Javadoc)
226 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class)
227 */
228 @Override
229 public Object getAdapter(Class adapter) {
230 if (adapter == IPropertySource.class) {
231 return new TraceChannelPropertySource(this);
232 }
233 return null;
234 }
235
236 /**
237 * @return session name from parent
238 */
239 public String getSessionName() {
240 return ((TraceDomainComponent)getParent()).getSessionName();
241 }
242
243 /**
244 * @return session from parent
245 */
246 public TraceSessionComponent getSession() {
247 return ((TraceDomainComponent)getParent()).getSession();
248 }
249
250 /**
251 * @return if domain is kernel or UST
252 */
253 public boolean isKernel() {
254 return ((TraceDomainComponent)getParent()).isKernel();
255 }
256
257 /**
258 * @return the parent target node
259 */
260 public TargetNodeComponent getTargetNode() {
261 return ((TraceDomainComponent)getParent()).getTargetNode();
262 }
263
264 // ------------------------------------------------------------------------
265 // Operations
266 // ------------------------------------------------------------------------
267 /**
268 * Enables a list of events with no additional parameters.
269 *
270 * @param eventNames
271 * - a list of event names to enabled.
272 * @throws ExecutionException
273 * If the command fails
274 */
275 public void enableEvents(List<String> eventNames) throws ExecutionException {
276 enableEvents(eventNames, new NullProgressMonitor());
277 }
278
279 /**
280 * Enables a list of events with no additional parameters.
281 *
282 * @param eventNames
283 * - a list of event names to enabled.
284 * @param monitor
285 * - a progress monitor
286 * @throws ExecutionException
287 * If the command fails
288 */
289 public void enableEvents(List<String> eventNames, IProgressMonitor monitor) throws ExecutionException {
290 enableEvents(eventNames, null, monitor);
291 }
292
293 /**
294 * Enables a list of events with no additional parameters.
295 *
296 * @param eventNames
297 * - a list of event names to enabled.
298 * @param filterExpression
299 * - a filter expression
300 * @param monitor
301 * - a progress monitor
302 * @throws ExecutionException
303 * If the command fails
304 */
305 public void enableEvents(List<String> eventNames, String filterExpression, IProgressMonitor monitor) throws ExecutionException {
306 getControlService().enableEvents(getSessionName(), getName(), eventNames, isKernel(), filterExpression, monitor);
307 }
308
309 /**
310 * Enables all syscalls (for kernel domain)
311 *
312 * @throws ExecutionException
313 * If the command fails
314 */
315 public void enableSyscalls() throws ExecutionException {
316 enableSyscalls(new NullProgressMonitor());
317 }
318
319 /**
320 * Enables all syscalls (for kernel domain)
321 *
322 * @param monitor
323 * - a progress monitor
324 * @throws ExecutionException
325 * If the command fails
326 */
327 public void enableSyscalls(IProgressMonitor monitor) throws ExecutionException {
328 getControlService().enableSyscalls(getSessionName(), getName(), monitor);
329 }
330
331 /**
332 * Enables a dynamic probe (for kernel domain)
333 *
334 * @param eventName
335 * - event name for probe
336 * @param isFunction
337 * - true for dynamic function entry/return probe else false
338 * @param probe
339 * - the actual probe
340 * @throws ExecutionException
341 * If the command fails
342 */
343 public void enableProbe(String eventName, boolean isFunction, String probe)
344 throws ExecutionException {
345 enableProbe(eventName, isFunction, probe, new NullProgressMonitor());
346 }
347
348 /**
349 * Enables a dynamic probe (for kernel domain)
350 *
351 * @param eventName
352 * - event name for probe
353 * @param isFunction
354 * - true for dynamic function entry/return probe else false
355 * @param probe
356 * - the actual probe
357 * @param monitor
358 * - a progress monitor
359 * @throws ExecutionException
360 * If the command fails
361 */
362 public void enableProbe(String eventName, boolean isFunction, String probe,
363 IProgressMonitor monitor) throws ExecutionException {
364 getControlService().enableProbe(getSessionName(), getName(), eventName, isFunction, probe, monitor);
365 }
366
367 /**
368 * Enables events using log level.
369 *
370 * @param eventName
371 * - a event name
372 * @param logLevelType
373 * - a log level type
374 * @param level
375 * - a log level
376 * @param filterExpression
377 * - a filter expression
378 * @throws ExecutionException
379 * If the command fails
380 */
381 public void enableLogLevel(String eventName, LogLevelType logLevelType,
382 TraceLogLevel level, String filterExpression) throws ExecutionException {
383 enableLogLevel(eventName, logLevelType, level, filterExpression, new NullProgressMonitor());
384 }
385
386 /**
387 * Enables events using log level.
388 *
389 * @param eventName
390 * - a event name
391 * @param logLevelType
392 * - a log level type
393 * @param level
394 * - a log level
395 * @param filterExpression
396 * - a filter expression
397 * @param monitor
398 * - a progress monitor
399 * @throws ExecutionException
400 * If the command fails
401 */
402 public void enableLogLevel(String eventName, LogLevelType logLevelType,
403 TraceLogLevel level, String filterExpression, IProgressMonitor monitor)
404 throws ExecutionException {
405 getControlService().enableLogLevel(getSessionName(), getName(), eventName, logLevelType, level, filterExpression, monitor);
406 }
407
408 /**
409 * Enables a list of events with no additional parameters.
410 *
411 * @param eventNames
412 * - a list of event names to enabled.
413 * @throws ExecutionException
414 * If the command fails
415 */
416 public void disableEvent(List<String> eventNames) throws ExecutionException {
417 disableEvent(eventNames, new NullProgressMonitor());
418 }
419
420 /**
421 * Enables a list of events with no additional parameters.
422 *
423 * @param eventNames
424 * - a list of event names to enabled.
425 * @param monitor
426 * - a progress monitor
427 * @throws ExecutionException
428 * If the command fails
429 */
430 public void disableEvent(List<String> eventNames, IProgressMonitor monitor)
431 throws ExecutionException {
432 getControlService().disableEvent(getParent().getParent().getName(),
433 getName(), eventNames, isKernel(), monitor);
434 }
435
436 /**
437 * Add contexts to given channels and or events
438 *
439 * @param contexts
440 * - a list of contexts to add
441 * @throws ExecutionException
442 * If the command fails
443 */
444 public void addContexts(List<String> contexts) throws ExecutionException {
445 addContexts(contexts, new NullProgressMonitor());
446 }
447
448 /**
449 * Add contexts to given channels and or events
450 *
451 * @param contexts
452 * - a list of contexts to add
453 * @param monitor
454 * - a progress monitor
455 * @throws ExecutionException
456 * If the command fails
457 */
458 public void addContexts(List<String> contexts, IProgressMonitor monitor)
459 throws ExecutionException {
460 getControlService().addContexts(getSessionName(), getName(), null,
461 isKernel(), contexts, monitor);
462 }
463 }
This page took 0.041497 seconds and 5 git commands to generate.