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