56
|
1 |
/*
|
|
2 |
* Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
* Access point to the exported interfaces of TraceCompiler engine
|
|
17 |
*
|
|
18 |
*/
|
|
19 |
package com.nokia.tracecompiler.engine;
|
|
20 |
|
|
21 |
import java.io.BufferedReader;
|
|
22 |
import java.io.IOException;
|
|
23 |
import java.io.InputStream;
|
|
24 |
import java.io.InputStreamReader;
|
|
25 |
|
|
26 |
import com.nokia.tracecompiler.TraceCompilerLogger;
|
|
27 |
import com.nokia.tracecompiler.engine.source.SourceEngine;
|
|
28 |
import com.nokia.tracecompiler.model.TraceCompilerException;
|
|
29 |
import com.nokia.tracecompiler.model.TraceModel;
|
|
30 |
import com.nokia.tracecompiler.plugin.TraceCompilerPlugin;
|
|
31 |
import com.nokia.tracecompiler.source.SourceConstants;
|
|
32 |
|
|
33 |
/**
|
|
34 |
* Access point to the exported interfaces of TraceCompiler engine
|
|
35 |
*
|
|
36 |
*/
|
|
37 |
public class TraceCompilerEngineGlobals {
|
|
38 |
|
|
39 |
/**
|
|
40 |
* Max group ID
|
|
41 |
*/
|
|
42 |
public static final int MAX_GROUP_ID = 65535; // CodForChk_Dis_Magic
|
|
43 |
|
|
44 |
/**
|
|
45 |
* Max trace ID
|
|
46 |
*/
|
|
47 |
public static final int MAX_TRACE_ID = 65535; // CodForChk_Dis_Magic
|
|
48 |
|
|
49 |
/**
|
|
50 |
* TraceCompiler engine instance
|
|
51 |
*/
|
|
52 |
private static TraceCompilerEngine instance;
|
|
53 |
|
|
54 |
/**
|
|
55 |
* default licence
|
|
56 |
*/
|
|
57 |
static String defaultLicence;
|
|
58 |
|
|
59 |
/**
|
|
60 |
* default licence
|
|
61 |
*/
|
|
62 |
static String defaultLicenceWithHash;
|
|
63 |
|
|
64 |
/**
|
|
65 |
* Constructor is hidden
|
|
66 |
*/
|
|
67 |
private TraceCompilerEngineGlobals() {
|
|
68 |
}
|
|
69 |
|
|
70 |
/**
|
|
71 |
* Starts TraceCompiler engine.
|
|
72 |
* @throws TraceCompilerException
|
|
73 |
*/
|
|
74 |
public static void start() throws TraceCompilerException {
|
|
75 |
if (instance == null) {
|
|
76 |
instance = new TraceCompilerEngine();
|
|
77 |
instance.start();
|
|
78 |
}
|
|
79 |
}
|
|
80 |
|
|
81 |
/**
|
|
82 |
* Shuts down the TraceCompiler instance
|
|
83 |
* @throws TraceCompilerException
|
|
84 |
*/
|
|
85 |
public static void shutdown() throws TraceCompilerException {
|
|
86 |
if (instance != null) {
|
|
87 |
instance.shutdown();
|
|
88 |
instance = null;
|
|
89 |
}
|
|
90 |
}
|
|
91 |
|
|
92 |
/**
|
|
93 |
* Gets the configuration interface. The configuration interface is not
|
|
94 |
* available until view has been registered.
|
|
95 |
*
|
|
96 |
* @return the configuration
|
|
97 |
*/
|
|
98 |
public static TraceCompilerEngineConfiguration getConfiguration() {
|
|
99 |
return instance.getConfiguration();
|
|
100 |
}
|
|
101 |
|
|
102 |
/**
|
|
103 |
* Gets the trace model
|
|
104 |
*
|
|
105 |
* @return the model
|
|
106 |
*/
|
|
107 |
public static TraceModel getTraceModel() {
|
|
108 |
return instance.getModel();
|
|
109 |
}
|
|
110 |
|
|
111 |
/**
|
|
112 |
* Gets the source engine
|
|
113 |
*
|
|
114 |
* @return the source engine
|
|
115 |
*/
|
|
116 |
public static SourceEngine getSourceEngine() {
|
|
117 |
return instance.getSourceEngine();
|
|
118 |
}
|
|
119 |
|
|
120 |
/**
|
|
121 |
* Gets the trace compiler interface
|
|
122 |
*
|
|
123 |
* @return trace compiler
|
|
124 |
*/
|
|
125 |
public static TraceCompilerEngineInterface getTraceCompiler() {
|
|
126 |
return instance.getTraceCompiler();
|
|
127 |
}
|
|
128 |
|
|
129 |
/**
|
|
130 |
* Gets the events interface
|
|
131 |
*
|
|
132 |
* @return the events interface
|
|
133 |
*/
|
|
134 |
public static TraceCompilerEngineEvents getEvents() {
|
|
135 |
if (instance != null) {
|
|
136 |
return instance.getEvents();
|
|
137 |
} else {
|
|
138 |
return null;
|
|
139 |
}
|
|
140 |
}
|
|
141 |
|
|
142 |
/**
|
|
143 |
* Called by a plug-in to register itself
|
|
144 |
*
|
|
145 |
* @param plugin
|
|
146 |
* the plugin to be registered
|
|
147 |
*/
|
|
148 |
public static void registerPlugin(TraceCompilerPlugin plugin) {
|
|
149 |
instance.registerPlugin(plugin);
|
|
150 |
}
|
|
151 |
|
|
152 |
/**
|
|
153 |
* Called by a plug-in to unregister itself
|
|
154 |
*
|
|
155 |
* @param plugin
|
|
156 |
* the plugin to be unregistered
|
|
157 |
*/
|
|
158 |
public static void unregisterPlugin(TraceCompilerPlugin plugin) {
|
|
159 |
if (instance != null) {
|
|
160 |
instance.unregisterPlugin(plugin);
|
|
161 |
}
|
|
162 |
}
|
|
163 |
|
|
164 |
/**
|
|
165 |
* Called by the view plug-in to register the view
|
|
166 |
*
|
|
167 |
* @param view
|
|
168 |
* the view
|
|
169 |
* @throws TraceCompilerException
|
|
170 |
*/
|
|
171 |
public static void setView(TraceCompilerEngineView view) throws TraceCompilerException {
|
|
172 |
instance.setView(view);
|
|
173 |
}
|
|
174 |
|
|
175 |
/**
|
|
176 |
* Gets the source context manager
|
|
177 |
*
|
|
178 |
* @return the context manager
|
|
179 |
*/
|
|
180 |
public static SourceContextManager getSourceContextManager() {
|
|
181 |
return instance.getSourceContextManager();
|
|
182 |
}
|
|
183 |
|
|
184 |
/**
|
|
185 |
* Get project path
|
|
186 |
*
|
|
187 |
* @return project path
|
|
188 |
*/
|
|
189 |
public static String getProjectPath() {
|
|
190 |
String projetcPath = instance.getProjectPath();
|
|
191 |
return projetcPath;
|
|
192 |
}
|
|
193 |
|
|
194 |
/**
|
|
195 |
* Set project path
|
|
196 |
*
|
|
197 |
* @param path
|
|
198 |
* the path
|
|
199 |
*/
|
|
200 |
public static void setProjectPath(String path) {
|
|
201 |
instance.setProjectPath(path);
|
|
202 |
}
|
|
203 |
|
|
204 |
/**
|
|
205 |
* get default licence from com/nokia/tracecompiler/licence.lic
|
|
206 |
* c++ comment format
|
|
207 |
* @param boolean cppCommented
|
|
208 |
* if true, it returns the licence in cpp comment \/** ... **\/
|
|
209 |
* else it retuen the licence in a # comment ## ... ##
|
|
210 |
* @return String licence
|
|
211 |
*/
|
|
212 |
public static String getDefaultLicence(boolean cppCommented) {
|
|
213 |
String licenceResourceName;
|
|
214 |
if (cppCommented) {
|
|
215 |
if (defaultLicence == null) {
|
|
216 |
licenceResourceName = "/com/nokia/tracecompiler/licence.lic"; //$NON-NLS-1$
|
|
217 |
defaultLicence = readLicence(licenceResourceName);
|
|
218 |
}
|
|
219 |
return defaultLicence;
|
|
220 |
} else {
|
|
221 |
if (defaultLicenceWithHash == null) {
|
|
222 |
licenceResourceName = "/com/nokia/tracecompiler/licence_hash.lic"; //$NON-NLS-1$
|
|
223 |
defaultLicenceWithHash = readLicence(licenceResourceName);
|
|
224 |
}
|
|
225 |
return defaultLicenceWithHash;
|
|
226 |
}
|
|
227 |
}
|
|
228 |
|
|
229 |
/**
|
|
230 |
* read the provided resource file and return the text in it.
|
|
231 |
*/
|
|
232 |
private static String readLicence(String aLicenceResourceName) {
|
|
233 |
String licenceText = null;
|
|
234 |
InputStream is = instance.getClass().getResourceAsStream(aLicenceResourceName);
|
|
235 |
if (is != null) {
|
|
236 |
InputStreamReader isr = new InputStreamReader(is);
|
|
237 |
BufferedReader br = new BufferedReader(isr);
|
|
238 |
StringBuffer sb = new StringBuffer();
|
|
239 |
String line;
|
|
240 |
try {
|
|
241 |
while ((line = br.readLine()) != null) {
|
|
242 |
sb.append(line + SourceConstants.LINE_FEED);
|
|
243 |
}
|
|
244 |
licenceText = sb.toString();
|
|
245 |
br.close();
|
|
246 |
isr.close();
|
|
247 |
is.close();
|
|
248 |
} catch (IOException e) {
|
|
249 |
TraceCompilerLogger.printWarning(Messages.getString("TraceCompilerErrorMessages.LicenceFileError") + e.getMessage()); //$NON-NLS-1$
|
|
250 |
}
|
|
251 |
}
|
|
252 |
return licenceText;
|
|
253 |
}
|
|
254 |
|
|
255 |
}
|