| 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.internal.lttng2.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.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.IDomainInfo; |
| 23 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ISessionInfo; |
| 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.TraceLogLevel; |
| 27 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceSessionState; |
| 28 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.property.TraceSessionPropertySource; |
| 29 | import org.eclipse.swt.graphics.Image; |
| 30 | import org.eclipse.ui.views.properties.IPropertySource; |
| 31 | |
| 32 | /** |
| 33 | * <b><u>TraceSessionComponent</u></b> |
| 34 | * <p> |
| 35 | * Implementation of the trace session component. |
| 36 | * </p> |
| 37 | */ |
| 38 | public class TraceSessionComponent extends TraceControlComponent { |
| 39 | |
| 40 | // ------------------------------------------------------------------------ |
| 41 | // Constants |
| 42 | // ------------------------------------------------------------------------ |
| 43 | /** |
| 44 | * Path to icon file for this component (inactive state). |
| 45 | */ |
| 46 | public static final String TRACE_SESSION_ICON_FILE_INACTIVE = "icons/obj16/session_inactive.gif"; //$NON-NLS-1$ |
| 47 | /** |
| 48 | * Path to icon file for this component (active state). |
| 49 | */ |
| 50 | public static final String TRACE_SESSION_ICON_FILE_ACTIVE = "icons/obj16/session_active.gif"; //$NON-NLS-1$ |
| 51 | /** |
| 52 | * Path to icon file for this component (destroyed state). |
| 53 | */ |
| 54 | public static final String TRACE_SESSION_ICON_FILE_DESTROYED = "icons/obj16/session_destroyed.gif"; //$NON-NLS-1$ |
| 55 | |
| 56 | // ------------------------------------------------------------------------ |
| 57 | // Attributes |
| 58 | // ------------------------------------------------------------------------ |
| 59 | /** |
| 60 | * The session information. |
| 61 | */ |
| 62 | private ISessionInfo fSessionInfo = null; |
| 63 | /** |
| 64 | * A flag to indicate if session has been destroyed. |
| 65 | */ |
| 66 | private boolean fIsDestroyed = false; |
| 67 | /** |
| 68 | * The image to be displayed in state active. |
| 69 | */ |
| 70 | private Image fActiveImage = null; |
| 71 | /** |
| 72 | * The image to be displayed in state destroyed |
| 73 | */ |
| 74 | private Image fDestroyedImage = null; |
| 75 | |
| 76 | // ------------------------------------------------------------------------ |
| 77 | // Constructors |
| 78 | // ------------------------------------------------------------------------ |
| 79 | /** |
| 80 | * Constructor |
| 81 | * @param name - the name of the component. |
| 82 | * @param parent - the parent of this component. |
| 83 | */ |
| 84 | public TraceSessionComponent(String name, ITraceControlComponent parent) { |
| 85 | super(name, parent); |
| 86 | setImage(TRACE_SESSION_ICON_FILE_INACTIVE); |
| 87 | setToolTip(Messages.TraceControl_SessionDisplayName); |
| 88 | fSessionInfo = new SessionInfo(name); |
| 89 | fActiveImage = Activator.getDefault().loadIcon(TRACE_SESSION_ICON_FILE_ACTIVE); |
| 90 | fDestroyedImage = Activator.getDefault().loadIcon(TRACE_SESSION_ICON_FILE_DESTROYED); |
| 91 | } |
| 92 | |
| 93 | // ------------------------------------------------------------------------ |
| 94 | // Accessors |
| 95 | // ------------------------------------------------------------------------ |
| 96 | /* |
| 97 | * (non-Javadoc) |
| 98 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getImage() |
| 99 | */ |
| 100 | @Override |
| 101 | public Image getImage() { |
| 102 | if (fIsDestroyed) { |
| 103 | return fDestroyedImage; |
| 104 | } |
| 105 | |
| 106 | if (fSessionInfo.getSessionState() == TraceSessionState.INACTIVE) { |
| 107 | return super.getImage(); |
| 108 | } |
| 109 | |
| 110 | return fActiveImage; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * @return the whether the session is destroyed or not. |
| 115 | */ |
| 116 | public boolean isDestroyed() { |
| 117 | return fIsDestroyed; |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Sets the session destroyed state to the given value. |
| 122 | * @param destroyed - value to set. |
| 123 | */ |
| 124 | public void setDestroyed(boolean destroyed) { |
| 125 | fIsDestroyed = destroyed; |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * @return the session state state (active or inactive). |
| 130 | */ |
| 131 | public TraceSessionState getSessionState() { |
| 132 | return fSessionInfo.getSessionState(); |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Sets the session state to the given value. |
| 137 | * @param state - state to set. |
| 138 | */ |
| 139 | public void setSessionState(TraceSessionState state) { |
| 140 | fSessionInfo.setSessionState(state); |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * Sets the event state to the value specified by the given name. |
| 145 | * @param stateName - state to set. |
| 146 | */ |
| 147 | public void setSessionState(String stateName) { |
| 148 | fSessionInfo.setSessionState(stateName); |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * @return path string where session is located. |
| 153 | */ |
| 154 | public String getSessionPath() { |
| 155 | return fSessionInfo.getSessionPath(); |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Sets the path string (where session is located) to the given value. |
| 160 | * @param path - session path to set. |
| 161 | */ |
| 162 | public void setSessionPath(String sessionPath) { |
| 163 | fSessionInfo.setSessionPath(sessionPath); |
| 164 | } |
| 165 | |
| 166 | /* |
| 167 | * (non-Javadoc) |
| 168 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class) |
| 169 | */ |
| 170 | @SuppressWarnings("rawtypes") |
| 171 | @Override |
| 172 | public Object getAdapter(Class adapter) { |
| 173 | if (adapter == IPropertySource.class) { |
| 174 | return new TraceSessionPropertySource(this); |
| 175 | } |
| 176 | return null; |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * @return all available domains of this session. |
| 181 | */ |
| 182 | public TraceDomainComponent[] getDomains() { |
| 183 | List<ITraceControlComponent> sessions = getChildren(TraceDomainComponent.class); |
| 184 | return (TraceDomainComponent[])sessions.toArray(new TraceDomainComponent[sessions.size()]); |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * @return the parent target node |
| 189 | */ |
| 190 | public TargetNodeComponent getTargetNode() { |
| 191 | return ((TraceSessionGroup)getParent()).getTargetNode(); |
| 192 | } |
| 193 | |
| 194 | // ------------------------------------------------------------------------ |
| 195 | // Operations |
| 196 | // ------------------------------------------------------------------------ |
| 197 | /** |
| 198 | * Retrieves the session configuration from the node. |
| 199 | * @throws ExecutionException |
| 200 | */ |
| 201 | public void getConfigurationFromNode() throws ExecutionException { |
| 202 | getConfigurationFromNode(new NullProgressMonitor()); |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Retrieves the session configuration from the node. |
| 207 | * @param monitor - a progress monitor |
| 208 | * @throws ExecutionException |
| 209 | */ |
| 210 | public void getConfigurationFromNode(IProgressMonitor monitor) throws ExecutionException { |
| 211 | removeAllChildren(); |
| 212 | fSessionInfo = getControlService().getSession(getName(), monitor); |
| 213 | IDomainInfo[] domains = fSessionInfo.getDomains(); |
| 214 | for (int i = 0; i < domains.length; i++) { |
| 215 | TraceDomainComponent domainComponent = new TraceDomainComponent(domains[i].getName(), this); |
| 216 | addChild(domainComponent); |
| 217 | domainComponent.setDomainInfo(domains[i]); |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * Starts the session. |
| 223 | * throws ExecutionExecption |
| 224 | */ |
| 225 | public void startSession() throws ExecutionException { |
| 226 | startSession(new NullProgressMonitor()); |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * Starts the session. |
| 231 | * @param monitor - a progress monitor |
| 232 | * throws ExecutionExecption |
| 233 | */ |
| 234 | public void startSession(IProgressMonitor monitor) throws ExecutionException { |
| 235 | getControlService().startSession(getName(), monitor); |
| 236 | } |
| 237 | |
| 238 | /** |
| 239 | * Starts the session. |
| 240 | * throws ExecutionExecption |
| 241 | */ |
| 242 | public void stopSession() throws ExecutionException { |
| 243 | startSession(new NullProgressMonitor()); |
| 244 | } |
| 245 | |
| 246 | /** |
| 247 | * Starts the session. |
| 248 | * @param monitor - a progress monitor |
| 249 | * throws ExecutionExecption |
| 250 | */ |
| 251 | public void stopSession(IProgressMonitor monitor) throws ExecutionException { |
| 252 | getControlService().stopSession(getName(), monitor); |
| 253 | } |
| 254 | |
| 255 | /** |
| 256 | * Enables channels with given names which are part of this domain. If a given channel |
| 257 | * doesn't exists it creates a new channel with the given parameters (or default values |
| 258 | * if given parameter is null). |
| 259 | * @param channelNames - a list of channel names to enable on this domain |
| 260 | * @param info - channel information to set for the channel (use null for default) |
| 261 | * @param isKernel - a flag for indicating kernel or UST. |
| 262 | * @throws ExecutionException |
| 263 | */ |
| 264 | public void enableChannels(List<String> channelNames, IChannelInfo info, boolean isKernel) throws ExecutionException { |
| 265 | enableChannels(channelNames, info, isKernel, new NullProgressMonitor()); |
| 266 | } |
| 267 | |
| 268 | /** |
| 269 | * Enables channels with given names which are part of this domain. If a given channel |
| 270 | * doesn't exists it creates a new channel with the given parameters (or default values |
| 271 | * if given parameter is null). |
| 272 | * @param channelNames - a list of channel names to enable on this domain |
| 273 | * @param info - channel information to set for the channel (use null for default) |
| 274 | * @param isKernel - a flag for indicating kernel or UST. |
| 275 | * @param monitor - a progress monitor |
| 276 | * @throws ExecutionException |
| 277 | */ |
| 278 | public void enableChannels(List<String> channelNames, IChannelInfo info, boolean isKernel, IProgressMonitor monitor) throws ExecutionException { |
| 279 | getControlService().enableChannels(getName(), channelNames, isKernel, info, monitor); |
| 280 | } |
| 281 | |
| 282 | /** |
| 283 | * Enables a list of events with no additional parameters. |
| 284 | * @param eventNames - a list of event names to enabled. |
| 285 | * @param isKernel - a flag for indicating kernel or UST. |
| 286 | * @throws ExecutionException |
| 287 | */ |
| 288 | public void enableEvent(List<String> eventNames, boolean isKernel) throws ExecutionException { |
| 289 | enableEvents(eventNames, isKernel, new NullProgressMonitor()); |
| 290 | } |
| 291 | |
| 292 | /** |
| 293 | * Enables a list of events with no additional parameters. |
| 294 | * @param eventNames - a list of event names to enabled. |
| 295 | * @param isKernel - a flag for indicating kernel or UST. |
| 296 | * @param monitor - a progress monitor |
| 297 | * @throws ExecutionException |
| 298 | */ |
| 299 | public void enableEvents(List<String> eventNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException { |
| 300 | getControlService().enableEvents(getName(), null, eventNames, isKernel, monitor); |
| 301 | } |
| 302 | |
| 303 | /** |
| 304 | * Enables all syscalls (for kernel domain) |
| 305 | * @throws ExecutionException |
| 306 | */ |
| 307 | public void enableSyscalls() throws ExecutionException { |
| 308 | enableSyscalls(new NullProgressMonitor()); |
| 309 | } |
| 310 | |
| 311 | /** |
| 312 | * Enables all syscalls (for kernel domain) |
| 313 | * @param monitor - a progress monitor |
| 314 | * @throws ExecutionException |
| 315 | */ |
| 316 | public void enableSyscalls(IProgressMonitor monitor) throws ExecutionException { |
| 317 | getControlService().enableSyscalls(getName(), null, monitor); |
| 318 | } |
| 319 | |
| 320 | /** |
| 321 | * Enables a dynamic probe (for kernel domain) |
| 322 | * @param eventName - event name for probe |
| 323 | * @param isFunction - true for dynamic function entry/return probe else false |
| 324 | * @param probe - the actual probe |
| 325 | * @throws ExecutionException |
| 326 | */ |
| 327 | public void enableProbe(String eventName, boolean isFunction, String probe) throws ExecutionException { |
| 328 | enableProbe(eventName, isFunction, probe, new NullProgressMonitor()); |
| 329 | } |
| 330 | |
| 331 | /** |
| 332 | * Enables a dynamic probe (for kernel domain) |
| 333 | * @param eventName - event name for probe |
| 334 | * @param isFunction - true for dynamic function entry/return probe else false |
| 335 | * @param probe - the actual probe |
| 336 | * @param monitor - a progress monitor |
| 337 | * @throws ExecutionException |
| 338 | */ |
| 339 | public void enableProbe(String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException { |
| 340 | getControlService().enableProbe(getName(), null, eventName, isFunction, probe, monitor); |
| 341 | } |
| 342 | |
| 343 | /** |
| 344 | * Enables events using log level. |
| 345 | * @param eventName - a event name |
| 346 | * @param logLevelType - a log level type |
| 347 | * @param level - a log level |
| 348 | * @throws ExecutionException |
| 349 | */ |
| 350 | public void enableLogLevel(String eventName, LogLevelType logLevelType, TraceLogLevel level) throws ExecutionException { |
| 351 | enableLogLevel(eventName, logLevelType, level, new NullProgressMonitor()); |
| 352 | } |
| 353 | |
| 354 | /** |
| 355 | * Enables events using log level. |
| 356 | * @param eventName - a event name |
| 357 | * @param logLevelType - a log level type |
| 358 | * @param level - a log level |
| 359 | * @param monitor - a progress monitor |
| 360 | * @throws ExecutionException |
| 361 | */ |
| 362 | public void enableLogLevel(String eventName, LogLevelType logLevelType, TraceLogLevel level, IProgressMonitor monitor) throws ExecutionException { |
| 363 | getControlService().enableLogLevel(getName(), null, eventName, logLevelType, level, monitor); |
| 364 | } |
| 365 | |
| 366 | /** |
| 367 | * Gets all available contexts to be added to channels/events. |
| 368 | * @return the list of available contexts |
| 369 | */ |
| 370 | public List<String> getContextList() throws ExecutionException { |
| 371 | return getContextList(new NullProgressMonitor()); |
| 372 | } |
| 373 | |
| 374 | /** |
| 375 | * Gets all available contexts to be added to channels/events. |
| 376 | * @param monitor |
| 377 | * @return the list of available contexts |
| 378 | */ |
| 379 | public List<String> getContextList(IProgressMonitor monitor) throws ExecutionException { |
| 380 | return getControlService().getContextList(monitor); |
| 381 | } |
| 382 | } |