| 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 | **********************************************************************/ |
| 12 | package org.eclipse.linuxtools.lttng.ui.views.control.model.impl; |
| 13 | |
| 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; |
| 19 | import org.eclipse.linuxtools.lttng.ui.LTTngUiPlugin; |
| 20 | import org.eclipse.linuxtools.lttng.ui.views.control.Messages; |
| 21 | import org.eclipse.linuxtools.lttng.ui.views.control.model.IChannelInfo; |
| 22 | import org.eclipse.linuxtools.lttng.ui.views.control.model.IEventInfo; |
| 23 | import org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent; |
| 24 | import org.eclipse.linuxtools.lttng.ui.views.control.model.LogLevelType; |
| 25 | import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceEnablement; |
| 26 | import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceLogLevel; |
| 27 | import org.eclipse.linuxtools.lttng.ui.views.control.property.TraceChannelPropertySource; |
| 28 | import org.eclipse.swt.graphics.Image; |
| 29 | import org.eclipse.ui.views.properties.IPropertySource; |
| 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); |
| 76 | fDisabledImage = LTTngUiPlugin.getDefault().loadIcon(TRACE_CHANNEL_ICON_FILE_DISABLED); |
| 77 | } |
| 78 | |
| 79 | // ------------------------------------------------------------------------ |
| 80 | // Accessors |
| 81 | // ------------------------------------------------------------------------ |
| 82 | /* |
| 83 | * (non-Javadoc) |
| 84 | * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent#getImage() |
| 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++) { |
| 102 | TraceEventComponent event = new TraceEventComponent(events[i].getName(), this); |
| 103 | event.setEventInfo(events[i]); |
| 104 | addChild(event); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * @return the overwrite mode value. |
| 110 | */ |
| 111 | public boolean isOverwriteMode() { |
| 112 | return fChannelInfo.isOverwriteMode(); |
| 113 | } |
| 114 | /** |
| 115 | * Sets the overwrite mode value to the given mode. |
| 116 | * @param mode - mode to set. |
| 117 | */ |
| 118 | public void setOverwriteMode(boolean mode){ |
| 119 | fChannelInfo.setOverwriteMode(mode); |
| 120 | } |
| 121 | /** |
| 122 | * @return the sub-buffer size. |
| 123 | */ |
| 124 | public long getSubBufferSize() { |
| 125 | return fChannelInfo.getSubBufferSize(); |
| 126 | } |
| 127 | /** |
| 128 | * Sets the sub-buffer size to the given value. |
| 129 | * @param bufferSize - size to set to set. |
| 130 | */ |
| 131 | public void setSubBufferSize(long bufferSize) { |
| 132 | fChannelInfo.setSubBufferSize(bufferSize); |
| 133 | } |
| 134 | /** |
| 135 | * @return the number of sub-buffers. |
| 136 | */ |
| 137 | public int getNumberOfSubBuffers() { |
| 138 | return fChannelInfo.getNumberOfSubBuffers(); |
| 139 | } |
| 140 | /** |
| 141 | * Sets the number of sub-buffers to the given value. |
| 142 | * @param numberOfSubBuffers - value to set. |
| 143 | */ |
| 144 | public void setNumberOfSubBuffers(int numberOfSubBuffers) { |
| 145 | fChannelInfo.setNumberOfSubBuffers(numberOfSubBuffers); |
| 146 | } |
| 147 | /** |
| 148 | * @return the switch timer interval. |
| 149 | */ |
| 150 | public long getSwitchTimer() { |
| 151 | return fChannelInfo.getSwitchTimer(); |
| 152 | } |
| 153 | /** |
| 154 | * Sets the switch timer interval to the given value. |
| 155 | * @param timer - timer value to set. |
| 156 | */ |
| 157 | public void setSwitchTimer(long timer) { |
| 158 | fChannelInfo.setSwitchTimer(timer); |
| 159 | } |
| 160 | /** |
| 161 | * @return the read timer interval. |
| 162 | */ |
| 163 | public long getReadTimer() { |
| 164 | return fChannelInfo.getReadTimer(); |
| 165 | } |
| 166 | /** |
| 167 | * Sets the read timer interval to the given value. |
| 168 | * @param timer - timer value to set.. |
| 169 | */ |
| 170 | public void setReadTimer(long timer) { |
| 171 | fChannelInfo.setReadTimer(timer); |
| 172 | } |
| 173 | /** |
| 174 | * @return the output type. |
| 175 | */ |
| 176 | public String getOutputType() { |
| 177 | return fChannelInfo.getOutputType(); |
| 178 | } |
| 179 | /** |
| 180 | * Sets the output type to the given value. |
| 181 | * @param type - type to set. |
| 182 | */ |
| 183 | public void setOutputType(String type) { |
| 184 | fChannelInfo.setOutputType(type); |
| 185 | } |
| 186 | /** |
| 187 | * @return the channel state (enabled or disabled). |
| 188 | */ |
| 189 | public TraceEnablement getState() { |
| 190 | return fChannelInfo.getState(); |
| 191 | } |
| 192 | /** |
| 193 | * Sets the channel state (enablement) to the given value. |
| 194 | * @param state - state to set. |
| 195 | */ |
| 196 | public void setState(TraceEnablement state) { |
| 197 | fChannelInfo.setState(state); |
| 198 | } |
| 199 | /** |
| 200 | * Sets the channel state (enablement) to the value specified by the given name. |
| 201 | * @param stateName - state to set. |
| 202 | */ |
| 203 | public void setState(String stateName) { |
| 204 | fChannelInfo.setState(stateName); |
| 205 | } |
| 206 | /* |
| 207 | * (non-Javadoc) |
| 208 | * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class) |
| 209 | */ |
| 210 | @SuppressWarnings("rawtypes") |
| 211 | @Override |
| 212 | public Object getAdapter(Class adapter) { |
| 213 | if (adapter == IPropertySource.class) { |
| 214 | return new TraceChannelPropertySource(this); |
| 215 | } |
| 216 | return null; |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * @return session name from parent |
| 221 | */ |
| 222 | public String getSessionName() { |
| 223 | return ((TraceDomainComponent)getParent()).getSessionName(); |
| 224 | } |
| 225 | |
| 226 | /** |
| 227 | * @return session from parent |
| 228 | */ |
| 229 | public TraceSessionComponent getSession() { |
| 230 | return ((TraceDomainComponent)getParent()).getSession(); |
| 231 | } |
| 232 | |
| 233 | /** |
| 234 | * @return if domain is kernel or UST |
| 235 | */ |
| 236 | public boolean isKernel() { |
| 237 | return ((TraceDomainComponent)getParent()).isKernel(); |
| 238 | } |
| 239 | |
| 240 | /** |
| 241 | * @return the parent target node |
| 242 | */ |
| 243 | public TargetNodeComponent getTargetNode() { |
| 244 | return ((TraceDomainComponent)getParent()).getTargetNode(); |
| 245 | } |
| 246 | |
| 247 | // ------------------------------------------------------------------------ |
| 248 | // Operations |
| 249 | // ------------------------------------------------------------------------ |
| 250 | /** |
| 251 | * Enables a list of events with no additional parameters. |
| 252 | * @param eventNames - a list of event names to enabled. |
| 253 | * @throws ExecutionException |
| 254 | */ |
| 255 | public void enableEvents(List<String> eventNames) throws ExecutionException { |
| 256 | enableEvents(eventNames, new NullProgressMonitor()); |
| 257 | } |
| 258 | |
| 259 | /** |
| 260 | * Enables a list of events with no additional parameters. |
| 261 | * @param eventNames - a list of event names to enabled. |
| 262 | * @param monitor - a progress monitor |
| 263 | * @throws ExecutionException |
| 264 | */ |
| 265 | public void enableEvents(List<String> eventNames, IProgressMonitor monitor) throws ExecutionException { |
| 266 | getControlService().enableEvents(getSessionName(), getName(), eventNames, isKernel(), monitor); |
| 267 | } |
| 268 | |
| 269 | /** |
| 270 | * Enables all syscalls (for kernel domain) |
| 271 | * @throws ExecutionException |
| 272 | */ |
| 273 | public void enableSyscalls() throws ExecutionException { |
| 274 | enableSyscalls(new NullProgressMonitor()); |
| 275 | } |
| 276 | |
| 277 | /** |
| 278 | * Enables all syscalls (for kernel domain) |
| 279 | * @param monitor - a progress monitor |
| 280 | * @throws ExecutionException |
| 281 | */ |
| 282 | public void enableSyscalls(IProgressMonitor monitor) throws ExecutionException { |
| 283 | getControlService().enableSyscalls(getSessionName(), getName(), monitor); |
| 284 | } |
| 285 | |
| 286 | /** |
| 287 | * Enables a dynamic probe (for kernel domain) |
| 288 | * @param eventName - event name for probe |
| 289 | * @param probe - the actual probe |
| 290 | * @throws ExecutionException |
| 291 | */ |
| 292 | public void enableProbe(String eventName, String probe) throws ExecutionException { |
| 293 | enableProbe(eventName, probe, new NullProgressMonitor()); |
| 294 | } |
| 295 | |
| 296 | /** |
| 297 | * Enables a dynamic probe (for kernel domain) |
| 298 | * @param eventName - event name for probe |
| 299 | * @param probe - the actual probe |
| 300 | * @param monitor - a progress monitor |
| 301 | * @throws ExecutionException |
| 302 | */ |
| 303 | public void enableProbe(String eventName, String probe, IProgressMonitor monitor) throws ExecutionException { |
| 304 | getControlService().enableProbe(getSessionName(), getName(), eventName, probe, monitor); |
| 305 | } |
| 306 | |
| 307 | /** |
| 308 | * Enables a dynamic function entry/return probe (for kernel domain) |
| 309 | * @param eventName - event name for probe |
| 310 | * @param probe - the actual probe |
| 311 | * @throws ExecutionException |
| 312 | */ |
| 313 | public void enableFunctionProbe(String eventName, String probe) throws ExecutionException { |
| 314 | enableFunctionProbe(eventName, probe, new NullProgressMonitor()); |
| 315 | } |
| 316 | |
| 317 | /** |
| 318 | * Enables a dynamic function entry/return probe (for kernel domain) |
| 319 | * @param eventName - event name for probe |
| 320 | * @param probe - the actual probe |
| 321 | * @param monitor - a progress monitor |
| 322 | * @throws ExecutionException |
| 323 | */ |
| 324 | public void enableFunctionProbe(String eventName, String probe, IProgressMonitor monitor) throws ExecutionException { |
| 325 | getControlService().enableFunctionProbe(getSessionName(), getName(), eventName, probe, monitor); |
| 326 | } |
| 327 | |
| 328 | /** |
| 329 | * Enables events using log level. |
| 330 | * @param eventName - a event name |
| 331 | * @param logLevelType - a log level type |
| 332 | * @param level - a log level |
| 333 | * @throws ExecutionException |
| 334 | */ |
| 335 | public void enableLogLevel(String eventName, LogLevelType logLevelType, TraceLogLevel level) throws ExecutionException { |
| 336 | enableLogLevel(eventName, logLevelType, level, new NullProgressMonitor()); |
| 337 | } |
| 338 | |
| 339 | /** |
| 340 | * Enables events using log level. |
| 341 | * @param eventName - a event name |
| 342 | * @param logLevelType - a log level type |
| 343 | * @param level - a log level |
| 344 | * @param monitor - a progress monitor |
| 345 | * @throws ExecutionException |
| 346 | */ |
| 347 | public void enableLogLevel(String eventName, LogLevelType logLevelType, TraceLogLevel level, IProgressMonitor monitor) throws ExecutionException { |
| 348 | getControlService().enableLogLevel(getSessionName(), getName(), eventName, logLevelType, level, monitor); |
| 349 | } |
| 350 | |
| 351 | /** |
| 352 | * Enables a list of events with no additional parameters. |
| 353 | * @param eventNames - a list of event names to enabled. |
| 354 | * @throws ExecutionException |
| 355 | */ |
| 356 | public void disableEvent(List<String> eventNames) throws ExecutionException { |
| 357 | disableEvent(eventNames, new NullProgressMonitor()); |
| 358 | } |
| 359 | |
| 360 | /** |
| 361 | * Enables a list of events with no additional parameters. |
| 362 | * @param eventNames - a list of event names to enabled. |
| 363 | * @param monitor - a progress monitor |
| 364 | * @throws ExecutionException |
| 365 | */ |
| 366 | public void disableEvent(List<String> eventNames, IProgressMonitor monitor) throws ExecutionException { |
| 367 | getControlService().disableEvent(getParent().getParent().getName(), getName(), eventNames, isKernel(), monitor); |
| 368 | } |
| 369 | } |