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