15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 package com.nokia.carbide.cpp.pi; |
18 package com.nokia.carbide.cpp.pi; |
19 |
19 |
|
20 import org.eclipse.core.runtime.IConfigurationElement; |
|
21 import org.eclipse.core.runtime.IExtension; |
|
22 import org.eclipse.core.runtime.IExtensionPoint; |
|
23 import org.eclipse.core.runtime.IExtensionRegistry; |
|
24 import org.eclipse.core.runtime.Platform; |
20 import org.eclipse.jface.resource.ImageDescriptor; |
25 import org.eclipse.jface.resource.ImageDescriptor; |
21 import org.eclipse.swt.graphics.Image; |
26 import org.eclipse.swt.graphics.Image; |
|
27 import org.eclipse.swt.widgets.Shell; |
|
28 import org.eclipse.ui.IWorkbenchPage; |
22 import org.osgi.framework.BundleContext; |
29 import org.osgi.framework.BundleContext; |
23 |
30 |
24 import com.nokia.carbide.cpp.internal.pi.model.Binary; |
31 import com.nokia.carbide.cpp.internal.pi.model.Binary; |
25 import com.nokia.carbide.cpp.internal.pi.model.CusSample; |
32 import com.nokia.carbide.cpp.internal.pi.model.CusSample; |
26 import com.nokia.carbide.cpp.internal.pi.model.Function; |
33 import com.nokia.carbide.cpp.internal.pi.model.Function; |
35 import com.nokia.carbide.cpp.internal.pi.plugin.model.AbstractPiPlugin; |
42 import com.nokia.carbide.cpp.internal.pi.plugin.model.AbstractPiPlugin; |
36 import com.nokia.carbide.cpp.internal.pi.test.BappeaAnalysisInfo; |
43 import com.nokia.carbide.cpp.internal.pi.test.BappeaAnalysisInfo; |
37 import com.nokia.carbide.cpp.internal.pi.test.EnabledTrace; |
44 import com.nokia.carbide.cpp.internal.pi.test.EnabledTrace; |
38 import com.nokia.carbide.cpp.internal.pi.test.PIAnalysisInfo; |
45 import com.nokia.carbide.cpp.internal.pi.test.PIAnalysisInfo; |
39 import com.nokia.carbide.cpp.internal.pi.test.TraceAdditionalInfo; |
46 import com.nokia.carbide.cpp.internal.pi.test.TraceAdditionalInfo; |
|
47 import com.nokia.carbide.cpp.pi.export.ITraceProvider; |
|
48 |
40 |
49 |
41 |
50 |
42 /** |
51 /** |
43 * The main plugin class to be used in the desktop. |
52 * The main plugin class to be used in the desktop. |
44 */ |
53 */ |
46 |
55 |
47 //The shared instance. |
56 //The shared instance. |
48 private static PiPlugin plugin; |
57 private static PiPlugin plugin; |
49 |
58 |
50 public final static String PLUGIN_ID = "com.nokia.carbide.cpp.pi"; //$NON-NLS-1$ |
59 public final static String PLUGIN_ID = "com.nokia.carbide.cpp.pi"; //$NON-NLS-1$ |
|
60 public final static String ACTION_SCALE_CPU = PLUGIN_ID + ".scaleCPU"; //$NON-NLS-1$ |
|
61 |
|
62 /** |
|
63 * Trace provider extension name. |
|
64 */ |
|
65 final String EXTENSION_TRACE_PROVIDER = "traceprovider"; //$NON-NLS-1$ |
|
66 |
|
67 /** |
|
68 * Storing reference to possibly installed trace provider plug-in. |
|
69 */ |
|
70 private static ITraceProvider traceProvider; |
|
71 |
|
72 |
51 |
73 |
52 private static void setPlugin(PiPlugin localPlugin) { |
74 private static void setPlugin(PiPlugin localPlugin) { |
53 plugin = localPlugin; |
75 plugin = localPlugin; |
54 } |
76 } |
55 |
77 |
107 public static Image getImage(String aLocation){ |
132 public static Image getImage(String aLocation){ |
108 getImageDescriptor(aLocation); //make sure the ImageDescriptor gets created |
133 getImageDescriptor(aLocation); //make sure the ImageDescriptor gets created |
109 return getDefault().getImageRegistry().get(aLocation); |
134 return getDefault().getImageRegistry().get(aLocation); |
110 } |
135 } |
111 |
136 |
|
137 @SuppressWarnings("unchecked") |
112 public static Class getReplacedClass(String className) { |
138 public static Class getReplacedClass(String className) { |
113 // handle legacy PI analysis file class names |
139 // handle legacy PI analysis file class names |
114 if (!className.startsWith("fi.")) //$NON-NLS-1$ |
140 if (!className.startsWith("fi.")) //$NON-NLS-1$ |
115 return null; |
141 return null; |
116 |
142 |
173 return BappeaAnalysisInfo.class; |
199 return BappeaAnalysisInfo.class; |
174 } |
200 } |
175 |
201 |
176 return null; |
202 return null; |
177 } |
203 } |
|
204 |
|
205 /** |
|
206 * This must be called from UI thread. If called |
|
207 * from non-ui thread this returns <code>null</code>. |
|
208 * @return Currently active workbench page. |
|
209 */ |
|
210 public static IWorkbenchPage getCurrentlyActivePage(){ |
|
211 return getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage(); |
|
212 } |
|
213 |
|
214 /** |
|
215 * This must be called from UI thread. If called |
|
216 * from non-UI thread this returns <code>null</code>. |
|
217 * @return The shell of the currently active workbench window.. |
|
218 */ |
|
219 public static Shell getCurrentlyActiveWbWindowShell(){ |
|
220 IWorkbenchPage page = getCurrentlyActivePage(); |
|
221 if(page != null){ |
|
222 return page.getWorkbenchWindow().getShell(); |
|
223 } |
|
224 return null; |
|
225 } |
|
226 |
|
227 /** |
|
228 * Checks if trace provider plug-in is available. |
|
229 * @return <code>true</code> if trace provider interface available, otherwise <code>false</code> |
|
230 */ |
|
231 public static boolean isTraceProviderAvailable(){ |
|
232 return (traceProvider != null); |
|
233 } |
|
234 |
|
235 /** |
|
236 * Gets trace provider interface instance if available. |
|
237 * @return trace provider interface instance or <code>null</code> if not available |
|
238 */ |
|
239 public static ITraceProvider getTraceProvider(){ |
|
240 if(isTraceProviderAvailable()){ |
|
241 return traceProvider; |
|
242 } |
|
243 return null; |
|
244 } |
|
245 |
|
246 /** |
|
247 * Tries to find trace provider plug-ins. Selecting the first found one. |
|
248 * @return reference to trace provider instance if found, otherwise <code>null</code> |
|
249 */ |
|
250 ITraceProvider findTraceProviderExtension() { |
|
251 try { |
|
252 IExtensionRegistry er = Platform.getExtensionRegistry(); |
|
253 IExtensionPoint ep = er.getExtensionPoint(PLUGIN_ID, EXTENSION_TRACE_PROVIDER); |
|
254 IExtension[] extensions = ep.getExtensions(); |
|
255 |
|
256 // if plug-ins were found. |
|
257 if (extensions != null && extensions.length > 0) { |
|
258 |
|
259 // read all found trace providers |
|
260 for (int i = 0; i < extensions.length; i++) { |
|
261 IConfigurationElement[] ce = extensions[i].getConfigurationElements(); |
|
262 if (ce != null && ce.length > 0) { |
|
263 try { |
|
264 ITraceProvider provider = (ITraceProvider)ce[0].createExecutableExtension("class"); //$NON-NLS-1$ |
|
265 // We support only one trace provider |
|
266 if (provider != null) { |
|
267 return provider; |
|
268 } |
|
269 } catch (Exception e) { |
|
270 e.printStackTrace(); |
|
271 } |
|
272 } |
|
273 } |
|
274 } |
|
275 } catch (Exception e) { |
|
276 e.printStackTrace(); |
|
277 } |
|
278 |
|
279 return null; |
|
280 } |
178 } |
281 } |