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