Commit | Line | Data |
---|---|---|
eb1bab5b | 1 | /********************************************************************** |
ba3a9bd2 | 2 | * Copyright (c) 2012, 2013 Ericsson |
cfdb727a | 3 | * |
eb1bab5b BH |
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 | |
cfdb727a AM |
8 | * |
9 | * Contributors: | |
eb1bab5b | 10 | * Bernd Hufmann - Initial API and implementation |
ba3a9bd2 | 11 | * Bernd Hufmann - Updated for support of LTTng Tools 2.1 |
eb1bab5b | 12 | **********************************************************************/ |
115b4a01 | 13 | package org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl; |
eb1bab5b | 14 | |
b957fb8c | 15 | import java.util.ArrayList; |
6503ae0f BH |
16 | import java.util.List; |
17 | ||
18 | import org.eclipse.core.commands.ExecutionException; | |
19 | import org.eclipse.core.runtime.IProgressMonitor; | |
9315aeee BH |
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; | |
115b4a01 | 27 | import org.eclipse.linuxtools.internal.lttng2.ui.Activator; |
9315aeee | 28 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.messages.Messages; |
115b4a01 | 29 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent; |
115b4a01 | 30 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.property.TraceChannelPropertySource; |
eb1bab5b | 31 | import org.eclipse.swt.graphics.Image; |
06b9339e | 32 | import org.eclipse.ui.views.properties.IPropertySource; |
eb1bab5b BH |
33 | |
34 | ||
35 | /** | |
eb1bab5b BH |
36 | * <p> |
37 | * Implementation of the trace channel component. | |
38 | * </p> | |
cfdb727a | 39 | * |
dbd4432d | 40 | * @author Bernd Hufmann |
eb1bab5b BH |
41 | */ |
42 | public class TraceChannelComponent extends TraceControlComponent { | |
43 | // ------------------------------------------------------------------------ | |
44 | // Constants | |
45 | // ------------------------------------------------------------------------ | |
46 | /** | |
47 | * Path to icon file for this component (state enabled). | |
48 | */ | |
49 | public static final String TRACE_CHANNEL_ICON_FILE_ENABLED = "icons/obj16/channel.gif"; //$NON-NLS-1$ | |
50 | /** | |
51 | * Path to icon file for this component (state disabled). | |
52 | */ | |
53 | public static final String TRACE_CHANNEL_ICON_FILE_DISABLED = "icons/obj16/channel_disabled.gif"; //$NON-NLS-1$ | |
cfdb727a | 54 | |
eb1bab5b BH |
55 | // ------------------------------------------------------------------------ |
56 | // Attributes | |
57 | // ------------------------------------------------------------------------ | |
58 | /** | |
59 | * The channel information. | |
60 | */ | |
61 | private IChannelInfo fChannelInfo = null; | |
62 | /** | |
63 | * The image to be displayed in disabled state. | |
64 | */ | |
65 | private Image fDisabledImage = null; | |
cfdb727a | 66 | |
eb1bab5b BH |
67 | // ------------------------------------------------------------------------ |
68 | // Constructors | |
69 | // ------------------------------------------------------------------------ | |
70 | /** | |
cfdb727a | 71 | * Constructor |
eb1bab5b BH |
72 | * @param name - the name of the component. |
73 | * @param parent - the parent of this component. | |
74 | */ | |
75 | public TraceChannelComponent(String name, ITraceControlComponent parent) { | |
76 | super(name, parent); | |
77 | setImage(TRACE_CHANNEL_ICON_FILE_ENABLED); | |
78 | setToolTip(Messages.TraceControl_ChannelDisplayName); | |
79 | fChannelInfo = new ChannelInfo(name); | |
31a6a4e4 | 80 | fDisabledImage = Activator.getDefault().loadIcon(TRACE_CHANNEL_ICON_FILE_DISABLED); |
eb1bab5b | 81 | } |
cfdb727a | 82 | |
eb1bab5b BH |
83 | // ------------------------------------------------------------------------ |
84 | // Accessors | |
85 | // ------------------------------------------------------------------------ | |
86 | /* | |
87 | * (non-Javadoc) | |
115b4a01 | 88 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getImage() |
eb1bab5b BH |
89 | */ |
90 | @Override | |
91 | public Image getImage() { | |
92 | if (fChannelInfo.getState() == TraceEnablement.DISABLED) { | |
93 | return fDisabledImage; | |
94 | } | |
95 | return super.getImage(); | |
96 | } | |
97 | ||
98 | /** | |
99 | * Sets the channel information. | |
cfdb727a | 100 | * |
eb1bab5b | 101 | * @param channelInfo |
cfdb727a | 102 | * The channel info to assign to this component |
eb1bab5b BH |
103 | */ |
104 | public void setChannelInfo(IChannelInfo channelInfo) { | |
105 | fChannelInfo = channelInfo; | |
106 | IEventInfo[] events = fChannelInfo.getEvents(); | |
b957fb8c | 107 | List<ITraceControlComponent> eventComponents = new ArrayList<ITraceControlComponent>(); |
eb1bab5b | 108 | for (int i = 0; i < events.length; i++) { |
d132bcc7 BH |
109 | TraceEventComponent event = null; |
110 | if (events[i].getClass() == ProbeEventInfo.class) { | |
111 | event = new TraceProbeEventComponent(events[i].getName(), this); | |
112 | } else { | |
113 | event = new TraceEventComponent(events[i].getName(), this); | |
114 | } | |
115 | ||
b957fb8c | 116 | eventComponents.add(event); |
eb1bab5b | 117 | event.setEventInfo(events[i]); |
b957fb8c BH |
118 | // addChild(event); |
119 | } | |
120 | if (!eventComponents.isEmpty()) { | |
121 | setChildren(eventComponents); | |
eb1bab5b BH |
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() { | |
cfdb727a | 181 | return fChannelInfo.getReadTimer(); |
eb1bab5b BH |
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 | } | |
06b9339e BH |
223 | /* |
224 | * (non-Javadoc) | |
115b4a01 | 225 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class) |
06b9339e | 226 | */ |
06b9339e BH |
227 | @Override |
228 | public Object getAdapter(Class adapter) { | |
229 | if (adapter == IPropertySource.class) { | |
230 | return new TraceChannelPropertySource(this); | |
231 | } | |
232 | return null; | |
cfdb727a | 233 | } |
bbb3538a BH |
234 | |
235 | /** | |
236 | * @return session name from parent | |
237 | */ | |
238 | public String getSessionName() { | |
cfdb727a | 239 | return ((TraceDomainComponent)getParent()).getSessionName(); |
bbb3538a BH |
240 | } |
241 | ||
6503ae0f BH |
242 | /** |
243 | * @return session from parent | |
244 | */ | |
245 | public TraceSessionComponent getSession() { | |
cfdb727a | 246 | return ((TraceDomainComponent)getParent()).getSession(); |
6503ae0f BH |
247 | } |
248 | ||
bbb3538a BH |
249 | /** |
250 | * @return if domain is kernel or UST | |
251 | */ | |
252 | public boolean isKernel() { | |
253 | return ((TraceDomainComponent)getParent()).isKernel(); | |
254 | } | |
cfdb727a | 255 | |
498704b3 BH |
256 | /** |
257 | * @return the parent target node | |
258 | */ | |
259 | public TargetNodeComponent getTargetNode() { | |
260 | return ((TraceDomainComponent)getParent()).getTargetNode(); | |
261 | } | |
cfdb727a | 262 | |
eb1bab5b BH |
263 | // ------------------------------------------------------------------------ |
264 | // Operations | |
265 | // ------------------------------------------------------------------------ | |
6503ae0f BH |
266 | |
267 | /** | |
268 | * Enables a list of events with no additional parameters. | |
cfdb727a AM |
269 | * |
270 | * @param eventNames | |
271 | * - a list of event names to enabled. | |
272 | * @param monitor | |
273 | * - a progress monitor | |
6503ae0f | 274 | * @throws ExecutionException |
cfdb727a | 275 | * If the command fails |
6503ae0f | 276 | */ |
498704b3 | 277 | public void enableEvents(List<String> eventNames, IProgressMonitor monitor) throws ExecutionException { |
d4514365 BH |
278 | enableEvents(eventNames, null, monitor); |
279 | } | |
280 | ||
281 | /** | |
282 | * Enables a list of events with no additional parameters. | |
283 | * | |
284 | * @param eventNames | |
285 | * - a list of event names to enabled. | |
286 | * @param filterExpression | |
287 | * - a filter expression | |
288 | * @param monitor | |
289 | * - a progress monitor | |
290 | * @throws ExecutionException | |
291 | * If the command fails | |
292 | */ | |
293 | public void enableEvents(List<String> eventNames, String filterExpression, IProgressMonitor monitor) throws ExecutionException { | |
294 | getControlService().enableEvents(getSessionName(), getName(), eventNames, isKernel(), filterExpression, monitor); | |
498704b3 | 295 | } |
cfdb727a | 296 | |
498704b3 BH |
297 | /** |
298 | * Enables all syscalls (for kernel domain) | |
cfdb727a AM |
299 | * |
300 | * @param monitor | |
301 | * - a progress monitor | |
498704b3 | 302 | * @throws ExecutionException |
cfdb727a | 303 | * If the command fails |
498704b3 BH |
304 | */ |
305 | public void enableSyscalls(IProgressMonitor monitor) throws ExecutionException { | |
306 | getControlService().enableSyscalls(getSessionName(), getName(), monitor); | |
307 | } | |
308 | ||
498704b3 BH |
309 | /** |
310 | * Enables a dynamic probe (for kernel domain) | |
cfdb727a AM |
311 | * |
312 | * @param eventName | |
313 | * - event name for probe | |
314 | * @param isFunction | |
315 | * - true for dynamic function entry/return probe else false | |
316 | * @param probe | |
317 | * - the actual probe | |
318 | * @param monitor | |
319 | * - a progress monitor | |
498704b3 | 320 | * @throws ExecutionException |
cfdb727a | 321 | * If the command fails |
498704b3 | 322 | */ |
cfdb727a AM |
323 | public void enableProbe(String eventName, boolean isFunction, String probe, |
324 | IProgressMonitor monitor) throws ExecutionException { | |
d132bcc7 | 325 | getControlService().enableProbe(getSessionName(), getName(), eventName, isFunction, probe, monitor); |
498704b3 BH |
326 | } |
327 | ||
ccc66d01 BH |
328 | /** |
329 | * Enables events using log level. | |
cfdb727a AM |
330 | * |
331 | * @param eventName | |
332 | * - a event name | |
333 | * @param logLevelType | |
334 | * - a log level type | |
335 | * @param level | |
336 | * - a log level | |
d4514365 BH |
337 | * @param filterExpression |
338 | * - a filter expression | |
cfdb727a AM |
339 | * @param monitor |
340 | * - a progress monitor | |
ccc66d01 | 341 | * @throws ExecutionException |
cfdb727a | 342 | * If the command fails |
ccc66d01 | 343 | */ |
cfdb727a | 344 | public void enableLogLevel(String eventName, LogLevelType logLevelType, |
d4514365 | 345 | TraceLogLevel level, String filterExpression, IProgressMonitor monitor) |
cfdb727a | 346 | throws ExecutionException { |
d4514365 | 347 | getControlService().enableLogLevel(getSessionName(), getName(), eventName, logLevelType, level, filterExpression, monitor); |
ccc66d01 BH |
348 | } |
349 | ||
6503ae0f BH |
350 | /** |
351 | * Enables a list of events with no additional parameters. | |
cfdb727a AM |
352 | * |
353 | * @param eventNames | |
354 | * - a list of event names to enabled. | |
355 | * @param monitor | |
356 | * - a progress monitor | |
6503ae0f | 357 | * @throws ExecutionException |
cfdb727a | 358 | * If the command fails |
6503ae0f | 359 | */ |
cfdb727a AM |
360 | public void disableEvent(List<String> eventNames, IProgressMonitor monitor) |
361 | throws ExecutionException { | |
362 | getControlService().disableEvent(getParent().getParent().getName(), | |
363 | getName(), eventNames, isKernel(), monitor); | |
6503ae0f | 364 | } |
cfdb727a | 365 | |
b793fbe1 BH |
366 | /** |
367 | * Add contexts to given channels and or events | |
cfdb727a AM |
368 | * |
369 | * @param contexts | |
370 | * - a list of contexts to add | |
371 | * @param monitor | |
372 | * - a progress monitor | |
b793fbe1 | 373 | * @throws ExecutionException |
cfdb727a | 374 | * If the command fails |
b793fbe1 | 375 | */ |
cfdb727a AM |
376 | public void addContexts(List<String> contexts, IProgressMonitor monitor) |
377 | throws ExecutionException { | |
378 | getControlService().addContexts(getSessionName(), getName(), null, | |
379 | isKernel(), contexts, monitor); | |
b793fbe1 | 380 | } |
eb1bab5b | 381 | } |