Commit | Line | Data |
---|---|---|
eb1bab5b | 1 | /********************************************************************** |
ed902a2b | 2 | * Copyright (c) 2012, 2014 Ericsson |
ea21cd65 | 3 | * |
eb1bab5b BH |
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 | |
ea21cd65 AM |
8 | * |
9 | * Contributors: | |
eb1bab5b BH |
10 | * Bernd Hufmann - Initial API and implementation |
11 | **********************************************************************/ | |
12 | ||
9bc60be7 | 13 | package org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl; |
eb1bab5b | 14 | |
f0a2a4be BH |
15 | import java.util.ArrayList; |
16 | import java.util.List; | |
a20452b1 | 17 | import java.util.stream.Collectors; |
f0a2a4be | 18 | |
9bc60be7 | 19 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.IBaseEventInfo; |
a20452b1 | 20 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.ILoggerInfo; |
9bc60be7 | 21 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.IUstProviderInfo; |
a20452b1 | 22 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceDomainType; |
9bc60be7 AM |
23 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.impl.UstProviderInfo; |
24 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.messages.Messages; | |
25 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.ITraceControlComponent; | |
26 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.property.UstProviderPropertySource; | |
06b9339e | 27 | import org.eclipse.ui.views.properties.IPropertySource; |
eb1bab5b BH |
28 | |
29 | /** | |
eb1bab5b BH |
30 | * <p> |
31 | * Implementation of the UST provider component. | |
32 | * </p> | |
ea21cd65 | 33 | * |
dbd4432d | 34 | * @author Bernd Hufmann |
eb1bab5b BH |
35 | */ |
36 | public class UstProviderComponent extends TraceControlComponent { | |
ea21cd65 | 37 | |
eb1bab5b BH |
38 | // ------------------------------------------------------------------------ |
39 | // Constants | |
40 | // ------------------------------------------------------------------------ | |
41 | /** | |
42 | * Path to icon file for this component. | |
43 | */ | |
a20452b1 BR |
44 | private static final String USTL_PROVIDER_ICON_FILE = "icons/obj16/targets.gif"; //$NON-NLS-1$ |
45 | /** | |
46 | * UST domain event created by a Java application. | |
47 | */ | |
48 | private static final String LTTNG_JUL_USER_EVENT = "lttng_jul:user_event"; //$NON-NLS-1$ | |
49 | /** | |
50 | * UST domain event created by a Java application. | |
51 | */ | |
52 | private static final String LTTNG_JUL_SYS_EVENT = "lttng_jul:sys_event"; //$NON-NLS-1$ | |
53 | /** | |
54 | * UST domain event created by a Java application. | |
55 | */ | |
56 | private static final String LTTNG_LOG4J_USER_EVENT = "lttng_log4j:user_event"; //$NON-NLS-1$ | |
57 | /** | |
58 | * UST domain event created by a Java application. | |
59 | */ | |
60 | private static final String LTTNG_LOG4J_SYS_EVENT = "lttng_log4j:sys_event"; //$NON-NLS-1$ | |
61 | /** | |
62 | * UST domain event created by a Java application. | |
63 | */ | |
64 | private static final String LTTNG_JUL_EVENT = "lttng_jul:event"; //$NON-NLS-1$ | |
65 | /** | |
66 | * UST domain event created by a Java application. | |
67 | */ | |
68 | private static final String LTTNG_LOG4J_EVENT = "lttng_log4j:event"; //$NON-NLS-1$ | |
3d2d8c9f BR |
69 | /** |
70 | * UST domain event created by a Python application. | |
71 | */ | |
72 | private static final String LTTNG_PYTHON_EVENT = "lttng_python:event"; //$NON-NLS-1$ | |
ea21cd65 | 73 | |
eb1bab5b BH |
74 | // ------------------------------------------------------------------------ |
75 | // Attributes | |
76 | // ------------------------------------------------------------------------ | |
77 | /** | |
78 | * The UST provider information. | |
79 | */ | |
80 | private IUstProviderInfo fProviderInfo = null; | |
ea21cd65 | 81 | |
eb1bab5b BH |
82 | // ------------------------------------------------------------------------ |
83 | // Constructors | |
84 | // ------------------------------------------------------------------------ | |
85 | /** | |
ea21cd65 | 86 | * Constructor |
eb1bab5b BH |
87 | * @param name - the name of the component. |
88 | * @param parent - the parent of this component. | |
ea21cd65 | 89 | */ |
eb1bab5b BH |
90 | public UstProviderComponent(String name, ITraceControlComponent parent) { |
91 | super(name, parent); | |
92 | setImage(USTL_PROVIDER_ICON_FILE); | |
7b48c899 | 93 | setToolTip(Messages.TraceControl_ProviderDisplayName); |
eb1bab5b BH |
94 | fProviderInfo = new UstProviderInfo(name); |
95 | } | |
96 | ||
97 | // ------------------------------------------------------------------------ | |
98 | // Accessors | |
99 | // ------------------------------------------------------------------------ | |
100 | /** | |
ea21cd65 | 101 | * Sets the UST provider information to the given value. |
eb1bab5b BH |
102 | * @param providerInfo - the provider information to set |
103 | */ | |
104 | public void setUstProvider(IUstProviderInfo providerInfo) { | |
105 | fProviderInfo = providerInfo; | |
106 | IBaseEventInfo[] events = providerInfo.getEvents(); | |
f0a2a4be | 107 | List<ITraceControlComponent> eventComponents = new ArrayList<>(); |
eb1bab5b BH |
108 | for (int i = 0; i < events.length; i++) { |
109 | BaseEventComponent component = new BaseEventComponent(events[i].getName(), this); | |
110 | component.setEventInfo(events[i]); | |
a20452b1 BR |
111 | |
112 | // Only add the events that are useful for the user, no JUL and log4j events | |
113 | if ( !events[i].getName().equals(LTTNG_JUL_USER_EVENT) && | |
114 | !events[i].getName().equals(LTTNG_JUL_SYS_EVENT) && | |
115 | !events[i].getName().equals(LTTNG_LOG4J_USER_EVENT) && | |
116 | !events[i].getName().equals(LTTNG_LOG4J_SYS_EVENT) && | |
117 | !events[i].getName().equals(LTTNG_JUL_EVENT) && | |
3d2d8c9f BR |
118 | !events[i].getName().equals(LTTNG_LOG4J_EVENT) && |
119 | !events[i].getName().equals(LTTNG_PYTHON_EVENT)) { | |
a20452b1 BR |
120 | eventComponents.add(component); |
121 | } | |
eb1bab5b | 122 | } |
f0a2a4be | 123 | setChildren(eventComponents); |
a20452b1 BR |
124 | |
125 | // Adding loggers | |
126 | List<ILoggerInfo> loggers = providerInfo.getLoggers(); | |
127 | List<ITraceControlComponent> loggerComponents = new ArrayList<>(); | |
128 | ||
129 | for (ILoggerInfo logger : loggers) { | |
130 | BaseLoggerComponent component = new BaseLoggerComponent(logger.getName(), this); | |
131 | component.setLoggerInfo(logger); | |
132 | ||
133 | // Only add the loggers that are useful for the user, not global | |
134 | if (!logger.getName().equals("global")) { //$NON-NLS-1$ | |
135 | loggerComponents.add(component); | |
136 | } | |
137 | } | |
138 | setChildren(loggerComponents); | |
139 | ||
140 | StringBuilder providerName = new StringBuilder(); | |
141 | providerName.append(getName() + " [PID=" + fProviderInfo.getPid() + "]"); //$NON-NLS-1$ //$NON-NLS-2$ | |
142 | ||
143 | // If the UST provider contains logger(s) | |
144 | if (!loggerComponents.isEmpty()) { | |
145 | providerName.append(" (With logger)"); //$NON-NLS-1$ | |
146 | } | |
147 | setName(providerName.toString()); | |
eb1bab5b | 148 | } |
ea21cd65 | 149 | |
eb1bab5b BH |
150 | /** |
151 | * @return the process ID of the UST provider. | |
152 | */ | |
153 | public int getPid() { | |
154 | return fProviderInfo.getPid(); | |
155 | } | |
156 | ||
157 | /** | |
158 | * Sets the process ID of the UST provider to the given value. | |
159 | * @param pid - process ID to set | |
160 | */ | |
161 | public void setPid(int pid) { | |
162 | fProviderInfo.setPid(pid); | |
163 | } | |
164 | ||
a20452b1 BR |
165 | /** |
166 | * Gets all logger components of a certain domain | |
167 | * | |
168 | * @param domain | |
169 | * the logger domain type | |
170 | * | |
171 | * @return all logger components of a certain domain | |
172 | */ | |
173 | public List<ITraceControlComponent> getLoggerComponents(TraceDomainType domain) { | |
174 | return getChildren(BaseLoggerComponent.class).stream() | |
175 | .filter(loggerComp -> domain.equals(((BaseLoggerComponent) loggerComp).getDomain())) | |
176 | .collect(Collectors.toList()); | |
177 | } | |
178 | ||
06b9339e | 179 | @Override |
e58fe1d5 | 180 | public <T> T getAdapter(Class<T> adapter) { |
06b9339e | 181 | if (adapter == IPropertySource.class) { |
e58fe1d5 | 182 | return adapter.cast(new UstProviderPropertySource(this)); |
06b9339e BH |
183 | } |
184 | return null; | |
ea21cd65 AM |
185 | } |
186 | ||
eb1bab5b | 187 | } |