# HG changeset patch
# User hgs
# Date 1282566576 -10800
# Node ID 838cdffd57cec4730b0287ba5ac5b1f94bcd0efd
# Parent 813b186005b68639ff25261bdeeec8ce68edfb8c
201031
diff -r 813b186005b6 -r 838cdffd57ce layers.sysdef.xml
--- a/layers.sysdef.xml Thu Jul 29 16:04:29 2010 +0300
+++ b/layers.sysdef.xml Mon Aug 23 15:29:36 2010 +0300
@@ -7,7 +7,12 @@
-
+
+
+
+
+
+
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/group/bld.inf
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/group/bld.inf Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,30 @@
+/*
+* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* TraceCompiler
+*/
+
+PRJ_PLATFORMS
+TOOLS2
+
+PRJ_EXPORTS
+../tracecompiler/tracecompiler.pl +/tools/ //
+../tracecompiler/tracecompiler.pm +/tools/ //
+../tracecompiler/tracecompiler_parse_mmp.pl +/tools/ //
+../tracecompiler/tracecompiler_mmp_data.pm +/tools/ //
+
+
+:zip ../tracecompiler/tracecompiler.zip +/tools/tracecompiler overwrite//
+
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/group/build.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/group/build.xml Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,119 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Cleaning the ${build.dir}
+
+ Creating the build directory
+
+
+ Deleting *.xml_ files
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Copying html and properties files from src/com.nokia.tracecompiler/src to ${build.dir}
+
+
+
+
+
+
+
+
+
+
+ Zip TraceCompiler binaries
+
+
+
+
+ Unzip recompiled TraceCompiler binaries intop epoc32/tools/tracecompiler
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/.classpath
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/.classpath Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/.project
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/.project Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,30 @@
+
+
+ com.nokia.tracecompiler
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.eclipse.pde.ManifestBuilder
+
+
+
+
+ org.eclipse.pde.SchemaBuilder
+
+
+
+
+
+ org.eclipse.jem.workbench.JavaEMFNature
+ org.eclipse.pde.PluginNature
+ org.eclipse.jdt.core.javanature
+ org.eclipse.jem.beaninfo.BeanInfoNature
+
+
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/.settings/org.eclipse.core.resources.prefs
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/.settings/org.eclipse.core.resources.prefs Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,8 @@
+#Fri Sep 04 14:04:36 BST 2009
+eclipse.preferences.version=1
+encoding//src/com/nokia/tracecompiler/autogen/messages.properties=8859_1
+encoding//src/com/nokia/tracecompiler/dictionary/messages.properties=8859_1
+encoding//src/com/nokia/tracecompiler/engine/header/messages.properties=8859_1
+encoding//src/com/nokia/tracecompiler/engine/messages.properties=8859_1
+encoding//src/com/nokia/tracecompiler/engine/project/messages.properties=8859_1
+encoding//src/com/nokia/tracecompiler/engine/rules/messages.properties=8859_1
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/.settings/org.eclipse.jdt.core.prefs
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/.settings/org.eclipse.jdt.core.prefs Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,3 @@
+#Tue Apr 14 13:07:47 EEST 2009
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.source=1.5
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/.settings/org.eclipse.jdt.ui.prefs
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/.settings/org.eclipse.jdt.ui.prefs Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,3 @@
+#Tue Apr 14 13:07:47 EEST 2009
+eclipse.preferences.version=1
+internal.default.compliance=default
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/about.html
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/about.html Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,20 @@
+
+
+
+About
+
+
+
+
+About This Content
+
+February 4, 2009
+
+Copyright
+Copyright © 2007-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
+This component and the accompanying materials are made available under the
+terms of the License "Symbian Foundation License v1.0" which accompanies this
+distribution, and is available at the URL: http://www.symbianfoundation.org/legal/sfl-v10.html.
+
+
+
\ No newline at end of file
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/build.properties
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/build.properties Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,2 @@
+source.. = src/
+output.. = bin/
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/Messages.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/Messages.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ *
+ * Description:
+ *
+ ** Localization for tracecompiler package
+ *
+ */
+package com.nokia.tracecompiler;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+@SuppressWarnings("all")
+public final class Messages {
+
+ /**
+ * Bundle name
+ */
+ private static final String BUNDLE_NAME = "com.nokia.tracecompiler.messages"; //$NON-NLS-1$
+
+ /**
+ * Bundle
+ */
+ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
+ .getBundle(BUNDLE_NAME);
+
+ /**
+ * Prevents construction
+ */
+ private Messages() {
+ }
+
+ /**
+ * Gets localized string based on key
+ *
+ * @param key
+ * the resource key
+ * @return the localized resource
+ */
+ public static String getString(String key) {
+ try {
+ return RESOURCE_BUNDLE.getString(key);
+ } catch (MissingResourceException e) {
+ return '!' + key + '!';
+ }
+ }
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/TraceCompiler.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/TraceCompiler.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,758 @@
+/*
+ * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ *
+ * Description:
+ *
+ * TraceCompiler command-line main class
+ *
+ */
+package com.nokia.tracecompiler;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import com.nokia.tracecompiler.document.FileDocumentMonitor;
+import com.nokia.tracecompiler.document.StringDocumentFactory;
+import com.nokia.tracecompiler.engine.TraceCompilerEngineEvents;
+import com.nokia.tracecompiler.engine.TraceCompilerEngineGlobals;
+import com.nokia.tracecompiler.engine.TraceCompilerEngineInterface;
+import com.nokia.tracecompiler.engine.TraceLocationList;
+import com.nokia.tracecompiler.engine.project.ProjectEngine;
+import com.nokia.tracecompiler.engine.utils.TraceUtils;
+import com.nokia.tracecompiler.model.TraceCompilerException;
+import com.nokia.tracecompiler.model.TraceModel;
+import com.nokia.tracecompiler.plugin.TraceCompilerPlugin;
+import com.nokia.tracecompiler.project.GroupNames;
+import com.nokia.tracecompiler.source.SourceConstants;
+import com.nokia.tracecompiler.source.SymbianConstants;
+import com.nokia.tracecompiler.utils.DocumentFactory;
+import com.nokia.tracecompiler.utils.TraceCompilerVersion;
+
+/**
+ * TraceCompiler command-line main class
+ *
+ */
+public class TraceCompiler {
+
+ private static String LINE_SEPARATOR = System.getProperty("line.separator"); //$NON-NLS-1$
+
+ /**
+ * Index of third character
+ */
+ private static final int INDEX_OF_THIRD_CHARACTER = 2;
+
+ /**
+ * Index of first character
+ */
+ private static final int INDEX_OF_FIRST_CHARACTER = 0;
+
+ /**
+ * Version option
+ */
+ private static final String VERSION_OPTION = "--version"; //$NON-NLS-1$
+ private static final String LEGACY_VERSION_OPTION = "-version"; //$NON-NLS-1$
+ private static final String VERSION_OPTION_SF = "-v"; //$NON-NLS-1$
+ /**
+ * Version option instruction text
+ */
+ private static final String VERSION_OPTION_INSTRUCTION_TEXT = "print TraceCompiler version"; //$NON-NLS-1$
+
+
+ /**
+ * help option
+ */
+ private static final String HELP_OPTION = "--help"; //$NON-NLS-1$
+ private static final String HELP_OPTION_SF = "-h"; //$NON-NLS-1$
+ private static final String HELP_OPTION_INSTRUCTION_TEXT = "print help"; //$NON-NLS-1$
+
+ /**
+ * Verbose option
+ */
+ private static final String VERBOSE_OPTION = "--verbose"; //$NON-NLS-1$
+ private static final String VERBOSE_OPTION_SF = "-vb"; //$NON-NLS-1$
+ /**
+ * Verbose option instruction text
+ */
+ private static final String VERBOSE_OPTION_INSTRUCTION_TEXT = "print info messages."; //$NON-NLS-1$
+
+ /**
+ * keep going option
+ */
+ private static final String STOP_ON_ERROR_OPTION = "--stopOnError"; //$NON-NLS-1$
+ private static final String STOP_ON_ERROR_OPTION_SF = "-soe"; //$NON-NLS-1$
+ /**
+ * keep going option instruction text
+ */
+ private static final String STOP_ON_ERROR_OPTION_INSTRUCTION_TEXT = "On error, stop at the end of the compilation unit."; //$NON-NLS-1$
+
+
+
+ /**
+ * Version text
+ */
+ private static final String VERSION_TEXT = "TraceCompiler version "; //$NON-NLS-1$
+
+ /**
+ * Option instruction text
+ */
+ private static final String OPTION_INSTRUCTION_TEXT = "Options:"; //$NON-NLS-1$
+
+
+ private static final String USAGE = "Usage: " + LINE_SEPARATOR + //$NON-NLS-1$
+ "tracecompiler [options] Component_UID [Component_name MMP_path source_file...]" + LINE_SEPARATOR + //$NON-NLS-1$
+ "\t" + OPTION_INSTRUCTION_TEXT + LINE_SEPARATOR + //$NON-NLS-1$
+ "\t" + HELP_OPTION_SF + ", " + HELP_OPTION + ", " + HELP_OPTION_INSTRUCTION_TEXT + LINE_SEPARATOR + //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
+ "\t" + VERSION_OPTION_SF + ", " + VERSION_OPTION + ", " + LEGACY_VERSION_OPTION + "\t" + VERSION_OPTION_INSTRUCTION_TEXT + LINE_SEPARATOR + //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$
+ "\t" + VERBOSE_OPTION_SF + ", " + VERBOSE_OPTION + "\t\t" + VERBOSE_OPTION_INSTRUCTION_TEXT + LINE_SEPARATOR + //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ "\t" + STOP_ON_ERROR_OPTION_SF + ", " + STOP_ON_ERROR_OPTION + "\t" + STOP_ON_ERROR_OPTION_INSTRUCTION_TEXT + LINE_SEPARATOR; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+
+
+
+ /**
+ * End of source files tag
+ */
+ private static final String ENDOFSOURCEFILES = "*ENDOFSOURCEFILES*"; //$NON-NLS-1$
+
+
+ /**
+ * Offset to UID
+ */
+ private static final int COMPONENT_UID_ARG = 0;
+
+ /**
+ * Offset to component name
+ */
+ private static final int COMPONENT_NAME_ARG = 1;
+
+ /**
+ * Offset to MMP path
+ */
+ private static final int COMPONENT_MMP_PATH_ARG = 2; // CodForChk_Dis_Magic
+
+ /**
+ * Offset to source files
+ */
+ private static final int SOURCE_FILE_START_OFFSET = 3; // CodForChk_Dis_Magic
+
+ /**
+ * Number of arguments
+ */
+ private static final int MANDATORY_ARGUMENT_COUNT = 1;
+
+ /**
+ * MMP file extension
+ */
+ private static final String MMP = ".mmp"; //$NON-NLS-1$
+
+ /**
+ * Underscore character
+ */
+ private static final String UNDERSCORE = "_"; //$NON-NLS-1$
+
+ /**
+ * Name of the trace folder that include component name
+ */
+ private String traceFolderName;
+
+ /**
+ * Decode plugins path
+ */
+ private String DECODE_PLUGINS_PATH = "com/nokia/tracecompiler/decodeplugins"; //$NON-NLS-1$
+
+ /**
+ * Decode plugin name tag
+ */
+ private String DECODE_PLUGIN_NAME_TAG = ""; //$NON-NLS-1$
+
+ /**
+ * Decode plugin class name tag
+ */
+ private String DECODE_PLUGIN_CLASS_NAME_TAG = ""; //$NON-NLS-1$
+
+ /**
+ * Decode plugin engine class name template
+ */
+ private String ENGINE_CLASS_NAME_TEMPLATE = DECODE_PLUGIN_NAME_TAG
+ + "Engine"; //$NON-NLS-1$
+
+ /**
+ * Decode plugin engine file name template
+ */
+ private String ENGINE_FILE_NAME_TEMPLATE = DECODE_PLUGIN_CLASS_NAME_TAG
+ + ".class"; //$NON-NLS-1$
+
+ /**
+ * Decode plugins class template
+ */
+ private String CLASS_TEMPLATE = "com.nokia.tracecompiler.decodeplugins." + DECODE_PLUGIN_NAME_TAG + "." + DECODE_PLUGIN_CLASS_NAME_TAG; //$NON-NLS-1$ //$NON-NLS-2$
+
+ /**
+ * Main function
+ *
+ * @param args
+ * the command line arguments
+ */
+ public static void main(String[] args) {
+ ArrayList list = new ArrayList(Arrays.asList(args));
+ long startTime = System.currentTimeMillis();
+ //create a new session of TraceCompiler
+ TraceCompiler console = new TraceCompiler();
+
+ try {
+ console.parseCommandLine(list);
+ } catch (Exception e) { //should cover IOException and TraceCompilerIllegalArgumentsException
+ //There is no point to continue if there are problems with the arguments.
+ TraceCompilerLogger.printError(e.getMessage());
+ printUsage();
+ System.exit(1);
+ }
+
+ boolean error = false;
+ try {
+ if(list.size() != 0) {
+ console.createPlugins();
+ console.start();
+ console.buildTraceFiles();
+
+ }
+ } catch (Exception e) {
+ if (e instanceof TraceCompilerRootException) {
+ TraceCompilerLogger.printError(e.getMessage());
+ } //else the error should have been reported earlier
+ error = true;
+ } finally {
+ try {
+ if (!error) { //check if errors have been logged by EventEngine
+ TraceCompilerEngineEvents events = TraceCompilerEngineGlobals.getEvents();
+ if (events != null && events.hasErrorHappened()) {
+ error = true;
+ }
+ }
+ console.shutdown();
+ } catch (TraceCompilerException e) {
+ error = true;
+ }
+ }
+
+ if (console.componentName != null) {
+ TraceCompilerLogger.printMessage(console.componentName + " took " //$NON-NLS-1$
+ + (System.currentTimeMillis() - startTime) + " ms"); //$NON-NLS-1$
+ }
+ if (error) {
+ System.exit(1);
+ } else {
+ System.exit(0);
+ }
+ }
+
+ /**
+ * With Eclipse, the plug-ins are loaded by Eclipse framework. Here they
+ * must be manually created and started
+ */
+ private ArrayList plugIns = new ArrayList();
+
+ /**
+ * Model listener
+ */
+ private TraceCompilerModelListener modelListener;
+
+ /**
+ * Name of the component
+ */
+ private String componentName;
+
+ /**
+ * UID of the component
+ */
+ private long componentUID;
+
+ /**
+ * Component path
+ */
+ private String componentPath;
+
+ /**
+ * MMP file path
+ */
+ private File mmpPath;
+
+ /**
+ * Constructor
+ */
+ TraceCompiler() {
+
+ // Creates listeners and preferences
+ modelListener = new TraceCompilerModelListener();
+ }
+
+ /**
+ * Creates the plug-ins to be registered with TraceCompiler
+ * @throws TraceCompilerRootException if fail to create a valid plugins
+ */
+ private void createPlugins() throws TraceCompilerRootException {
+
+ // Get location of the TraceCompiler
+ URL path = getClass().getProtectionDomain().getCodeSource()
+ .getLocation();
+ String decodePluginsPath = path.getPath();
+
+ // If first character is forward slash and it is located before drive
+ // letter remove it
+ if (decodePluginsPath.charAt(INDEX_OF_FIRST_CHARACTER) == SourceConstants.FORWARD_SLASH_CHAR
+ && decodePluginsPath.charAt(INDEX_OF_THIRD_CHARACTER) == SourceConstants.COLON_CHAR) {
+ decodePluginsPath = decodePluginsPath.substring(1);
+ }
+
+ // Concatenate decode plugins path
+ decodePluginsPath = decodePluginsPath.concat(DECODE_PLUGINS_PATH);
+
+ // Replace slashes with correct separator character
+ decodePluginsPath = decodePluginsPath.replace(
+ SourceConstants.FORWARD_SLASH_CHAR, File.separatorChar);
+ decodePluginsPath = decodePluginsPath.replace(
+ SourceConstants.BACKSLASH_CHAR, File.separatorChar);
+ File decodePluginsDir = new File(decodePluginsPath);
+ String[] decodePlugins = decodePluginsDir.list();
+ if (decodePlugins != null) {
+ for (int i = 0; i < decodePlugins.length; i++) {
+
+ // Get decode plugin name
+ String decodePluginName = decodePlugins[i];
+
+ // Get decode plugin path
+ String decodePluginPath = decodePluginsPath
+ + File.separatorChar + decodePluginName;
+
+ // Decode plugin must be in own directory
+ Boolean isDirectory = (new File(decodePluginPath))
+ .isDirectory();
+ if (isDirectory) {
+
+ // Construct decode plugin engine class name
+ String engineClassName = ENGINE_CLASS_NAME_TEMPLATE
+ .replaceFirst(DECODE_PLUGIN_NAME_TAG,
+ decodePluginName.substring(0, 1)
+ .toUpperCase()
+ + decodePluginName.substring(1));
+
+ // Construct decode plugin engine file name
+ String engineFileName = ENGINE_FILE_NAME_TEMPLATE
+ .replaceFirst(DECODE_PLUGIN_CLASS_NAME_TAG,
+ engineClassName);
+ String engineFileFullName = decodePluginPath
+ + File.separatorChar + engineFileName;
+
+ // Check does engine file exist
+ Boolean exists = (new File(engineFileFullName)).exists();
+ if (exists) {
+ String engineClassFullName = CLASS_TEMPLATE
+ .replaceFirst(DECODE_PLUGIN_NAME_TAG,
+ decodePluginName).replaceFirst(
+ DECODE_PLUGIN_CLASS_NAME_TAG,
+ engineClassName);
+ try {
+ Class> engineClass = Class
+ .forName(engineClassFullName);
+ TraceCompilerPlugin engine = (TraceCompilerPlugin) engineClass
+ .newInstance();
+ plugIns.add(engine);
+ TraceCompilerLogger.printInfo("Decode plugin " + engineClassFullName + " added"); //$NON-NLS-1$ //$NON-NLS-2$
+ } catch (Exception e) {
+ String msg = "Decode plugin " + engineClassFullName + " adding failed"; //$NON-NLS-1$ //$NON-NLS-2$
+ throw new TraceCompilerRootException(msg, e);
+ }
+ } else {
+ String msg = "Decode plugin file " + engineFileFullName + " does not exist"; //$NON-NLS-1$ //$NON-NLS-2$
+ throw new TraceCompilerRootException(msg, null);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Parses the command line
+ *
+ * @param args
+ * the arguments
+ * @throws TraceCompilerRootException if arguments are invalid
+ * @throws IOException
+ */
+ private void parseCommandLine(ArrayList list) throws TraceCompilerIllegalArgumentsException, IOException {
+ TraceCompilerLogger.printInfo("Building traces..."); //$NON-NLS-1$
+ if (list.size() == 0) {
+ printUsage();
+ System.exit(0);
+ }
+ List switches = new ArrayList();
+
+ // version, verbose, keepgoing if available could be anywhere, so process them and remove them from the list
+ for (String element : list) {
+ if (element.equalsIgnoreCase(HELP_OPTION) || element.equalsIgnoreCase(HELP_OPTION_SF)) {
+ printUsage();
+ System.exit(0);
+ }
+ if (element.equalsIgnoreCase(VERBOSE_OPTION) || element.equalsIgnoreCase(VERBOSE_OPTION_SF)) {
+ TraceCompilerGlobals.setVerbose(true);
+ switches.add(element);
+ }
+ if (element.equalsIgnoreCase(LEGACY_VERSION_OPTION) || element.equalsIgnoreCase(VERSION_OPTION) || element.equalsIgnoreCase(VERSION_OPTION_SF)) {
+ TraceCompilerLogger.printMessage(VERSION_TEXT + TraceCompilerVersion.getVersion());
+ System.exit(0);
+ }
+ if (element.equalsIgnoreCase(STOP_ON_ERROR_OPTION) || element.equalsIgnoreCase(STOP_ON_ERROR_OPTION_SF)) {
+ TraceCompilerGlobals.setKeepGoing(false);
+ switches.add(element);
+ }
+ }
+
+ //remove switches from the list
+ for (String string : switches) {
+ list.remove(string);
+ }
+
+ switches = null;
+
+ if (list.size() < MANDATORY_ARGUMENT_COUNT) {
+ throw new TraceCompilerIllegalArgumentsException(Messages.getString("TraceCompiler.invalidTraceCompilerArgumetsExceptionText"), null); //$NON-NLS-1$
+ }
+
+
+ //the rest of elements must be in the order COMPONENT_UID, COMPONENT_NAME, COMPONENT_MMP_PATH, source...
+ //COMPONENT_UID must be on the command line, the rest can either be on the command line or stdin
+
+ try {
+ componentUID = Long.parseLong(list.get(COMPONENT_UID_ARG),
+ TraceCompilerConstants.HEX_RADIX);
+ TraceCompilerLogger.printInfo("Component UID: 0x" + Long.toHexString(componentUID)); //$NON-NLS-1$
+
+ } catch (NumberFormatException e) {
+ String msg = Messages.getString("TraceCompiler.componentUidIsNotValidExceptionText") + componentUID; //$NON-NLS-1$
+ throw new TraceCompilerIllegalArgumentsException(msg, null);
+ }
+ if (componentUID > 0) {
+
+ // Arguments are given as a parameter
+ if (list.size() > MANDATORY_ARGUMENT_COUNT + 1) {
+ parseParameters(list);
+
+ // Otherwise, read arguments from STDIN
+ } else {
+ readFromStdin();
+ }
+ } else {
+ String msg = Messages.getString("TraceCompiler.componentUidIsNotValidExceptionText") + componentUID; //$NON-NLS-1$
+ throw new TraceCompilerIllegalArgumentsException(msg, null);
+ }
+ }
+
+
+ private static void printUsage() {
+ TraceCompilerLogger.printMessage(VERSION_TEXT + TraceCompilerVersion.getVersion());
+ TraceCompilerLogger.printMessage(USAGE);
+ }
+
+ /**
+ * Parses parameters
+ *
+ * @param args
+ * the parameters
+ * @throws TraceCompilerRootException if arguments are not valid
+ */
+ private void parseParameters(List args) throws TraceCompilerIllegalArgumentsException {
+ //index is safe, already checked by the caller
+ componentName = args.get(COMPONENT_NAME_ARG);
+ traceFolderName = TraceCompilerConstants.TRACES_DIRECTORY + UNDERSCORE
+ + componentName;
+
+ mmpPath = new File(args.get(COMPONENT_MMP_PATH_ARG));
+
+ if (isMmpValid()) {
+
+ // Move the files from args array to source file list
+ ArrayList sources = new ArrayList();
+ for (int i = 0; i < args.size() - SOURCE_FILE_START_OFFSET; i++) {
+ sources.add(args.get(SOURCE_FILE_START_OFFSET + i));
+ }
+
+ registerFiles(sources);
+ } else {
+ throw new TraceCompilerIllegalArgumentsException(Messages.getString("TraceCompiler.invalidMmpExceptionText") + mmpPath, null); //$NON-NLS-1$
+ }
+
+ }
+
+ /**
+ * Read information from STDIN
+ * @throws IOException if fails to read the input
+ * @throws TraceCompilerRootException if the list of files is empty
+ */
+ private void readFromStdin() throws IOException, TraceCompilerIllegalArgumentsException {
+ ArrayList files = new ArrayList();
+
+ // Create reader
+ BufferedReader stdin = new BufferedReader(
+ new InputStreamReader(System.in));
+
+ int numberOfReceivedLines = 1;
+
+ String line = stdin.readLine();
+
+ while (line != null) {
+
+ // End of source files received
+ if (line.equals(ENDOFSOURCEFILES)) {
+ break;
+ }
+
+ // Component name
+ if (numberOfReceivedLines == COMPONENT_NAME_ARG) {
+ componentName = line;
+ traceFolderName = TraceCompilerConstants.TRACES_DIRECTORY
+ + UNDERSCORE + componentName;
+
+ // MMP path
+ } else if (numberOfReceivedLines == COMPONENT_MMP_PATH_ARG) {
+ mmpPath = new File(line);
+ if (!isMmpValid()) {
+ stdin.close();
+ throw new TraceCompilerIllegalArgumentsException(Messages.getString("TraceCompiler.invalidMmpExceptionText") + mmpPath, null); //$NON-NLS-1$
+ }
+
+ // Source files
+ } else {
+ // Add to the files list
+ File file = new File(line);
+ files.add(file.getAbsolutePath());
+ }
+
+ numberOfReceivedLines++;
+
+ // Read new line from STDIN
+ line = stdin.readLine();
+ }
+ stdin.close();
+ registerFiles(files);
+ }
+
+ /**
+ * Registers files to document monitor.
+ *
+ * @param sources
+ * sources
+ * @throws TraceCompilerRootException
+ */
+ private void registerFiles(ArrayList sources) throws TraceCompilerIllegalArgumentsException {
+
+ if (sources.size() == 0) {
+ throw new TraceCompilerIllegalArgumentsException(Messages.getString("TraceCompiler.noSourceFilesExceptionText"), null); //$NON-NLS-1$
+ }
+ File parent = mmpPath.getParentFile();
+ boolean found = false;
+
+ componentPath = parent.getAbsolutePath();
+
+ ProjectEngine.traceFolderName = TraceCompilerConstants.TRACES_DIRECTORY;
+
+ // Find location of "traces" or "traces_" -folder. If
+ // "traces" or "traces_" -folder does not
+ // exist, "traces" -folder will be add to same level than "group" or
+ // "mmpfiles" -folder. If "group" or "mmpfiles" -folder does not exist
+ // then "traces" -folder will be added to same level than source file.
+ while (!found && parent != null) {
+ File[] children = parent.listFiles();
+ if (children != null) {
+ for (int i = 0; i < children.length; i++) {
+ File child = children[i];
+ String childName = child.getName();
+ if (child.isDirectory() && isProjectRoot(childName)) {
+ componentPath = parent.getAbsolutePath();
+ found = true;
+
+ // Check that does subdirectory that name is
+ // "traces_" exist in this directory. If
+ // it exist use that as traces directory name.
+ for (i = 0; i < children.length; i++) {
+ child = children[i];
+ childName = child.getName();
+ if (child.isDirectory()
+ && childName
+ .equalsIgnoreCase(traceFolderName)) {
+ ProjectEngine.traceFolderName = traceFolderName;
+ break;
+ }
+ }
+ break;
+ }
+ }
+ }
+
+ if (found == false) {
+ parent = parent.getParentFile();
+ }
+ }
+
+ registerSourceFiles(sources);
+ }
+
+ /**
+ * Checks if this folder is the project root
+ *
+ * @param name
+ * name of the folder
+ * @return true if this folder is the project root
+ */
+ private boolean isProjectRoot(String name) {
+ boolean retval = false;
+ if (name.equalsIgnoreCase(traceFolderName)
+ || name.equalsIgnoreCase(SymbianConstants.GROUP_DIRECTORY)
+ || name.equalsIgnoreCase(SymbianConstants.MMPFILES_DIRECTORY)
+ || name
+ .equalsIgnoreCase(TraceCompilerConstants.TRACES_DIRECTORY)) {
+ retval = true;
+ }
+ return retval;
+ }
+
+ /**
+ * Registers source files
+ *
+ * @param files
+ */
+ private void registerSourceFiles(ArrayList files) {
+ if (files.size() > 0) {
+ String[] fileArr = new String[files.size()];
+ files.toArray(fileArr);
+
+ // Sets the source files to the TraceCompiler document
+ // factory. It will create a document from each source in the array
+ FileDocumentMonitor.setFiles(fileArr);
+ DocumentFactory.registerDocumentFramework(
+ new FileDocumentMonitor(), StringDocumentFactory.class);
+ }
+ }
+
+ /**
+ * Initializes TraceCompiler
+ * @throws TraceCompilerRootException if fail to initialize the plugins
+ * @throws TraceCompilerException
+ */
+ private void start() throws TraceCompilerRootException, TraceCompilerException {
+
+ // Starts TraceCompiler. This is normally called from the Eclipse
+ // plug-in
+ // activator, but in console case that does not exist
+ TraceCompilerEngineGlobals.start();
+
+
+ //Reads the GroupId values from opensystemtrace_types.h
+ //If this fails a message is logged and trace compiler stops
+ GroupNames.initialiseGroupName();
+
+
+ // Registers a view to TraceCompiler
+ TraceCompilerEngineGlobals
+ .setView(new TraceCompilerView(componentPath));
+
+ // Registers all plug-in components
+ for (TraceCompilerPlugin plugin : plugIns) {
+ TraceCompilerEngineGlobals.registerPlugin(plugin);
+ }
+ // Adds a model event listener
+ TraceCompilerEngineGlobals.getTraceModel().addModelListener(
+ modelListener);
+ TraceCompilerEngineGlobals.getTraceModel().addExtensionListener(
+ modelListener);
+ TraceCompilerEngineGlobals.getTraceModel().getExtension(
+ TraceLocationList.class).addLocationListListener(modelListener);
+ TraceCompilerEngineGlobals.getTraceModel().addProcessingListener(modelListener);
+ }
+
+ /**
+ * Parses the sources and generates trace files
+ * @throws Exception
+ */
+ private void buildTraceFiles() throws Exception {
+ TraceCompilerEngineInterface tbi = TraceCompilerEngineGlobals
+ .getTraceCompiler();
+ try {
+ // Opens a trace project
+ componentName = TraceUtils.convertName(componentName);
+
+ // Set project path before opening project
+ TraceCompilerEngineGlobals.setProjectPath(componentPath);
+ tbi.openProject(componentName);
+ TraceModel model = TraceCompilerEngineGlobals.getTraceModel();
+ if (model.isValid()) {
+ model.setID((int) componentUID);
+
+ // Location errors are printed after a file changes, but the
+ // last file is not detected by the listener
+ if (modelListener.getErrors().size() > 0) {
+ modelListener.printLocationErrors();
+ tbi.closeProject();
+ throw new TraceCompilerRootException(null, null);
+ }
+ tbi.exportProject();
+ tbi.closeProject();
+ } else {
+ String msg = "Project creation was cancelled"; //$NON-NLS-1$
+ throw new TraceCompilerRootException(msg, null);
+ }
+ } catch (TraceCompilerException e) {
+ TraceCompilerEngineGlobals.getEvents().postError(e);
+ throw new TraceCompilerRootException("Build trace files failed.", e); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Shuts down TraceCompiler
+ * @throws TraceCompilerException
+ */
+ private void shutdown() throws TraceCompilerException {
+ for (TraceCompilerPlugin plugin : plugIns) {
+ TraceCompilerEngineGlobals.unregisterPlugin(plugin);
+ }
+ TraceCompilerEngineGlobals.shutdown();
+ }
+
+ /**
+ * Checks if the MMP file is valid
+ *
+ * @return true if MMP file is valid
+ */
+ private boolean isMmpValid() {
+ boolean valid = false;
+ String pathStr = mmpPath.getAbsolutePath();
+
+ if (mmpPath.exists() && pathStr.length() > MMP.length()) {
+ String end = pathStr.substring(pathStr.length() - MMP.length());
+ if (end.equalsIgnoreCase(MMP)) {
+ valid = true;
+ } else {
+ TraceCompilerLogger.printError("Invalid MMP file: " + mmpPath.getAbsolutePath()); //$NON-NLS-1$
+ }
+ } else {
+ TraceCompilerLogger.printError("Missing or can not access MMP path: " + mmpPath.getAbsolutePath()); //$NON-NLS-1$
+ }
+ return valid;
+
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/TraceCompilerConfiguration.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/TraceCompilerConfiguration.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,153 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Configuration for the console UI
+*
+*/
+package com.nokia.tracecompiler;
+
+import com.nokia.tracecompiler.engine.TraceCompilerEngineConfiguration;
+import com.nokia.tracecompiler.engine.TraceCompilerEngineConfigurationListener;
+
+/**
+ * Configuration for the TraceCompiler UI
+ *
+ */
+final class TraceCompilerConfiguration implements TraceCompilerEngineConfiguration {
+
+ /**
+ * Export path
+ */
+ private String exportPath;
+
+ /**
+ * Constructor
+ *
+ * @param exportPath
+ * the export path for decode files
+ */
+ TraceCompilerConfiguration(String exportPath) {
+ this.exportPath = exportPath;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.TraceCompilerConfiguration#
+ * addConfigurationListener(com.nokia.tracecompiler.engine.TraceCompilerConfigurationListener)
+ */
+ public void addConfigurationListener(
+ TraceCompilerEngineConfigurationListener configurationListener) {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.TraceCompilerConfiguration#
+ * getFlag(java.lang.String)
+ */
+ public boolean getFlag(String flagName) {
+ boolean retval;
+ if (flagName.equals(TraceCompilerEngineConfiguration.CONSOLE_UI_MODE)) {
+ retval = true;
+ } else {
+ retval = false;
+ }
+ return retval;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.TraceCompilerConfiguration#
+ * getText(java.lang.String)
+ */
+ public String getText(String textName) {
+ String retval;
+ if (textName.equals(TraceCompilerEngineConfiguration.ENVIRONMENT_ROOT)) {
+ retval = exportPath;
+ } else {
+ retval = ""; //$NON-NLS-1$
+ }
+ return retval;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.TraceCompilerConfiguration#
+ * getValue(java.lang.String)
+ */
+ public int getValue(String valueName) {
+ return 0;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.TraceCompilerConfiguration#
+ * hasEntry(java.lang.String)
+ */
+ public boolean hasEntry(String entryName) {
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.TraceCompilerConfiguration#isAvailable()
+ */
+ public boolean isAvailable() {
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.TraceCompilerConfiguration#
+ * removeConfigurationListener(com.nokia.tracecompiler.engine.TraceCompilerConfigurationListener)
+ */
+ public void removeConfigurationListener(
+ TraceCompilerEngineConfigurationListener configurationListener) {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.TraceCompilerConfiguration#setFlag(java.lang.String,
+ * boolean)
+ */
+ public void setFlag(String flagName, boolean flag) {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.TraceCompilerConfiguration#setText(java.lang.String,
+ * java.lang.String)
+ */
+ public void setText(String textName, String text) {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.TraceCompilerConfiguration#setValue(java.lang.String,
+ * int)
+ */
+ public void setValue(String valueName, int value) {
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/TraceCompilerConstants.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/TraceCompilerConstants.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,43 @@
+/*
+* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Constants for console UI
+*
+*/
+package com.nokia.tracecompiler;
+
+
+/**
+ * Constants for TraceCompiler UI
+ *
+ */
+public interface TraceCompilerConstants {
+
+ /**
+ * Default UID if component does not have one
+ */
+ int DEFAULT_UID = 0x0;
+
+ /**
+ * Traces directory
+ */
+ String TRACES_DIRECTORY = "traces"; //$NON-NLS-1$
+
+ /**
+ * Radix for hex numbers
+ */
+ int HEX_RADIX = 16; // CodForChk_Dis_Magic
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/TraceCompilerGlobals.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/TraceCompilerGlobals.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ *
+ * Description:
+ *
+ * TraceCompilerGlobals global constants
+ *
+ */
+package com.nokia.tracecompiler;
+
+/**
+ * TraceCompiler Global constants
+ *
+ */
+public class TraceCompilerGlobals {
+
+ /**
+ * Verbose output. Verbose is usually checked to print Infos
+ */
+ private static boolean VERBOSE = false;
+
+ /**
+ * KepGoing is used to decide whether we continue processing on errors
+ */
+ private static boolean KEEPGOING = true;
+
+ //disallow instances
+ private TraceCompilerGlobals() {
+ // singleton
+ }
+
+ /**
+ * set verbose mode
+ * @param verbose
+ */
+ public static void setVerbose(boolean verbose) {
+ VERBOSE = verbose;
+ }
+
+ /**
+ * is vebose mode on/off
+ * @return boolean
+ */
+ public static boolean isVebose() {
+ return VERBOSE;
+ }
+
+ /**
+ * set keep going mode
+ * @param keepgoing
+ */
+ public static void setKeepGoing(boolean keepgoing) {
+ KEEPGOING = keepgoing;
+ }
+
+ /**
+ * is keepgoing mode on/off
+ * @return boolean
+ */
+ public static boolean keepGoing() {
+ return KEEPGOING;
+ }
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/TraceCompilerIllegalArgumentsException.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/TraceCompilerIllegalArgumentsException.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ *
+ * Description:
+ *
+ * TraceCompilerIllegalArgumentsException thrown when tracecompiler can not process its arguments
+ *
+ */
+package com.nokia.tracecompiler;
+
+/**
+ * TraceCompilerIllegalArgumentsException thrown when tracecompiler can not process its arguments
+ *
+ */
+public class TraceCompilerIllegalArgumentsException extends TraceCompilerRootException {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1387782275931306398L;
+
+ public TraceCompilerIllegalArgumentsException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/TraceCompilerLogger.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/TraceCompilerLogger.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ *
+ * Description:
+ *
+ * Simple Logger
+ *
+ */
+package com.nokia.tracecompiler;
+
+
+
+/**
+ * Simple logger for errors warnings and infos
+ *
+ */
+public class TraceCompilerLogger {
+
+ /**
+ * Prints errors message to STDERR.
+ *
+ * @param msg
+ * the message
+ */
+ static public void printError(String msg) {
+ if (msg != null) {
+ System.err.println(Messages.getString("TraceCompilerLogger.errorPrefix") + msg); //$NON-NLS-1$
+ System.err.flush();
+ }
+ }
+
+ /**
+ * Prints warning message to STDERR.
+ * @param msg
+ */
+ static public void printWarning(String msg) {
+ System.err.println(Messages.getString("TraceCompilerLogger.warningPrefix") + msg); //$NON-NLS-1$
+ System.err.flush();
+ }
+
+ /**
+ * Prints warning message to STDOUT if verbose is on.
+ * @param msg
+ */
+ static public void printInfo(String msg) {
+ if (TraceCompilerGlobals.isVebose()) {
+ System.out.println(Messages.getString("TraceCompilerLogger.infoPrefix") + msg); //$NON-NLS-1$
+ System.out.flush();
+ }
+ }
+
+ /**
+ * Prints warning message to STDOUT.
+ * @param msg
+ */
+ static public void printMessage(String msg) {
+ System.out.println(msg);
+ System.out.flush();
+ }
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/TraceCompilerMain.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/TraceCompilerMain.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,766 @@
+/*
+ * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ *
+ * Description:
+ *
+ * TraceCompiler command-line main class
+ *
+ */
+package com.nokia.tracecompiler;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import com.nokia.tracecompiler.document.FileDocumentMonitor;
+import com.nokia.tracecompiler.document.StringDocumentFactory;
+import com.nokia.tracecompiler.engine.TraceCompilerEngineEvents;
+import com.nokia.tracecompiler.engine.TraceCompilerEngineGlobals;
+import com.nokia.tracecompiler.engine.TraceCompilerEngineInterface;
+import com.nokia.tracecompiler.engine.TraceLocationList;
+import com.nokia.tracecompiler.engine.project.ProjectEngine;
+import com.nokia.tracecompiler.file.FileUtils;
+import com.nokia.tracecompiler.model.TraceCompilerException;
+import com.nokia.tracecompiler.model.TraceModel;
+import com.nokia.tracecompiler.plugin.TraceCompilerPlugin;
+import com.nokia.tracecompiler.project.GroupNames;
+import com.nokia.tracecompiler.source.SourceConstants;
+import com.nokia.tracecompiler.utils.DocumentFactory;
+import com.nokia.tracecompiler.utils.TraceCompilerVersion;
+
+/**
+ * TraceCompiler command-line main class
+ *
+ */
+public class TraceCompilerMain {
+
+ /** line separator */
+ private static String LINE_SEPARATOR = System.getProperty("line.separator"); //$NON-NLS-1$
+
+ /**
+ * Index of third character
+ */
+ private static final int INDEX_OF_THIRD_CHARACTER = 2;
+
+ /**
+ * Index of first character
+ */
+ private static final int INDEX_OF_FIRST_CHARACTER = 0;
+
+ /**
+ * TraceCompiler options
+ */
+
+ /**
+ * UID : it is used to create the dictionary file
+ */
+ private static final String UID_SWITCH = Messages.getString("TraceCompiler.UidStwich"); //$NON-NLS-1$
+ private static final String UID_SWITCH_TEXT = Messages.getString("TraceCompiler.UidText"); //$NON-NLS-1$
+ /**
+ * project name : it is used to create the dictionary file
+ */
+ private static final String PRJ_NAME_SWITCH = Messages.getString("TraceCompiler.ProjectSwitch");//$NON-NLS-1$
+ private static final String PRJ_NAME_SWITCH_TEXT = Messages.getString("TraceCompiler.ProjectText"); //$NON-NLS-1$
+ /**
+ * mmp file path: may be used to compute the traces folder
+ */
+ private static final String MMP_PATH_SWITCH = Messages.getString("TraceCompiler.MmpSwitch");//$NON-NLS-1$
+ private static final String MMP_PATH_SWITCH_TEXT = Messages.getString("TraceCompiler.MmpText"); //$NON-NLS-1$
+ /**
+ * traces folder: absolute or relative to the mmp folder
+ */
+ private static final String TRACES_PATH_SWITCH = Messages.getString("TraceCompiler.TracesSwitch");//$NON-NLS-1$
+ private static final String TRACES_PATH_SWITCH_TEXT = Messages.getString("TraceCompiler.TracesText"); //$NON-NLS-1$
+
+
+ /**
+ * Version option
+ */
+ private static final String VERSION_OPTION = Messages.getString("TraceCompiler.VersionSwitchLong"); //$NON-NLS-1$
+ private static final String VERSION_OPTION_SF = Messages.getString("TraceCompiler.VersionSwitchShort"); //$NON-NLS-1$
+ private static final String VERSION_OPTION_INSTRUCTION_TEXT = Messages.getString("TraceCompiler.VersionText"); //$NON-NLS-1$
+
+
+ /**
+ * help option
+ */
+ private static final String HELP_OPTION = Messages.getString("TraceCompiler.HelpSwicthLong"); //$NON-NLS-1$
+ private static final String HELP_OPTION_SF = Messages.getString("TraceCompiler.HelpSwitchShort"); //$NON-NLS-1$
+ private static final String HELP_OPTION_INSTRUCTION_TEXT = Messages.getString("TraceCompiler.HelpText"); //$NON-NLS-1$
+
+ /**
+ * Verbose option
+ */
+ private static final String VERBOSE_OPTION = Messages.getString("TraceCompiler.VerboseSwitchLong"); //$NON-NLS-1$
+ private static final String VERBOSE_OPTION_SF = Messages.getString("TraceCompiler.VerboseSwitchShort"); //$NON-NLS-1$
+ private static final String VERBOSE_OPTION_INSTRUCTION_TEXT = Messages.getString("TraceCompiler.VerboseText"); //$NON-NLS-1$
+
+ /**
+ * keep going option
+ */
+ private static final String STOP_ON_ERROR_OPTION = Messages.getString("TraceCompiler.StopSwitchLong"); //$NON-NLS-1$
+ private static final String STOP_ON_ERROR_OPTION_SF = Messages.getString("TraceCompiler.StopSwitchShort"); //$NON-NLS-1$
+ private static final String STOP_ON_ERROR_OPTION_INSTRUCTION_TEXT = Messages.getString("TraceCompiler.StopText"); //$NON-NLS-1$
+
+
+
+ /**
+ * Version text
+ */
+ private static final String VERSION_TEXT = Messages.getString("TraceCompiler.DisplayVersionText"); //$NON-NLS-1$
+
+ /**
+ * Option instruction text
+ */
+ private static final String OPTION_INSTRUCTION_TEXT = Messages.getString("TraceCompiler.Options"); //$NON-NLS-1$
+ private static final String VALUE=Messages.getString("TraceCompiler.Value"); //$NON-NLS-1$
+
+
+
+ private static final String USAGE = Messages.getString("TraceCompiler.Usage") + LINE_SEPARATOR + //$NON-NLS-1$
+ Messages.getString("TraceCompiler.UsageText") + LINE_SEPARATOR + //$NON-NLS-1$
+ "\t" + OPTION_INSTRUCTION_TEXT + LINE_SEPARATOR + //$NON-NLS-1$
+ "\t" + HELP_OPTION_SF + ", " + HELP_OPTION + ", " + HELP_OPTION_INSTRUCTION_TEXT + LINE_SEPARATOR + //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
+ "\t" + VERSION_OPTION_SF + ", " + VERSION_OPTION + "\t" + VERSION_OPTION_INSTRUCTION_TEXT + LINE_SEPARATOR + //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
+ "\t" + VERBOSE_OPTION_SF + ", " + VERBOSE_OPTION + "\t\t" + VERBOSE_OPTION_INSTRUCTION_TEXT + LINE_SEPARATOR + //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ "\t" + STOP_ON_ERROR_OPTION_SF + ", " + STOP_ON_ERROR_OPTION + "\t" + STOP_ON_ERROR_OPTION_INSTRUCTION_TEXT + LINE_SEPARATOR + //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ "\t" + UID_SWITCH + "=" + VALUE + "\t" + UID_SWITCH_TEXT + LINE_SEPARATOR + //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
+ "\t" + PRJ_NAME_SWITCH + "=" + VALUE + "\t" + PRJ_NAME_SWITCH_TEXT + LINE_SEPARATOR + //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
+ "\t" + MMP_PATH_SWITCH + "=" + VALUE + "\t" + MMP_PATH_SWITCH_TEXT + LINE_SEPARATOR + //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
+ "\t" + TRACES_PATH_SWITCH + "=" + VALUE + "\t" + TRACES_PATH_SWITCH_TEXT; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
+
+
+
+ /**
+ * End of source files tag
+ */
+ private static final String ENDOFSOURCEFILES = Messages.getString("TraceCompiler.EndOfList"); //$NON-NLS-1$
+
+ /**
+ * MMP file extension
+ */
+ private static final String MMP_FILE_TYPE = Messages.getString("TraceCompiler.MmpExtension"); //$NON-NLS-1$
+
+ /**
+ * Decode plugins path
+ */
+ private String DECODE_PLUGINS_PATH = Messages.getString("TraceCompiler.PluginPath"); //$NON-NLS-1$
+
+ /**
+ * Decode plugin name tag
+ */
+ private String DECODE_PLUGIN_NAME_TAG = Messages.getString("TraceCompiler.DecodeText1"); //$NON-NLS-1$
+
+ /**
+ * Decode plugin class name tag
+ */
+ private String DECODE_PLUGIN_CLASS_NAME_TAG = Messages.getString("TraceCompiler.DecodeText2"); //$NON-NLS-1$
+
+ /**
+ * Decode plugin engine class name template
+ */
+ private String ENGINE_CLASS_NAME_TEMPLATE = DECODE_PLUGIN_NAME_TAG
+ + "Engine"; //$NON-NLS-1$
+
+ /**
+ * Decode plugin engine file name template
+ */
+ private String ENGINE_FILE_NAME_TEMPLATE = DECODE_PLUGIN_CLASS_NAME_TAG
+ + ".class"; //$NON-NLS-1$
+
+ /**
+ * Decode plugins class template
+ */
+ private String CLASS_TEMPLATE = Messages.getString("TraceCompiler.DecodePluginsNameSpace") + DECODE_PLUGIN_NAME_TAG + "." + DECODE_PLUGIN_CLASS_NAME_TAG; //$NON-NLS-1$ //$NON-NLS-2$
+
+ //switch with value such as --uid=value
+ private Pattern valueSwitchPattern = Pattern.compile("(--\\S+)=(\\S+)"); //$NON-NLS-1$
+ //switches with no values such -v, --version
+ private Pattern singleSwitchPattern = Pattern.compile("-{1,2}([^=]+)"); //$NON-NLS-1$
+
+ /**
+ * list of source files
+ */
+ private ArrayList sources = new ArrayList();
+ /**
+ * traces path
+ */
+ private String traces_path = null;
+
+
+
+
+ /**
+ * Main function
+ *
+ * @param args
+ * the command line arguments
+ */
+ public static void main(String[] args) {
+ if (args.length == 0) {
+ printUsage();
+ return;
+ }
+
+ ArrayList list = null;
+
+ //support spaces in switches, build a long string, clean it and convert it back to array - a bit expensive
+ String tmpString = ""; //$NON-NLS-1$
+ for (int i = 0; i < args.length; i++) {
+ tmpString = tmpString + " " + args[i]; //$NON-NLS-1$
+ }
+ tmpString = tmpString.replaceAll("\\s*=\\s*", "="); //$NON-NLS-1$ //$NON-NLS-2$
+ tmpString = tmpString.replaceAll("\\s+", " "); //$NON-NLS-1$ //$NON-NLS-2$
+ String[] split = tmpString.trim().split(" "); //$NON-NLS-1$
+ tmpString = null; // not needed anymore
+
+ //rebuild array of arguments
+ if (split.length > 0) {
+ list = new ArrayList(Arrays.asList(split));
+ }
+
+ long startTime = System.currentTimeMillis();
+ //create a new session of TraceCompiler
+ TraceCompilerMain console = new TraceCompilerMain();
+
+ try {
+ console.parseCommandLine(list);
+ } catch (Exception e) { //should cover IOException and TraceCompilerIllegalArgumentsException
+ //There is no point to continue if there are problems with the arguments.
+ TraceCompilerLogger.printError(e.getMessage());
+ printUsage();
+ System.exit(1);
+ }
+
+ boolean error = false;
+ try {
+ if(list.size() != 0) {
+ console.createPlugins();
+ console.start();
+ console.buildTraceFiles();
+ }
+ } catch (Exception e) {
+ if (e instanceof TraceCompilerRootException) {
+ TraceCompilerLogger.printError(e.getMessage());
+ } //else the error should have been reported earlier
+ error = true;
+ } finally {
+ try {
+ if (!error) { //check if errors have been logged by EventEngine
+ TraceCompilerEngineEvents events = TraceCompilerEngineGlobals.getEvents();
+ if (events != null && events.hasErrorHappened()) {
+ error = true;
+ }
+ }
+ console.shutdown();
+ } catch (TraceCompilerException e) {
+ error = true;
+ }
+ }
+
+ if (console.projectName != null) {
+ TraceCompilerLogger.printMessage(console.projectName + Messages.getString("TraceCompiler.Took") //$NON-NLS-1$
+ + (System.currentTimeMillis() - startTime) + Messages.getString("TraceCompiler.MS")); //$NON-NLS-1$
+ }
+ if (error) {
+ System.exit(1);
+ } else {
+ System.exit(0);
+ }
+ }
+
+ /**
+ * With Eclipse, the plug-ins are loaded by Eclipse framework. Here they
+ * must be manually created and started
+ */
+ private ArrayList plugIns = new ArrayList();
+
+ /**
+ * Model listener
+ */
+ private TraceCompilerModelListener modelListener;
+
+ /**
+ * Name of the component
+ */
+ private String projectName = null;
+
+
+ /**
+ * UID of the component
+ */
+ private long componentUID = 0L;
+
+ /**
+ * Component path
+ */
+ private String componentPath = null;
+
+ /**
+ * MMP file path
+ */
+ private File mmpPath = null;
+
+ /**
+ * Constructor
+ */
+ TraceCompilerMain() {
+
+ // Creates listeners and preferences
+ modelListener = new TraceCompilerModelListener();
+ }
+
+ /**
+ * Creates the plug-ins to be registered with TraceCompiler
+ * @throws TraceCompilerRootException if fail to create a valid plugins
+ */
+ private void createPlugins() throws TraceCompilerRootException {
+
+ // Get location of the TraceCompiler
+ URL path = getClass().getProtectionDomain().getCodeSource()
+ .getLocation();
+ String decodePluginsPath = path.getPath();
+
+ // If first character is forward slash and it is located before drive
+ // letter remove it
+ if (decodePluginsPath.charAt(INDEX_OF_FIRST_CHARACTER) == SourceConstants.FORWARD_SLASH_CHAR
+ && decodePluginsPath.charAt(INDEX_OF_THIRD_CHARACTER) == SourceConstants.COLON_CHAR) {
+ decodePluginsPath = decodePluginsPath.substring(1);
+ }
+
+ // Concatenate decode plugins path
+ decodePluginsPath = decodePluginsPath.concat(DECODE_PLUGINS_PATH);
+
+ // Replace slashes with correct separator character
+ decodePluginsPath = decodePluginsPath.replace(
+ SourceConstants.FORWARD_SLASH_CHAR, File.separatorChar);
+ decodePluginsPath = decodePluginsPath.replace(
+ SourceConstants.BACKSLASH_CHAR, File.separatorChar);
+ File decodePluginsDir = new File(decodePluginsPath);
+ String[] decodePlugins = decodePluginsDir.list();
+ if (decodePlugins != null) {
+ for (int i = 0; i < decodePlugins.length; i++) {
+
+ // Get decode plugin name
+ String decodePluginName = decodePlugins[i];
+
+ // Get decode plugin path
+ String decodePluginPath = decodePluginsPath
+ + File.separatorChar + decodePluginName;
+
+ // Decode plugin must be in own directory
+ Boolean isDirectory = (new File(decodePluginPath))
+ .isDirectory();
+ if (isDirectory) {
+
+ // Construct decode plugin engine class name
+ String engineClassName = ENGINE_CLASS_NAME_TEMPLATE
+ .replaceFirst(DECODE_PLUGIN_NAME_TAG,
+ decodePluginName.substring(0, 1)
+ .toUpperCase()
+ + decodePluginName.substring(1));
+
+ // Construct decode plugin engine file name
+ String engineFileName = ENGINE_FILE_NAME_TEMPLATE
+ .replaceFirst(DECODE_PLUGIN_CLASS_NAME_TAG,
+ engineClassName);
+ String engineFileFullName = decodePluginPath
+ + File.separatorChar + engineFileName;
+
+ // Check does engine file exist
+ Boolean exists = (new File(engineFileFullName)).exists();
+ if (exists) {
+ String engineClassFullName = CLASS_TEMPLATE
+ .replaceFirst(DECODE_PLUGIN_NAME_TAG,
+ decodePluginName).replaceFirst(
+ DECODE_PLUGIN_CLASS_NAME_TAG,
+ engineClassName);
+ try {
+ Class> engineClass = Class
+ .forName(engineClassFullName);
+ TraceCompilerPlugin engine = (TraceCompilerPlugin) engineClass
+ .newInstance();
+ plugIns.add(engine);
+ TraceCompilerLogger.printInfo(Messages.getString(Messages.getString("TraceCompiler.DecodePlugin") + engineClassFullName + Messages.getString("TraceCompiler.Added"))); //$NON-NLS-1$ //$NON-NLS-2$
+ } catch (Exception e) {
+ String msg = Messages.getString("TraceCompiler.DecodePlugin" + engineClassFullName + Messages.getString("TraceCompiler.AddingFailed")); //$NON-NLS-1$ //$NON-NLS-2$
+ throw new TraceCompilerRootException(msg, e);
+ }
+ } else {
+ String msg = Messages.getString("TraceCompiler.DecodePluginFile") + Messages.getString("TraceCompiler.EngineFullName") + engineFileFullName + Messages.getString("TraceCompiler.DoesNotExist"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ throw new TraceCompilerRootException(msg, null);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Parses the command line
+ *
+ * @param args
+ * the arguments
+ * @throws TraceCompilerRootException if arguments are invalid
+ * @throws IOException
+ */
+ private void parseCommandLine(ArrayList list) throws TraceCompilerIllegalArgumentsException, IOException {
+ TraceCompilerLogger.printInfo(Messages.getString("TraceCompiler.BuildingTracesMess")); //$NON-NLS-1$
+ Iterator argIterator = list.iterator();
+
+ if (list.size() == 0) {
+ printUsage();
+ System.exit(0);
+ }
+ while (argIterator.hasNext()) {
+ String element = argIterator.next().trim();
+ Matcher m = singleSwitchPattern.matcher(element);
+
+ if (m.matches()) { //it's one of the single switches
+ if (element.equalsIgnoreCase(HELP_OPTION) || element.equalsIgnoreCase(HELP_OPTION_SF)) {
+ printUsage();
+ System.exit(0);
+ }
+ if (element.equalsIgnoreCase(VERBOSE_OPTION) || element.equalsIgnoreCase(VERBOSE_OPTION_SF)) {
+ TraceCompilerGlobals.setVerbose(true);
+ TraceCompilerLogger.printInfo(Messages.getString("TraceCompiler.veboseEnabled")); //$NON-NLS-1$
+ continue;
+ }
+ if ( element.equalsIgnoreCase(VERSION_OPTION) || element.equalsIgnoreCase(VERSION_OPTION_SF)) {
+ TraceCompilerLogger.printMessage(VERSION_TEXT + TraceCompilerVersion.getVersion());
+ System.exit(0);
+ }
+ if (element.equalsIgnoreCase(STOP_ON_ERROR_OPTION) || element.equalsIgnoreCase(STOP_ON_ERROR_OPTION_SF)) {
+ TraceCompilerGlobals.setKeepGoing(false);
+ TraceCompilerLogger.printInfo(Messages.getString("TraceCompiler.StopOnErrorEnabled")); //$NON-NLS-1$
+ continue;
+ }
+ TraceCompilerLogger.printMessage(Messages.getString("TraceCompiler.UnsupportedSwitch") + element); //$NON-NLS-1$
+ } else {
+ m = valueSwitchPattern.matcher(element.trim());
+ if (m.matches()) { //it's one of the swithes with values
+ if (m.group(1).equalsIgnoreCase(UID_SWITCH)) {
+ // UID
+ try {
+ componentUID = Long.parseLong(m.group(2),TraceCompilerConstants.HEX_RADIX);
+ TraceCompilerLogger.printInfo("Component UID: 0x" + Long.toHexString(componentUID)); //$NON-NLS-1$
+ if (componentUID <= 0L) {
+ String msg = Messages.getString("TraceCompiler.componentUidIsNotValidExceptionText") + componentUID; //$NON-NLS-1$
+ throw new TraceCompilerIllegalArgumentsException(msg, null);
+ }
+ } catch (NumberFormatException e) {
+ String msg = Messages.getString("TraceCompiler.componentUidIsNotValidExceptionText") + componentUID; //$NON-NLS-1$
+ throw new TraceCompilerIllegalArgumentsException(msg, null);
+ }
+ } else {
+ if (m.group(1).equalsIgnoreCase(PRJ_NAME_SWITCH)) {
+ // project name
+ projectName = m.group(2);
+ TraceCompilerLogger.printInfo(Messages.getString("TraceCompiler.CompNameSet") + projectName); //$NON-NLS-1$
+ } else {
+ if (m.group(1).equalsIgnoreCase(MMP_PATH_SWITCH)) {
+ //mmp path. for the moment only the mmp folder is used.
+ mmpPath = new File(m.group(2));
+ TraceCompilerLogger.printInfo(Messages.getString("TraceCompiler.MMPPathSet") + mmpPath); //$NON-NLS-1$
+ } else {
+ if (m.group(1).equalsIgnoreCase(TRACES_PATH_SWITCH)) {
+ //traces path
+ traces_path = m.group(2);
+ } else {
+ //unsupported switch
+ TraceCompilerLogger.printMessage(Messages.getString("TraceCompiler.UnsupportedSwitch") + element); //$NON-NLS-1$
+ }
+ }
+ }
+ }
+
+ } else {
+ //it must be a file name
+ //it's a good time to stop TC here if the file does not exist
+ if (!(new File(element)).exists()) {
+ throw new TraceCompilerIllegalArgumentsException(Messages.getString("TraceCompiler.sourceFileDoesNotExist") + element, null); //$NON-NLS-1$
+ }
+ sources.add(element);
+ }
+ }
+ }
+
+ // by now, if the user wanted just help or version they would have got it and TC stopped
+
+ if (componentUID <= 0L) {
+ String msg = Messages.getString("TraceCompiler.componentUidIsNotValidExceptionText") + componentUID; //$NON-NLS-1$
+ throw new TraceCompilerIllegalArgumentsException(msg, null);
+ }
+
+ if (projectName == null) {
+ throw new TraceCompilerIllegalArgumentsException(Messages.getString("TraceCompiler.projectNameMissing"), null); //$NON-NLS-1$
+ }
+
+ //if files have not been provided , get them from stdin
+ if (sources.size() == 0) {
+ //get them from the stdin
+ readFromStdin();
+ }
+
+ if (mmpPath == null ) {
+ throw new TraceCompilerIllegalArgumentsException(Messages.getString("TraceCompiler.mmpPathMissing"), null); //$NON-NLS-1$
+ } else if (!isMmpValid()) {
+ throw new TraceCompilerIllegalArgumentsException(Messages.getString("TraceCompiler.invalidMmpExceptionText") + mmpPath, null); //$NON-NLS-1$
+ }
+
+ if (traces_path == null ) {
+ throw new TraceCompilerIllegalArgumentsException(Messages.getString("TraceCompiler.tracesPathMissing"), null); //$NON-NLS-1$
+ } else {
+ computeTracesPath(traces_path);
+ }
+
+ if (sources.size() == 0 ) {
+ throw new TraceCompilerIllegalArgumentsException(Messages.getString("TraceCompiler.fileListMissing"), null); //$NON-NLS-1$
+ }
+
+ //we have all parameters input and validated, register files.
+ registerSourceFiles(sources);
+ }
+
+
+ /**
+ * If traces path is relative, work out the full path relative to the location of the mmp file
+ * @param path
+ * @throws TraceCompilerIllegalArgumentsException
+ */
+ private void computeTracesPath(String path) throws TraceCompilerIllegalArgumentsException {
+ String traces_pathString = path;
+ traces_pathString = traces_pathString.replace('/', File.separatorChar);
+ traces_pathString = traces_pathString.replace('\\', File.separatorChar);
+
+ File traces_path = new File(traces_pathString);
+
+ Pattern p = Pattern.compile("(([a-zA-Z]:[\\\\/])|([\\\\/])).*"); //$NON-NLS-1$
+ Matcher m = p.matcher(traces_pathString);
+
+ if (!m.matches() /* workaround for isAbsolute in java */) {
+ //traces path is relative to mmp location
+ traces_pathString = mmpPath.getAbsoluteFile().getParent() + File.separator + traces_pathString;
+ }
+
+ traces_path = new File(traces_pathString);
+
+ if (traces_path.isDirectory() && !traces_path.canWrite()) {
+ throw new TraceCompilerIllegalArgumentsException(Messages.getString("TraceCompiler.TracesPathWriteProtected") + traces_path, null); //$NON-NLS-1$
+ }
+
+ boolean dirExists = true;
+ if (!traces_path.exists()) {
+ dirExists = FileUtils.createDirectories(traces_path);
+ }
+ if (!dirExists) {
+ throw new TraceCompilerIllegalArgumentsException(Messages.getString("TraceCompiler.mkdirFailed") + traces_path, null); //$NON-NLS-1$
+ }
+
+ //set component path and trace folder
+ componentPath = traces_path.getParent();
+ ProjectEngine.traceFolderName = traces_path.getName();
+ TraceCompilerLogger.printInfo(Messages.getString("TraceCompiler.settingComponentPath") + componentPath); //$NON-NLS-1$
+ TraceCompilerLogger.printInfo(Messages.getString("TraceCompiler.settingTracesPath") + ProjectEngine.traceFolderName); //$NON-NLS-1$
+ }
+
+ private static void printUsage() {
+ TraceCompilerLogger.printMessage(VERSION_TEXT + TraceCompilerVersion.getVersion());
+ TraceCompilerLogger.printMessage(USAGE);
+ }
+
+ /**
+ * Read information from STDIN
+ * @throws IOException if fails to read the input
+ * @throws TraceCompilerRootException if the list of files is empty
+ */
+ private void readFromStdin() throws IOException, TraceCompilerIllegalArgumentsException {
+ TraceCompilerLogger.printInfo(Messages.getString("TraceCompiler.ReadingFilesMess") + ENDOFSOURCEFILES); //$NON-NLS-1$
+ // Create reader
+ BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
+
+ String line = stdin.readLine();
+
+ while (line != null) {
+ line = line.trim();
+ if (line.length() > 0) {
+ // End of source files received
+ if (line.equals(ENDOFSOURCEFILES)) {
+ break;
+ }
+ line = line.replaceAll("\\s+", ""); //$NON-NLS-1$ //$NON-NLS-2$
+ Matcher m = valueSwitchPattern.matcher(line.trim());
+ //because mmp path and traces path can be very long, we should allow them to be input'ed through stdin too.
+ if (m.matches()) { //it's one of the swithes with values
+ if (m.group(1).equalsIgnoreCase(MMP_PATH_SWITCH)) {
+ //mmp path. for the moment only the mmp folder is used.
+ mmpPath = new File(m.group(2));
+ TraceCompilerLogger.printInfo(Messages.getString("TraceCompiler.MMPPathSet") + mmpPath); //$NON-NLS-1$
+ } else {
+ if (m.group(1).equalsIgnoreCase(TRACES_PATH_SWITCH)) {
+ //traces path
+ traces_path = m.group(2);
+ } else {
+ //unsupported switch
+ TraceCompilerLogger.printMessage(Messages.getString("TraceCompiler.UnsupportedSwitch") + line); //$NON-NLS-1$
+ }
+ }
+ } else {
+
+ //it must be a file name
+ //it's a good time to stop TC here if the file does not exist
+ if (!(new File(line)).exists()) {
+ throw new TraceCompilerIllegalArgumentsException(Messages.getString("TraceCompiler.sourceFileDoesNotExist") + line, null); //$NON-NLS-1$
+ }
+ sources.add(line);
+ }
+ }
+ // Read new line from STDIN
+ line = stdin.readLine();
+ }
+ stdin.close();
+ }
+
+ /**
+ * Registers source files
+ *
+ * @param files
+ */
+ private void registerSourceFiles(ArrayList files) throws TraceCompilerIllegalArgumentsException {
+ if (sources.size() == 0) {
+ throw new TraceCompilerIllegalArgumentsException(Messages.getString("TraceCompiler.noSourceFilesExceptionText"), null); //$NON-NLS-1$
+ }
+ if (files.size() > 0) {
+ String[] fileArr = new String[files.size()];
+ files.toArray(fileArr);
+
+ // Sets the source files to the TraceCompiler document
+ // factory. It will create a document from each source in the array
+ FileDocumentMonitor.setFiles(fileArr);
+ DocumentFactory.registerDocumentFramework(
+ new FileDocumentMonitor(), StringDocumentFactory.class);
+ }
+ }
+
+ /**
+ * Initializes TraceCompiler
+ * @throws TraceCompilerRootException if fail to initialize the plugins
+ * @throws TraceCompilerException
+ */
+ private void start() throws TraceCompilerRootException, TraceCompilerException {
+
+ // Starts TraceCompiler. This is normally called from the Eclipse
+ // plug-in
+ // activator, but in console case that does not exist
+ TraceCompilerEngineGlobals.start();
+
+ //Reads the GroupId values from opensystemtrace_types.h
+ //If this fails a message is logged and trace compiler stops
+ GroupNames.initialiseGroupName();
+
+
+ // Registers a view to TraceCompiler
+ TraceCompilerEngineGlobals
+ .setView(new TraceCompilerView(componentPath));
+
+ // Registers all plug-in components
+ for (TraceCompilerPlugin plugin : plugIns) {
+ TraceCompilerEngineGlobals.registerPlugin(plugin);
+ }
+ // Adds a model event listener
+ TraceCompilerEngineGlobals.getTraceModel().addModelListener(
+ modelListener);
+ TraceCompilerEngineGlobals.getTraceModel().addExtensionListener(
+ modelListener);
+ TraceCompilerEngineGlobals.getTraceModel().getExtension(
+ TraceLocationList.class).addLocationListListener(modelListener);
+ TraceCompilerEngineGlobals.getTraceModel().addProcessingListener(modelListener);
+ }
+
+ /**
+ * Parses the sources and generates trace files
+ * @throws Exception
+ */
+ private void buildTraceFiles() throws Exception {
+ TraceCompilerEngineInterface tbi = TraceCompilerEngineGlobals
+ .getTraceCompiler();
+ try {
+ // Opens a trace project
+
+ // Set project path before opening project
+ TraceCompilerEngineGlobals.setProjectPath(componentPath);
+ tbi.openProject(projectName);
+ TraceModel model = TraceCompilerEngineGlobals.getTraceModel();
+ if (model.isValid()) {
+ model.setID((int) componentUID);
+
+ // Location errors are printed after a file changes, but the
+ // last file is not detected by the listener
+ if (modelListener.getErrors().size() > 0) {
+ modelListener.printLocationErrors();
+ tbi.closeProject();
+ throw new TraceCompilerRootException(null, null);
+ }
+ tbi.exportProject();
+ tbi.closeProject();
+ } else {
+ String msg = Messages.getString("TraceCompiler.ProjectCancelledMess"); //$NON-NLS-1$
+ throw new TraceCompilerRootException(msg, null);
+ }
+ } catch (TraceCompilerException e) {
+ TraceCompilerEngineGlobals.getEvents().postError(e);
+ throw new TraceCompilerRootException(Messages.getString("TraceCompiler.BuildFailed"), e); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Shuts down TraceCompiler
+ * @throws TraceCompilerException
+ */
+ private void shutdown() throws TraceCompilerException {
+ for (TraceCompilerPlugin plugin : plugIns) {
+ TraceCompilerEngineGlobals.unregisterPlugin(plugin);
+ }
+ TraceCompilerEngineGlobals.shutdown();
+ }
+
+ /**
+ * Checks if the MMP file is valid
+ *
+ * @return true if MMP file is valid
+ */
+ private boolean isMmpValid() {
+ boolean valid = false;
+ String pathStr = mmpPath.getAbsolutePath();
+
+ if (mmpPath.exists() && pathStr.length() > MMP_FILE_TYPE.length()) {
+ String end = pathStr.substring(pathStr.length() - MMP_FILE_TYPE.length());
+ if (end.equalsIgnoreCase(MMP_FILE_TYPE)) {
+ valid = true;
+ } else {
+ TraceCompilerLogger.printError(Messages.getString("TraceCompiler.invalidMmpExceptionText") + mmpPath.getAbsolutePath()); //$NON-NLS-1$
+ }
+ } else {
+ TraceCompilerLogger.printError(Messages.getString("TraceCompiler.InvalidMMP2") + mmpPath.getAbsolutePath()); //$NON-NLS-1$
+ }
+ return valid;
+
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/TraceCompilerModelListener.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/TraceCompilerModelListener.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,246 @@
+/*
+ * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ *
+ * Description:
+ *
+ * Model extension listener for console UI
+ *
+ */
+package com.nokia.tracecompiler;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+
+import com.nokia.tracecompiler.engine.TraceCompilerEngineErrorMessages;
+import com.nokia.tracecompiler.engine.TraceCompilerEngineGlobals;
+import com.nokia.tracecompiler.engine.TraceLocation;
+import com.nokia.tracecompiler.engine.TraceLocationList;
+import com.nokia.tracecompiler.engine.TraceLocationListListener;
+import com.nokia.tracecompiler.engine.TraceCompilerEngineErrorCodes.TraceCompilerErrorCode;
+import com.nokia.tracecompiler.model.TraceModelExtension;
+import com.nokia.tracecompiler.model.TraceModelExtensionListener;
+import com.nokia.tracecompiler.model.TraceModelListener;
+import com.nokia.tracecompiler.model.TraceObject;
+import com.nokia.tracecompiler.model.TraceProcessingListener;
+import com.nokia.tracecompiler.source.SourceConstants;
+import com.nokia.tracecompiler.source.SourceLocationListener;
+
+/**
+ * Model extension listener for TraceCompiler UI
+ *
+ */
+final class TraceCompilerModelListener implements TraceModelListener,
+ TraceModelExtensionListener, TraceLocationListListener,
+ SourceLocationListener, TraceProcessingListener {
+
+ /**
+ * List of errors for a source
+ */
+ private ArrayList errorList = new ArrayList();
+
+ /**
+ * Name of the file being processed
+ */
+ private String currentFileName;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.model.TraceModelListener#
+ * objectAdded(com.nokia.tracecompiler.model.TraceObject,
+ * com.nokia.tracecompiler.model.TraceObject)
+ */
+ public void objectAdded(TraceObject owner, TraceObject object) {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.model.TraceModelListener#
+ * objectCreationComplete(com.nokia.tracecompiler.model.TraceObject)
+ */
+ public void objectCreationComplete(TraceObject object) {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.model.TraceModelListener#
+ * objectRemoved(com.nokia.tracecompiler.model.TraceObject,
+ * com.nokia.tracecompiler.model.TraceObject)
+ */
+ public void objectRemoved(TraceObject owner, TraceObject object) {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.model.TraceModelListener#
+ * propertyUpdated(com.nokia.tracecompiler.model.TraceObject, int)
+ */
+ public void propertyUpdated(TraceObject object, int property) {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.model.TraceModelExtensionListener#
+ * extensionAdded(com.nokia.tracecompiler.model.TraceObject,
+ * com.nokia.tracecompiler.model.TraceModelExtension)
+ */
+ public void extensionAdded(TraceObject object, TraceModelExtension extension) {
+ if (extension instanceof TraceLocationList) {
+ ((TraceLocationList) extension).addLocationListListener(this);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.model.TraceModelExtensionListener#
+ * extensionRemoved(com.nokia.tracecompiler.model.TraceObject,
+ * com.nokia.tracecompiler.model.TraceModelExtension)
+ */
+ public void extensionRemoved(TraceObject object,
+ TraceModelExtension extension) {
+ if (extension instanceof TraceLocationList) {
+ ((TraceLocationList) extension).removeLocationListListener(this);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.source.TraceLocationListListener#
+ * locationAdded(com.nokia.tracecompiler.engine.TraceLocation)
+ */
+ public void locationAdded(TraceLocation location) {
+ location.addLocationListener(this);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.source.TraceLocationListListener#
+ * locationRemoved(com.nokia.tracecompiler.engine.TraceLocation)
+ */
+ public void locationRemoved(TraceLocation location) {
+ location.removeLocationListener(this);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.source.SourceLocationListener#
+ * locationValidityChanged(com.nokia.tracecompiler.engine.TraceLocation)
+ */
+ public void locationValidityChanged(TraceLocation location) {
+ String fileName = location.getFileName();
+ if (currentFileName != null) {
+ if (!fileName.equals(currentFileName)) {
+ currentFileName = fileName;
+ printLocationErrors();
+ }
+ } else {
+ currentFileName = fileName;
+ }
+ TraceCompilerErrorCode code = location.getValidityCode();
+ if (code != TraceCompilerErrorCode.OK
+ && code != TraceCompilerErrorCode.TRACE_DOES_NOT_EXIST) {
+ if (!errorList.contains(location)) {
+ errorList.add(location);
+ location.reference();
+ }
+ } else {
+ if (errorList.remove(location)) {
+ location.dereference();
+ }
+ }
+ }
+
+ /**
+ * Prints the errors from the error list
+ */
+ void printLocationErrors() {
+ Collections.sort(errorList, new Comparator() {
+
+ /**
+ * Sorts the array by line number
+ *
+ * @param o1
+ * location 1
+ * @param o2
+ * location 2
+ * @return the result
+ */
+ public int compare(TraceLocation o1, TraceLocation o2) {
+ int line1 = o1.getLineNumber();
+ int line2 = o2.getLineNumber();
+ return line1 > line2 ? 1 : line1 == line2 ? 0 : -1;
+ }
+
+ });
+ for (TraceLocation location : errorList) {
+ printLocationError(location);
+ }
+ errorList.clear();
+ }
+
+ /**
+ * Prints a location error
+ *
+ * @param location
+ * the location
+ */
+ private void printLocationError(TraceLocation location) {
+ TraceCompilerEngineGlobals.getEvents().postErrorMessage(
+ location.getFileName()
+ + Messages.getString("TraceCompilerModelListener.lineNumberPrefix") //$NON-NLS-1$
+ + location.getLineNumber()
+ + SourceConstants.COLON
+ + SourceConstants.SPACE
+ + TraceCompilerEngineErrorMessages.getErrorMessage(
+ location.getValidityCode(), location
+ .getValidityParameters()), null, true);
+ }
+
+ /**
+ * get list of cumulated erros.
+ *
+ * @return list of TaceLocaion
+ */
+ public ArrayList getErrors() {
+ return errorList;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.nokia.tracecompiler.model.TraceProcessingListener#processingComplete
+ * (boolean)
+ */
+ public void processingComplete(boolean changed) {
+ printLocationErrors();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.nokia.tracecompiler.model.TraceProcessingListener#processingStarted()
+ */
+ public void processingStarted() {
+ }
+}
\ No newline at end of file
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/TraceCompilerRootException.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/TraceCompilerRootException.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ *
+ * Description:
+ *
+ * Command-line based view implementation
+ *
+ */
+package com.nokia.tracecompiler;
+
+
+public class TraceCompilerRootException extends Exception {
+ // Serial version UID, as required for all Exceptions
+ private static final long serialVersionUID = 2126996710246333574L;
+
+
+ /**
+ * Constructs a TraceCompilerRootException with the given detail message and
+ * cause.
+ * @param message the detail message
+ * @param cause the Exception that caused this Exception
+ */
+ public TraceCompilerRootException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/TraceCompilerView.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/TraceCompilerView.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ *
+ * Description:
+ *
+ * Console view implementation
+ *
+ */
+package com.nokia.tracecompiler;
+
+import java.io.File;
+
+import com.nokia.tracecompiler.engine.TraceCompilerEngineConfiguration;
+import com.nokia.tracecompiler.engine.ViewAdapter;
+
+/**
+ * TraceCompiler view implementation
+ *
+ */
+class TraceCompilerView extends ViewAdapter {
+
+ /**
+ * Epoc root name in environment variables
+ */
+ private static final String EPOCROOT = "EPOCROOT"; //$NON-NLS-1$
+
+ /**
+ * Export path
+ */
+ private String exportPath;
+
+ /**
+ * Configuration
+ */
+ private TraceCompilerConfiguration configuration;
+
+ /**
+ * Constructor
+ *
+ * @param projectPath
+ * the project path
+ */
+ TraceCompilerView(String projectPath) {
+ // First try to get EPOCROOT from environment
+ exportPath = System.getenv(EPOCROOT);
+
+ // Windows substed drive
+ if (exportPath == null) {
+ int index = projectPath.indexOf(':');
+ if (index >= 0) {
+ exportPath = projectPath.substring(0, index + 2); // CodForChk_Dis_Magic
+ } else {
+ exportPath = File.separator;
+ }
+
+ // Check if it ends with a file separator, if not add one at the end
+ } else if (!exportPath.endsWith(File.separator)) {
+ exportPath = exportPath + File.separator;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.ViewAdapter#getConfiguration()
+ */
+ @Override
+ public TraceCompilerEngineConfiguration getConfiguration() {
+ if (configuration == null) {
+ configuration = new TraceCompilerConfiguration(exportPath);
+ }
+ return configuration;
+ }
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/DictionaryDefRef.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/DictionaryDefRef.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,37 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Reference to a trace definition
+*
+*/
+package com.nokia.tracecompiler.decodeplugins.dictionary;
+
+/**
+ * Reference to a trace definition
+ *
+ */
+final class DictionaryDefRef extends DictionaryRef {
+
+ /**
+ * Constructor
+ *
+ * @param refid
+ * the reference id
+ */
+ DictionaryDefRef(int refid) {
+ super(refid);
+ }
+
+}
\ No newline at end of file
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/DictionaryEngine.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/DictionaryEngine.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,100 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* TraceCompilerExport implementation for Symbian dictionary files
+*
+*/
+package com.nokia.tracecompiler.decodeplugins.dictionary;
+
+import com.nokia.tracecompiler.model.TraceCompilerException;
+import com.nokia.tracecompiler.model.TraceModel;
+import com.nokia.tracecompiler.plugin.TraceCompilerExport;
+
+/**
+ * TraceCompilerExport implementation for Symbian dictionary files
+ *
+ */
+public final class DictionaryEngine implements TraceCompilerExport {
+
+ /**
+ * The trace model
+ */
+ private TraceModel model;
+
+ /**
+ * Dictionary instance
+ */
+ private static DictionaryEngine instance;
+
+ /**
+ * Gets the shared instance
+ *
+ * @return the instance
+ */
+ static DictionaryEngine getInstance() {
+ return instance;
+ }
+
+ /**
+ * Constructor
+ */
+ public DictionaryEngine() {
+ instance = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.TraceCompilerPlugin#
+ * traceProjectOpened(com.nokia.tracecompiler.model.TraceModel)
+ */
+ public void traceProjectOpened(TraceModel model) {
+ this.model = model;
+ DictionaryFile file = model.getExtension(DictionaryFile.class);
+ if (file == null) {
+ file = new DictionaryFile(DictionaryFileExport
+ .getPathForDictionary(model));
+ model.addExtension(file);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.TraceCompilerPlugin#traceProjectClosed()
+ */
+ public void traceProjectClosed() {
+ if (model != null && model.isValid()) {
+ model.removeExtensions(DictionaryFile.class);
+ }
+ model = null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.TraceCompilerExport#exportTraceProject()
+ */
+ public void exportTraceProject() throws TraceCompilerException {
+ if (model != null && model.isValid()) {
+ DictionaryFile df = model.getExtension(DictionaryFile.class);
+ if (df != null) {
+ DictionaryFileExport export = new DictionaryFileExport(df);
+ export.exportDictionary();
+ }
+ }
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/DictionaryFile.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/DictionaryFile.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,65 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Project file for Dictionary format
+*
+*/
+package com.nokia.tracecompiler.decodeplugins.dictionary;
+
+import com.nokia.tracecompiler.project.TraceProjectFile;
+
+/**
+ * Project file for Dictionary format
+ *
+ */
+final class DictionaryFile extends TraceProjectFile {
+
+ /**
+ * Title shown in UI
+ */
+ private static final String TITLE = Messages
+ .getString("DictionaryFile.Title"); //$NON-NLS-1$
+
+ /**
+ * Constructor
+ *
+ * @param absolutePath
+ * the path to the dictionary file
+ */
+ DictionaryFile(String absolutePath) {
+ super(absolutePath, true);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.project.TraceProjectFile#getFileExtension()
+ */
+ @Override
+ protected String getFileExtension() {
+ return DictionaryFileConstants.DICTIONARY_FILE_EXTENSION;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.project.TraceProjectFile#getTitle()
+ */
+ @Override
+ public String getTitle() {
+ return TITLE;
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/DictionaryFileConstants.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/DictionaryFileConstants.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,37 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Constants related to dictionary file
+*
+*/
+package com.nokia.tracecompiler.decodeplugins.dictionary;
+
+/**
+ * Constants related to dictionary file
+ *
+ */
+interface DictionaryFileConstants {
+
+ /**
+ * Dictionary file extension
+ */
+ String DICTIONARY_FILE_EXTENSION = "Dictionary.xml"; //$NON-NLS-1$
+
+ /**
+ * Search depth for dictionary file
+ */
+ int DICTIONARY_SEARCH_DEPTH = 3; // CodForChk_Dis_Magic
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/DictionaryFileExport.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/DictionaryFileExport.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,102 @@
+/*
+* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Exporter for dictionary file
+*
+*/
+package com.nokia.tracecompiler.decodeplugins.dictionary;
+
+import java.io.File;
+
+import com.nokia.tracecompiler.engine.TraceCompilerEngineConfiguration;
+import com.nokia.tracecompiler.engine.TraceCompilerEngineGlobals;
+import com.nokia.tracecompiler.file.FileUtils;
+import com.nokia.tracecompiler.model.TraceModel;
+import com.nokia.tracecompiler.source.SourceConstants;
+
+/**
+ * Exporter for dictionary file
+ *
+ */
+final class DictionaryFileExport {
+
+ /**
+ * The dictionary file properties
+ */
+ private DictionaryFile dictionaryFile;
+
+ /**
+ * Constructor
+ *
+ * @param dictionary
+ * the dictionary file
+ */
+ DictionaryFileExport(DictionaryFile dictionary) {
+ this.dictionaryFile = dictionary;
+ }
+
+ /**
+ * Exports the dictionary file
+ */
+ void exportDictionary() {
+ String exportPath = getExportPath(File.separatorChar);
+ String exportFile = dictionaryFile.getFileName();
+ String envRoot = TraceCompilerEngineGlobals.getConfiguration().getText(
+ TraceCompilerEngineConfiguration.ENVIRONMENT_ROOT);
+ if (envRoot != null) {
+ File target = new File(envRoot + exportPath + exportFile);
+ // The dictionary file is updated with the new environment root
+ dictionaryFile.updatePath(target.getAbsolutePath());
+ DictionaryFileWriter writer = new DictionaryFileWriter(
+ dictionaryFile);
+ writer.write();
+ dictionaryFile.postFileWrittenEvent(dictionaryFile
+ .getAbsolutePathWithID());
+ }
+ }
+
+ /**
+ * Returns the export path for dictionary files
+ *
+ * @param separator
+ * the file separator to use
+ * @return the export path
+ */
+ private static String getExportPath(char separator) {
+ String exportPath = DictionaryPreferences.DEFAULT_EXPORT_PATH;
+
+ // Accepts both types of separators, ends with separator
+ exportPath = FileUtils.convertSeparators(separator, exportPath, true);
+ return exportPath;
+ }
+
+ /**
+ * Gets the default path to the dictionary file
+ *
+ * @param model
+ * trace model
+ * @return the file
+ */
+ static String getPathForDictionary(TraceModel model) {
+ String fileName = model.getName()
+ + DictionaryFileConstants.DICTIONARY_FILE_EXTENSION;
+ String exportPath = getExportPath(File.separatorChar);
+ String envRoot = TraceCompilerEngineGlobals.getConfiguration().getText(
+ TraceCompilerEngineConfiguration.ENVIRONMENT_ROOT);
+ return FileUtils.convertSeparators(SourceConstants.FORWARD_SLASH_CHAR,
+ envRoot + exportPath + fileName, false);
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/DictionaryFileRef.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/DictionaryFileRef.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,60 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Reference to a file
+*
+*/
+package com.nokia.tracecompiler.decodeplugins.dictionary;
+
+/**
+ * Reference to a file
+ *
+ */
+final class DictionaryFileRef extends DictionaryRef {
+
+ /**
+ * File name
+ */
+ String file;
+
+ /**
+ * File path
+ */
+ String path;
+
+ /**
+ * Trace
+ */
+ com.nokia.tracecompiler.model.Trace trace;
+
+ /**
+ * Constructor
+ *
+ * @param file
+ * the file name
+ * @param path
+ * the file path
+ * @param trace
+ * the trace
+ */
+ DictionaryFileRef(String file, String path,
+ com.nokia.tracecompiler.model.Trace trace) {
+ super(0);
+ this.file = file;
+ this.path = path;
+ this.trace = trace;
+ }
+
+}
\ No newline at end of file
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/DictionaryFileWriter.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/DictionaryFileWriter.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,586 @@
+/*
+* Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Writer for dictionary file
+*
+*/
+package com.nokia.tracecompiler.decodeplugins.dictionary;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Iterator;
+
+import com.nokia.tracecompiler.decodeplugins.dictionary.encoder.DataType;
+import com.nokia.tracecompiler.decodeplugins.dictionary.encoder.Dictionary;
+import com.nokia.tracecompiler.decodeplugins.dictionary.encoder.LocationStore;
+import com.nokia.tracecompiler.decodeplugins.dictionary.encoder.TraceComponent;
+import com.nokia.tracecompiler.decodeplugins.dictionary.encoder.TraceDataStore;
+import com.nokia.tracecompiler.decodeplugins.dictionary.encoder.TraceDictionaryEncoder;
+import com.nokia.tracecompiler.decodeplugins.dictionary.encoder.TypeDef;
+import com.nokia.tracecompiler.decodeplugins.dictionary.encoder.TypeDefStore;
+import com.nokia.tracecompiler.engine.LocationListBase;
+import com.nokia.tracecompiler.engine.LocationProperties;
+import com.nokia.tracecompiler.file.FileUtils;
+import com.nokia.tracecompiler.model.Trace;
+import com.nokia.tracecompiler.model.TraceConstantTable;
+import com.nokia.tracecompiler.model.TraceConstantTableEntry;
+import com.nokia.tracecompiler.model.TraceGroup;
+import com.nokia.tracecompiler.model.TraceModel;
+import com.nokia.tracecompiler.model.TraceObjectUtils;
+import com.nokia.tracecompiler.model.TraceParameter;
+import com.nokia.tracecompiler.project.FormattingUtils;
+import com.nokia.tracecompiler.project.PropertyNames;
+import com.nokia.tracecompiler.project.TraceProjectAPI;
+import com.nokia.tracecompiler.project.TraceProjectAPI.TraceFormatFlags;
+import com.nokia.tracecompiler.rules.FillerParameterRule;
+import com.nokia.tracecompiler.rules.HiddenTraceObjectRule;
+import com.nokia.tracecompiler.source.SourceConstants;
+import com.nokia.tracecompiler.source.SourceUtils;
+
+/**
+ * Writer for dictionary file
+ *
+ */
+final class DictionaryFileWriter {
+
+ /**
+ * Comparator for file references
+ */
+ private final class FileRefComparator implements
+ Comparator {
+ public int compare(DictionaryFileRef o1, DictionaryFileRef o2) {
+ int val = o1.path.compareTo(o2.path);
+ if (val == 0) {
+ val = o1.file.compareTo(o2.file);
+ }
+ return val;
+ }
+ }
+
+ /**
+ * Dictionary file
+ */
+ private DictionaryFile dictionaryFile;
+
+ /**
+ * Sequential number for trace definitions
+ */
+ private int defref;
+
+ /**
+ * Sequential number for file definitions
+ */
+ private int fileref;
+
+ /**
+ * Constructor
+ *
+ * @param dictionaryFile
+ * the dictionary file
+ */
+ DictionaryFileWriter(DictionaryFile dictionaryFile) {
+ this.dictionaryFile = dictionaryFile;
+ }
+
+ /**
+ * Writes the dictionary file
+ */
+ void write() {
+ defref = 0;
+ fileref = 0;
+ File file = new File(dictionaryFile.getAbsolutePathWithID());
+ // Delete removes possible read-only flags
+ if (file.exists()) {
+ file.delete();
+ }
+
+ TraceDictionaryEncoder encoder = new TraceDictionaryEncoder();
+ File path = file.getParentFile();
+ if (!path.exists()) {
+ FileUtils.createDirectories(path);
+ }
+ encoder.createNewDictionary(file.getAbsolutePath());
+ Dictionary.startDictionary();
+ createTypedefs();
+ createDefs();
+ createLocations();
+ createComponent();
+ Dictionary.endDictionary();
+ }
+
+ /**
+ * Creates the type definitions
+ */
+ private void createTypedefs() {
+ TypeDefStore.startTypeDefs();
+ ArrayList typeList = buildTypeList();
+ writeTypeDefinitions(typeList);
+ TypeDefStore.endTypeDefs();
+ }
+
+ /**
+ * Builds the list of parameter types
+ *
+ * @return the list of types found from the model
+ */
+ private ArrayList buildTypeList() {
+ TraceModel model = dictionaryFile.getOwner().getModel();
+ ArrayList typeList = new ArrayList();
+ for (TraceGroup group : model) {
+ for (Trace trace : group) {
+ for (TraceParameter parameter : trace) {
+ if ((parameter.getExtension(HiddenTraceObjectRule.class) == null)
+ || (parameter
+ .getExtension(FillerParameterRule.class) != null)) {
+ String type = parameter.getType();
+ if (!typeList.contains(type)) {
+ typeList.add(type);
+ }
+ }
+ }
+ }
+ }
+ return typeList;
+ }
+
+ /**
+ * Writes the data type definitions
+ *
+ * @param typeList
+ * the list of data types
+ */
+ private void writeTypeDefinitions(ArrayList typeList) {
+ for (String type : typeList) {
+ DataType dt = mapTypeToDataType(type);
+ if (dt != null) {
+ // Normal parameters
+ int size = mapParameterTypeToSize(type);
+ String formatChar = SourceUtils.mapNormalTypeToFormat(type);
+ if (formatChar != null && formatChar.length() > 1
+ && formatChar.charAt(0) == '%') {
+ formatChar = formatChar.substring(1);
+ TypeDefStore.writeTypeDef(type, size, formatChar, dt);
+
+ // Write alternative format characters
+ writeAlternativeFormatChars(formatChar, type, size, dt);
+
+ } else {
+ TypeDefStore.writeTypeDef(type, size, null, dt);
+ }
+ } else {
+ // Enum parameters
+ TraceModel model = dictionaryFile.getOwner().getModel();
+ TraceConstantTable table = model.findConstantTableByName(type);
+ if (table != null) {
+ TypeDefStore.startTypeDef(table.getName(),
+ mapParameterTypeToSize(table.getType()), null,
+ DataType.ENUM);
+ for (TraceConstantTableEntry entry : table) {
+ TypeDef.writeTypeMember(entry.getID(), entry.getName(),
+ null);
+ }
+ TypeDefStore.endTypeDef();
+ }
+ }
+ }
+ }
+
+ /**
+ * Writes alternative format characters to the Dictionary
+ *
+ * @param formatChar
+ * formatchar
+ * @param type
+ * parameter type
+ * @param size
+ * parameter size
+ * @param dt
+ * data type
+ */
+ private void writeAlternativeFormatChars(String formatChar, String type,
+ int size, DataType dt) {
+
+ // If there's big L, write also 'll' type
+ if (formatChar.indexOf('L') != -1) {
+
+ // Double small l
+ String newFormatChar = formatChar.replace("L", "ll"); //$NON-NLS-1$ //$NON-NLS-2$
+ TypeDefStore.writeTypeDef(type, size, newFormatChar, dt);
+ writeCapitalHexType(newFormatChar, type, size, dt);
+
+ }
+
+ // Write alternative option to float types
+ else if (formatChar.equals("f") || formatChar.equals("e") //$NON-NLS-1$//$NON-NLS-2$
+ || formatChar.equals("g")) { //$NON-NLS-1$
+
+ String newFormatChar = 'L' + formatChar;
+ TypeDefStore.writeTypeDef(type, size, newFormatChar, dt);
+ }
+
+ else {
+ // If length is one, add also formatchar with "l"
+ if (formatChar.length() == 1) {
+ String newFormatChar = "l" + formatChar; //$NON-NLS-1$
+ TypeDefStore.writeTypeDef(type, size, newFormatChar, dt);
+ writeCapitalHexType(newFormatChar, type, size, dt);
+ }
+
+ // Check capital hex need
+ writeCapitalHexType(formatChar, type, size, dt);
+ }
+ }
+
+ /**
+ * Writes capital hex type
+ *
+ * @param formatChar
+ * formatchar
+ * @param type
+ * parameter type
+ * @param size
+ * parameter size
+ * @param dt
+ * data type
+ */
+ private void writeCapitalHexType(String formatChar, String type, int size,
+ DataType dt) {
+
+ // Write also capital X if there are hex values
+ if (formatChar.indexOf('x') != -1) {
+ type = type.toUpperCase();
+ TypeDefStore.writeTypeDef(type, size, formatChar.replace('x', 'X'),
+ dt);
+ }
+ }
+
+ /**
+ * Gets the parameter size from type
+ *
+ * @param type
+ * the type
+ * @return the size in bytes
+ */
+ private int mapParameterTypeToSize(String type) {
+ int size = SourceUtils.mapParameterTypeToSize(type);
+ if (size == 0) {
+ if (type.equals(TraceParameter.ASCII)) {
+ size = 1;
+ } else if (type.equals(TraceParameter.UNICODE)) {
+ size = 2; // CodForChk_Dis_Magic
+ }
+ }
+ return size;
+ }
+
+ /**
+ * Creates the trace definitions
+ */
+ private void createDefs() {
+ // This should check for duplicates
+ TraceDataStore.startDataStore();
+ TraceModel model = dictionaryFile.getOwner().getModel();
+ TraceProjectAPI api = model.getExtension(TraceProjectAPI.class);
+ for (TraceGroup group : model) {
+ for (Trace trace : group) {
+ trace.addExtension(new DictionaryDefRef(++defref));
+ TraceFormatFlags flags = new TraceFormatFlags();
+ flags.isFormattingSupported = true;
+ String data = api.formatTraceForExport(trace, flags);
+ data = replaceUnescapeQuotes(data);
+ TraceDataStore.writeData(defref, DataType.STRING, data);
+ }
+ }
+ TraceDataStore.endDataStore();
+ }
+
+ /**
+ * Replaces unescape quates
+ *
+ * @param data
+ * the data
+ * @return the new string
+ */
+ private String replaceUnescapeQuotes(String data) {
+ data = data.replace("\\\"", "\""); //$NON-NLS-1$ //$NON-NLS-2$
+ return data;
+ }
+
+ /**
+ * Maps a basic type to a Dictionary data type
+ *
+ * @param type
+ * the type
+ * @return the data type
+ */
+ private DataType mapTypeToDataType(String type) { // CodForChk_Dis_ComplexFunc
+ DataType retval;
+ // Unsigned is not supported in Dictionary
+ if (type.equals(TraceParameter.SDEC32)) {
+ retval = DataType.INTEGER;
+ } else if (type.equals(TraceParameter.HEX32)) {
+ retval = DataType.HEX;
+ } else if (type.equals(TraceParameter.UDEC32)) {
+ retval = DataType.INTEGER;
+ } else if (type.equals(TraceParameter.OCT32)) {
+ retval = DataType.OCTAL;
+ } else if (type.equals(TraceParameter.SDEC16)) {
+ retval = DataType.INTEGER;
+ } else if (type.equals(TraceParameter.HEX16)) {
+ retval = DataType.HEX;
+ } else if (type.equals(TraceParameter.UDEC16)) {
+ retval = DataType.INTEGER;
+ } else if (type.equals(TraceParameter.OCT16)) {
+ retval = DataType.OCTAL;
+ } else if (type.equals(TraceParameter.SDEC8)) {
+ retval = DataType.INTEGER;
+ } else if (type.equals(TraceParameter.HEX8)) {
+ retval = DataType.HEX;
+ } else if (type.equals(TraceParameter.UDEC8)) {
+ retval = DataType.INTEGER;
+ } else if (type.equals(TraceParameter.OCT8)) {
+ retval = DataType.OCTAL;
+ } else if (type.equals(TraceParameter.SDEC64)) {
+ retval = DataType.INTEGER;
+ } else if (type.equals(TraceParameter.HEX64)) {
+ retval = DataType.HEX;
+ } else if (type.equals(TraceParameter.UDEC64)) {
+ retval = DataType.INTEGER;
+ } else if (type.equals(TraceParameter.OCT64)) {
+ retval = DataType.OCTAL;
+ } else if (type.equals(TraceParameter.ASCII)) {
+ retval = DataType.STRING;
+ } else if (type.equals(TraceParameter.UNICODE)) {
+ retval = DataType.STRING;
+ } else if (type.equals(TraceParameter.FLOAT_FIX)) {
+ retval = DataType.FLOAT;
+ } else if (type.equals(TraceParameter.FLOAT_EXP)) {
+ retval = DataType.FLOAT;
+ } else if (type.equals(TraceParameter.FLOAT_OPT)) {
+ retval = DataType.FLOAT;
+ } else if (type.equals(TraceParameter.POINTER)) {
+ retval = DataType.HEX;
+ } else {
+ retval = null;
+ }
+ return retval;
+ }
+
+ /**
+ * Creates the location definitions
+ */
+ private void createLocations() {
+ ArrayList files = new ArrayList();
+ LocationStore.startLocations();
+ for (TraceGroup group : dictionaryFile.getOwner().getModel()) {
+ for (Trace trace : group) {
+ writeLocation(files, trace);
+ }
+ }
+ // Build XML and assign ID's to refs
+ Collections.sort(files, new FileRefComparator());
+ String lastpath = null;
+ for (DictionaryFileRef ref : files) {
+ if (!ref.path.equals(lastpath)) {
+ if (lastpath != null) {
+ LocationStore.endPath();
+ }
+ LocationStore.startPath(ref.path);
+ lastpath = ref.path;
+ }
+ LocationStore.writeFile(++fileref, ref.file);
+ ref.refid = fileref;
+ }
+ if (lastpath != null) {
+ LocationStore.endPath();
+ }
+ LocationStore.endLocations();
+ }
+
+ /**
+ * Writes the location of a trace
+ *
+ * @param files
+ * file references
+ * @param trace
+ * trace to be written
+ */
+ private void writeLocation(ArrayList files, Trace trace) {
+ LocationProperties loc = findFirstLocation(trace);
+ if (loc != null) {
+ String path = loc.getFilePath();
+ String file = loc.getFileName();
+ if (path != null) {
+ path = FileUtils.convertSeparators(
+ SourceConstants.FORWARD_SLASH_CHAR, path, true);
+ // TODO: Remove drive letter. Actually cannot remove drive
+ // letter because EPOCROOT might not be in the root of the drive
+ }
+ DictionaryFileRef ref = getRef(files, file, path);
+ if (ref == null) {
+ ref = new DictionaryFileRef(file, path, trace);
+ files.add(ref);
+ trace.addExtension(ref);
+ } else {
+ trace.addExtension(ref);
+ }
+ }
+ }
+
+ /**
+ * Finds the first location from trace
+ *
+ * @param trace
+ * the trace
+ * @return the location
+ */
+ private LocationProperties findFirstLocation(Trace trace) {
+ Iterator itr = trace
+ .getExtensions(LocationListBase.class);
+ LocationProperties loc = null;
+ while (itr.hasNext() && loc == null) {
+ Iterator locs = itr.next().iterator();
+ if (locs.hasNext()) {
+ loc = locs.next();
+ }
+ }
+ return loc;
+ }
+
+ /**
+ * Gets a file reference
+ *
+ * @param files
+ * the list of file references
+ * @param file
+ * file name
+ * @param path
+ * file path
+ * @return the file reference
+ */
+ private DictionaryFileRef getRef(ArrayList files,
+ String file, String path) {
+ DictionaryFileRef retval = null;
+ for (int i = 0; i < files.size() && retval == null; i++) {
+ DictionaryFileRef ref = files.get(i);
+ if (ref.file.equals(file) && ref.path.equals(path)) {
+ retval = ref;
+ }
+ }
+ return retval;
+ }
+
+ /**
+ * Creates the component definition
+ */
+ private void createComponent() {
+ TraceModel model = dictionaryFile.getOwner().getModel();
+ int compid = model.getID();
+ // Component prefix and suffix are in property file.
+ // If not there, the default values are used
+ String prefix = TraceObjectUtils.findProperty(model,
+ PropertyNames.PREFIX);
+ if (prefix == null || prefix.length() == 0) {
+ prefix = FormattingUtils.getDefaultComponentPrefix(model);
+ }
+ String suffix = TraceObjectUtils.findProperty(model,
+ PropertyNames.SUFFIX);
+ if (suffix == null || suffix.length() == 0) {
+ suffix = FormattingUtils.getDefaultComponentSuffix(model);
+ }
+ Dictionary.startComponent(compid, dictionaryFile.getProjectName(),
+ prefix, suffix);
+ for (TraceGroup group : model) {
+ createGroup(group);
+ }
+ Dictionary.endComponent();
+ }
+
+ /**
+ * Creates a group definition
+ *
+ * @param group
+ * the group
+ */
+ private void createGroup(TraceGroup group) {
+ String prefix = TraceObjectUtils.findProperty(group,
+ PropertyNames.PREFIX);
+ if (prefix == null || prefix.length() == 0) {
+ prefix = FormattingUtils.getDefaultGroupPrefix(group);
+ }
+ String suffix = TraceObjectUtils.findProperty(group,
+ PropertyNames.SUFFIX);
+ if (suffix == null || suffix.length() == 0) {
+ suffix = FormattingUtils.getDefaultGroupSuffix(group);
+ }
+ TraceComponent.startGroup(group.getID(), group.getName(), prefix,
+ suffix);
+ for (Trace trace : group) {
+ createTrace(trace);
+ }
+ TraceComponent.endGroup();
+ }
+
+ /**
+ * Creates a trace definition
+ *
+ * @param trace
+ * the trace
+ */
+ private void createTrace(Trace trace) {
+ DictionaryDefRef defref = trace.getExtension(DictionaryDefRef.class);
+ if (defref != null) {
+ DictionaryFileRef fileref = trace
+ .getExtension(DictionaryFileRef.class);
+ com.nokia.tracecompiler.decodeplugins.dictionary.encoder.TraceGroup.startTrace(defref
+ .getRefId(), trace.getName());
+ if (fileref != null) {
+ writeTraceWithLocation(fileref.getRefId(), trace);
+ } else {
+ com.nokia.tracecompiler.decodeplugins.dictionary.encoder.Trace.writeInstance(trace
+ .getID(), 0, 0, "", //$NON-NLS-1$
+ ""); //$NON-NLS-1$
+ }
+ com.nokia.tracecompiler.decodeplugins.dictionary.encoder.TraceGroup.endTrace();
+ }
+ trace.removeExtensions(DictionaryRef.class);
+
+ }
+
+ /**
+ * Writes a trace which has a source location
+ *
+ * @param refId
+ * file reference number
+ * @param trace
+ * the trace
+ */
+ private void writeTraceWithLocation(int refId, Trace trace) {
+ LocationProperties loc = findFirstLocation(trace);
+ int line = 0;
+ String className = ""; //$NON-NLS-1$
+ String functionName = ""; //$NON-NLS-1$
+ if (loc != null) {
+ line = loc.getLineNumber();
+ className = loc.getClassName();
+ functionName = loc.getFunctionName();
+ }
+ com.nokia.tracecompiler.decodeplugins.dictionary.encoder.Trace.writeInstance(trace.getID(),
+ refId, line, functionName, className);
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/DictionaryPreferences.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/DictionaryPreferences.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,46 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Preferences for dictionary
+*
+*/
+package com.nokia.tracecompiler.decodeplugins.dictionary;
+
+/**
+ * Preferences for dictionary
+ *
+ */
+public interface DictionaryPreferences {
+
+ /**
+ * Export path for dictionary files
+ */
+ String EXPORT_PATH = "Dictionary.exportPath"; //$NON-NLS-1$
+
+ /**
+ * Default path where to export dictionary files
+ */
+ String DEFAULT_EXPORT_PATH = "epoc32/ost_dictionaries"; //$NON-NLS-1$
+
+ /**
+ * Gets a property from preferences
+ *
+ * @param name
+ * the property name
+ * @return the property value
+ */
+ public String getString(String name);
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/DictionaryRef.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/DictionaryRef.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,72 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Reference base class
+*
+*/
+package com.nokia.tracecompiler.decodeplugins.dictionary;
+
+import com.nokia.tracecompiler.model.TraceModelExtension;
+import com.nokia.tracecompiler.model.TraceObject;
+
+/**
+ * Reference base class
+ *
+ */
+class DictionaryRef implements TraceModelExtension {
+
+ /**
+ * Reference id
+ */
+ int refid;
+
+ /**
+ * Constructor
+ *
+ * @param refid
+ * the reference id
+ */
+ DictionaryRef(int refid) {
+ this.refid = refid;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.model.TraceModelExtension#getOwner()
+ */
+ public TraceObject getOwner() {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.model.TraceModelExtension#
+ * setOwner(com.nokia.tracecompiler.model.TraceObject)
+ */
+ public void setOwner(TraceObject owner) {
+ }
+
+ /**
+ * Gets the reference id
+ *
+ * @return ID
+ */
+ int getRefId() {
+ return refid;
+ }
+
+}
\ No newline at end of file
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/Messages.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/Messages.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,64 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Localization for dictionary package
+*
+*/
+package com.nokia.tracecompiler.decodeplugins.dictionary;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+/**
+ * Localization for dictionary package
+ *
+ */
+class Messages {
+
+ /**
+ * Bundle name
+ */
+ private static final String BUNDLE_NAME = "com.nokia.tracecompiler.decodeplugins.dictionary.messages"; //$NON-NLS-1$
+
+ /**
+ * Bundle
+ */
+ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
+ .getBundle(BUNDLE_NAME);
+
+ /**
+ * Prevents construction
+ */
+ private Messages() {
+
+ }
+
+ /**
+ * Gets localized string based on key
+ *
+ * @param key
+ * the resource key
+ * @return the localized resource
+ */
+ public static String getString(String key) {
+ String value;
+ try {
+ value = RESOURCE_BUNDLE.getString(key);
+ } catch (MissingResourceException e) {
+ value = '!' + key + '!';
+ }
+ return value;
+ }
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/encoder/DataType.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/encoder/DataType.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,96 @@
+/*
+* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* DataType enumeration
+*
+*/
+package com.nokia.tracecompiler.decodeplugins.dictionary.encoder;
+
+/**
+ * DataType enumeration
+ *
+ */
+public enum DataType {
+
+ /**
+ * String type
+ */
+ STRING("string"), //$NON-NLS-1$
+
+ /**
+ * Integer type
+ */
+ INTEGER("integer"), //$NON-NLS-1$
+
+ /**
+ * Float type
+ */
+ FLOAT("float"), //$NON-NLS-1$
+
+ /**
+ * Hex type
+ */
+ HEX("hex"), //$NON-NLS-1$
+
+ /**
+ * Binary type
+ */
+ BINARY("binary"), //$NON-NLS-1$
+
+ /**
+ * Octal type
+ */
+ OCTAL("octal"), //$NON-NLS-1$
+
+ /**
+ * Enum type
+ */
+ ENUM("enum"), //$NON-NLS-1$
+
+ /**
+ * Raw type
+ */
+ RAW("raw"), //$NON-NLS-1$
+
+ /**
+ * Compound type
+ */
+ COMPOUND("compound"); //$NON-NLS-1$
+
+ /**
+ * Data type
+ */
+ private final String type;
+
+ /**
+ * Constructor
+ *
+ * @param type
+ * the type
+ */
+ private DataType(String type) {
+ this.type = type;
+ }
+
+ /**
+ * Gets the type as string
+ *
+ * @return type
+ */
+ public String getType() {
+ return type;
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/encoder/Dictionary.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/encoder/Dictionary.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,101 @@
+/*
+* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Dictionary tag
+*
+*/
+package com.nokia.tracecompiler.decodeplugins.dictionary.encoder;
+
+/**
+ * Dictionary tag
+ *
+ */
+public class Dictionary {
+
+ /**
+ * Writes start of the XML file and starts <tracedictionary> structure
+ */
+ public static void startDictionary() {
+ TagWriter.write(TagWriter.XML_START, TagWriter.INDENT_0);
+ TagWriter.write(TagWriter.DICTIONARY_START, TagWriter.INDENT_0);
+ }
+
+ /**
+ * Writes </tracedictionary>
+ */
+ public static void endDictionary() {
+ TagWriter.write(TagWriter.DICTIONARY_END, TagWriter.INDENT_0);
+ TagWriter.close();
+ }
+
+ /**
+ * Starts <component id="", name="" prefix="" suffix=""> structure
+ *
+ * @param id
+ * unique component id within dictionary
+ * @param name
+ * name of the component
+ * @param prefix
+ * optional prefix for the component
+ * @param suffix
+ * optional suffix for the component
+ */
+ public static void startComponent(int id, String name, String prefix,
+ String suffix) {
+ TraceComponent.startComponent(id, name, prefix, suffix);
+
+ }
+
+ /**
+ * Writes </component>
+ */
+ public static void endComponent() {
+ TraceComponent.endComponent();
+ }
+
+ /**
+ * Starts <metadata> structure
+ */
+ public static void startMetaData() {
+ TagWriter.write(TagWriter.METADATA_START, TagWriter.INDENT_1);
+ }
+
+ /**
+ * Writes user defined tags <mytagXXX>value</mytagXXX>
+ *
+ * @param name
+ * tag
+ * @param value
+ * value of the tag
+ */
+ public static void writeMetaData(String name, String value) {
+ StringBuffer sb = new StringBuffer();
+ sb.append(TagWriter.START_TAG_OPEN);
+ sb.append(name);
+ sb.append(TagWriter.TAG_CLOSE);
+ sb.append(XMLDataFilter.changeData(value));
+ sb.append(TagWriter.END_TAG_OPEN);
+ sb.append(name);
+ sb.append(TagWriter.TAG_CLOSE);
+ TagWriter.write(sb.toString(), TagWriter.INDENT_2);
+ }
+
+ /**
+ * Writes </metadata>
+ */
+ public static void endMetaData() {
+ TagWriter.write(TagWriter.METADATA_END, TagWriter.INDENT_1);
+ }
+}
\ No newline at end of file
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/encoder/LocationStore.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/encoder/LocationStore.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,81 @@
+/*
+* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Location store
+*
+*/
+package com.nokia.tracecompiler.decodeplugins.dictionary.encoder;
+
+/**
+ * Location store
+ *
+ */
+public class LocationStore {
+
+ /**
+ * Writes <locations>
+ */
+ public static void startLocations() {
+ TagWriter.write(TagWriter.LOCATIONS_START, TagWriter.INDENT_1);
+ }
+
+ /**
+ * Starts <path val=""> structure
+ *
+ * @param path
+ * relative or absolute path to some directory
+ */
+ public static void startPath(String path) {
+ StringBuffer sb = new StringBuffer();
+ sb.append(TagWriter.PATH_START_OPEN);
+ TagWriter.appendAttribute(sb, TagWriter.VAL_ATTR, path, false);
+ sb.append(TagWriter.TAG_CLOSE);
+ TagWriter.write(sb.toString(), TagWriter.INDENT_2);
+ }
+
+ /**
+ * Writes <file id="">fileName</file> structure
+ *
+ * @param id
+ * unique number within <locations> structure
+ * @param fileName
+ * value of the file element
+ */
+ public static void writeFile(int id, String fileName) {
+ StringBuffer sb = new StringBuffer();
+ sb.append(TagWriter.FILE_START_OPEN);
+ TagWriter.appendAttribute(sb, TagWriter.ID_ATTR, String.valueOf(id),
+ false);
+ sb.append(TagWriter.TAG_CLOSE);
+ sb.append(XMLDataFilter.changeData(fileName));
+ sb.append(TagWriter.FILE_END);
+ TagWriter.write(sb.toString(), TagWriter.INDENT_3);
+ }
+
+ /**
+ * Writes </path>
+ */
+ public static void endPath() {
+ TagWriter.write(TagWriter.PATH_END, TagWriter.INDENT_2);
+ }
+
+ /**
+ * Writes </locations>
+ */
+ public static void endLocations() {
+ TagWriter.write(TagWriter.LOCATIONS_END, TagWriter.INDENT_1);
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/encoder/Options.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/encoder/Options.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,69 @@
+/*
+* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Options
+*
+*/
+package com.nokia.tracecompiler.decodeplugins.dictionary.encoder;
+
+/**
+ * Options
+ *
+ */
+public class Options {
+
+ /**
+ * Writes <options>
+ *
+ * @param indent
+ * amount of tabs for indent
+ */
+ static void startOptions(int indent) {
+ TagWriter.write(TagWriter.OPTIONS_START, indent);
+ }
+
+ /**
+ * Writes </options>
+ *
+ * @param indent
+ * amount of tabs for indent
+ */
+ static void endOptions(int indent) {
+ TagWriter.write(TagWriter.OPTIONS_END, indent);
+ }
+
+ /**
+ * Writes user defined tags <mytagXXX>value</mytagXXX>
+ *
+ * @param tag
+ * user defined tag
+ * @param value
+ * value of the tag
+ * @param indent
+ * amount of tabs for indent
+ */
+ static void writeOptions(String tag, String value, int indent) {
+ StringBuffer sb = new StringBuffer();
+ sb.append(TagWriter.START_TAG_OPEN);
+ sb.append(tag);
+ sb.append(TagWriter.TAG_CLOSE);
+ sb.append(XMLDataFilter.changeData(value));
+ sb.append(TagWriter.END_TAG_OPEN);
+ sb.append(tag);
+ sb.append(TagWriter.TAG_CLOSE);
+ TagWriter.write(sb.toString(), indent);
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/encoder/TagWriter.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/encoder/TagWriter.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,489 @@
+/*
+* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Tag writer
+*
+*/
+package com.nokia.tracecompiler.decodeplugins.dictionary.encoder;
+
+import java.io.BufferedOutputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+
+/**
+ * Tag writer
+ *
+ */
+class TagWriter {
+
+ /**
+ *
+ */
+ private static final String OUTPUT_FORMAT_UTF8 = "UTF-8"; //$NON-NLS-1$
+
+ /**
+ *
+ */
+ private static OutputStreamWriter m_writer = null;
+
+ /**
+ *
+ */
+ static final String XML_START = ""; //$NON-NLS-1$
+
+ /**
+ *
+ */
+ static final String CLASSIFICATION_ATTR = "classification="; //$NON-NLS-1$
+
+ /**
+ *
+ */
+ static final String CLASSNAME_ATTR = "classname="; //$NON-NLS-1$
+
+ /**
+ *
+ */
+ static final String COMPONENT_START_OPEN = "";//$NON-NLS-1$
+
+ /**
+ *
+ */
+ static final String DICTIONARY_END = ""; //$NON-NLS-1$
+
+ /**
+ *
+ */
+ static final String END_TAG_OPEN = ""; //$NON-NLS-1$
+
+ /**
+ *
+ */
+ static final String EXTERNAL_DEF_END = ""; //$NON-NLS-1$
+
+ /**
+ *
+ */
+ static final String EXTERNAL_DEF_START = ""; //$NON-NLS-1$
+
+ /**
+ *
+ */
+ static final String FILE_START_OPEN = ""); //$NON-NLS-1$ //$NON-NLS-2$
+ Dictionary.writeMetaData("id", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ Dictionary.endMetaData();
+ TypeDefStore.startTypeDefs();
+ TypeDefStore.writeExternalDefFile(" c:\\Temp\\ExternalDef.xml"); //$NON-NLS-1$
+ TypeDefStore.startTypeDef("TBool", 1, null, DataType.BINARY); //$NON-NLS-1$
+ TypeDef.writeTypeMember(0, "EFalse", "BOOL"); //$NON-NLS-1$ //$NON-NLS-2$
+ TypeDef.writeTypeMember(-1, "iX", "TInt"); //$NON-NLS-1$ //$NON-NLS-2$
+ TypeDef.writeTypeMember(0, "EFalse", null); //$NON-NLS-1$
+ TypeDefStore.endTypeDef();
+ TypeDefStore.startTypeDef("TPoint", -1, null, DataType.COMPOUND); //$NON-NLS-1$
+ TypeDef.writeTypeMember(-1, "iX", "TInt"); //$NON-NLS-1$ //$NON-NLS-2$
+ TypeDef.writeTypeMember(-1, "iY", "TInt"); //$NON-NLS-1$ //$NON-NLS-2$
+ TypeDefStore.endTypeDef();
+ TypeDefStore.writeTypeDef("TPixel", 1, "u", DataType.RAW); //$NON-NLS-1$ //$NON-NLS-2$
+ TypeDefStore.endTypeDefs();
+ TraceDataStore.startDataStore();
+ TraceDataStore.writeData(3, DataType.HEX, " value is 0xFF"); //$NON-NLS-1$ CodForChk_Dis_Magic
+ TraceDataStore.writeData(2, DataType.OCTAL, " value is 8"); //$NON-NLS-1$ CodForChk_Dis_Magic
+ TraceDataStore.writeData(1, DataType.BINARY, " value is 0"); //$NON-NLS-1$
+ TraceDataStore.endDataStore();
+ LocationStore.startLocations();
+ LocationStore.startPath("C:\\Temp\\"); //$NON-NLS-1$
+ LocationStore.writeFile(1, "C:\\Temp\\file1.txt"); //$NON-NLS-1$
+ LocationStore.writeFile(2, "C:\\Temp\\file2.txt"); //$NON-NLS-1$
+ LocationStore.endPath();
+ LocationStore.endLocations();
+ Dictionary.startComponent(666, "Satan", null, null); //$NON-NLS-1$ CodForChk_Dis_Magic
+ TraceComponent.startOptions();
+ TraceComponent.writeOption("background", "red"); //$NON-NLS-1$ //$NON-NLS-2$
+ TraceComponent.startGroup(1, "Group UNO", "pre", "suf"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ TraceGroup.startOptions();
+ TraceGroup.writeOption("JeesTag", ""); //$NON-NLS-1$ //$NON-NLS-2$
+ TraceGroup.writeOption("NoTag", ""); //$NON-NLS-1$ //$NON-NLS-2$
+ TraceGroup.endOptions();
+ TraceGroup.startTrace(-1, null);
+ Trace.startOptions();
+ Trace.writeOption("MyTag", "Value"); //$NON-NLS-1$ //$NON-NLS-2$
+ Trace.endOptions();
+ Trace.writeInstance(99, 1, 22, "testMethod", "testClass"); //$NON-NLS-1$ //$NON-NLS-2$ CodForChk_Dis_Magic
+ TraceGroup.endTrace();
+ TraceGroup.startTrace(-1, null);
+ Trace.writeInstance(100, 1, 235, "heyBabe", "auts"); //$NON-NLS-1$ //$NON-NLS-2$ CodForChk_Dis_Magic
+ Trace.writeInstance(100, 2, 291, "heyBabe2", "auts2"); //$NON-NLS-1$ //$NON-NLS-2$ CodForChk_Dis_Magic
+ TraceGroup.endTrace();
+ TraceComponent.endGroup();
+ Dictionary.endComponent();
+ Dictionary.endDictionary();
+
+ TraceDictionaryEncoder encoder2 = new TraceDictionaryEncoder();
+ encoder2.createNewDictionary(DICTIONARY2);
+ Dictionary.startDictionary();
+ Dictionary.startMetaData();
+ Dictionary.writeMetaData("id", "1"); //$NON-NLS-1$ //$NON-NLS-2$
+ Dictionary.writeMetaData("name", "Metadata Example"); //$NON-NLS-1$ //$NON-NLS-2$
+ Dictionary.endMetaData();
+ TypeDefStore.startTypeDefs();
+ TypeDefStore.writeExternalDefFile("StandardTypeDefs.xml"); //$NON-NLS-1$
+ TypeDefStore.writeTypeDef("TUint", 4, "u", DataType.ENUM); //$NON-NLS-1$ //$NON-NLS-2$ CodForChk_Dis_Magic
+ TypeDefStore.startTypeDef("TBool", 1, null, DataType.ENUM); //$NON-NLS-1$
+ TypeDef.writeTypeMember(0, "EFalse", null); //$NON-NLS-1$
+ TypeDef.writeTypeMember(1, "ETrue", null); //$NON-NLS-1$
+ TypeDefStore.endTypeDef();
+ TraceDataStore.startDataStore();
+ TraceDataStore.writeData(1, DataType.STRING, "My integer value: %d"); //$NON-NLS-1$
+ TraceDataStore.endDataStore();
+ LocationStore.startLocations();
+ LocationStore.startPath("../src"); //$NON-NLS-1$
+ LocationStore.writeFile(1, "foo.cpp"); //$NON-NLS-1$
+ LocationStore.writeFile(2, "foo2.cpp"); //$NON-NLS-1$ CodForChk_Dis_Magic
+ LocationStore.endPath();
+ LocationStore.endLocations();
+ Dictionary.startComponent(12345678, "ComName", "ComPrefix", null); //$NON-NLS-1$ //$NON-NLS-2$ CodForChk_Dis_Magic
+ TraceComponent.startGroup(1, "Flow", "GroupPrefix", "GroupSuffix"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ TraceGroup.startTrace(1, null);
+ Trace.writeInstance(1, 1, 14, "MyGlobalMethodL", null); //$NON-NLS-1$ CodForChk_Dis_Magic
+ Trace.writeInstance(2, 1, 214, "MyClassMethod", null); //$NON-NLS-1$ CodForChk_Dis_Magic
+ TraceGroup.endTrace();
+ TraceComponent.endGroup();
+ Dictionary.endComponent();
+ Dictionary.endDictionary();
+
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/encoder/Trace.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/encoder/Trace.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,120 @@
+/*
+* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Writes Trace objects
+*
+*/
+package com.nokia.tracecompiler.decodeplugins.dictionary.encoder;
+
+/**
+ * Writes Trace objects
+ *
+ */
+public class Trace {
+
+ /**
+ * Starts <trace data-ref=""> structure
+ *
+ * @param dataRef
+ * reference to actual data stored in <data> structure
+ * @param name
+ * name of the trace. Can be null if trace doesn't have name
+ */
+ static void startTrace(int dataRef, String name) {
+ StringBuffer sb = new StringBuffer();
+ sb.append(TagWriter.TRACE_START_OPEN);
+ if (dataRef >= 0) {
+ TagWriter.appendAttribute(sb, TagWriter.DATA_REF_ATTR, String
+ .valueOf(dataRef), false);
+
+ if (name != null && name != "") { //$NON-NLS-1$
+ TagWriter.appendAttribute(sb, TagWriter.NAME_ATTR, name, true);
+ }
+ }
+ sb.append(TagWriter.TAG_CLOSE);
+ TagWriter.write(sb.toString(), TagWriter.INDENT_3);
+
+ }
+
+ /**
+ * Writes </trace>
+ */
+ static void endTrace() {
+ TagWriter.write(TagWriter.TRACE_END, TagWriter.INDENT_3);
+ }
+
+ /**
+ * Writes <options>
+ */
+ public static void startOptions() {
+ Options.startOptions(TagWriter.INDENT_4);
+ }
+
+ /**
+ * Writes </options>
+ */
+ public static void endOptions() {
+ Options.endOptions(TagWriter.INDENT_4);
+ }
+
+ /**
+ * Writes user defined tags <mytagXXX>value</mytagXXX>
+ *
+ * @param tag
+ * user defined tag
+ * @param value
+ * value of the tag
+ */
+ public static void writeOption(String tag, String value) {
+ Options.writeOptions(tag, value, TagWriter.INDENT_5);
+ }
+
+ /**
+ * Writes <instance id="" locRef="" line="" methodName=""
+ * className=""/> structure
+ *
+ * @param id
+ * unique id number for this instance in current group structure
+ * @param locRef
+ * unique location reference for instance (reference to
+ * <locations> structure
+ * @param line
+ * positive number of line where data were founded in source file
+ * @param methodName
+ * name of the function from which trace was generated
+ * @param className
+ * this is class name or namespace name for method described in
+ * methodname attribute
+ */
+ public static void writeInstance(int id, int locRef, int line,
+ String methodName, String className) {
+ StringBuffer sb = new StringBuffer();
+ sb.append(TagWriter.INSTANCE_START_OPEN);
+ TagWriter.appendAttribute(sb, TagWriter.ID_ATTR, String.valueOf(id),
+ false);
+ TagWriter.appendAttribute(sb, TagWriter.LOC_REF_ATTR, String
+ .valueOf(locRef), true);
+ TagWriter.appendAttribute(sb, TagWriter.LINE_ATTR,
+ String.valueOf(line), true);
+ TagWriter.appendAttribute(sb, TagWriter.METHODNAME_ATTR, methodName,
+ true);
+ if (className != null) {
+ TagWriter.appendAttribute(sb, TagWriter.CLASSNAME_ATTR, className,
+ true);
+ }
+ sb.append(TagWriter.TAG_END);
+ TagWriter.write(sb.toString(), TagWriter.INDENT_4);
+ }
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/encoder/TraceComponent.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/encoder/TraceComponent.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,111 @@
+/*
+* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Writes component objects
+*
+*/
+package com.nokia.tracecompiler.decodeplugins.dictionary.encoder;
+
+/**
+ * Writes component objects
+ *
+ */
+public class TraceComponent {
+
+ /**
+ * Starts <component id="", name="" prefix="" suffix=""> structure
+ *
+ * @param id
+ * unique component id within dictionary
+ * @param name
+ * name of the component
+ * @param prefix
+ * optional prefix for the component
+ * @param suffix
+ * optional suffix for the component
+ */
+ static void startComponent(int id, String name, String prefix, String suffix) {
+ StringBuffer sb = new StringBuffer();
+ sb.append(TagWriter.COMPONENT_START_OPEN);
+ TagWriter.appendAttribute(sb, TagWriter.ID_ATTR, String.valueOf(id),
+ false);
+ TagWriter.appendAttribute(sb, TagWriter.NAME_ATTR, name, true);
+ if (prefix != null) {
+ TagWriter.appendAttribute(sb, TagWriter.PREFIX_ATTR, prefix, true);
+ }
+ if (suffix != null) {
+ TagWriter.appendAttribute(sb, TagWriter.SUFFIX_ATTR, suffix, true);
+ }
+ sb.append(TagWriter.TAG_CLOSE);
+ TagWriter.write(sb.toString(), TagWriter.INDENT_1);
+ }
+
+ /**
+ * Writes </component>
+ */
+ static void endComponent() {
+ TagWriter.write(TagWriter.COMPONENT_END, TagWriter.INDENT_1);
+ }
+
+ /**
+ * Writes <options>
+ */
+ public static void startOptions() {
+ Options.startOptions(TagWriter.INDENT_2);
+ }
+
+ /**
+ * Writes user defined tags <mytagXXX>value</mytagXXX>
+ *
+ * @param tag
+ * user defined tag
+ * @param value
+ * value of the tag
+ */
+ public static void writeOption(String tag, String value) {
+ Options.writeOptions(tag, value, TagWriter.INDENT_3);
+ }
+
+ /**
+ * Writes </options>
+ */
+ public static void endOptions() {
+ Options.endOptions(TagWriter.INDENT_2);
+ }
+
+ /**
+ * Starts <group id="", name="" prefix="" suffix=""> structure
+ *
+ * @param id
+ * unique group identifier within dictionary
+ * @param name
+ * group name
+ * @param prefix
+ * optional prefix for the group
+ * @param suffix
+ * optional suffix for the group
+ */
+ public static void startGroup(int id, String name, String prefix,
+ String suffix) {
+ TraceGroup.startGroup(id, name, prefix, suffix);
+ }
+
+ /**
+ * Writes </group>
+ */
+ public static void endGroup() {
+ TraceGroup.endGroup();
+ }
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/encoder/TraceDataStore.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/encoder/TraceDataStore.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,66 @@
+/*
+* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Writes Data objects
+*
+*/
+package com.nokia.tracecompiler.decodeplugins.dictionary.encoder;
+
+/**
+ * Writes Data objects
+ *
+ */
+public class TraceDataStore {
+
+ /**
+ * Writes <data>
+ */
+ public static void startDataStore() {
+ TagWriter.write(TagWriter.TRACE_DATA_START, TagWriter.INDENT_1);
+ }
+
+ /**
+ * Writes <def id="" dataType="">value</def> structure
+ *
+ * @param id
+ * unique number in <data> structure, it is data identifier
+ * @param dataType
+ * data type, defaults to string
+ * @param value
+ * the value
+ *
+ */
+ public static void writeData(int id, DataType dataType, String value) {
+ StringBuffer sb = new StringBuffer();
+ sb.append(TagWriter.DEF_START_OPEN);
+ TagWriter.appendAttribute(sb, TagWriter.ID_ATTR, String.valueOf(id),
+ false);
+ if (dataType != null) {
+ TagWriter.appendAttribute(sb, TagWriter.TYPE_ATTR, dataType
+ .getType(), true);
+ }
+ sb.append(TagWriter.TAG_CLOSE);
+ sb.append(XMLDataFilter.changeData(value));
+ sb.append(TagWriter.DEF_END);
+ TagWriter.write(sb.toString(), TagWriter.INDENT_2);
+ }
+
+ /**
+ * Writes </data>
+ */
+ public static void endDataStore() {
+ TagWriter.write(TagWriter.TRACE_DATA_END, TagWriter.INDENT_1);
+ }
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/encoder/TraceDictionaryEncoder.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/encoder/TraceDictionaryEncoder.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,42 @@
+/*
+* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Dictionary encoder class
+*
+*/
+package com.nokia.tracecompiler.decodeplugins.dictionary.encoder;
+
+/**
+ * Dictionary encoder class
+ *
+ */
+public class TraceDictionaryEncoder {
+
+ /**
+ * Constructor
+ */
+ public TraceDictionaryEncoder() {
+ }
+
+ /**
+ * Creates a new dictionary XML file to given path
+ *
+ * @param filePath
+ * the path
+ */
+ public void createNewDictionary(String filePath) {
+ TagWriter.initialize(filePath);
+ }
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/encoder/TraceGroup.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/encoder/TraceGroup.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,107 @@
+/*
+* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Writes groups objects
+*
+*/
+package com.nokia.tracecompiler.decodeplugins.dictionary.encoder;
+
+/**
+ * Writes groups objects
+ *
+ */
+public class TraceGroup {
+
+ /**
+ * Writes <options>
+ */
+ public static void startOptions() {
+ Options.startOptions(TagWriter.INDENT_3);
+ }
+
+ /**
+ * Writes user defined tags <mytagXXX>value</mytagXXX>
+ *
+ * @param tag
+ * user defined tag
+ * @param value
+ * value of the tag
+ */
+ public static void writeOption(String tag, String value) {
+ Options.writeOptions(tag, value, TagWriter.INDENT_4);
+ }
+
+ /**
+ * Writes </options>
+ */
+ public static void endOptions() {
+ Options.endOptions(TagWriter.INDENT_3);
+ }
+
+ /**
+ * Starts <trace data-ref=""> structure
+ *
+ * @param dataRef
+ * reference to actual data stored in <data> structure
+ * @param name
+ * name of the trace. Can be null if trace doesn't have name
+ */
+ public static void startTrace(int dataRef, String name) {
+ Trace.startTrace(dataRef, name);
+ }
+
+ /**
+ * Writes </trace>
+ */
+ public static void endTrace() {
+ Trace.endTrace();
+ }
+
+ /**
+ * Starts <group id="", name="" prefix="" suffix=""> structure
+ *
+ * @param id
+ * unique group identifier within dictionary
+ * @param name
+ * group name
+ * @param prefix
+ * optional prefix for the group
+ * @param suffix
+ * optional suffix for the group
+ */
+ static void startGroup(int id, String name, String prefix, String suffix) {
+ StringBuffer sb = new StringBuffer();
+ sb.append(TagWriter.GROUP_START_OPEN);
+ TagWriter.appendAttribute(sb, TagWriter.ID_ATTR, String.valueOf(id),
+ false);
+ TagWriter.appendAttribute(sb, TagWriter.NAME_ATTR, name, true);
+ if (prefix != null) {
+ TagWriter.appendAttribute(sb, TagWriter.PREFIX_ATTR, prefix, true);
+ }
+ if (suffix != null) {
+ TagWriter.appendAttribute(sb, TagWriter.SUFFIX_ATTR, suffix, true);
+ }
+ sb.append(TagWriter.TAG_CLOSE);
+ TagWriter.write(sb.toString(), TagWriter.INDENT_2);
+
+ }
+
+ /**
+ * Writes </group>
+ */
+ static void endGroup() {
+ TagWriter.write(TagWriter.GROUP_END, TagWriter.INDENT_2);
+ }
+}
\ No newline at end of file
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/encoder/TypeDef.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/encoder/TypeDef.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,52 @@
+/*
+* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Writes type def objects
+*
+*/
+package com.nokia.tracecompiler.decodeplugins.dictionary.encoder;
+
+/**
+ * Writes type def objects
+ *
+ */
+public class TypeDef {
+
+ /**
+ * Writes <typemember value="" name="" type=""/> structure
+ *
+ * @param value
+ * value which will be assigned to name attribute in case where
+ * object have classification equals enum
+ * @param name
+ * text which is assigned to value attribute or to type attribute
+ * @param type
+ * name of data type that will be assigned to name attribute in
+ * case where object classification equals compound
+ */
+ public static void writeTypeMember(int value, String name, String type) {
+ StringBuffer sb = new StringBuffer();
+ sb.append(TagWriter.TYPEMEMBER_START_OPEN);
+ TagWriter.appendAttribute(sb, TagWriter.VALUE_ATTR, String
+ .valueOf(value), false);
+ TagWriter.appendAttribute(sb, TagWriter.NAME_ATTR, name, true);
+ if (type != null) { // optional attribute
+ TagWriter.appendAttribute(sb, TagWriter.TYPE_ATTR, type, true);
+ }
+ sb.append(TagWriter.TAG_END);
+ TagWriter.write(sb.toString(), TagWriter.INDENT_3);
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/encoder/TypeDefStore.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/encoder/TypeDefStore.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,128 @@
+/*
+* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Writes type definition objects
+*
+*/
+package com.nokia.tracecompiler.decodeplugins.dictionary.encoder;
+
+/**
+ * Writes type definition objects
+ *
+ */
+public class TypeDefStore {
+
+ /**
+ * Writes <typedef>
+ */
+ public static void startTypeDefs() {
+ TagWriter.write(TagWriter.TYPEDEFS_START, TagWriter.INDENT_1);
+ }
+
+ /**
+ * Writes <external-def>path</external-def> structure
+ *
+ * @param path
+ * path to external dictionary file
+ */
+ public static void writeExternalDefFile(String path) {
+ StringBuffer sb = new StringBuffer();
+ sb.append(TagWriter.EXTERNAL_DEF_START);
+ sb.append(XMLDataFilter.changeData(path));
+ sb.append(TagWriter.EXTERNAL_DEF_END);
+ TagWriter.write(sb.toString(), TagWriter.INDENT_2);
+ }
+
+ /**
+ * Starts <object type="" size="" formatChar="" dataType=""> structure
+ *
+ * @param type
+ * original type name
+ * @param size
+ * size of typical object, it’s optional because dictionary user
+ * can calculate size for compound types by sum size of each
+ * member. Give -1 if not used.
+ * @param formatChar
+ * used for formatting
+ * @param dataType
+ * one value form <datatype> enumeration
+ */
+ public static void startTypeDef(String type, int size, String formatChar,
+ DataType dataType) {
+ StringBuffer sb = new StringBuffer();
+ sb.append(TagWriter.OBJECT_START_OPEN);
+ TagWriter.appendAttribute(sb, TagWriter.TYPE_ATTR, type, false);
+ if (size >= 0) { // optional attribute
+ TagWriter.appendAttribute(sb, TagWriter.SIZE_ATTR, String
+ .valueOf(size), true);
+ }
+ if (formatChar != null) { // optional attribute
+ TagWriter.appendAttribute(sb, TagWriter.FORMATCHAR_ATTR,
+ formatChar, true);
+ }
+ TagWriter.appendAttribute(sb, TagWriter.CLASSIFICATION_ATTR, dataType
+ .getType(), true);
+ sb.append(TagWriter.TAG_CLOSE);
+ TagWriter.write(sb.toString(), TagWriter.INDENT_2);
+ }
+
+ /**
+ * Writes <object type="" size="" formatChar="" dataType=""/>
+ * structure
+ *
+ * @param type
+ * original type name
+ * @param size
+ * size of typical object, it’s optional because dictionary user
+ * can calculate size for compound types by sum size of each
+ * member. Give -1 if not used.
+ * @param formatChar
+ * used for formatting
+ * @param dataType
+ * one value form <datatype> enumeration
+ */
+ public static void writeTypeDef(String type, int size, String formatChar,
+ DataType dataType) {
+ StringBuffer sb = new StringBuffer();
+ sb.append(TagWriter.OBJECT_START_OPEN);
+ TagWriter.appendAttribute(sb, TagWriter.TYPE_ATTR, type, false);
+ if (size >= 0) {
+ TagWriter.appendAttribute(sb, TagWriter.SIZE_ATTR, String
+ .valueOf(size), true);
+ }
+ if (formatChar != null) {
+ TagWriter.appendAttribute(sb, TagWriter.FORMATCHAR_ATTR,
+ formatChar, true);
+ }
+ TagWriter.appendAttribute(sb, TagWriter.CLASSIFICATION_ATTR, dataType
+ .getType(), true);
+ sb.append(TagWriter.TAG_END);
+ TagWriter.write(sb.toString(), TagWriter.INDENT_2);
+ }
+
+ /**
+ * Writes </object>
+ */
+ public static void endTypeDef() {
+ TagWriter.write(TagWriter.OBJECT_END, TagWriter.INDENT_2);
+ }
+
+ /**
+ * Writes </typedef>
+ */
+ public static void endTypeDefs() {
+ TagWriter.write(TagWriter.TYPEDEFS_END, TagWriter.INDENT_1);
+ }
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/encoder/XMLDataFilter.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/encoder/XMLDataFilter.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,85 @@
+/*
+* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Replaces special characters with escape sequences
+*
+*/
+package com.nokia.tracecompiler.decodeplugins.dictionary.encoder;
+
+/**
+ * Replaces special characters with escape sequences
+ *
+ */
+class XMLDataFilter {
+
+ /**
+ * XML start tag
+ */
+ private static final String LEFT_ARROW = "<"; //$NON-NLS-1$
+
+ /**
+ * XML end tag
+ */
+ private static final String RIGHT_ARROW = ">"; //$NON-NLS-1$
+
+ /**
+ * XML entity tag
+ */
+ private static final String AMPERSAND = "&"; //$NON-NLS-1$
+
+ /**
+ * XML start tag escaped
+ */
+ private static final String LEFT_ARROW_SUBST = "<"; //$NON-NLS-1$
+
+ /**
+ * XML end tag escaped
+ */
+ private static final String RIGHT_ARROW_SUBST = ">"; //$NON-NLS-1$
+
+ /**
+ * XML entity tag escaped
+ */
+ private static final String AMPERSAND_SUBST = "&"; //$NON-NLS-1$
+
+ /**
+ * Not found result
+ */
+ private static final int NOT_FOUND = -1;
+
+ /**
+ * Changes XML data
+ *
+ * @param data
+ * data to be changed
+ * @return changed data
+ */
+ static String changeData(String data) {
+
+ // This must be before any other that will add & marks to the text.
+ // Otherwise those will be replaced also.
+ if (data.indexOf(AMPERSAND) != NOT_FOUND) {
+ data = data.replaceAll(AMPERSAND, AMPERSAND_SUBST);
+ }
+ if (data.indexOf(LEFT_ARROW) != NOT_FOUND) {
+ data = data.replaceAll(LEFT_ARROW, LEFT_ARROW_SUBST);
+ }
+ if (data.indexOf(RIGHT_ARROW) != NOT_FOUND) {
+ data = data.replaceAll(RIGHT_ARROW, RIGHT_ARROW_SUBST);
+ }
+
+ return data;
+ }
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/encoder/package.html
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/encoder/package.html Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,3 @@
+
+Dictionary encoder is used to create dictionary XML files
+
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/messages.properties
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/messages.properties Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,1 @@
+DictionaryFile.Title=Dictionary File
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/package.html
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/decodeplugins/dictionary/package.html Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,3 @@
+
+TraceCompiler plug-in implementation to export the project to Symbian Dictionary format
+
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/document/FileDocument.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/document/FileDocument.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,89 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* File-based implementation of the document interface
+*
+*/
+package com.nokia.tracecompiler.document;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+
+import com.nokia.tracecompiler.file.FileUtils;
+import com.nokia.tracecompiler.source.SourceConstants;
+import com.nokia.tracecompiler.source.SourcePropertyProvider;
+
+/**
+ * File-based implementation of the document interface. This extends the string
+ * document with SourcePropertyProvider implementation which can provide the
+ * file name to TraceCompiler source framework
+ *
+ */
+final class FileDocument extends StringDocument implements
+ SourcePropertyProvider {
+
+ /**
+ * The file
+ */
+ private File file;
+
+ /**
+ * Constructor
+ *
+ * @param file
+ * the document file
+ * @throws IOException
+ * if processing fails
+ */
+ FileDocument(File file) throws IOException {
+ this.file = file;
+ byte[] buf = new byte[(int) file.length()];
+ FileInputStream fis = new FileInputStream(file);
+ fis.read(buf);
+ fis.close();
+ setSourceData(new String(buf));
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.utils.DocumentAdapter#getPropertyProvider()
+ */
+ @Override
+ public SourcePropertyProvider getPropertyProvider() {
+ return this;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.source.SourcePropertyProvider#getFileName()
+ */
+ public String getFileName() {
+ return file.getName();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.source.SourcePropertyProvider#getFilePath()
+ */
+ public String getFilePath() {
+ return FileUtils.convertSeparators(
+ SourceConstants.FORWARD_SLASH_CHAR, file.getParent(), true);
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/document/FileDocumentMonitor.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/document/FileDocumentMonitor.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,135 @@
+/*
+* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Document monitor implementation which reads all files from a directory
+*
+*/
+package com.nokia.tracecompiler.document;
+
+import java.io.File;
+import java.util.ArrayList;
+
+import com.nokia.tracecompiler.TraceCompilerGlobals;
+import com.nokia.tracecompiler.engine.TraceCompilerEngineErrorMessages;
+import com.nokia.tracecompiler.engine.TraceCompilerEngineGlobals;
+import com.nokia.tracecompiler.engine.TraceCompilerEngineErrorCodes.TraceCompilerErrorCode;
+import com.nokia.tracecompiler.engine.source.SourceEngine;
+import com.nokia.tracecompiler.file.FileUtils;
+import com.nokia.tracecompiler.source.SourceDocumentFactory;
+import com.nokia.tracecompiler.source.SourceDocumentProcessor;
+import com.nokia.tracecompiler.utils.DocumentMonitorBase;
+
+/**
+ * Document monitor implementation which reads files
+ *
+ */
+public final class FileDocumentMonitor extends DocumentMonitorBase {
+
+ /**
+ * Document factory
+ */
+ private StringDocumentFactory documentFactory;
+
+ /**
+ * Files to be processed
+ */
+ private static String[] files;
+
+ /**
+ * Sets the files to be used by the document monitor
+ *
+ * @param files
+ * the files
+ */
+ public static void setFiles(String[] files) {
+ FileDocumentMonitor.files = files;
+ }
+
+ /**
+ * Constructor
+ */
+ public FileDocumentMonitor() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.utils.DocumentMonitorBase#getFactory()
+ */
+ @Override
+ public SourceDocumentFactory getFactory() {
+ if (documentFactory == null) {
+ documentFactory = new StringDocumentFactory();
+ }
+ return documentFactory;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.utils.DocumentMonitorAdapter#
+ * startMonitor(com.nokia.tracecompiler.source.SourceDocumentProcessor)
+ */
+ @Override
+ public void startMonitor(SourceDocumentProcessor processor) throws Exception {
+
+ // Put source files and non-source files to same list
+ SourceEngine sourceEngine = TraceCompilerEngineGlobals.getSourceEngine();
+ ArrayList list = sourceEngine.getNonSourceFiles();
+ for (int i=0; i < files.length; i++) {
+ String fileName = files[i];
+ if (!list.contains(fileName)) {
+ list.add(fileName);
+ }
+ }
+ String[] fileArr = new String[list.size()];
+ list.toArray(fileArr);
+ String err = ""; //$NON-NLS-1$
+
+ for (String fileName : fileArr) {
+ File file = new File(fileName);
+ if (file.exists() && !file.isDirectory()
+ && FileUtils.isFileAllowed(file.getName())) {
+ try {
+ TraceCompilerEngineGlobals.getEvents().postInfoMessage(Messages.getString("FileDocumentMonitor.processingSourceFileText") + file.getAbsolutePath(), null); //$NON-NLS-1$
+ processor.sourceOpened(new FileDocument(file));
+ } catch (Exception e) {
+ // Error after processing one file
+ String msg = TraceCompilerEngineErrorMessages
+ .getErrorMessage(
+ TraceCompilerErrorCode.CANNOT_OPEN_SOURCE_FILE,
+ null);
+ TraceCompilerEngineGlobals.getEvents().postErrorMessage(msg,
+ file.getAbsolutePath(),true);
+ err = e.getMessage();
+ } finally {
+ if (TraceCompilerEngineGlobals.getEvents().hasErrorHappened() && !TraceCompilerGlobals.keepGoing()) {
+ throw new Exception("TraceCompiler stopping on error. " + err); //$NON-NLS-1$
+ }
+ }
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.utils.DocumentMonitorAdapter#stopMonitor()
+ */
+ @Override
+ public void stopMonitor() {
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/document/Messages.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/document/Messages.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,57 @@
+/*
+* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Localized strings for engine package
+*
+*/
+package com.nokia.tracecompiler.document;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class Messages {
+
+ /**
+ * Bundle name
+ */
+ private static final String BUNDLE_NAME = "com.nokia.tracecompiler.document.messages"; //$NON-NLS-1$
+
+ /**
+ * Bundle
+ */
+ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
+ .getBundle(BUNDLE_NAME);
+
+ /**
+ * Prevents construction
+ */
+ private Messages() {
+ }
+
+ /**
+ * Gets localized string based on key
+ *
+ * @param key
+ * the resource key
+ * @return the localized resource
+ */
+ public static String getString(String key) {
+ try {
+ return RESOURCE_BUNDLE.getString(key);
+ } catch (MissingResourceException e) {
+ return '!' + key + '!';
+ }
+ }
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/document/StringDocument.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/document/StringDocument.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,126 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* String-based document object
+*
+*/
+package com.nokia.tracecompiler.document;
+
+import java.util.ArrayList;
+
+import com.nokia.tracecompiler.source.SourceParserException;
+import com.nokia.tracecompiler.utils.DocumentAdapter;
+
+/**
+ * String-based document object
+ *
+ */
+class StringDocument extends DocumentAdapter {
+
+ /**
+ * The document data
+ */
+ private String sourceData;
+
+ /**
+ * Line information
+ */
+ private ArrayList lines = new ArrayList();
+
+ /**
+ * Constructor
+ */
+ StringDocument() {
+ }
+
+ /**
+ * Constructor
+ *
+ * @param data
+ * the document data
+ */
+ StringDocument(String data) {
+ setSourceData(data);
+ }
+
+ /**
+ * Sets the source data
+ *
+ * @param data
+ * the source data
+ */
+ void setSourceData(String data) {
+ this.sourceData = data;
+ if (data.length() > 0) {
+ lines.add(0);
+ }
+ for (int i = 0; i < data.length(); i++) {
+ if (data.charAt(i) == '\n') {
+ lines.add(i + 1);
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.utils.DocumentAdapter#get(int, int)
+ */
+ @Override
+ public String get(int start, int length) throws SourceParserException {
+ return sourceData.substring(start, start + length);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.utils.DocumentAdapter#getChar(int)
+ */
+ @Override
+ public char getChar(int offset) throws SourceParserException {
+ return sourceData.charAt(offset);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.utils.DocumentAdapter#getLength()
+ */
+ @Override
+ public int getLength() {
+ return sourceData.length();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.utils.DocumentAdapter#getLineOfOffset(int)
+ */
+ @Override
+ public int getLineOfOffset(int offset) throws SourceParserException {
+ int retval = -1;
+ if (offset >= 0 && offset < sourceData.length()) {
+ for (int i = 0; i < lines.size(); i++) {
+ int lineStart = lines.get(i);
+ if (lineStart > offset) {
+ retval = i - 1;
+ i = lines.size();
+ }
+ }
+ }
+ return retval;
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/document/StringDocumentFactory.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/document/StringDocumentFactory.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,41 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Document factory for file-based documents
+*
+*/
+package com.nokia.tracecompiler.document;
+
+import com.nokia.tracecompiler.source.SourceDocumentInterface;
+import com.nokia.tracecompiler.utils.DocumentFactoryBase;
+
+/**
+ * Document factory for string-based documents and simple locations which do not
+ * support changes or selections.
+ *
+ */
+public final class StringDocumentFactory extends DocumentFactoryBase {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.utils.DocumentFactoryBase#createDocument(java.lang.String)
+ */
+ @Override
+ public SourceDocumentInterface createDocument(String sourceData) {
+ return new StringDocument(sourceData);
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/document/messages.properties
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/document/messages.properties Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,1 @@
+FileDocumentMonitor.processingSourceFileText=Processing source file :
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/ConfigurationDelegate.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/ConfigurationDelegate.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,204 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Delegate to configuration of the view
+*
+*/
+package com.nokia.tracecompiler.engine;
+
+import java.util.ArrayList;
+
+/**
+ * Delegate to configuration of the view
+ *
+ */
+final class ConfigurationDelegate implements TraceCompilerEngineConfiguration {
+
+ /**
+ * Configuration from view
+ */
+ private TraceCompilerEngineConfiguration configuration;
+
+ /**
+ * Temporary list of configuration listeners
+ */
+ private ArrayList tempListeners;
+
+ /**
+ * Sets the configuration delegate
+ *
+ * @param configuration
+ * the configuration
+ */
+ void setConfiguration(TraceCompilerEngineConfiguration configuration) {
+ this.configuration = configuration;
+ if (configuration != null && tempListeners != null) {
+ for (int i = 0; i < tempListeners.size(); i++) {
+ TraceCompilerEngineConfigurationListener listener = tempListeners
+ .get(i);
+ configuration.addConfigurationListener(listener);
+ listener.configurationCreated();
+ }
+ tempListeners.clear();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.TraceCompilerConfiguration#isAvailable()
+ */
+ public boolean isAvailable() {
+ boolean retval;
+ if (configuration != null) {
+ retval = configuration.isAvailable();
+ } else {
+ retval = false;
+ }
+ return retval;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.TraceCompilerConfiguration#
+ * addConfigurationListener(com.nokia.tracecompiler.engine.TraceCompilerConfigurationListener)
+ */
+ public void addConfigurationListener(
+ TraceCompilerEngineConfigurationListener configurationListener) {
+ if (configuration != null) {
+ configuration.addConfigurationListener(configurationListener);
+ } else {
+ if (tempListeners == null) {
+ tempListeners = new ArrayList();
+ }
+ tempListeners.add(configurationListener);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.TraceCompilerConfiguration#
+ * removeConfigurationListener(com.nokia.tracecompiler.engine.TraceCompilerConfigurationListener)
+ */
+ public void removeConfigurationListener(
+ TraceCompilerEngineConfigurationListener configurationListener) {
+ if (configuration != null) {
+ configuration.removeConfigurationListener(configurationListener);
+ } else {
+ if (tempListeners != null) {
+ tempListeners.remove(configurationListener);
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.TraceCompilerConfiguration#getFlag(java.lang.String)
+ */
+ public boolean getFlag(String flagName) {
+ boolean retval;
+ if (configuration != null) {
+ retval = configuration.getFlag(flagName);
+ } else {
+ retval = false;
+ }
+ return retval;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.TraceCompilerConfiguration#getText(java.lang.String)
+ */
+ public String getText(String textName) {
+ String retval;
+ if (configuration != null) {
+ retval = configuration.getText(textName);
+ } else {
+ retval = ""; //$NON-NLS-1$
+ }
+ return retval;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.TraceCompilerConfiguration#getValue(java.lang.String)
+ */
+ public int getValue(String valueName) {
+ int retval;
+ if (configuration != null) {
+ retval = configuration.getValue(valueName);
+ } else {
+ retval = 0;
+ }
+ return retval;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.TraceCompilerConfiguration#hasEntry(java.lang.String)
+ */
+ public boolean hasEntry(String entryName) {
+ boolean retval;
+ if (configuration != null) {
+ retval = configuration.hasEntry(entryName);
+ } else {
+ retval = false;
+ }
+ return retval;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.TraceCompilerConfiguration#
+ * setFlag(java.lang.String, boolean)
+ */
+ public void setFlag(String flagName, boolean flag) {
+ if (configuration != null) {
+ configuration.setFlag(flagName, flag);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.TraceCompilerConfiguration#
+ * setText(java.lang.String, java.lang.String)
+ */
+ public void setText(String textName, String text) {
+ if (configuration != null) {
+ configuration.setText(textName, text);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.TraceCompilerConfiguration#setValue(java.lang.String,
+ * int)
+ */
+ public void setValue(String valueName, int value) {
+ if (configuration != null) {
+ configuration.setValue(valueName, value);
+ }
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/LocationListBase.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/LocationListBase.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,121 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Base class for TraceLocationList and PersistentLocationList
+*
+*/
+package com.nokia.tracecompiler.engine;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import com.nokia.tracecompiler.model.TraceModelExtension;
+import com.nokia.tracecompiler.model.TraceObject;
+
+/**
+ * Base class for TraceLocationList and PersistentLocationList
+ *
+ */
+public class LocationListBase implements TraceModelExtension,
+ Iterable {
+
+ /**
+ * List of locations
+ */
+ private ArrayList locations = new ArrayList();
+
+ /**
+ * Owning trace object
+ */
+ private TraceObject owner;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.model.TraceModelExtension#getOwner()
+ */
+ public TraceObject getOwner() {
+ return owner;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.model.TraceModelExtension#setOwner(com.nokia.tracecompiler.model.TraceObject)
+ */
+ public void setOwner(TraceObject owner) {
+ this.owner = owner;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Iterable#iterator()
+ */
+ public Iterator iterator() {
+ return locations.iterator();
+ }
+
+ /**
+ * Gets the location count of this list
+ *
+ * @return the count
+ */
+ public final int getLocationCount() {
+ return locations.size();
+ }
+
+ /**
+ * Checks if there are locations in this list
+ *
+ * @return true if list has locations
+ */
+ public final boolean hasLocations() {
+ return !locations.isEmpty();
+ }
+
+ /**
+ * Adds a location to this list
+ *
+ * @param location
+ * the location to be added
+ */
+ void add(LocationProperties location) {
+ locations.add(location);
+ }
+
+ /**
+ * Removes a location from this list
+ *
+ * @param location
+ * the location to be removed
+ * @return true if removed
+ */
+ boolean remove(LocationProperties location) {
+ return locations.remove(location);
+ }
+
+ /**
+ * Checks if location exists
+ *
+ * @param location
+ * the location
+ * @return true if exists
+ */
+ boolean contains(LocationProperties location) {
+ return locations.contains(location);
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/LocationMapModelListener.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/LocationMapModelListener.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,113 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Model listener for trace location mapper
+*
+*/
+package com.nokia.tracecompiler.engine;
+
+import com.nokia.tracecompiler.model.Trace;
+import com.nokia.tracecompiler.model.TraceCompilerException;
+import com.nokia.tracecompiler.model.TraceGroup;
+import com.nokia.tracecompiler.model.TraceModelListener;
+import com.nokia.tracecompiler.model.TraceObject;
+import com.nokia.tracecompiler.model.TraceParameter;
+
+/**
+ * Model listener for trace location mapper
+ *
+ */
+final class LocationMapModelListener implements TraceModelListener {
+
+ /**
+ * Trace location mapper
+ */
+ private final TraceLocationMap locationMap;
+
+ /**
+ * Constructor
+ *
+ * @param map
+ * the location mapper
+ */
+ LocationMapModelListener(TraceLocationMap map) {
+ locationMap = map;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.model.TraceModelListener#
+ * objectAdded(com.nokia.tracecompiler.model.TraceObject,
+ * com.nokia.tracecompiler.model.TraceObject)
+ */
+ public void objectAdded(TraceObject owner, TraceObject object) {
+ // A trace does not have a name yet, so this does nothing
+ // The locations are assigned to the trace in propertyChanged
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.model.TraceModelListener#
+ * objectRemoved(com.nokia.tracecompiler.model.TraceObject,
+ * com.nokia.tracecompiler.model.TraceObject)
+ */
+ public void objectRemoved(TraceObject owner, TraceObject object) throws TraceCompilerException {
+ if (object instanceof Trace) {
+ locationMap.moveToUnrelated((Trace) object);
+ } else if (object instanceof TraceGroup) {
+ // Moves locations to unrelated list
+ for (Trace trace : (TraceGroup) object) {
+ locationMap.moveToUnrelated(trace);
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.model.TraceModelListener#
+ * propertiesUpdated(com.nokia.tracecompiler.model.TraceObject)
+ */
+ public void propertyUpdated(TraceObject object, int property) throws TraceCompilerException {
+ if (object instanceof Trace && property == NAME && object.isComplete()) {
+ Trace trace = (Trace) object;
+ locationMap.moveFromUnrelated(trace);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.model.TraceModelListener#
+ * objectCreationComplete(com.nokia.tracecompiler.model.TraceObject)
+ */
+ public void objectCreationComplete(TraceObject object) throws TraceCompilerException {
+ if (object instanceof Trace) {
+ Trace trace = (Trace) object;
+ locationMap.moveFromUnrelated(trace);
+ } else if (object instanceof TraceParameter) {
+ // If a parameter is added, the validity needs to be checked
+ TraceLocationList list = ((TraceParameter) object).getTrace()
+ .getExtension(TraceLocationList.class);
+ if (list != null) {
+ for (LocationProperties loc : list) {
+ ((TraceLocation) loc).runValidityCheck();
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/LocationProperties.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/LocationProperties.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,62 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Common properties of locations
+*
+*/
+package com.nokia.tracecompiler.engine;
+
+/**
+ * Common properties of locations
+ *
+ */
+public interface LocationProperties {
+
+ /**
+ * Gets the file path
+ *
+ * @return the file path
+ */
+ public String getFilePath();
+
+ /**
+ * Gets the file name
+ *
+ * @return the file name
+ */
+ public String getFileName();
+
+ /**
+ * Gets the line number
+ *
+ * @return the line number
+ */
+ public int getLineNumber();
+
+ /**
+ * Gets the name of the class which owns this location
+ *
+ * @return the class name
+ */
+ public String getClassName();
+
+ /**
+ * Gets the name of function which owns this location
+ *
+ * @return the function name
+ */
+ public String getFunctionName();
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/Messages.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/Messages.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,63 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Localized strings for engine package
+*
+*/
+package com.nokia.tracecompiler.engine;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+/**
+ * Messages for engine package
+ *
+ */
+public class Messages {
+
+ /**
+ * Bundle name
+ */
+ private static final String BUNDLE_NAME = "com.nokia.tracecompiler.engine.messages"; //$NON-NLS-1$
+
+ /**
+ * Bundle
+ */
+ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
+ .getBundle(BUNDLE_NAME);
+
+ /**
+ * Prevents construction
+ */
+ private Messages() {
+ }
+
+ /**
+ * Gets localized string based on key
+ *
+ * @param key
+ * the resource key
+ * @return the localized resource
+ */
+ public static String getString(String key) {
+ String value;
+ try {
+ value = RESOURCE_BUNDLE.getString(key);
+ } catch (MissingResourceException e) {
+ value = '!' + key + '!';
+ }
+ return value;
+ }
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/SourceContextManager.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/SourceContextManager.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,59 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Interface to change the currently active source context
+*
+*/
+package com.nokia.tracecompiler.engine;
+
+import com.nokia.tracecompiler.source.SourceContext;
+
+/**
+ * Interface to the currently active source context
+ *
+ */
+public interface SourceContextManager {
+
+ /**
+ * Gets the active source context
+ *
+ * @return the context
+ */
+ public SourceContext getContext();
+
+ /**
+ * Sets the active source context
+ *
+ * @param context
+ * the context
+ */
+ public void setContext(SourceContext context);
+
+ /**
+ * Checks if the auto-converter is running
+ *
+ * @return true if converter is running, false otherwise
+ */
+ public boolean isConverting();
+
+ /**
+ * Sets the auto-converter flag
+ *
+ * @param flag
+ * the new flag value
+ */
+ public void setConverting(boolean flag);
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/SourceContextManagerImpl.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/SourceContextManagerImpl.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,84 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* SourceContextManager interface implementation
+*
+*/
+package com.nokia.tracecompiler.engine;
+
+import com.nokia.tracecompiler.source.SourceContext;
+
+/**
+ * SourceContextManager interface implementation
+ *
+ */
+final class SourceContextManagerImpl implements SourceContextManager {
+
+ /**
+ * Active context
+ */
+ private SourceContext activeContext;
+
+ /**
+ * Converting flag
+ */
+ private boolean isConverting;
+
+ /**
+ * Constructor
+ *
+ * @param sourceEngine
+ * the source engine
+ */
+ SourceContextManagerImpl() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.SourceContextManager#getContext()
+ */
+ public SourceContext getContext() {
+ return activeContext;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.SourceContextManager#
+ * setContext(com.nokia.tracecompiler.source.SourceContext)
+ */
+ public void setContext(SourceContext context) {
+ activeContext = context;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.SourceContextManager#isConverting()
+ */
+ public boolean isConverting() {
+ return isConverting;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.SourceContextManager#setConverting(boolean)
+ */
+ public void setConverting(boolean flag) {
+ this.isConverting = flag;
+ }
+}
\ No newline at end of file
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/TraceCompilerEngine.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/TraceCompilerEngine.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,393 @@
+/*
+ * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ *
+ * Description:
+ *
+ * A singleton access point to functionality of Trace Compiler
+ *
+ */
+package com.nokia.tracecompiler.engine;
+
+import java.util.ArrayList;
+
+import com.nokia.tracecompiler.engine.TraceCompilerEngineErrorCodes.TraceCompilerErrorCode;
+import com.nokia.tracecompiler.engine.event.EventEngine;
+import com.nokia.tracecompiler.engine.header.HeaderEngine;
+import com.nokia.tracecompiler.engine.plugin.PluginEngine;
+import com.nokia.tracecompiler.engine.project.ProjectEngine;
+import com.nokia.tracecompiler.engine.propertyfile.PropertyFileEngine;
+import com.nokia.tracecompiler.engine.rules.RulesEngine;
+import com.nokia.tracecompiler.engine.source.SourceEngine;
+import com.nokia.tracecompiler.engine.source.SourceListener;
+import com.nokia.tracecompiler.engine.source.SourceProperties;
+import com.nokia.tracecompiler.model.TraceCompilerException;
+import com.nokia.tracecompiler.model.TraceModel;
+import com.nokia.tracecompiler.plugin.TraceCompilerPlugin;
+
+/**
+ * A singleton access point to functionality of Trace Compiler
+ *
+ */
+final class TraceCompilerEngine implements SourceListener, TraceCompilerEngineInterface {
+
+ /**
+ * TraceCompiler plug-in engine
+ */
+ private PluginEngine pluginEngine;
+
+ /**
+ * Event handler interface implementation
+ */
+ private TraceCompilerEngineEvents eventEngine;
+
+ /**
+ * Source editor engine
+ */
+ private SourceEngine sourceEngine;
+
+ /**
+ * Trace header engine
+ */
+ private HeaderEngine headerEngine;
+
+ /**
+ * Trace project engine
+ */
+ private ProjectEngine projectEngine;
+
+ /**
+ * Rule engine
+ */
+ private RulesEngine rulesEngine;
+
+ /**
+ * Trace property file engine
+ */
+ private PropertyFileEngine propertyFileEngine;
+
+ /**
+ * Source context manager
+ */
+ private SourceContextManager contextManager;
+
+ /**
+ * Location map
+ */
+ private TraceLocationMap locationMap;
+
+ /**
+ * Location converter
+ */
+ private TraceLocationConverter locationConverter;
+
+ /**
+ * Trace model
+ */
+ private TraceModel model;
+
+ /**
+ * Interface to the view
+ */
+ private TraceCompilerEngineView view = new ViewAdapter();
+
+ /**
+ * Configuration
+ */
+ private ConfigurationDelegate configurationDelegate;
+
+ /**
+ * List of engines that need project open / export / close notifications
+ */
+ private ArrayList engines = new ArrayList();
+
+ /**
+ * View has been registered flag
+ */
+ private boolean isViewRegistered = false;
+
+ /**
+ * Project path is stored in case the view unregisters and re-registers
+ */
+ private String currentProjectPath;
+
+ /**
+ * Gets the configuration of TraceCompiler
+ *
+ * @return the configuration
+ */
+ TraceCompilerEngineConfiguration getConfiguration() {
+ return configurationDelegate;
+ }
+
+ /**
+ * Gets the trace compiler interface
+ *
+ * @return this object
+ */
+ TraceCompilerEngineInterface getTraceCompiler() {
+ return this;
+ }
+
+ /**
+ * Gets the trace model
+ *
+ * @return the trace model
+ */
+ TraceModel getModel() {
+ return model;
+ }
+
+ /**
+ * Gets the source engine
+ *
+ * @return the source engine
+ */
+ SourceEngine getSourceEngine() {
+ return sourceEngine;
+ }
+
+ /**
+ * Gets the events interface
+ *
+ * @return the events interface
+ */
+ TraceCompilerEngineEvents getEvents() {
+ return eventEngine;
+ }
+
+ /**
+ * Adds a plug-in
+ *
+ * @param plugin
+ * the plugin
+ */
+ void registerPlugin(TraceCompilerPlugin plugin) {
+ pluginEngine.add(plugin);
+ }
+
+ /**
+ * Removes an existing plug-in
+ *
+ * @param plugin
+ * the plugin
+ */
+ void unregisterPlugin(TraceCompilerPlugin plugin) {
+ pluginEngine.remove(plugin);
+ }
+
+ /**
+ * Gets the source context manager
+ *
+ * @return the context manager
+ */
+ public SourceContextManager getSourceContextManager() {
+ return contextManager;
+ }
+
+ /**
+ * Starts TraceCompiler.
+ * @throws TraceCompilerException
+ */
+ void start() throws TraceCompilerException {
+ configurationDelegate = new ConfigurationDelegate();
+ rulesEngine = new RulesEngine();
+ pluginEngine = new PluginEngine();
+ model = new TraceModel(rulesEngine, pluginEngine.getVerifier());
+ pluginEngine.setModel(model);
+ projectEngine = new ProjectEngine(model);
+ propertyFileEngine = new PropertyFileEngine(model);
+ eventEngine = new EventEngine(model);
+ sourceEngine = new SourceEngine(model);
+ locationMap = new TraceLocationMap(model);
+ locationConverter = new TraceLocationConverter(model);
+ sourceEngine.addSourceListener(this);
+ contextManager = new SourceContextManagerImpl();
+ headerEngine = new HeaderEngine(model);
+ // Keep this order -> Exports need to be in correct order
+ // Property file engine manages the ID cache so it needs to be run
+ // before plug-in's and header
+ engines.add(projectEngine);
+ engines.add(propertyFileEngine);
+ engines.add(headerEngine);
+ engines.add(pluginEngine);
+ }
+
+ /**
+ * Shuts down TraceCompiler
+ * @throws TraceCompilerException
+ */
+ void shutdown() throws TraceCompilerException {
+ closeProject();
+ }
+
+ /**
+ * Registers the view
+ *
+ * @param view
+ * the view
+ * @throws TraceCompilerException
+ */
+ void setView(TraceCompilerEngineView view) throws TraceCompilerException {
+ if (view == null) {
+ // Closes the project, but leaves the currentProjectName and
+ // currentProjectPath variables. When view re-registers the project
+ // is opened back
+ internalCloseProject();
+ this.view = new ViewAdapter();
+ isViewRegistered = false;
+ } else {
+ this.view = view;
+ isViewRegistered = true;
+ }
+ configurationDelegate.setConfiguration(this.view.getConfiguration());
+ }
+
+ /**
+ * Checks that model is valid
+ *
+ * @throws TraceCompilerException
+ * if model is not valid
+ */
+ private void checkIsModelValid() throws TraceCompilerException {
+ if (!model.isValid()) {
+ throw new TraceCompilerException(
+ TraceCompilerErrorCode.MODEL_NOT_READY);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.TraceCompilerEngineInterface#openProject(java.lang.String,
+ * java.lang.String)
+ */
+ public void openProject(String modelName) throws Exception {
+ try {
+ if (view != null && isViewRegistered && !model.isValid()) {
+ projectEngine.openTraceProject(currentProjectPath, modelName);
+ for (TraceCompilerEngineBase engine : engines) {
+ engine.projectOpened();
+ }
+ model.setValid(true);
+ sourceEngine.start();
+ }
+ } catch (TraceCompilerException e) {
+ closeModel();
+ throw e;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.TraceCompilerEngineInterface#exportProject()
+ */
+ public void exportProject() throws TraceCompilerException {
+ checkIsModelValid();
+ if (model.getID() != 0) {
+ for (TraceCompilerEngineBase engine : engines) {
+ engine.exportProject();
+ }
+ } else {
+ throw new TraceCompilerException(
+ TraceCompilerErrorCode.INVALID_MODEL_PROPERTIES_FOR_EXPORT);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.TraceCompilerEngineInterface#closeProject()
+ */
+ public void closeProject() throws TraceCompilerException {
+ internalCloseProject();
+ currentProjectPath = null;
+ }
+
+ /**
+ * Closes the project
+ * @throws TraceCompilerException
+ */
+ private void internalCloseProject() throws TraceCompilerException {
+ if (model.isValid()) {
+ if (!TraceCompilerEngineGlobals.getConfiguration().getFlag(
+ TraceCompilerEngineConfiguration.CONSOLE_UI_MODE)) {
+ try {
+ // Plug-in's are not exported when project is closed
+ // They can do cleanup in traceProjectClosed call
+ for (TraceCompilerEngineBase engine : engines) {
+ if (engine != pluginEngine) {
+ engine.exportProject();
+ }
+ }
+ } catch (TraceCompilerException e) {
+ getEvents().postError(e);
+ throw e;
+ }
+ }
+ // Engines are closed in reverse order
+ for (int i = engines.size() - 1; i >= 0; i--) {
+ engines.get(i).projectClosed();
+ }
+ sourceEngine.shutdown();
+ closeModel();
+ }
+ }
+
+ /**
+ * Closes the trace model
+ */
+ private void closeModel() {
+ try {
+ if (model != null) {
+ model.reset();
+ model.setValid(false);
+ }
+ } catch (Exception e) {
+ if (TraceCompilerEngineConfiguration.ASSERTIONS_ENABLED) {
+ getEvents().postAssertionFailed("Failed to close model", e); //$NON-NLS-1$
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.SourceListener#
+ * sourceOpened(com.nokia.tracecompiler.engine.SourceProperties)
+ */
+ public void sourceOpened(SourceProperties properties) throws TraceCompilerException {
+ locationMap.addSource(properties);
+ locationConverter.sourceOpened(properties);
+ }
+
+ /**
+ * Get project path
+ *
+ * @return project path
+ */
+ public String getProjectPath() {
+ return currentProjectPath;
+ }
+
+ /**
+ * Set project path
+ *
+ * @param path
+ * the path
+ */
+ public void setProjectPath(String path) {
+ currentProjectPath = path;
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/TraceCompilerEngineActions.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/TraceCompilerEngineActions.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,35 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Action interface
+*
+*/
+package com.nokia.tracecompiler.engine;
+
+/**
+ * Action interface
+ *
+ */
+public interface TraceCompilerEngineActions {
+
+ /**
+ * Enables actions based on selected object
+ *
+ * @param object
+ * the object that has been selected
+ */
+ public void enableActions(Object object);
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/TraceCompilerEngineBase.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/TraceCompilerEngineBase.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,48 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Base class for all engine classes
+*
+*/
+package com.nokia.tracecompiler.engine;
+
+import com.nokia.tracecompiler.model.TraceCompilerException;
+
+/**
+ * Base class for all engine classes
+ *
+ */
+public abstract class TraceCompilerEngineBase {
+
+ /**
+ * Called after trace project has been opened
+ * @throws TraceCompilerException
+ */
+ public abstract void projectOpened() throws TraceCompilerException;
+
+ /**
+ * Called when trace project is closed
+ */
+ public abstract void projectClosed();
+
+ /**
+ * Called when exporting the project
+ *
+ * @throws TraceCompilerException
+ * if export fails
+ */
+ public abstract void exportProject() throws TraceCompilerException;
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/TraceCompilerEngineConfiguration.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/TraceCompilerEngineConfiguration.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,188 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Access to configuration of TraceCompiler
+*
+*/
+package com.nokia.tracecompiler.engine;
+
+/**
+ * Access to configuration of TraceCompiler
+ *
+ */
+public interface TraceCompilerEngineConfiguration {
+
+ /**
+ * Name of the currently selected source formatter
+ */
+ public String FORMATTER_NAME = "TraceCompiler.sourceFormatter"; //$NON-NLS-1$
+
+ /**
+ * Environment root
+ */
+ public String ENVIRONMENT_ROOT = "TraceCompiler.environmentRoot"; //$NON-NLS-1$
+
+ /**
+ * Printf support flag
+ */
+ public String PRINTF_SUPPORT = "TraceCompiler.printfSupport"; //$NON-NLS-1$
+
+ /**
+ * Printf extension macro
+ */
+ public String PRINTF_EXTENSION = "TraceCompiler.printfMacro"; //$NON-NLS-1$
+
+ /**
+ * Console UI mode flag
+ */
+ public String CONSOLE_UI_MODE = "TraceCompiler.consoleUI"; //$NON-NLS-1$
+
+ /**
+ * Flag to show the project files in view
+ */
+ public boolean SHOW_PROJECT_FILES = false;
+
+ /**
+ * Compiler flag to show hidden parameters in view
+ */
+ public boolean SHOW_HIDDEN_PARAMETERS_IN_VIEW = false;
+
+ /**
+ * Compiler flag to show location tag in view
+ */
+ public boolean SHOW_LOCATION_TAG_IN_VIEW = false;
+
+ /**
+ * Assertions events are enabled
+ */
+ public boolean ASSERTIONS_ENABLED = true;
+
+ /**
+ * Trace location assertions are enabled
+ */
+ public boolean GLOBAL_LOCATION_ASSERTS = false;
+
+ /**
+ * Traces the view state
+ */
+ public boolean TRACE_VIEW_STATE = false;
+
+ /**
+ * Allow changes to source formatter
+ */
+ public boolean ALLOW_FORMAT_CHANGE = false;
+
+ /**
+ * Comment after trace
+ */
+ public String COMMENT_POSITION_AFTER_TRACE = "before"; //$NON-NLS-1$
+
+ /**
+ * Comment before trace
+ */
+ public String COMMENT_POSITION_BEFORE_TRACE = "after"; //$NON-NLS-1$
+
+ /**
+ * Flag which determines if the configuration is available
+ *
+ * @return true if available, false if not
+ */
+ public boolean isAvailable();
+
+ /**
+ * Stores a boolean flag into properties
+ *
+ * @param flagName
+ * name for the flag
+ * @param flag
+ * flag to be stored
+ */
+ public void setFlag(String flagName, boolean flag);
+
+ /**
+ * Gets a configuration flag based on flag name
+ *
+ * @param flagName
+ * the confiugration flag name
+ * @return the flag value
+ */
+ public boolean getFlag(String flagName);
+
+ /**
+ * Stores an integer value into properties
+ *
+ * @param valueName
+ * name for the value
+ * @param value
+ * value to be stored
+ */
+ public void setValue(String valueName, int value);
+
+ /**
+ * Gets a configuration value based on value name
+ *
+ * @param valueName
+ * configuration value name
+ * @return the value
+ */
+ public int getValue(String valueName);
+
+ /**
+ * Stores text into properties
+ *
+ * @param textName
+ * name for the text
+ * @param text
+ * text to be stored
+ */
+ public void setText(String textName, String text);
+
+ /**
+ * Gets a text entry based on property name
+ *
+ * @param textName
+ * configuration value name
+ * @return the text
+ */
+ public String getText(String textName);
+
+ /**
+ * Checks if the given entry exists in configuration.
+ *
+ * @param entryName
+ * the name of the entry
+ * @return true if entry exists, false otherwise
+ */
+ public boolean hasEntry(String entryName);
+
+ /**
+ * Adds a configuration listener to this configuration
+ *
+ * @param configurationListener
+ * the listener to be added
+ */
+ public void addConfigurationListener(
+ TraceCompilerEngineConfigurationListener configurationListener);
+
+ /**
+ * Removes an existing configuration listener
+ *
+ * @param configurationListener
+ * the listener to be removed
+ */
+ public void removeConfigurationListener(
+ TraceCompilerEngineConfigurationListener configurationListener);
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/TraceCompilerEngineConfigurationListener.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/TraceCompilerEngineConfigurationListener.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,32 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Configuration listener interface
+*
+*/
+package com.nokia.tracecompiler.engine;
+
+/**
+ * Configuration listener interface
+ *
+ */
+public interface TraceCompilerEngineConfigurationListener {
+
+ /**
+ * Configuration creation notification
+ */
+ public void configurationCreated();
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/TraceCompilerEngineErrorCodes.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/TraceCompilerEngineErrorCodes.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,489 @@
+/*
+ * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ *
+ * Description:
+ *
+ * Error codes for TraceCompiler
+ *
+ */
+package com.nokia.tracecompiler.engine;
+
+import com.nokia.tracecompiler.model.TraceCompilerErrorParameters;
+import com.nokia.tracecompiler.model.TraceCompilerException.TraceCompilerExceptionCode;
+
+/**
+ * Error codes for TraceCompiler
+ *
+ */
+public interface TraceCompilerEngineErrorCodes {
+
+ /**
+ * Error parameters for a file-related errors
+ */
+ public class FileErrorParameters extends TraceCompilerErrorParameters {
+
+ /**
+ * Path to the file
+ */
+ public String file;
+
+ }
+
+ /**
+ * Error parameters for errors related to names, titles etc.
+ */
+ public class StringErrorParameters extends TraceCompilerErrorParameters {
+
+ /**
+ * String
+ */
+ public String string;
+
+ }
+
+ /**
+ * Error parameters for integer values that must be between two values
+ */
+ public class RangeErrorParameters extends TraceCompilerErrorParameters {
+
+ /**
+ * Start of range
+ */
+ public int start;
+
+ /**
+ * End of range
+ */
+ public int end;
+
+ /**
+ * Hex / decimal flag
+ */
+ public boolean isHex;
+
+ }
+
+ /**
+ * Error codes for TraceCompiler
+ */
+ public enum TraceCompilerErrorCode implements TraceCompilerExceptionCode {
+
+ /**
+ * Success
+ */
+ OK,
+
+ /**
+ * Trace ID was duplicate
+ */
+ DUPLICATE_TRACE_ID,
+
+ /**
+ * Group ID was duplicate
+ */
+ DUPLICATE_GROUP_ID,
+
+ /**
+ * Trace name was duplicate
+ */
+ DUPLICATE_TRACE_NAME,
+
+ /**
+ * Trace name was duplicate
+ */
+ DUPLICATE_GROUP_NAME,
+
+ /**
+ * Trace ID was not valid. Parameters for this error are either
+ * RangeErrorParameters or null (no range)
+ */
+ INVALID_TRACE_ID,
+
+ /**
+ * Group ID was not valid. Parameters for this error are either
+ * RangeErrorParameters or null (no range)
+ */
+ INVALID_GROUP_ID,
+
+ /**
+ * Name was not valid
+ */
+ INVALID_TRACE_NAME,
+
+ /**
+ * Name was not valid
+ */
+ INVALID_GROUP_NAME,
+
+ /**
+ * Trace string was not valid
+ */
+ INVALID_TRACE_DATA,
+
+ /**
+ * Cannot edit source file
+ */
+ SOURCE_NOT_EDITABLE,
+
+ /**
+ * Source location was not valid
+ */
+ INVALID_SOURCE_LOCATION,
+
+ /**
+ * Unreachable trace location
+ */
+ UNREACHABLE_TRACE_LOCATION,
+
+ /**
+ * Tried to perform group operation when group was not selected
+ */
+ GROUP_NOT_SELECTED,
+
+ /**
+ * Tried to perform trace operation when trace was not selected
+ */
+ TRACE_NOT_SELECTED,
+
+ /**
+ * Not enough parameters in trace
+ */
+ NOT_ENOUGH_PARAMETERS,
+
+ /**
+ * Unexpected exception occurred
+ */
+ UNEXPECTED_EXCEPTION,
+
+ /**
+ * Trace model is not ready
+ */
+ MODEL_NOT_READY,
+
+ /**
+ * No trace groups
+ */
+ NO_TRACE_GROUPS,
+
+ /**
+ * Parameter name is not valid
+ */
+ INVALID_PARAMETER_NAME,
+
+ /**
+ * Model properties are not valid
+ */
+ INVALID_MODEL_PROPERTIES_FOR_EXPORT,
+
+ /**
+ * Model name is not valid
+ */
+ INVALID_MODEL_NAME,
+
+ /**
+ * Trace project file cannot be parsed
+ */
+ INVALID_PROJECT_FILE,
+
+ /**
+ * File was not found. This error is related to FileErrorParameters
+ * class
+ */
+ FILE_NOT_FOUND,
+
+ /**
+ * Path was not valid. This is related to FileErrorParameters class
+ */
+ INVALID_PATH,
+
+ /**
+ * Constant value was duplicate
+ */
+ DUPLICATE_CONSTANT_VALUE,
+
+ /**
+ * Constant name was already in use
+ */
+ DUPLICATE_CONSTANT_TABLE_NAME,
+
+ /**
+ * Constant table name was not valid
+ */
+ INVALID_CONSTANT_TABLE_NAME,
+
+ /**
+ * Constant table not part of project
+ */
+ CONSTANT_TABLE_NOT_PART_OF_PROJECT,
+
+ /**
+ * Constant ID was already in use
+ */
+ DUPLICATE_CONSTANT_ID,
+
+ /**
+ * Constant value was not valid
+ */
+ INVALID_CONSTANT_VALUE,
+
+ /**
+ * Parameter name was already in use
+ */
+ DUPLICATE_PARAMETER_NAME,
+
+ /**
+ * Parameter type was not supported
+ */
+ INVALID_PARAMETER_TYPE,
+
+ /**
+ * Parameters cannot be added
+ */
+ PARAMETER_ADD_NOT_ALLOWED,
+
+ /**
+ * Parameters cannot be removed
+ */
+ PARAMETER_REMOVE_NOT_ALLOWED,
+
+ /**
+ * Parameter name was empty. This is generated when automatically adding
+ * function parameters to new trace and a parameter does not have a name
+ * in the declaration.
+ */
+ EMPTY_PARAMETER_NAME,
+
+ /**
+ * Parameter template was already used by another parameter
+ */
+ PARAMETER_TEMPLATE_ALREADY_IN_USE,
+
+ /**
+ * Tried to remove trace location when one was not selected
+ */
+ LOCATION_NOT_SELECTED,
+
+ /**
+ * Cannot add a constant, since constant table was not selected
+ */
+ CONSTANT_TABLE_NOT_SELECTED,
+
+ /**
+ * The selected object was not valid target for delete operation
+ */
+ CANNOT_DELETE_SELECTED_OBJECT,
+
+ /**
+ * Trace text format is not valid
+ */
+ INVALID_TRACE_TEXT_FORMAT,
+
+ /**
+ * Trace name format is not valid
+ */
+ INVALID_TRACE_NAME_FORMAT,
+
+ /**
+ * Missing function name from trace name format
+ */
+ TRACE_NAME_FORMAT_MISSING_FUNCTION,
+
+ /**
+ * No traces to delete
+ */
+ NO_TRACES_TO_DELETE,
+
+ /**
+ * Source file is not open
+ */
+ SOURCE_NOT_OPEN,
+
+ /**
+ * Failed to parse a constant table from source
+ */
+ CONSTANT_TABLE_PARSE_FAILED,
+
+ /**
+ * Cannot open project file
+ */
+ CANNOT_OPEN_PROJECT_FILE,
+
+ /**
+ * Cannot write project file
+ */
+ CANNOT_WRITE_PROJECT_FILE,
+
+ /**
+ * Parameter ID was already in use
+ */
+ DUPLICATE_PARAMETER_ID,
+
+ /**
+ * Constant table ID was already in use
+ */
+ DUPLICATE_CONSTANT_TABLE_ID,
+
+ /**
+ * Instrumenter function list was empty
+ */
+ NO_FUNCTIONS_TO_INSTRUMENT,
+
+ /**
+ * Instrumenter function list was empty. Related to
+ * StringErrorParameters
+ */
+ NO_FUNCTIONS_TO_INSTRUMENT_WITH_TEMPLATE,
+
+ /**
+ * Multiple errors during an operation
+ */
+ MULTIPLE_ERRORS_IN_OPERATION,
+
+ /**
+ * Printf parameter parameter format specification did not match the
+ * parameter count
+ */
+ PARAMETER_FORMAT_MISMATCH,
+
+ /**
+ * A trace does not exist
+ */
+ TRACE_DOES_NOT_EXIST,
+
+ /**
+ * Trace needs to be converted to correct API
+ */
+ TRACE_NEEDS_CONVERSION,
+
+ /**
+ * Parameter count of location and trace do not match
+ */
+ PARAMETER_COUNT_MISMATCH,
+
+ /**
+ * Parameter count in location does not match the API macro
+ */
+ PARAMETER_COUNT_DOES_NOT_MATCH_API,
+
+ /**
+ * Location parser failed
+ */
+ LOCATION_PARSER_FAILED,
+
+ /**
+ * Trace is not referenced from source files
+ */
+ TRACE_HAS_NO_LOCATIONS,
+
+ /**
+ * Trace is used from multiple locations in source files
+ */
+ TRACE_HAS_MULTIPLE_LOCATIONS,
+
+ /**
+ * Project was empty when export was called
+ */
+ NO_TRACES_TO_EXPORT,
+
+ /**
+ * Source file cannot be opened
+ */
+ CANNOT_OPEN_SOURCE_FILE,
+
+ /**
+ * Trace in source cannot be updated
+ */
+ CANNOT_UPDATE_TRACE_INTO_SOURCE,
+
+ /**
+ * Parameter format is not supported
+ */
+ PARAMETER_FORMAT_NOT_SUPPORTED,
+
+ /**
+ * Parameter format is not supported by default macros
+ */
+ PARAMETER_FORMAT_NEEDS_EXT_MACRO,
+
+ /**
+ * Ext macro usage is not necessary with
+ */
+ PARAMETER_FORMAT_UNNECESSARY_EXT_MACRO,
+
+ /**
+ * Parameter format cannot be used as an array
+ */
+ PARAMETER_FORMAT_NOT_SUPPORTED_IN_ARRAY,
+
+ /**
+ * Property file element was unknown
+ */
+ PROPERTY_FILE_ELEMENT_NOT_SUPPORTED,
+
+ /**
+ * Property file element was in wrong place
+ */
+ PROPERTY_FILE_ELEMENT_MISPLACED,
+
+ /**
+ * Property file attribute was not valid
+ */
+ PROPERTY_FILE_ATTRIBUTE_INVALID,
+
+ /**
+ * Inserting a trace into source will produce incorrect results
+ */
+ INSERT_TRACE_DOES_NOT_WORK,
+
+ /**
+ * Trace found from source is not in valid source context
+ */
+ NO_CONTEXT_FOR_LOCATION,
+
+ /**
+ * Function parameters could not be parsed
+ */
+ CANNOT_PARSE_FUNCTION_PARAMETERS,
+
+ /**
+ * Parameter name is not valid exit trace return parameter name
+ */
+ INVALID_PARAMETER_NAME_IN_RETURN_VALUE,
+
+ /**
+ * Run out of Group IDs
+ */
+ RUN_OUT_OF_GROUP_IDS,
+
+ /**
+ * Run out of Trace IDs
+ */
+ RUN_OUT_OF_TRACE_IDS,
+
+ /**
+ * Cannot add function parameters if there is var arg list
+ */
+ VAR_ARG_LIST_PARAMETER_FOUND,
+
+ /**
+ * TRACE_STATE group name was used in non state trace
+ */
+ INVALID_USAGE_OF_TRACE_STATE_GROUP_NAME,
+
+ /**
+ * TRACE_PERFORMANCE group name was used in non performance trace
+ */
+ INVALID_USAGE_OF_TRACE_PERFORMACE_GROUP_NAME
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/TraceCompilerEngineErrorMessages.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/TraceCompilerEngineErrorMessages.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,722 @@
+/*
+ * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ *
+ * Description:
+ *
+ * Error code to error message mapper
+ *
+ */
+package com.nokia.tracecompiler.engine;
+
+import java.io.File;
+
+import com.nokia.tracecompiler.engine.TraceCompilerEngineErrorCodes.FileErrorParameters;
+import com.nokia.tracecompiler.engine.TraceCompilerEngineErrorCodes.RangeErrorParameters;
+import com.nokia.tracecompiler.engine.TraceCompilerEngineErrorCodes.StringErrorParameters;
+import com.nokia.tracecompiler.engine.TraceCompilerEngineErrorCodes.TraceCompilerErrorCode;
+import com.nokia.tracecompiler.model.TraceCompilerErrorParameters;
+import com.nokia.tracecompiler.model.TraceCompilerException;
+import com.nokia.tracecompiler.source.SourceConstants;
+import com.nokia.tracecompiler.source.SourceUtils;
+
+/**
+ * Error code to error message mapper
+ *
+ */
+public final class TraceCompilerEngineErrorMessages {
+
+ /**
+ * Maps an exception to error message
+ *
+ * @param e
+ * the exception
+ * @return the message
+ */
+ public static String getErrorMessage(TraceCompilerException e) {
+ return TraceCompilerEngineErrorMessages.getErrorMessage(
+ (TraceCompilerErrorCode) e.getErrorCode(), e
+ .getErrorParameters());
+ }
+
+ /**
+ * Maps error code to error message
+ *
+ * @param error
+ * the error code
+ * @param parameters
+ * the parameters of the error
+ * @return the message
+ */
+ public static String getErrorMessage(TraceCompilerErrorCode error,
+ TraceCompilerErrorParameters parameters) {
+ // CodForChk_Dis_LengthyFunc
+ // CodForChk_Dis_ComplexFunc
+ String s;
+ StringBuffer sb = new StringBuffer();
+ switch (error) {
+ case DUPLICATE_GROUP_ID:
+ sb.append(Messages
+ .getString("TraceCompilerErrorMessages.DuplicateGroupID")); //$NON-NLS-1$
+ break;
+ case DUPLICATE_GROUP_NAME:
+ sb.append(Messages
+ .getString("TraceCompilerErrorMessages.DuplicateGroupName")); //$NON-NLS-1$
+ break;
+ case DUPLICATE_TRACE_ID:
+ sb.append(Messages
+ .getString("TraceCompilerErrorMessages.DuplicateTraceID")); //$NON-NLS-1$
+ break;
+ case DUPLICATE_TRACE_NAME:
+ sb.append(Messages
+ .getString("TraceCompilerErrorMessages.DuplicateTraceName")); //$NON-NLS-1$
+ break;
+ case DUPLICATE_PARAMETER_ID:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.DuplicateParameterID"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case DUPLICATE_CONSTANT_VALUE:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.DuplicateConstantValue"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case DUPLICATE_CONSTANT_ID:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.DuplicateConstantID"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case DUPLICATE_CONSTANT_TABLE_NAME:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.DuplicateConstantTableName"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case DUPLICATE_CONSTANT_TABLE_ID:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.DuplicateConstantTableID"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case DUPLICATE_PARAMETER_NAME:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.DuplicateParameterName"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case INVALID_GROUP_ID:
+ createInvalidGroupIDMessage(parameters, sb);
+ break;
+ case INVALID_TRACE_ID:
+ createInvalidTraceIDMessage(parameters, sb);
+ break;
+ case INVALID_MODEL_PROPERTIES_FOR_EXPORT:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.InvalidModelPropertiesForExport"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case INVALID_MODEL_NAME:
+ sb.append(Messages
+ .getString("TraceCompilerErrorMessages.InvalidProjectName")); //$NON-NLS-1$
+ break;
+ case INVALID_GROUP_NAME:
+ sb.append(Messages
+ .getString("TraceCompilerErrorMessages.InvalidGroupName")); //$NON-NLS-1$
+ break;
+ case INVALID_TRACE_NAME:
+ sb.append(Messages
+ .getString("TraceCompilerErrorMessages.InvalidTraceName")); //$NON-NLS-1$
+ break;
+ case INVALID_PARAMETER_NAME:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.InvalidParameterName"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case EMPTY_PARAMETER_NAME:
+ sb.append(Messages
+ .getString("TraceCompilerErrorMessages.EmptyParameterName")); //$NON-NLS-1$
+ break;
+ case INVALID_CONSTANT_TABLE_NAME:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.InvalidConstantTableName"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case CONSTANT_TABLE_NOT_PART_OF_PROJECT:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.ConstantTableNotPartOfProject"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case INVALID_TRACE_DATA:
+ sb.append(Messages
+ .getString("TraceCompilerErrorMessages.InvalidTraceData")); //$NON-NLS-1$
+ break;
+ case INVALID_PARAMETER_TYPE:
+ createInvalidParameterTypeMessage(parameters, sb);
+ break;
+ case INVALID_CONSTANT_VALUE:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.InvalidConstantValue"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case SOURCE_NOT_EDITABLE:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.SourceNotEditable"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case INVALID_SOURCE_LOCATION:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.InvalidSourceLocation"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case UNREACHABLE_TRACE_LOCATION:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.UnreachableTraceLocation"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case INVALID_PROJECT_FILE:
+ sb.append(Messages
+ .getString("TraceCompilerErrorMessages.InvalidTraceFile")); //$NON-NLS-1$
+ break;
+ case FILE_NOT_FOUND:
+ createFileNotFoundMessage((FileErrorParameters) parameters, sb);
+ break;
+ case INVALID_PATH:
+ createInvalidPathMessage((FileErrorParameters) parameters, sb);
+ break;
+ case SOURCE_NOT_OPEN:
+ sb.append(Messages
+ .getString("TraceCompilerErrorMessages.SourceNotOpen")); //$NON-NLS-1$
+ break;
+ case CANNOT_OPEN_PROJECT_FILE:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.CannotOpenProjectFile"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case CANNOT_WRITE_PROJECT_FILE:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.CannotWriteProjectFile"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case PARAMETER_FORMAT_MISMATCH:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.ParameterFormatMismatch"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case GROUP_NOT_SELECTED:
+ sb.append(Messages
+ .getString("TraceCompilerErrorMessages.GroupNotSelected")); //$NON-NLS-1$
+ break;
+ case TRACE_NOT_SELECTED:
+ sb.append(Messages
+ .getString("TraceCompilerErrorMessages.TraceNotSelected")); //$NON-NLS-1$
+ break;
+ case CONSTANT_TABLE_NOT_SELECTED:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.ConstantTableNotSelected"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case LOCATION_NOT_SELECTED:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.TraceLocationNotSelected"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case CANNOT_DELETE_SELECTED_OBJECT:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.CannotDeleteSelectedObject"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case MODEL_NOT_READY:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.TraceProjectNotOpen"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case NO_TRACE_GROUPS:
+ sb.append(Messages
+ .getString("TraceCompilerErrorMessages.NoTraceGroups")); //$NON-NLS-1$
+ break;
+ case NOT_ENOUGH_PARAMETERS:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.NotEnoughParameters"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case PARAMETER_ADD_NOT_ALLOWED:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.ParameterAddNotAllowed"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case PARAMETER_REMOVE_NOT_ALLOWED:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.ParameterRemoveNotAllowed"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case PARAMETER_TEMPLATE_ALREADY_IN_USE:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.ParameterTemplateInUse"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case CONSTANT_TABLE_PARSE_FAILED:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.ConstantTableParseFailed"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case UNEXPECTED_EXCEPTION:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.UnexpectedException"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case TRACE_NAME_FORMAT_MISSING_FUNCTION:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.NameFormatMissingFunction"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case INVALID_TRACE_TEXT_FORMAT:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.InvalidTraceTextFormat"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case INVALID_TRACE_NAME_FORMAT:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.InvalidTraceNameFormat"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case NO_FUNCTIONS_TO_INSTRUMENT_WITH_TEMPLATE:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.NoFunctionsToInstrumentPrefix"); //$NON-NLS-1$
+ sb.append(s);
+ sb.append(((StringErrorParameters) parameters).string);
+ s = Messages
+ .getString("TraceCompilerErrorMessages.NoFunctionsToInstrumentPostfix"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case NO_FUNCTIONS_TO_INSTRUMENT:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.NoFunctionsToInstrument"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case MULTIPLE_ERRORS_IN_OPERATION:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.MultipleErrorsInOperation"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case NO_TRACES_TO_DELETE:
+ sb.append(Messages
+ .getString("TraceCompilerErrorMessages.NoTracesToDelete")); //$NON-NLS-1$
+ break;
+ case TRACE_DOES_NOT_EXIST:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.TraceDoesNotExist"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case TRACE_NEEDS_CONVERSION:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.TraceNeedsConversionPrefix"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case PARAMETER_COUNT_MISMATCH:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.ParameterCountMismatch"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case PARAMETER_COUNT_DOES_NOT_MATCH_API:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.ParameterCountDoesNotMatchApi"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case TRACE_HAS_NO_LOCATIONS:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.TraceHasNoLocations"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case TRACE_HAS_MULTIPLE_LOCATIONS:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.TraceHasMultipleLocations"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case LOCATION_PARSER_FAILED:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.LocationCouldNotBeParsed"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case NO_TRACES_TO_EXPORT:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.NoTracesToExport"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case CANNOT_OPEN_SOURCE_FILE:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.CannotOpenSourceFile"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case CANNOT_UPDATE_TRACE_INTO_SOURCE:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.CannotUpdateTraceIntoSource"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case PARAMETER_FORMAT_NOT_SUPPORTED:
+ createParameterFormatNotSupportedMessage(parameters, sb);
+ break;
+ case PARAMETER_FORMAT_NEEDS_EXT_MACRO:
+ createParameterFormatNotSupportedInMacroMessage(parameters, sb);
+ break;
+ case PARAMETER_FORMAT_NOT_SUPPORTED_IN_ARRAY:
+ createParameterFormatNotSupportedInArrayMessage(parameters, sb);
+ break;
+ case PARAMETER_FORMAT_UNNECESSARY_EXT_MACRO:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.ParameterFormatUnnecessaryExtMacro"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case PROPERTY_FILE_ELEMENT_NOT_SUPPORTED:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.PropertyFileElementNotSupportedPrefix"); //$NON-NLS-1$ CodForChk_Dis_LengthyLine
+ sb.append(s);
+ sb.append(((StringErrorParameters) parameters).string);
+ s = Messages
+ .getString("TraceCompilerErrorMessages.PropertyFileElementNotSupportedPostfix"); //$NON-NLS-1$ CodForChk_Dis_LengthyLine
+ sb.append(s);
+ break;
+ case PROPERTY_FILE_ELEMENT_MISPLACED:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.PropertyFileElementMisplacedPrefix"); //$NON-NLS-1$
+ sb.append(s);
+ sb.append(((StringErrorParameters) parameters).string);
+ s = Messages
+ .getString("TraceCompilerErrorMessages.PropertyFileElementMisplacedPostfix"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case PROPERTY_FILE_ATTRIBUTE_INVALID:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.PropertyFileAttributeInvalidPrefix"); //$NON-NLS-1$
+ sb.append(s);
+ sb.append(((StringErrorParameters) parameters).string);
+ s = Messages
+ .getString("TraceCompilerErrorMessages.PropertyFileAttributeInvalidPostfix"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case INSERT_TRACE_DOES_NOT_WORK:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.InsertTraceDoesNotWork"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case NO_CONTEXT_FOR_LOCATION:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.NoContextForLocation"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case CANNOT_PARSE_FUNCTION_PARAMETERS:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.CannotParseFunctionParameters"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case INVALID_PARAMETER_NAME_IN_RETURN_VALUE:
+ s = Messages
+ .getString("TraceCompilerErrorMessages.InvalidParameterNameInReturnValue"); //$NON-NLS-1$
+ sb.append(s);
+ break;
+ case RUN_OUT_OF_GROUP_IDS:
+ sb.append(Messages
+ .getString("TraceCompilerErrorMessages.RunOutOfGroupIDs")); //$NON-NLS-1$
+ break;
+ case RUN_OUT_OF_TRACE_IDS:
+ sb.append(Messages
+ .getString("TraceCompilerErrorMessages.RunOutOfTraceIDs")); //$NON-NLS-1$
+ break;
+ case VAR_ARG_LIST_PARAMETER_FOUND:
+ sb.append(Messages
+ .getString("TraceCompilerErrorMessages.VarArgListParameterFound")); //$NON-NLS-1$
+ break;
+ case INVALID_USAGE_OF_TRACE_STATE_GROUP_NAME:
+ sb.append(Messages
+ .getString("TraceCompilerErrorMessages.InvalidUsageOfTraceStateGroupName")); //$NON-NLS-1$
+ break;
+ case INVALID_USAGE_OF_TRACE_PERFORMACE_GROUP_NAME:
+ sb.append(Messages
+ .getString("TraceCompilerErrorMessages.InvalidUsageOfTracePerformanceGroupName")); //$NON-NLS-1$
+ break;
+ default:
+ break;
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Creates invalid parameter type message
+ *
+ * @param parameters
+ * the parameters
+ * @param sb
+ * the message buffer
+ */
+ private static void createInvalidParameterTypeMessage(
+ TraceCompilerErrorParameters parameters, StringBuffer sb) {
+ String s;
+ if (parameters instanceof StringErrorParameters) {
+ s = Messages
+ .getString("TraceCompilerErrorMessages.InvalidParameterTypePrefix"); //$NON-NLS-1$
+ sb.append(s);
+ sb.append(((StringErrorParameters) parameters).string);
+ String format = SourceUtils
+ .mapNormalTypeToFormat(((StringErrorParameters) parameters).string);
+ if (format != null) {
+ sb.append(" "); //$NON-NLS-1$
+ sb.append(format);
+ }
+ s = Messages
+ .getString("TraceCompilerErrorMessages.InvalidParameterTypePostfix"); //$NON-NLS-1$
+ sb.append(s);
+ } else {
+ s = Messages
+ .getString("TraceCompilerErrorMessages.InvalidParameterType"); //$NON-NLS-1$
+ sb.append(s);
+ }
+ }
+
+ /**
+ * Creates parameter format not supported message
+ *
+ * @param parameters
+ * the parameters
+ * @param sb
+ * the message buffer
+ */
+ private static void createParameterFormatNotSupportedMessage(
+ TraceCompilerErrorParameters parameters, StringBuffer sb) {
+ String s;
+ if (parameters instanceof StringErrorParameters) {
+ s = Messages
+ .getString("TraceCompilerErrorMessages.ParameterFormatNotSupportedPrefix"); //$NON-NLS-1$
+ sb.append(s);
+ sb.append(((StringErrorParameters) parameters).string);
+ s = Messages
+ .getString("TraceCompilerErrorMessages.ParameterFormatNotSupportedPostfix"); //$NON-NLS-1$
+ sb.append(s);
+ } else {
+ s = Messages
+ .getString("TraceCompilerErrorMessages.ParameterFormatNotSupported"); //$NON-NLS-1$
+ sb.append(s);
+ }
+ }
+
+ /**
+ * Creates parameter not supported in macro message
+ *
+ * @param parameters
+ * the parameters
+ * @param sb
+ * the message buffer
+ */
+ private static void createParameterFormatNotSupportedInMacroMessage(
+ TraceCompilerErrorParameters parameters, StringBuffer sb) {
+ String s;
+ if (parameters instanceof StringErrorParameters) {
+ s = Messages
+ .getString("TraceCompilerErrorMessages.ParameterFormatNotSupportedInMacroPrefix"); //$NON-NLS-1$ CodForChk_Dis_LengthyLine
+ sb.append(s);
+ sb.append(((StringErrorParameters) parameters).string);
+ s = Messages
+ .getString("TraceCompilerErrorMessages.ParameterFormatNotSupportedInMacroPostfix"); //$NON-NLS-1$ CodForChk_Dis_LengthyLine
+ sb.append(s);
+ } else {
+ s = Messages
+ .getString("TraceCompilerErrorMessages.ParameterFormatNotSupportedInMacro"); //$NON-NLS-1$
+ sb.append(s);
+ }
+ }
+
+ /**
+ * Creates parameter not supported in array message
+ *
+ * @param parameters
+ * the parameters
+ * @param sb
+ * the message buffer
+ */
+ private static void createParameterFormatNotSupportedInArrayMessage(
+ TraceCompilerErrorParameters parameters, StringBuffer sb) {
+ String s;
+ if (parameters instanceof StringErrorParameters) {
+ s = Messages
+ .getString("TraceCompilerErrorMessages.ParameterFormatNotSupportedInArrayPrefix"); //$NON-NLS-1$ CodForChk_Dis_LengthyLine
+ sb.append(s);
+ sb.append(((StringErrorParameters) parameters).string);
+ s = Messages
+ .getString("TraceCompilerErrorMessages.ParameterFormatNotSupportedInArrayPostfix"); //$NON-NLS-1$ CodForChk_Dis_LengthyLine
+ sb.append(s);
+ } else {
+ s = Messages
+ .getString("TraceCompilerErrorMessages.ParameterFormatNotSupportedInArray"); //$NON-NLS-1$
+ sb.append(s);
+ }
+ }
+
+ /**
+ * Creates invalid trace ID message
+ *
+ * @param parameters
+ * the parameters
+ * @param sb
+ * the message buffer
+ */
+ private static void createInvalidTraceIDMessage(
+ TraceCompilerErrorParameters parameters, StringBuffer sb) {
+ String s;
+ if (parameters instanceof RangeErrorParameters) {
+ s = Messages
+ .getString("TraceCompilerErrorMessages.InvalidTraceIDStart"); //$NON-NLS-1$
+ sb.append(s);
+ s = Messages
+ .getString("TraceCompilerErrorMessages.InvalidTraceIDMiddle"); //$NON-NLS-1$
+ addRangeParameter((RangeErrorParameters) parameters, sb, s);
+ sb.append(Messages
+ .getString("TraceCompilerErrorMessages.InvalidTraceIDEnd")); //$NON-NLS-1$
+ } else {
+ sb.append(Messages
+ .getString("TraceCompilerErrorMessages.InvalidTraceID")); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Creates invalid group ID message
+ *
+ * @param parameters
+ * the parameters
+ * @param sb
+ * the message buffer
+ */
+ private static void createInvalidGroupIDMessage(
+ TraceCompilerErrorParameters parameters, StringBuffer sb) {
+ String s;
+ if (parameters instanceof RangeErrorParameters) {
+ s = Messages
+ .getString("TraceCompilerErrorMessages.InvalidGroupIDStart"); //$NON-NLS-1$
+ sb.append(s);
+ s = Messages
+ .getString("TraceCompilerErrorMessages.InvalidGroupIDMiddle"); //$NON-NLS-1$
+ addRangeParameter((RangeErrorParameters) parameters, sb, s);
+ sb.append(Messages
+ .getString("TraceCompilerErrorMessages.InvalidGroupIDEnd")); //$NON-NLS-1$
+ } else {
+ sb.append(Messages
+ .getString("TraceCompilerErrorMessages.InvalidGroupID")); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Adds a range parameter to error buffer
+ *
+ * @param parameters
+ * the range
+ * @param sb
+ * the buffer
+ * @param middleText
+ * the text between the range
+ */
+ private static void addRangeParameter(RangeErrorParameters parameters,
+ StringBuffer sb, String middleText) {
+ if (parameters.isHex) {
+ sb.append(SourceConstants.HEX_PREFIX);
+ sb.append(Integer.toHexString(parameters.start));
+ } else {
+ sb.append(parameters.start);
+ }
+ sb.append(middleText);
+ if (parameters.isHex) {
+ sb.append(SourceConstants.HEX_PREFIX);
+ sb.append(Integer.toHexString(parameters.end));
+ } else {
+ sb.append(parameters.end);
+ }
+ }
+
+ /**
+ * Creates "Invalid directory" message
+ *
+ * @param parameters
+ * the message parameters
+ * @param sb
+ * the string buffer where the message is stored
+ */
+ private static void createInvalidPathMessage(
+ FileErrorParameters parameters, StringBuffer sb) {
+ String s;
+ if (parameters != null) {
+ s = Messages
+ .getString("TraceCompilerErrorMessages.InvalidDirectoryPrefix"); //$NON-NLS-1$
+ sb.append(s);
+ sb.append(convertPath(parameters.file));
+ s = Messages
+ .getString("TraceCompilerErrorMessages.InvalidDirectoryPostfix"); //$NON-NLS-1$
+ sb.append(s);
+ } else {
+ sb.append(Messages
+ .getString("TraceCompilerErrorMessages.InvalidDirectory")); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Creates "File not found" message
+ *
+ * @param parameters
+ * the message parameters
+ * @param sb
+ * the string buffer where the message is stored
+ */
+ private static void createFileNotFoundMessage(
+ FileErrorParameters parameters, StringBuffer sb) {
+ String s;
+ if (parameters != null) {
+ s = Messages
+ .getString("TraceCompilerErrorMessages.FileDoesNotExistPrefix"); //$NON-NLS-1$
+ sb.append(s);
+ sb.append(convertPath(parameters.file));
+ s = Messages
+ .getString("TraceCompilerErrorMessages.FileDoesNotExistPostfix"); //$NON-NLS-1$
+ sb.append(s);
+ } else {
+ sb.append(Messages
+ .getString("TraceCompilerErrorMessages.FileDoesNotExist")); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Adds some spaces to path string to allow folding
+ *
+ * @param path
+ * the path
+ * @return the converted path
+ */
+ public static String convertPath(String path) {
+ StringBuffer sb = new StringBuffer();
+ int strIndex = -1;
+ do {
+ strIndex++;
+ int lastIndex = strIndex;
+ strIndex = path.indexOf(File.separatorChar, strIndex);
+ if (strIndex != -1) {
+ String sub = path.substring(lastIndex, strIndex);
+ if (sub.length() > 0) {
+ sb.append(sub);
+ sb.append(' ');
+ sb.append(File.separatorChar);
+ sb.append(' ');
+ }
+ } else {
+ // If the data ends with file separator, lastIndex points to
+ // end-of-data. If not, the rest of the data is appended without
+ // further white spaces
+ if (lastIndex < path.length()) {
+ String sub = path.substring(lastIndex);
+ sb.append(sub);
+ }
+ }
+ } while (strIndex != -1);
+ return sb.toString();
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/TraceCompilerEngineEvents.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/TraceCompilerEngineEvents.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,98 @@
+/*
+* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Event listener interface
+*
+*/
+package com.nokia.tracecompiler.engine;
+
+import com.nokia.tracecompiler.model.TraceCompilerException;
+
+/**
+ * Event listener interface
+ *
+ */
+public interface TraceCompilerEngineEvents {
+
+ /**
+ * Posts an error event to TraceCompiler
+ *
+ * @param exception
+ * the error data
+ */
+ public void postError(TraceCompilerException exception);
+
+ /**
+ * Posts an error event to TraceCompiler
+ *
+ * @param message
+ * the error message
+ * @param source
+ * the error source
+ * @param postEvent
+ * defines is error event also posted to trace event view
+ */
+ public void postErrorMessage(String message, Object source, boolean postEvent);
+
+ /**
+ * Posts a warning event to TraceCompiler
+ *
+ * @param message
+ * the warning message
+ * @param source
+ * the warning source
+ */
+ public void postWarningMessage(String message, Object source);
+
+ /**
+ * Posts an info event to TraceCompiler
+ *
+ * @param message
+ * the info message
+ * @param source
+ * the info source
+ */
+ public void postInfoMessage(String message, Object source);
+
+ /**
+ * Posts a critical assertion failed event
+ *
+ * @param message
+ * the message
+ * @param source
+ * the source of the assertion
+ * @throws TraceCompilerException
+ */
+ public void postCriticalAssertionFailed(String message, Object source) throws TraceCompilerException;
+
+ /**
+ * Posts an assertion failed event
+ *
+ * @param message
+ * the message
+ * @param source
+ * the source of the assertion
+ */
+ public void postAssertionFailed(String message, Object source);
+
+ /**
+ * Gets the processing error
+ *
+ * @return the error
+ */
+ public boolean hasErrorHappened();
+
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/TraceCompilerEngineGlobals.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/TraceCompilerEngineGlobals.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,255 @@
+/*
+* Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Access point to the exported interfaces of TraceCompiler engine
+*
+*/
+package com.nokia.tracecompiler.engine;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+import com.nokia.tracecompiler.TraceCompilerLogger;
+import com.nokia.tracecompiler.engine.source.SourceEngine;
+import com.nokia.tracecompiler.model.TraceCompilerException;
+import com.nokia.tracecompiler.model.TraceModel;
+import com.nokia.tracecompiler.plugin.TraceCompilerPlugin;
+import com.nokia.tracecompiler.source.SourceConstants;
+
+/**
+ * Access point to the exported interfaces of TraceCompiler engine
+ *
+ */
+public class TraceCompilerEngineGlobals {
+
+ /**
+ * Max group ID
+ */
+ public static final int MAX_GROUP_ID = 65535; // CodForChk_Dis_Magic
+
+ /**
+ * Max trace ID
+ */
+ public static final int MAX_TRACE_ID = 65535; // CodForChk_Dis_Magic
+
+ /**
+ * TraceCompiler engine instance
+ */
+ private static TraceCompilerEngine instance;
+
+ /**
+ * default licence
+ */
+ static String defaultLicence;
+
+ /**
+ * default licence
+ */
+ static String defaultLicenceWithHash;
+
+ /**
+ * Constructor is hidden
+ */
+ private TraceCompilerEngineGlobals() {
+ }
+
+ /**
+ * Starts TraceCompiler engine.
+ * @throws TraceCompilerException
+ */
+ public static void start() throws TraceCompilerException {
+ if (instance == null) {
+ instance = new TraceCompilerEngine();
+ instance.start();
+ }
+ }
+
+ /**
+ * Shuts down the TraceCompiler instance
+ * @throws TraceCompilerException
+ */
+ public static void shutdown() throws TraceCompilerException {
+ if (instance != null) {
+ instance.shutdown();
+ instance = null;
+ }
+ }
+
+ /**
+ * Gets the configuration interface. The configuration interface is not
+ * available until view has been registered.
+ *
+ * @return the configuration
+ */
+ public static TraceCompilerEngineConfiguration getConfiguration() {
+ return instance.getConfiguration();
+ }
+
+ /**
+ * Gets the trace model
+ *
+ * @return the model
+ */
+ public static TraceModel getTraceModel() {
+ return instance.getModel();
+ }
+
+ /**
+ * Gets the source engine
+ *
+ * @return the source engine
+ */
+ public static SourceEngine getSourceEngine() {
+ return instance.getSourceEngine();
+ }
+
+ /**
+ * Gets the trace compiler interface
+ *
+ * @return trace compiler
+ */
+ public static TraceCompilerEngineInterface getTraceCompiler() {
+ return instance.getTraceCompiler();
+ }
+
+ /**
+ * Gets the events interface
+ *
+ * @return the events interface
+ */
+ public static TraceCompilerEngineEvents getEvents() {
+ if (instance != null) {
+ return instance.getEvents();
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Called by a plug-in to register itself
+ *
+ * @param plugin
+ * the plugin to be registered
+ */
+ public static void registerPlugin(TraceCompilerPlugin plugin) {
+ instance.registerPlugin(plugin);
+ }
+
+ /**
+ * Called by a plug-in to unregister itself
+ *
+ * @param plugin
+ * the plugin to be unregistered
+ */
+ public static void unregisterPlugin(TraceCompilerPlugin plugin) {
+ if (instance != null) {
+ instance.unregisterPlugin(plugin);
+ }
+ }
+
+ /**
+ * Called by the view plug-in to register the view
+ *
+ * @param view
+ * the view
+ * @throws TraceCompilerException
+ */
+ public static void setView(TraceCompilerEngineView view) throws TraceCompilerException {
+ instance.setView(view);
+ }
+
+ /**
+ * Gets the source context manager
+ *
+ * @return the context manager
+ */
+ public static SourceContextManager getSourceContextManager() {
+ return instance.getSourceContextManager();
+ }
+
+ /**
+ * Get project path
+ *
+ * @return project path
+ */
+ public static String getProjectPath() {
+ String projetcPath = instance.getProjectPath();
+ return projetcPath;
+ }
+
+ /**
+ * Set project path
+ *
+ * @param path
+ * the path
+ */
+ public static void setProjectPath(String path) {
+ instance.setProjectPath(path);
+ }
+
+ /**
+ * get default licence from com/nokia/tracecompiler/licence.lic
+ * c++ comment format
+ * @param boolean cppCommented
+ * if true, it returns the licence in cpp comment \/** ... **\/
+ * else it retuen the licence in a # comment ## ... ##
+ * @return String licence
+ */
+ public static String getDefaultLicence(boolean cppCommented) {
+ String licenceResourceName;
+ if (cppCommented) {
+ if (defaultLicence == null) {
+ licenceResourceName = "/com/nokia/tracecompiler/licence.lic"; //$NON-NLS-1$
+ defaultLicence = readLicence(licenceResourceName);
+ }
+ return defaultLicence;
+ } else {
+ if (defaultLicenceWithHash == null) {
+ licenceResourceName = "/com/nokia/tracecompiler/licence_hash.lic"; //$NON-NLS-1$
+ defaultLicenceWithHash = readLicence(licenceResourceName);
+ }
+ return defaultLicenceWithHash;
+ }
+ }
+
+ /**
+ * read the provided resource file and return the text in it.
+ */
+ private static String readLicence(String aLicenceResourceName) {
+ String licenceText = null;
+ InputStream is = instance.getClass().getResourceAsStream(aLicenceResourceName);
+ if (is != null) {
+ InputStreamReader isr = new InputStreamReader(is);
+ BufferedReader br = new BufferedReader(isr);
+ StringBuffer sb = new StringBuffer();
+ String line;
+ try {
+ while ((line = br.readLine()) != null) {
+ sb.append(line + SourceConstants.LINE_FEED);
+ }
+ licenceText = sb.toString();
+ br.close();
+ isr.close();
+ is.close();
+ } catch (IOException e) {
+ TraceCompilerLogger.printWarning(Messages.getString("TraceCompilerErrorMessages.LicenceFileError") + e.getMessage()); //$NON-NLS-1$
+ }
+ }
+ return licenceText;
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/TraceCompilerEngineInterface.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/TraceCompilerEngineInterface.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,55 @@
+/*
+* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* TraceCompiler interface
+*
+*/
+package com.nokia.tracecompiler.engine;
+
+import com.nokia.tracecompiler.model.TraceCompilerException;
+
+/**
+ * TraceCompiler interface
+ *
+ */
+public interface TraceCompilerEngineInterface {
+
+ /**
+ * Opens the trace project related to given source file
+ *
+ * @param modelName
+ * the name for the model
+ * @throws TraceCompilerException
+ * if startup fails
+ * @throws Exception
+ */
+ public void openProject(String modelName)
+ throws Exception; //this include TraceCompilerException
+
+ /**
+ * Exports the trace project
+ *
+ * @throws TraceCompilerException
+ * if export fails
+ */
+ public void exportProject() throws TraceCompilerException;
+
+ /**
+ * Closes the trace project
+ * @throws TraceCompilerException
+ */
+ public void closeProject() throws TraceCompilerException;
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/TraceCompilerEngineView.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/TraceCompilerEngineView.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,37 @@
+/*
+* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Interface implemented by the view of TraceCompiler
+*
+*/
+package com.nokia.tracecompiler.engine;
+
+/**
+ * Interface implemented by the view of TraceCompiler. The view is implemented
+ * as a separate plug-in, which is registered via
+ * {@link TraceCompilerEngineGlobals#setView(TraceCompilerView)}
+ *
+ * @see com.nokia.tracecompiler.engine.TraceCompilerEngineGlobals#setView(TraceCompilerView)
+ */
+public interface TraceCompilerEngineView {
+
+ /**
+ * Gets the configuration interface
+ *
+ * @return the configuration interface
+ */
+ public TraceCompilerEngineConfiguration getConfiguration();
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/TraceLocation.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/TraceLocation.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,491 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Represents a location of a trace within a source document
+*
+*/
+package com.nokia.tracecompiler.engine;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import com.nokia.tracecompiler.engine.TraceCompilerEngineErrorCodes.TraceCompilerErrorCode;
+import com.nokia.tracecompiler.engine.source.SourceParserResult;
+import com.nokia.tracecompiler.engine.source.SourceParserRule;
+import com.nokia.tracecompiler.engine.source.SourceProperties;
+import com.nokia.tracecompiler.model.Trace;
+import com.nokia.tracecompiler.model.TraceCompilerErrorParameters;
+import com.nokia.tracecompiler.model.TraceCompilerException;
+import com.nokia.tracecompiler.model.TraceObject;
+import com.nokia.tracecompiler.source.SourceConstants;
+import com.nokia.tracecompiler.source.SourceLocation;
+import com.nokia.tracecompiler.source.SourceLocationListener;
+
+/**
+ * Represents a location of a trace within a source document. The locations of a
+ * document are updated by TraceLocationUpdater when document is changed
+ *
+ */
+public class TraceLocation extends SourceLocation implements LocationProperties {
+
+ /**
+ * Source which owns this location
+ */
+ private SourceProperties source;
+
+ /**
+ * Name of the trace as parsed from source
+ */
+ private String originalName;
+
+ /**
+ * Name after conversion to valid trace name
+ */
+ private String convertedName;
+
+ /**
+ * Text of the trace as parsed from source
+ */
+ private String traceText;
+
+ /**
+ * The tag of the parser that found this trace location
+ */
+ private String tag;
+
+ /**
+ * Content changed flag
+ */
+ private boolean contentChanged;
+
+ /**
+ * Name changed flag
+ */
+ private boolean nameChanged;
+
+ /**
+ * The location list
+ */
+ private TraceLocationList list;
+
+ /**
+ * The parameters
+ */
+ private List parameters;
+
+ /**
+ * Parser-specific data associated with this location
+ */
+ private List parserData;
+
+ /**
+ * Rule which defines how the parameters found from source are interpreted
+ */
+ private SourceParserRule parserRule;
+
+ /**
+ * Flag, which determines if this location has changed after last convert
+ * operation
+ */
+ private boolean changedAfterConvert = true;
+
+ /**
+ * Last notified validity code
+ */
+ private TraceCompilerErrorCode notifiedValidity = TraceCompilerErrorCode.OK;
+
+ /**
+ * Last notified validity parameters
+ */
+ private TraceCompilerErrorParameters notifiedValidityParameters;
+
+ /**
+ * Parser error code
+ */
+ private TraceCompilerErrorCode parserErrorCode = TraceCompilerErrorCode.OK;
+
+ /**
+ * Parser error parameters
+ */
+ private TraceCompilerErrorParameters parserErrorParameters;
+
+ /**
+ * Converter error code
+ */
+ private TraceCompilerErrorCode converterErrorCode = TraceCompilerErrorCode.OK;
+
+ /**
+ * Converter error parameters
+ */
+ private TraceCompilerErrorParameters converterErrorParameters;
+
+ /**
+ * Creates a new location
+ *
+ * @param source
+ * the source where the location is associated
+ * @param offset
+ * the offset to the trace within the source document
+ * @param length
+ * the length of the trace
+ */
+ public TraceLocation(SourceProperties source, int offset, int length) {
+ super(source.getSourceParser(), offset, length);
+ this.source = source;
+ }
+
+ /**
+ * Sets the content changed flag. If changed is false this also sets
+ * the name changed flag to false
+ *
+ * @param changed
+ * the new changed flag
+ */
+ public void setContentChanged(boolean changed) {
+ this.contentChanged = changed;
+ if (!changed) {
+ nameChanged = false;
+ }
+ }
+
+ /**
+ * Checks if the content has changed.
+ *
+ * @return the content changed flag
+ */
+ public boolean isContentChanged() {
+ return contentChanged;
+ }
+
+ /**
+ * Checks if the name has changed.
+ *
+ * @return the name changed flag
+ */
+ public boolean isNameChanged() {
+ return contentChanged && nameChanged;
+ }
+
+ /**
+ * Gets the trace this location is associated to or null if unrelated
+ *
+ * @return the trace
+ */
+ public Trace getTrace() {
+ Trace retval = null;
+ if (list != null) {
+ TraceObject object = list.getOwner();
+ if (object instanceof Trace) {
+ retval = (Trace) object;
+ }
+ }
+ return retval;
+ }
+
+ /**
+ * Gets the name of the trace as parsed from source
+ *
+ * @return the name of the trace
+ */
+ public String getOriginalName() {
+ return originalName;
+ }
+
+ /**
+ * Gets the name of the trace after conversion to valid name
+ *
+ * @return the name of the trace
+ */
+ public String getConvertedName() {
+ return convertedName;
+ }
+
+ /**
+ * Gets the text of the trace
+ *
+ * @return the text of the trace
+ */
+ public String getTraceText() {
+ return traceText;
+ }
+
+ /**
+ * Returns the source properties this location belongs to
+ *
+ * @return source properties
+ */
+ public SourceProperties getSource() {
+ return source;
+ }
+
+ /**
+ * Sets the location list which owns this location
+ *
+ * @param list
+ * the location list
+ */
+ public void setLocationList(TraceLocationList list) {
+ this.list = list;
+ }
+
+ /**
+ * Gets the location list this location belongs to
+ *
+ * @return the list
+ */
+ public TraceLocationList getLocationList() {
+ return list;
+ }
+
+ /**
+ * Sets the parser rule that will be used to parse the data of this
+ * location. Must be called before setData
+ *
+ * @param rule
+ * the rule used to parse the data
+ */
+ public void setParserRule(SourceParserRule rule) {
+ parserRule = rule;
+ }
+
+ /**
+ * Gets the parser rule that found this location
+ *
+ * @return the parser rule
+ */
+ public SourceParserRule getParserRule() {
+ return parserRule;
+ }
+
+ /**
+ * Sets the trace tag that was found from source
+ *
+ * @param tag
+ * the trace tag
+ */
+ public void setTag(String tag) {
+ this.tag = tag;
+ }
+
+ /**
+ * Gets the trace tag
+ *
+ * @return the tag
+ */
+ public String getTag() {
+ return tag;
+ }
+
+ /**
+ * Sets the trace data
+ *
+ * @param list
+ * the list of parameters
+ */
+ public void setData(ArrayList list) {
+ try {
+ SourceParserResult result = parserRule.parseParameters(tag, list);
+ setData(result.originalName, result.convertedName,
+ result.traceText, result.parameters, result.parserData);
+ parserRule.getLocationParser().processNewLocation(this);
+ parserErrorCode = TraceCompilerErrorCode.OK;
+ parserErrorParameters = null;
+ converterErrorCode = TraceCompilerErrorCode.OK;
+ converterErrorParameters = null;
+ } catch (TraceCompilerException e) {
+ parserErrorCode = (TraceCompilerErrorCode) e.getErrorCode();
+ parserErrorParameters = e.getErrorParameters();
+ }
+ }
+
+ /**
+ * Sets the trace name and parameter list
+ *
+ * @param originalName
+ * the name parsed from source
+ * @param convertedName
+ * the name after conversion
+ * @param traceText
+ * the text parsed from source
+ * @param parameters
+ * the list of parameters parsed from source
+ * @param parserData
+ * list of parser-specific data
+ */
+ private void setData(String originalName, String convertedName,
+ String traceText, List parameters, List parserData) {
+ if (!convertedName.equals(this.convertedName)) {
+ this.convertedName = convertedName;
+ nameChanged = true;
+ }
+ this.originalName = originalName;
+ //remove line feed if the trace text spans multiple lines.
+ if (traceText != null ) {
+ this.traceText = traceText.replaceAll(SourceConstants.LINE_FEED, ""); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ this.parameters = parameters;
+ this.parserData = parserData;
+ }
+
+ /**
+ * Removes the parameter at given index
+ *
+ * @param index
+ * the index
+ */
+ public void removeParameterAt(int index) {
+ // NOTE: Does not cause validity callbacks
+ // This is currently only used temporarily when removing a parameter
+ // from trace. This is needed to correctly update the source code
+ if (parameters != null && index >= 0 && index < parameters.size()) {
+ parameters.remove(index);
+ }
+ }
+
+ /**
+ * Gets the number of parameters found from the source code
+ *
+ * @return the number of parameters
+ */
+ public int getParameterCount() {
+ return parameters != null ? parameters.size() : 0;
+ }
+
+ /**
+ * Gets the parameter at given index
+ *
+ * @param index
+ * the parameter index
+ * @return the parameter at the index
+ */
+ public String getParameter(int index) {
+ return parameters.get(index);
+ }
+
+ /**
+ * Gets the parameters
+ *
+ * @return iterator over the parameters
+ */
+ public Iterator getParameters() {
+ List list = null;
+ if (parameters != null) {
+ list = parameters;
+ } else {
+ list = Collections.emptyList();
+ }
+ return list.iterator();
+ }
+
+ /**
+ * Gets the parser-specific data
+ *
+ * @return the parser data
+ */
+ public List getParserData() {
+ return parserData;
+ }
+
+ /**
+ * Gets the current location validity code.
+ *
+ * @return the validity code
+ */
+ public TraceCompilerErrorCode getValidityCode() {
+ return notifiedValidity;
+ }
+
+ /**
+ * Gets the parameters associated with the current location validity code.
+ *
+ * @return the validity code
+ */
+ public TraceCompilerErrorParameters getValidityParameters() {
+ return notifiedValidityParameters;
+ }
+
+ /**
+ * Creates a notification if validity has changed. This is initially called
+ * from the location list when a location is added to it and after that from
+ * notifyLocationChanged.
+ */
+ void runValidityCheck() {
+ TraceCompilerErrorCode code;
+ TraceCompilerErrorParameters parameters;
+ if (parserErrorCode != TraceCompilerErrorCode.OK) {
+ code = parserErrorCode;
+ parameters = parserErrorParameters;
+ } else if (converterErrorCode != TraceCompilerErrorCode.OK) {
+ code = converterErrorCode;
+ parameters = converterErrorParameters;
+ } else {
+ code = TraceCompilerErrorCode.TRACE_DOES_NOT_EXIST;
+ parameters = null;
+ if (parserRule != null) {
+ code = parserRule.getLocationParser().checkLocationValidity(
+ this);
+ }
+ }
+ if (code != notifiedValidity) {
+ notifiedValidity = code;
+ notifiedValidityParameters = parameters;
+ Iterator itr = getListeners();
+ while (itr.hasNext()) {
+ SourceLocationListener listener = itr.next();
+ if (listener instanceof SourceLocationListener) {
+ ((SourceLocationListener) listener)
+ .locationValidityChanged(this);
+ }
+ }
+ }
+ }
+
+ /**
+ * Sets the converter error code and runs the validity check to notify
+ * listeners about change in error code
+ *
+ * @param errorCode
+ * the new error code
+ * @param parameters
+ * the error parameters
+ */
+ void setConverterErrorCode(TraceCompilerErrorCode errorCode,
+ TraceCompilerErrorParameters parameters) {
+ converterErrorCode = errorCode;
+ converterErrorParameters = parameters;
+ runValidityCheck();
+ }
+
+ /**
+ * Flag, which determines if the location has changed since last convert
+ * operation
+ *
+ * @return the flag
+ */
+ public boolean hasChangedAfterConvert() {
+ return changedAfterConvert;
+ }
+
+ /**
+ * Called when the location has been converted. Sets the changed after
+ * convert flag to false
+ */
+ public void locationConverted() {
+ changedAfterConvert = false;
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/TraceLocationConverter.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/TraceLocationConverter.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,679 @@
+/*
+ * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ *
+ * Description:
+ *
+ * Location converter monitors locations and converts them to traces if necessary.
+ *
+ */
+package com.nokia.tracecompiler.engine;
+
+import java.io.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+
+import com.nokia.tracecompiler.TraceCompilerConstants;
+import com.nokia.tracecompiler.TraceCompilerLogger;
+import com.nokia.tracecompiler.engine.TraceCompilerEngineErrorCodes.TraceCompilerErrorCode;
+import com.nokia.tracecompiler.engine.project.ProjectConstants;
+import com.nokia.tracecompiler.engine.project.ProjectEngine;
+import com.nokia.tracecompiler.engine.project.SortedProperties;
+import com.nokia.tracecompiler.engine.project.TraceIDCache;
+import com.nokia.tracecompiler.engine.rules.PerformanceEventRuleBase;
+import com.nokia.tracecompiler.engine.rules.StateTraceRule;
+import com.nokia.tracecompiler.engine.source.SourceParserRule;
+import com.nokia.tracecompiler.engine.source.SourceProperties;
+import com.nokia.tracecompiler.engine.source.SourceParserRule.ParameterConversionResult;
+import com.nokia.tracecompiler.engine.source.SourceParserRule.TraceConversionResult;
+import com.nokia.tracecompiler.model.Trace;
+import com.nokia.tracecompiler.model.TraceCompilerException;
+import com.nokia.tracecompiler.model.TraceGroup;
+import com.nokia.tracecompiler.model.TraceModel;
+import com.nokia.tracecompiler.model.TraceModelExtension;
+import com.nokia.tracecompiler.model.TraceModelPersistentExtension;
+import com.nokia.tracecompiler.model.TraceParameter;
+import com.nokia.tracecompiler.project.FormattingUtils;
+import com.nokia.tracecompiler.project.GroupNames;
+import com.nokia.tracecompiler.project.ProjectUtils;
+import com.nokia.tracecompiler.source.SourceConstants;
+
+/**
+ * Location converter monitors locations and converts them to traces if
+ * necessary.
+ *
+ */
+public final class TraceLocationConverter {
+
+ /**
+ * Number of deprecated groups
+ */
+ final static int NUMBER_OF_DEPRECATED_GROUPS = 3;
+
+ /**
+ * Deprecated group name map
+ */
+ Map deprecatedGroupNameMap = new HashMap(
+ NUMBER_OF_DEPRECATED_GROUPS);
+
+ /**
+ * Trace model
+ */
+ private TraceModel model;
+
+ /**
+ * Constructor
+ *
+ * @param model
+ * the trace model
+ */
+ TraceLocationConverter(TraceModel model) {
+ this.model = model;
+ initializeDeprecatedGroupNameMap();
+ }
+
+ /**
+ * Initialize deprecated group name map
+ */
+ private void initializeDeprecatedGroupNameMap() {
+ deprecatedGroupNameMap.put(GroupNames.TRACE_API,
+ GroupNames.TRACE_BORDER);
+ deprecatedGroupNameMap.put(GroupNames.TRACE_DEBUG,
+ GroupNames.TRACE_DUMP);
+ deprecatedGroupNameMap.put(GroupNames.TRACE_DETAILED,
+ GroupNames.TRACE_INTERNALS);
+ }
+
+ /**
+ * Source opened notification
+ *
+ * @param properties
+ * the source properties
+ * @throws TraceCompilerException
+ */
+ void sourceOpened(SourceProperties properties) throws TraceCompilerException {
+ //make sure all errors are reported AFTER processing a file
+ TraceCompilerEngineGlobals.getSourceContextManager()
+ .setConverting(true);
+ model.startProcessing();
+ try {
+ // Load fixed group and trace ids from definition file to model
+ //no errors are reported here
+ if (model.getFixedIds() == null) {
+ loadFixedIdsFromDefinitionFileToModel();
+ }
+
+ for (TraceLocation loc : properties) {
+ autoConvertLocation(loc);
+ }
+ // If there are duplicates or unused traces, they are removed
+ // Note that this will work across source files although this
+ // function is processing only one file.
+ // If a trace is created, all locations from all open source files
+ // are linked to that trace and thus it will be removed as
+ // duplicate.
+ removeDuplicateTraces();
+
+ } finally {
+ model.processingComplete();
+ SourceContextManager manager = TraceCompilerEngineGlobals
+ .getSourceContextManager();
+ manager.setConverting(false);
+ manager.setContext(null);
+ }
+ }
+
+ /**
+ * Load fixed Ids from definiton file to properties
+ *
+ */
+ private void loadFixedIdsFromDefinitionFileToModel() {
+ TraceIDCache cache = model.getExtension(TraceIDCache.class);
+
+ // Create trace Id cache if it does not exist
+ try {
+ if (cache == null) {
+ String path;
+ path = ProjectUtils.getLocationForFile(model,
+ ProjectEngine.traceFolderName,
+ ProjectConstants.FIXED_ID_DEFINITIONS_FILE_NAME, false);
+ if (path != null) {
+ cache = new TraceIDCache(new File(path).getParent());
+ model.addExtension(cache);
+ }
+ }
+ if (cache != null) {
+ File cacheFile = new File(cache.getAbsolutePath());
+ // Try to load Ids from trace Id cache file
+ try {
+ SortedProperties fixedIds = new SortedProperties();
+ if (cacheFile.exists()) {
+ String thisLine;
+ boolean allOldFixedIdsAreValid = true;
+ String group = model.GROUP_PROPERTY_PREFIX;
+ FileInputStream fis = new FileInputStream(cacheFile);
+ BufferedReader myInput = new BufferedReader(
+ new InputStreamReader(fis));
+ // Read the old fixed id definition file
+ while ((thisLine = myInput.readLine()) != null) {
+ if (thisLine.indexOf(group) != -1) {
+ thisLine = thisLine.substring(group.length(),
+ thisLine.length());
+ if (!searchForOldGroupIds(thisLine)) {
+ String msg = Messages.getString("TraceLocationConverter.GroupIdValueError"); //$NON-NLS-1$
+ TraceCompilerEngineGlobals.getEvents().postWarningMessage(msg, null);
+ // We need only one old invalid id to make all of them invalid
+ allOldFixedIdsAreValid = false;
+ break;
+ }
+ }
+ }
+ fis.close();
+
+ if (allOldFixedIdsAreValid) {
+ // Create file input stream again
+ FileInputStream newFis = new FileInputStream(cacheFile);
+ fixedIds.load(newFis);
+ // Load fixed Ids from properties to model
+ model.setFixedIds(fixedIds);
+ newFis.close();
+ }
+
+ }
+ } catch (IOException e) {
+ // If there is a problem with the cache file, just delete it
+ // make sure the model fixed ids is null
+ model.setFixedIds(null);
+ cacheFile.delete();
+ // We do not raise an exception but we need to report a info
+ TraceCompilerLogger.printWarning(Messages.getString("TraceLocationConverter.FixedIdProblemWarningBeginText") + cacheFile.toString() + Messages.getString("TraceLocationConverter.FixedIdProblemWarningMiddleText") + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+ } catch (TraceCompilerException e) {
+ // This exception can probably be ignored
+ TraceCompilerLogger.printWarning("Could not create ID cache : " + e.getMessage()); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Searches the fixed_id file to see if there are any old definitions
+ *
+ * @param string
+ * of text from the fixed_id files
+ * @return boolean
+ */
+ public static boolean searchForOldGroupIds(String str) {
+
+ boolean oldGroupIdValid = true;
+
+ //get group name from the string
+ int index = str.indexOf(SourceConstants.ASSIGN_WITH_OUT_SPACES);
+ if (index == -1) {
+ //not valid string, so ignore it, just return success
+ return true;
+ }
+
+ String groupName = str.substring(0, index);
+
+ //get group id
+ str = str.substring(str.indexOf(SourceConstants.HEX_PREFIX) + 2, str
+ .length());
+
+ int groupId = -1;
+
+ try {
+ groupId = Integer.parseInt(str.trim(),
+ TraceCompilerConstants.HEX_RADIX);
+ } catch (NumberFormatException e) {
+ //it's not an hex number so fail
+ oldGroupIdValid = false;
+ }
+
+ //get group id from ost header file
+ int fileGroupId = GroupNames.getIdByName(groupName);
+
+ if (fileGroupId != 0) {
+ //found 1
+ if (fileGroupId != groupId) //group id has changed, so old one can't be used
+ oldGroupIdValid = false;
+ } else {
+ if ((GroupNames.USER_GROUP_ID_FIRST > groupId)
+ || (groupId > GroupNames.USER_GROUP_ID_LAST)) //not within new user defined Ids
+ oldGroupIdValid = false;
+ }
+
+ return oldGroupIdValid;
+ }
+
+ /**
+ * Converts the given location to trace if parser supports auto-conversion
+ *
+ * @param location
+ * the location
+ */
+ private void autoConvertLocation(TraceLocation location) {
+ // Stores the context of the location to the context manager.
+ TraceCompilerEngineGlobals.getSourceContextManager().setContext(
+ location.getParser().getContext(location.getOffset()));
+ Trace trace = location.getTrace();
+ if (trace == null) {
+ // If the trace does not exist, the parser determines if the
+ // location can be converted
+ if (location.getParserRule().getLocationParser()
+ .isLocationConverted(location)) {
+ try {
+ convertLocation(location, null, true);
+ } catch (TraceCompilerException e) {
+ // If converter fails, the error code is stored into the
+ // location. The location notifies all validity listeners
+ // about the change
+ location.setConverterErrorCode((TraceCompilerErrorCode) e
+ .getErrorCode(), e.getErrorParameters());
+ }
+ }
+ } else {
+ // If the trace already exists in the model, it is updated
+ // based on the source file contents
+ updateLocation(location);
+ }
+ }
+
+ /**
+ * Recreates the trace from changed location when source is saved
+ *
+ * @param location
+ * the location to be checked
+ */
+ private void updateLocation(TraceLocation location) {
+ // Parser determines if the location can be converted
+ if (location.getParserRule().getLocationParser().isLocationConverted(
+ location)) {
+ try {
+ Trace trace = location.getTrace();
+ // If a location has changed, the old trace is removed
+ // and a new one created. Persistent extensions are moved to the
+ // new trace
+ Iterator extensions = null;
+ if (trace != null) {
+ extensions = trace
+ .getExtensions(TraceModelPersistentExtension.class);
+ trace.getGroup().removeTrace(trace);
+ }
+ convertLocation(location, extensions, true);
+
+ // Check that the location is inside a function. Otherwise throw
+ // an error because the code is unreachable
+ if (location.getFunctionName() == null) {
+ throw new TraceCompilerException(
+ TraceCompilerErrorCode.UNREACHABLE_TRACE_LOCATION);
+ }
+
+ } catch (TraceCompilerException e) {
+ // If converter fails, the error code is stored into the
+ // location. The location notifies all validity listeners about
+ // the change
+ location.setConverterErrorCode((TraceCompilerErrorCode) e
+ .getErrorCode(), e.getErrorParameters());
+ }
+ }
+ }
+
+ /**
+ * Removes all duplicate traces from the model
+ * @throws TraceCompilerException
+ */
+ private void removeDuplicateTraces() throws TraceCompilerException {
+ boolean groupRemoved = true;
+ while (groupRemoved) {
+ groupRemoved = false;
+ for (TraceGroup group : model) {
+ removeDuplicateTracesFromGroup(group);
+ if (!group.hasTraces()) {
+ model.removeGroup(group);
+ groupRemoved = true;
+ break;
+ }
+ }
+ }
+ }
+
+ /**
+ * Removes duplicate traces from a trace group
+ *
+ * @param group
+ * the group
+ * @throws TraceCompilerException
+ */
+ private void removeDuplicateTracesFromGroup(TraceGroup group) throws TraceCompilerException {
+ boolean traceRemoved = true;
+ while (traceRemoved) {
+ traceRemoved = false;
+ for (Trace trace : group) {
+ TraceLocationList list = trace
+ .getExtension(TraceLocationList.class);
+ if (list != null) {
+ if (list.getLocationCount() > 1) {
+ // All the locations are marked as duplicates and the
+ // trace is deleted
+ TraceCompilerErrorCode code = TraceCompilerErrorCode.TRACE_HAS_MULTIPLE_LOCATIONS;
+ for (LocationProperties loc : list) {
+ ((TraceLocation) loc).setConverterErrorCode(code,
+ null);
+ }
+ group.removeTrace(trace);
+ traceRemoved = true;
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Converts a location to a Trace object.
+ *
+ * @param location
+ * the location to be converted
+ * @param extensions
+ * persistent extensions to be added to the new trace
+ * @param autoConvert
+ * true if converting without user interaction
+ * @return the new trace
+ * @throws TraceCompilerException
+ * if conversion fails
+ */
+ private Trace convertLocation(TraceLocation location,
+ Iterator extensions,
+ boolean autoConvert) throws TraceCompilerException {
+ Trace trace = null;
+ // If the parser has failed, the validity code is not OK and the
+ // location cannot be converted. Traces marked with no-trace error code
+ // have not yet been converted, so that is OK. Traces that have
+ // duplicate ID's error code can be parsed, since the duplicates might
+ // no longer exist.
+ if (!autoConvert
+ || location.getValidityCode() == TraceCompilerErrorCode.OK
+ || location.getValidityCode() == TraceCompilerErrorCode.TRACE_DOES_NOT_EXIST
+ || location.getValidityCode() == TraceCompilerErrorCode.TRACE_HAS_MULTIPLE_LOCATIONS) {
+ // The parser does the actual conversion
+ SourceParserRule rule = location.getParserRule();
+ TraceConversionResult result = rule.getLocationParser()
+ .convertLocation(location);
+ // After parser has finished, the trace is created.
+ trace = convertWithoutUI(result, extensions);
+
+ if (trace != null) {
+ model.startProcessing();
+ try {
+ createParametersFromConversionResult(location, result,
+ trace);
+ // Runs a location validity check and notifies listeners
+ // that location is now OK
+ location.setConverterErrorCode(TraceCompilerErrorCode.OK,
+ null);
+ } catch (TraceCompilerException e) {
+ // If parameters cannot be created, the trace is removed
+ TraceGroup group = trace.getGroup();
+ trace.getGroup().removeTrace(trace);
+ if (!group.hasTraces()) {
+ group.getModel().removeGroup(group);
+ }
+ throw e;
+ } finally {
+ model.processingComplete();
+ }
+ }
+ }
+ return trace;
+ }
+
+ /**
+ * Converts a location to trace without UI
+ *
+ * @param result
+ * the conversion result from parser
+ * @param extensions
+ * persistent extensions to be added to the new trace
+ * @return the converted trace
+ * @throws TraceCompilerException
+ * if location properties are not valid
+ */
+ private Trace convertWithoutUI(TraceConversionResult result,
+ Iterator extensions)
+ throws TraceCompilerException {
+ Trace trace = null;
+ if (result.group != null) {
+ String groupName = result.group;
+ TraceGroup group = handleGroup(groupName);
+ trace = handleTrace(result, extensions, group);
+ } else {
+ throw new TraceCompilerException(
+ TraceCompilerErrorCode.GROUP_NOT_SELECTED);
+ }
+ return trace;
+ }
+
+ /**
+ * Handle trace
+ *
+ * @param result
+ * the conversion result from parser
+ * @param extensions
+ * persistent extensions to be added to the new trace
+ * @param group
+ * the group where trace belongs to
+ * @return the trace
+ * @throws TraceCompilerException
+ */
+ private Trace handleTrace(TraceConversionResult result,
+ Iterator extensions, TraceGroup group)
+ throws TraceCompilerException {
+ // First try to find Id to trace from fixed Ids
+ Trace trace = null;
+ Properties fixedIds = model.getFixedIds();
+ String groupName = result.group;
+ String traceName = result.name;
+ int groupId = group.getID();
+ String groupIdString = SourceConstants.HEX_PREFIX
+ + Integer.toString(groupId, model.HEX_RADIX).toUpperCase();
+ int traceId = 0;
+ if (fixedIds != null) {
+ String tracePropertyName = groupName + model.GROUP_ID_PREFIX
+ + groupIdString + model.GROUP_ID_SUFFIX
+ + SourceConstants.UNDERSCORE + traceName;
+ String value = fixedIds.getProperty(model.TRACE_PROPERTY_PREFIX
+ + tracePropertyName);
+ if (value != null) {
+ try {
+ traceId = Integer.decode(value).intValue();
+ } catch (NumberFormatException e) {
+ // Corrupted, assign a proper Id later on
+ traceId = 0;
+ }
+ }
+ }
+ // If there was no fixed Id to this trace, get Id from model
+ if (traceId == 0) {
+ traceId = model.getNextTraceId(group);
+ }
+
+ String text = result.text;
+ model.getVerifier().checkTraceProperties(group, null, traceId,
+ traceName, text);
+ TraceModelExtension[] extArray = createExtensionArray(result,
+ extensions);
+ trace = model.getFactory().createTrace(group, traceId, traceName, text,
+ extArray);
+
+ if ((trace.getExtension(StateTraceRule.class) == null)
+ && (group.getName()
+ .equals("TRACE_STATE"))) { //$NON-NLS-1$
+ throw new TraceCompilerException(
+ TraceCompilerErrorCode.INVALID_USAGE_OF_TRACE_STATE_GROUP_NAME);
+ } else if ((trace.getExtension(PerformanceEventRuleBase.class) == null)
+ && (group.getName()
+ .equals("TRACE_PERFORMANCE"))) { //$NON-NLS-1$
+ throw new TraceCompilerException(
+ TraceCompilerErrorCode.INVALID_USAGE_OF_TRACE_PERFORMACE_GROUP_NAME);
+ }
+
+ return trace;
+ }
+
+ /**
+ * Handle group. Try to fnd group from model. If it does not exist then
+ * create new group.
+ *
+ * @param groupName
+ * the name of the group
+ * @return the handled group
+ * @throws TraceCompilerException
+ */
+ private TraceGroup handleGroup(String groupName)
+ throws TraceCompilerException {
+ String deprecatedGroupName = null;
+
+ // Convert deprecated group name to valid group name if needed
+ if (deprecatedGroupNameMap.containsKey(groupName)) {
+ deprecatedGroupName = groupName;
+ groupName = deprecatedGroupNameMap.get(groupName);
+ }
+
+ // If auto-convert flag is set, the location is converted without
+ // user interaction. A new trace group is created if not found
+ TraceGroup group = model.findGroupByName(groupName);
+ if (group == null) {
+
+ // Print warning related to deprecated group name change if needed
+ if (deprecatedGroupName != null) {
+ String message = Messages
+ .getString("TraceLocationConverter.DeprecatedGroupIdWarningStart");//$NON-NLS-1$
+ message += SourceConstants.SPACE + deprecatedGroupName
+ + SourceConstants.SPACE;
+ message += Messages
+ .getString("TraceLocationConverter.DeprecatedGroupIdWarningMiddle");//$NON-NLS-1$
+ message += SourceConstants.SPACE + groupName
+ + SourceConstants.SPACE;
+ message += Messages
+ .getString("TraceLocationConverter.DeprecatedGroupIdWarningEnd");//$NON-NLS-1$
+ TraceCompilerLogger.printWarning(message);
+ }
+
+ int groupId = 0;
+ Properties fixedIds = model.getFixedIds();
+
+ // First try to find Id to group from fixed Ids
+ if (fixedIds != null) {
+ String value = fixedIds.getProperty(model.GROUP_PROPERTY_PREFIX
+ + groupName);
+ if (value != null) {
+ try {
+ groupId = Integer.decode(value).intValue();
+ } catch (NumberFormatException e) {
+ // Corrupted, assign a proper Id later on
+ groupId = 0;
+ }
+ }
+ }
+ // If there was no fixed Id to this group, get Id from model
+ if (groupId == 0) {
+ groupId = FormattingUtils.getGroupID(model, groupName);
+ }
+ model.getVerifier().checkTraceGroupProperties(model, null, groupId,
+ groupName);
+ group = model.getFactory().createTraceGroup(groupId, groupName,
+ null);
+ }
+
+ return group;
+ }
+
+ /**
+ * Combines extensions into one array
+ *
+ * @param result
+ * the conversion result
+ * @param extensions
+ * the persistent extensions from old trace
+ * @return the combined array of extensions
+ */
+ private TraceModelExtension[] createExtensionArray(
+ TraceConversionResult result,
+ Iterator extensions) {
+ TraceModelExtension[] extArray = null;
+ ArrayList ext = null;
+ if (result.extensions != null) {
+ ext = new ArrayList();
+ ext.addAll(result.extensions);
+ }
+ if (extensions != null) {
+ if (ext == null) {
+ ext = new ArrayList();
+ }
+ while (extensions.hasNext()) {
+ ext.add(extensions.next());
+ }
+ }
+ if (ext != null) {
+ extArray = new TraceModelExtension[ext.size()];
+ ext.toArray(extArray);
+ }
+ return extArray;
+ }
+
+ /**
+ * Creates the trace parameters based on trace conversion result
+ *
+ * @param converted
+ * the location that was converted
+ * @param result
+ * the conversion result
+ * @param trace
+ * the trace
+ * @throws TraceCompilerException
+ * if parameters cannot be created
+ */
+ private void createParametersFromConversionResult(TraceLocation converted,
+ TraceConversionResult result, Trace trace)
+ throws TraceCompilerException {
+ if (result.parameters != null) {
+ for (int i = 0; i < result.parameters.size(); i++) {
+ int id = trace.getNextParameterID();
+ ParameterConversionResult res = result.parameters.get(i);
+ boolean warning = false;
+ if (res.type == null) {
+ warning = true;
+ res.type = TraceParameter.HEX32;
+ }
+ model.getVerifier().checkTraceParameterProperties(trace, null,
+ id, res.name, res.type);
+ TraceModelExtension[] extArray = null;
+ if (res.extensions != null) {
+ extArray = new TraceModelExtension[res.extensions.size()];
+ res.extensions.toArray(extArray);
+ }
+ TraceParameter param = model.getFactory().createTraceParameter(
+ trace, id, res.name, res.type, extArray);
+ if (warning) {
+ String msg = Messages
+ .getString("TraceCompiler.UnknownTypeWarning"); //$NON-NLS-1$
+ TraceCompilerEngineGlobals.getEvents().postWarningMessage(
+ msg, param);
+ }
+ }
+ }
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/TraceLocationList.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/TraceLocationList.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,146 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* List of trace locations
+*
+*/
+package com.nokia.tracecompiler.engine;
+
+import java.util.ArrayList;
+
+import com.nokia.tracecompiler.model.TraceCompilerException;
+
+/**
+ * List of trace locations.
+ *
+ */
+public class TraceLocationList extends LocationListBase {
+
+ /**
+ * Location list listeners
+ */
+ private ArrayList listeners = new ArrayList();
+
+ /**
+ * List title, returned by getTitle
+ */
+ private String listTitle;
+
+ /**
+ * Constructor
+ */
+ TraceLocationList() {
+ }
+
+ /**
+ * Constructor
+ *
+ * @param listTitle
+ * the title of this location list
+ */
+ TraceLocationList(String listTitle) {
+ this.listTitle = listTitle;
+ }
+
+ /**
+ * Adds a location to this list.
+ *
+ * @param location
+ * the location to be added
+ * @throws TraceCompilerException
+ */
+ void addLocation(TraceLocation location) throws TraceCompilerException {
+ if (TraceCompilerEngineConfiguration.ASSERTIONS_ENABLED) {
+ if (contains(location)) {
+ //this can only happen if there is a programming error
+ TraceCompilerEngineGlobals.getEvents().postCriticalAssertionFailed(
+ "Duplicate trace location", //$NON-NLS-1$
+ location.getConvertedName());
+ throw new TraceCompilerException(null);
+ }
+ }
+ location.setLocationList(this);
+ add(location);
+ fireLocationAdded(location);
+ location.runValidityCheck();
+ }
+
+ /**
+ * Removes a location from this list.
+ *
+ * @param location
+ * the location to be removed
+ */
+ void removeLocation(TraceLocation location) {
+ if (remove(location)) {
+ fireLocationRemoved(location);
+ location.setLocationList(null);
+ }
+ }
+
+ /**
+ * Adds a location list listener to this object
+ *
+ * @param listener
+ * the listener interface
+ */
+ public void addLocationListListener(TraceLocationListListener listener) {
+ listeners.add(listener);
+ }
+
+ /**
+ * Removes the location list listener
+ *
+ * @param listener
+ * the listener interface
+ */
+ public void removeLocationListListener(TraceLocationListListener listener) {
+ listeners.remove(listener);
+ }
+
+ /**
+ * Creates locationAdded event to location list listeners
+ *
+ * @param location
+ * the location that was added
+ */
+ private void fireLocationAdded(TraceLocation location) {
+ for (TraceLocationListListener l : listeners) {
+ l.locationAdded(location);
+ }
+ }
+
+ /**
+ * Creates locationRemoved event to location list listeners
+ *
+ * @param location
+ * the location that was added
+ */
+ void fireLocationRemoved(TraceLocation location) {
+ for (TraceLocationListListener l : listeners) {
+ l.locationRemoved(location);
+ }
+ }
+
+ /**
+ * Gets the list title or null
+ *
+ * @return the list title
+ */
+ public String getListTitle() {
+ return listTitle;
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/TraceLocationListListener.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/TraceLocationListListener.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,43 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Listener for trace location lists
+*
+*/
+package com.nokia.tracecompiler.engine;
+
+/**
+ * Listener for trace location lists
+ *
+ */
+public interface TraceLocationListListener {
+
+ /**
+ * Location was added to this list
+ *
+ * @param location
+ * the new location
+ */
+ public void locationAdded(TraceLocation location);
+
+ /**
+ * Location was removed from this list
+ *
+ * @param location
+ * the location that was removed
+ */
+ public void locationRemoved(TraceLocation location);
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/TraceLocationMap.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/TraceLocationMap.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,174 @@
+/*
+* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Maps trace locations into traces and vice versa
+*
+*/
+package com.nokia.tracecompiler.engine;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import com.nokia.tracecompiler.engine.source.SourceProperties;
+import com.nokia.tracecompiler.model.Trace;
+import com.nokia.tracecompiler.model.TraceCompilerException;
+import com.nokia.tracecompiler.model.TraceModel;
+
+/**
+ * Maps trace locations into traces and vice versa.
+ *
+ */
+final class TraceLocationMap {
+
+ /**
+ * List of unrelated traces
+ */
+ private TraceLocationList unrelated = new TraceLocationList();
+
+ /**
+ * Parser groups
+ */
+ private HashMap parserGroups = new HashMap();
+
+ /**
+ * The trace model
+ */
+ private TraceModel model;
+
+ /**
+ * Global list of locations, used for verification purposes with
+ * GLOBAL_LOCATION_ASSERTS configuration flag
+ */
+ private ArrayList globalList;
+
+ /**
+ * Creates a location mapper
+ *
+ * @param model
+ * the trace model
+ */
+ public TraceLocationMap(TraceModel model) {
+ if (TraceCompilerEngineConfiguration.GLOBAL_LOCATION_ASSERTS) {
+ globalList = new ArrayList();
+ }
+ this.model = model;
+ model.addModelListener(new LocationMapModelListener(this));
+ model.addExtension(unrelated);
+ }
+
+ /**
+ * Adds the locations from the source file to the map
+ *
+ * @param source
+ * properties of the source to be added
+ * @throws TraceCompilerException
+ */
+ void addSource(SourceProperties source) throws TraceCompilerException {
+ for (TraceLocation location : source) {
+ if (TraceCompilerEngineConfiguration.GLOBAL_LOCATION_ASSERTS) {
+ if (globalList.contains(location)) {
+ TraceCompilerEngineGlobals.getEvents().postAssertionFailed(
+ "Location already in global list", //$NON-NLS-1$
+ location.getConvertedName());
+ } else {
+ globalList.add(location);
+ }
+ }
+ // Generates locationAdded event via TraceLocationListListener
+ addNewLocationToTrace(location);
+ }
+ }
+
+ /**
+ * Adds a location to trace or to the unrelated list if a trace cannot be
+ * found.
+ *
+ * @param location
+ * the location to be added
+ * @throws TraceCompilerException
+ */
+ private void addNewLocationToTrace(TraceLocation location) throws TraceCompilerException {
+ TraceLocationList list;
+ Trace trace = model.findTraceByName(location.getOriginalName());
+ if (trace != null) {
+ list = trace.getExtension(TraceLocationList.class);
+ if (list == null) {
+ list = new TraceLocationList();
+ trace.addExtension(list);
+ }
+ } else {
+ String name = location.getParserRule().getLocationParser()
+ .getLocationGroup();
+ if (name == null) {
+ list = unrelated;
+ } else {
+ list = parserGroups.get(name);
+ if (list == null) {
+ list = new TraceLocationList(name);
+ model.addExtension(list);
+ parserGroups.put(name, list);
+ }
+ }
+ }
+ list.addLocation(location);
+ }
+
+ /**
+ * Moves the locations from trace to unrelated list
+ *
+ * @param trace
+ * the trace
+ * @throws TraceCompilerException
+ */
+ void moveToUnrelated(Trace trace) throws TraceCompilerException {
+ TraceLocationList list = trace.getExtension(TraceLocationList.class);
+ if (list != null) {
+ trace.removeExtension(list);
+ for (LocationProperties loc : list) {
+ unrelated.addLocation((TraceLocation) loc);
+ }
+ }
+ }
+
+ /**
+ * Moves locations from unrelated to the given trace
+ *
+ * @param trace
+ * the trace
+ * @throws TraceCompilerException
+ */
+ void moveFromUnrelated(Trace trace) throws TraceCompilerException {
+ String name = trace.getName();
+ TraceLocationList list = null;
+ Iterator itr = unrelated.iterator();
+ while (itr.hasNext()) {
+ TraceLocation location = (TraceLocation) itr.next();
+ if (name.equals(location.getOriginalName())) {
+ list = trace.getExtension(TraceLocationList.class);
+ if (list == null) {
+ list = new TraceLocationList();
+ trace.addExtension(list);
+ }
+ // NOTE: This must replicate the behavior of
+ // TraceLocationList.removeLocation
+ itr.remove();
+ unrelated.fireLocationRemoved(location);
+ list.addLocation(location);
+ }
+ }
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/ViewAdapter.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/ViewAdapter.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,37 @@
+/*
+* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* View adapter
+*
+*/
+package com.nokia.tracecompiler.engine;
+
+
+/**
+ * View adapter implements the view interface.
+ *
+ */
+public class ViewAdapter implements TraceCompilerEngineView {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engi.TraceCompilerEngineView#getConfiguration()
+ */
+ public TraceCompilerEngineConfiguration getConfiguration() {
+ // This can be null, the configuration delegate checks it
+ return null;
+ }
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/event/EventEngine.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/event/EventEngine.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,239 @@
+/*
+* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Implements TraceCompilerEvents to forward events to the event router plug-in
+*
+*/
+package com.nokia.tracecompiler.engine.event;
+
+import com.nokia.tracecompiler.TraceCompilerGlobals;
+import com.nokia.tracecompiler.TraceCompilerLogger;
+import com.nokia.tracecompiler.engine.TraceCompilerEngineErrorMessages;
+import com.nokia.tracecompiler.engine.TraceCompilerEngineEvents;
+import com.nokia.tracecompiler.engine.TraceCompilerEngineGlobals;
+import com.nokia.tracecompiler.model.TraceCompilerException;
+import com.nokia.tracecompiler.model.TraceModel;
+import com.nokia.tracecompiler.source.SourceConstants;
+import com.nokia.tracecompiler.source.SourceLocationBase;
+
+/**
+ * Implements TraceCompilerEvents to forward events to the event router plug-in
+ *
+ */
+public final class EventEngine implements TraceCompilerEngineEvents {
+
+ /**
+ * Info event type
+ */
+ public final static int INFO = 1; // CodForChk_Dis_Magic
+
+ /**
+ * Warning event type
+ */
+ public final static int WARNING = 2; // CodForChk_Dis_Magic
+
+ /**
+ * Error event type
+ */
+ public final static int ERROR = 3; // CodForChk_Dis_Magic
+
+ /**
+ * Critical assertion failure event type
+ */
+ public final static int ASSERT_CRITICAL = 4; // CodForChk_Dis_Magic
+
+ /**
+ * Non-critical assertion failure event type
+ */
+ public final static int ASSERT_NORMAL = 5; // CodForChk_Dis_Magic
+
+
+ /**
+ * indicates if an error happened for all files
+ */
+ private boolean globalProcessingError = false;
+
+
+
+ /**
+ * Constructor
+ *
+ * @param model
+ * the trace model
+ */
+ public EventEngine(TraceModel model) {
+ }
+
+ /**
+ * check if an error happened
+ *
+ * @return the error
+ */
+ public boolean hasErrorHappened() {
+ return globalProcessingError;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.TraceCompilerEvents#
+ * postError(com.nokia.tracecompiler.engine.TraceCompilerException)
+ */
+ public void postError(TraceCompilerException exception) {
+ String message = TraceCompilerEngineErrorMessages.getErrorMessage(exception);
+ if (message != null && message.length() > 0) {
+ postErrorMessage(message, exception.getErrorSource(), exception.isEventWantedToPost());
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.TraceCompilerEvents#postErrorMessage(java.lang.String, java.lang.Object, boolean)
+ */
+ public void postErrorMessage(String message, Object source, boolean postEvent) {
+
+ if (postEvent) {
+ postEvent(ERROR, message, source);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.TraceCompilerEvents#
+ * postWarningMessage(java.lang.String, java.lang.Object)
+ */
+ public void postWarningMessage(String message, Object source) {
+ postEvent(WARNING, message, source);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.TraceCompilerEvents#
+ * postInfoMessage(java.lang.String, java.lang.Object)
+ */
+ public void postInfoMessage(String message, Object source) {
+ postEvent(INFO, message, source);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.TraceCompilerEvents#
+ * postAssertionFailed(java.lang.String, java.lang.Object)
+ */
+ public void postAssertionFailed(String message, Object source) {
+ message = "Assertion failed. Reason: " //$NON-NLS-1$
+ + message;
+ postEvent(ASSERT_NORMAL, message, source);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.TraceCompilerEvents#
+ * postCriticalAssertionFailed(java.lang.String, java.lang.Object)
+ */
+ public void postCriticalAssertionFailed(String message, Object source) throws TraceCompilerException {
+ message = "Critical assertion failure, the project has been closed. Reason: " //$NON-NLS-1$
+ + message;
+ // Closes the trace project and shows an error message
+ TraceCompilerEngineGlobals.getTraceCompiler().closeProject();
+ postEvent(ASSERT_CRITICAL, message, source);
+ }
+
+
+ /**
+ * Print an event to console
+ * @param type
+ * event type
+ * @param message
+ * event message
+ * @param source
+ * event source
+ */
+ private void postEvent(int type, String message, Object source) {
+ switch (type) {
+ case INFO:
+ if (TraceCompilerGlobals.isVebose()) {
+ printEvent(type, message, source);
+
+ // This means that the component has been processed. Let's
+ // print one space to ensure that parse_mmp.pl will print
+ // out something.
+ } else if (message.contains(
+ "Dictionary File written")) { //$NON-NLS-1$
+ System.out.print(" "); //$NON-NLS-1$
+ } else if (!message
+ .contains("No files were written")) { //$NON-NLS-1$
+ // If we get "no files written" message, let's dismiss it ->
+ // parse_mmp.pl won't print out anything
+ printEvent(type, message, source);
+ }
+ break;
+ case WARNING:
+ case ERROR:
+ case ASSERT_NORMAL:
+ case ASSERT_CRITICAL:
+ printEvent(type, message, source);
+ break;
+ }
+ }
+
+ /**
+ * Prints event
+ * @param type error type
+ * @param message
+ * event message
+ * @param source
+ * event source
+ */
+ private void printEvent(int type, String message, Object source) {
+ if (message == null) {
+ message = Messages.getString("EventEngine.unknowError"); //$NON-NLS-1$
+ }
+ String fullMessage = ""; //$NON-NLS-1$
+
+
+ if (source instanceof SourceLocationBase) {
+ SourceLocationBase location = (SourceLocationBase) source;
+ fullMessage = location.getFileName() + Messages.getString("EventEngine.lineNumberPrefix") + location.getLineNumber() + SourceConstants.COLON + SourceConstants.SPACE; //$NON-NLS-1$
+ } else if (source instanceof String) {
+ message = (String) source;
+ }
+ fullMessage = fullMessage + message;
+
+ switch (type) {
+ case INFO:
+ TraceCompilerLogger.printInfo(fullMessage);
+ break;
+ case WARNING:
+ case ASSERT_NORMAL:
+ TraceCompilerLogger.printWarning(fullMessage);
+ break;
+ case ERROR:
+ case ASSERT_CRITICAL:
+ globalProcessingError = true;
+ TraceCompilerLogger.printError(fullMessage);
+ break;
+ default:
+ break;
+ }
+ }
+
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/event/Messages.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/event/Messages.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,57 @@
+/*
+* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Localized strings for engine package
+*
+*/
+package com.nokia.tracecompiler.engine.event;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class Messages {
+
+ /**
+ * Bundle name
+ */
+ private static final String BUNDLE_NAME = "com.nokia.tracecompiler.engine.event.messages"; //$NON-NLS-1$
+
+ /**
+ * Bundle
+ */
+ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
+ .getBundle(BUNDLE_NAME);
+
+ /**
+ * Prevents construction
+ */
+ private Messages() {
+ }
+
+ /**
+ * Gets localized string based on key
+ *
+ * @param key
+ * the resource key
+ * @return the localized resource
+ */
+ public static String getString(String key) {
+ try {
+ return RESOURCE_BUNDLE.getString(key);
+ } catch (MissingResourceException e) {
+ return '!' + key + '!';
+ }
+ }
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/event/messages.properties
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/event/messages.properties Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,2 @@
+EventEngine.lineNumberPrefix=, line
+EventEngine.unknowError=Unknown error happened, Please report to trace team.
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/event/package.html
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/event/package.html Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,3 @@
+
+TraceCompiler event router implementation
+
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/CheckFormattedTraceExists.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/CheckFormattedTraceExists.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,37 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Kernel #endif flag check
+*
+*/
+package com.nokia.tracecompiler.engine.header;
+
+/**
+ * Trace activation length check template element
+ *
+ */
+public final class CheckFormattedTraceExists extends TemplateCheckBase {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.header.TemplateCheckBase#check()
+ */
+ @Override
+ boolean check() {
+ return writer.getCurrentTraceFormatted().length() > 0;
+ }
+
+}
\ No newline at end of file
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/CheckIsBufferSizeDynamic.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/CheckIsBufferSizeDynamic.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,37 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Dynamic buffer size check
+*
+*/
+package com.nokia.tracecompiler.engine.header;
+
+/**
+ * Dynamic buffer size check
+ *
+ */
+public final class CheckIsBufferSizeDynamic extends TemplateCheckBase {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.header.TemplateCheckBase#check()
+ */
+ @Override
+ boolean check() {
+ return writer.isBufferSizeDynamic();
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/CheckIsKernelModeEndifNeeded.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/CheckIsKernelModeEndifNeeded.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,37 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Kernel #endif flag check
+*
+*/
+package com.nokia.tracecompiler.engine.header;
+
+/**
+ * __KERNEL_MODE__ #endif flag check
+ *
+ */
+public final class CheckIsKernelModeEndifNeeded extends TemplateCheckBase {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.header.TemplateCheckBase#check()
+ */
+ @Override
+ boolean check() {
+ return writer.isKernelModeEndifNeeded();
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/CheckIsKernelModeFlagNeeded.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/CheckIsKernelModeFlagNeeded.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,47 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Kernel #endif flag check
+*
+*/
+package com.nokia.tracecompiler.engine.header;
+
+import com.nokia.tracecompiler.source.SymbianConstants;
+
+/**
+ * Check if __KERNEL_MODE__ flags needs to be added
+ *
+ */
+public final class CheckIsKernelModeFlagNeeded extends TemplateCheckBase {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.header.TemplateCheckBase#check()
+ */
+ @Override
+ boolean check() {
+ boolean retval;
+ if (writer.getCurrentTraceFormatted().contains(
+ SymbianConstants.CONST_TDESC16_REF)) {
+ retval = true;
+ writer.setKernelModeEndifNeeded(true);
+ } else {
+ retval = false;
+ writer.setKernelModeEndifNeeded(false);
+ }
+ return retval;
+ }
+}
\ No newline at end of file
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/CheckIsTraceBufferBuilt.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/CheckIsTraceBufferBuilt.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,37 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Trace buffer flag check
+*
+*/
+package com.nokia.tracecompiler.engine.header;
+
+/**
+ * Trace buffer flag check
+ *
+ */
+public final class CheckIsTraceBufferBuilt extends TemplateCheckBase {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.header.TemplateCheckBase#check()
+ */
+ @Override
+ boolean check() {
+ return writer.isTraceBufferBuilt();
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/CheckIsTraceFormatDuplicate.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/CheckIsTraceFormatDuplicate.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,37 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Checks if a trace format exists
+*
+*/
+package com.nokia.tracecompiler.engine.header;
+
+/**
+ * Checks if a trace format exists
+ *
+ */
+public final class CheckIsTraceFormatDuplicate extends TemplateCheckBase {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.header.TemplateCheckBase#check()
+ */
+ @Override
+ boolean check() {
+ return writer.isTraceFormatDuplicate();
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/CheckParameterNeedsAlignment.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/CheckParameterNeedsAlignment.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,37 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Checks if parameter needs 32-bit alignment
+*
+*/
+package com.nokia.tracecompiler.engine.header;
+
+/**
+ * Checks if parameter needs 32-bit alignment
+ *
+ */
+final class CheckParameterNeedsAlignment extends TemplateCheckBase {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.header.TemplateCheckBase#check()
+ */
+ @Override
+ boolean check() {
+ return writer.isParameterAlignmentNeeded();
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/ComplexHeaderRule.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/ComplexHeaderRule.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,44 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Rule which specifies that a trace cannot be represented by the normal trace API macros
+*
+*/
+package com.nokia.tracecompiler.engine.header;
+
+import com.nokia.tracecompiler.model.TraceObjectRule;
+
+/**
+ * Rule which specifies that a trace cannot be represented by the normal trace
+ * API macros
+ *
+ */
+public interface ComplexHeaderRule extends TraceObjectRule {
+
+ /**
+ * Returns true if an ext-function needs to be written for this trace
+ *
+ * @return function flag
+ */
+ public boolean needsFunction();
+
+ /**
+ * Gets an extension to be added to the trace ID define
+ *
+ * @return the extension
+ */
+ public String getTraceIDDefineExtension();
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/HeaderConstants.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/HeaderConstants.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,42 @@
+/*
+* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Constants for header engine package
+*
+*/
+package com.nokia.tracecompiler.engine.header;
+
+/**
+ * Constants for header engine package
+ *
+ */
+interface HeaderConstants {
+
+ /**
+ * Number of parent paths to check when locating include directory
+ */
+ int INC_SEARCH_DEPTH = 3; // CodForChk_Dis_Magic
+
+ /**
+ * Trace header extension
+ */
+ String TRACE_HEADER_EXTENSION = "Traces.h"; //$NON-NLS-1$
+
+ /**
+ * Main trace header name
+ */
+ String TRACE_HEADER_NAME = "OstTraceDefinitions.h"; //$NON-NLS-1$
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/HeaderEngine.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/HeaderEngine.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,289 @@
+/*
+* Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Header engine manages the trace header file that is included into source code
+*
+*/
+package com.nokia.tracecompiler.engine.header;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import com.nokia.tracecompiler.engine.LocationListBase;
+import com.nokia.tracecompiler.engine.LocationProperties;
+import com.nokia.tracecompiler.engine.TraceCompilerEngineBase;
+import com.nokia.tracecompiler.engine.TraceCompilerEngineEvents;
+import com.nokia.tracecompiler.engine.TraceCompilerEngineGlobals;
+import com.nokia.tracecompiler.engine.TraceCompilerEngineErrorCodes.TraceCompilerErrorCode;
+import com.nokia.tracecompiler.engine.project.ProjectEngine;
+import com.nokia.tracecompiler.file.FileCompareOutputStream;
+import com.nokia.tracecompiler.model.Trace;
+import com.nokia.tracecompiler.model.TraceCompilerException;
+import com.nokia.tracecompiler.model.TraceGroup;
+import com.nokia.tracecompiler.model.TraceModel;
+import com.nokia.tracecompiler.plugin.TraceHeaderContribution;
+import com.nokia.tracecompiler.plugin.TraceHeaderContribution.TraceHeaderContributionType;
+import com.nokia.tracecompiler.project.ProjectUtils;
+import com.nokia.tracecompiler.project.TraceProjectAPI;
+import com.nokia.tracecompiler.source.SourceUtils;
+
+/**
+ * Header engine manages the trace header file that is included into source
+ * code. This implements the plug-in interface to get notifications about
+ * project file opening and closing
+ *
+ */
+public final class HeaderEngine extends TraceCompilerEngineBase {
+
+ /**
+ * Trace model
+ */
+ private TraceModel model;
+
+ /**
+ * Constructor
+ *
+ * @param model
+ * trace model
+ */
+ public HeaderEngine(TraceModel model) {
+ this.model = model;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.TraceCompilerEngine#projectOpened()
+ */
+ @Override
+ public void projectOpened() {
+ TraceHeader header = model.getExtension(TraceHeader.class);
+ if (header == null) {
+ String fileName = null;
+ try {
+ fileName = ProjectUtils.getLocationForFile(model,
+ ProjectEngine.traceFolderName,
+ HeaderConstants.TRACE_HEADER_NAME, false);
+ } catch (TraceCompilerException e) {
+ // Model should always be open when traceProjectOpened is called
+ }
+ if (fileName != null) {
+ header = new TraceHeader(fileName, false);
+ model.addExtension(header);
+ } else {
+ String msg = Messages
+ .getString("HeaderEngine.FailedToAttachHeader"); //$NON-NLS-1$
+ TraceCompilerEngineGlobals.getEvents().postErrorMessage(msg, null, true);
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engin.TraceCompilererEngine#projectClosing()
+ */
+ @Override
+ public void projectClosed() {
+ model.removeExtensions(TraceHeader.class);
+ }
+
+ /**
+ * Gets the name for the trace header file based on given source
+ *
+ * @param sourceFile
+ * the source file name
+ * @return the header file name
+ */
+ public String getHeaderFileName(String sourceFile) {
+ String retval = null;
+ if (model != null) {
+ // The header file name is the source file name with extension
+ // replaced by Traces.h
+ File f = new File(sourceFile);
+ retval = removeFileExtension(f.getName())
+ + HeaderConstants.TRACE_HEADER_EXTENSION;
+ }
+ return retval;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engi.TraceCompilerlerEngine#projectExporting()
+ */
+ @Override
+ public void exportProject() throws TraceCompilerException {
+ if (model.isValid() && model.hasTraces()) {
+ TraceHeader header = model.getExtension(TraceHeader.class);
+ if (header != null) {
+ // Headers for each source are written first
+ String path = header.getPath();
+ ArrayList fileNames = new ArrayList();
+ collectSourceFilesFromTraces(fileNames);
+ for (String fileName : fileNames) {
+ String target = path + File.separator + fileName;
+ writeHeaderFile(target);
+ }
+ // The main header is written after everything else succeeds
+ writeMainHeaderFile(header);
+ }
+ }
+ }
+
+ /**
+ * Collects the source file names from traces
+ *
+ * @param fileNames
+ * the file names
+ */
+ private void collectSourceFilesFromTraces(ArrayList fileNames) {
+ for (TraceGroup group : model) {
+ for (Trace trace : group) {
+ Iterator itr = trace
+ .getExtensions(LocationListBase.class);
+ while (itr.hasNext()) {
+ LocationListBase base = itr.next();
+ for (LocationProperties loc : base) {
+ String locFileName = loc.getFileName();
+ if (locFileName != null) {
+ addFileToList(fileNames, locFileName);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Adds a file to list if it does not exist
+ *
+ * @param fileNames
+ * the list
+ * @param locFileName
+ * the file
+ */
+ private void addFileToList(ArrayList fileNames, String locFileName) {
+ locFileName = removeFileExtension(locFileName);
+ if (!fileNames.contains(locFileName)) {
+ fileNames.add(locFileName);
+ }
+ }
+
+ /**
+ * Removes the file extension from file name
+ *
+ * @param fileName
+ * the file name
+ * @return name without extension
+ */
+ private String removeFileExtension(String fileName) {
+ int index = fileName.lastIndexOf('.');
+ int sep1 = fileName.lastIndexOf('/');
+ int sep2 = fileName.lastIndexOf('\\');
+ if (index > sep1 && index > sep2) {
+ fileName = fileName.substring(0, index);
+ }
+ return fileName;
+ }
+
+ /**
+ * Writes the header to given target
+ *
+ * @param target
+ * the target file
+ * @throws TraceCompilerException
+ * if writing fails
+ */
+ private void writeHeaderFile(String target) throws TraceCompilerException {
+ // The TraceHeader stored into the model is not used when writing
+ // headers, since a separate header is written for each source file
+ TraceHeader header = new TraceHeader(target, true);
+ try {
+ header.setOwner(model);
+ TraceHeaderWriter writer = new TraceHeaderWriter(header);
+ TraceCompilerEngineEvents events = TraceCompilerEngineGlobals.getEvents();
+ if (writer.write()) {
+ header.postFileWrittenEvent(header.getAbsolutePath());
+ } else {
+ String msg = Messages
+ .getString("HeaderEngine.TraceHeaderNotChangedPrefix"); //$NON-NLS-1$
+ events.postInfoMessage(msg + header.getAbsolutePath(), null);
+ }
+ } finally {
+ // The header owner must be reset to null, since that makes
+ // unregisters it from the model
+ header.setOwner(null);
+ }
+ }
+
+ /**
+ * Writes the main header file to given target
+ *
+ * @param header
+ * the header
+ * @throws TraceCompilerException
+ * if writing fails
+ */
+ private void writeMainHeaderFile(TraceHeader header)
+ throws TraceCompilerException {
+ // The TraceHeader stored into the model is not used when writing
+ // headers, since a separate header is written for each source file
+ TraceCompilerEngineEvents events = TraceCompilerEngineGlobals.getEvents();
+ String path = header.getAbsolutePath();
+ try {
+ if (writeMainHeader(path)) {
+ header.postFileWrittenEvent(path);
+ } else {
+ String msg = Messages
+ .getString("HeaderEngine.TraceHeaderNotChangedPrefix"); //$NON-NLS-1$
+ events.postInfoMessage(msg + path, null);
+ }
+ } catch (IOException e) {
+ throw new TraceCompilerException(
+ TraceCompilerErrorCode.CANNOT_WRITE_PROJECT_FILE, e);
+ }
+ }
+
+ /**
+ * Writes the main header to given target
+ *
+ * @param target
+ * the target
+ * @return true if written, false if the file already had the same content
+ * @throws IOException
+ * if writing fails
+ */
+ private boolean writeMainHeader(String target) throws IOException {
+ File f = new File(target);
+ FileCompareOutputStream stream = new FileCompareOutputStream(f);
+ String licence = TraceCompilerEngineGlobals.getDefaultLicence(true);
+ if (licence != null) {
+ stream.write(licence.getBytes());
+ }
+ stream.write(SourceUtils.createHeaderGuard(f.getName()).getBytes());
+ TraceProjectAPI api = model.getExtension(TraceProjectAPI.class);
+ if (api instanceof TraceHeaderContribution) {
+ String[] content = ((TraceHeaderContribution) api)
+ .getContribution(TraceHeaderContributionType.MAIN_HEADER_CONTENT);
+ if (content != null && content.length == 1) {
+ stream.write(content[0].getBytes());
+ }
+ }
+ return stream.writeFile();
+ }
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/HeaderTemplate.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/HeaderTemplate.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,443 @@
+/*
+* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Header file template definition
+*
+*/
+package com.nokia.tracecompiler.engine.header;
+
+import com.nokia.tracecompiler.engine.header.TraceHeaderWriter.HeaderTemplateElementType;
+import com.nokia.tracecompiler.plugin.TraceAPIFormatter.TraceFormatType;
+import com.nokia.tracecompiler.plugin.TraceHeaderContribution.TraceHeaderContributionType;
+import com.nokia.tracecompiler.source.SymbianConstants;
+
+/**
+ * Header file template definition
+ *
+ */
+interface HeaderTemplate {
+
+ /**
+ * Tag written to trace header
+ */
+ String HEADER_COMMENT_CREATED_BY = "// Created by TraceCompiler"; //$NON-NLS-1$
+
+ /**
+ * Empty template
+ */
+ Object[] EMPTY_TEMPLATE = {};
+
+ /**
+ * Sets line count to 1
+ */
+ Object SET_LINES_PACKED = new SetNewLineCount(1);
+
+ /**
+ * Sets line count to 2
+ */
+ Object SET_LINES_MIDDLE = new SetNewLineCount(2); // CodForChk_Dis_Magic
+
+ /**
+ * Sets line count to 3
+ */
+ Object SET_LINES_LOOSE = new SetNewLineCount(3); // CodForChk_Dis_Magic
+
+ /**
+ * Template for empty trace macros
+ */
+ Object[] EMPTY_TRACE_FUNCTION_EXISTS_TEMPLATE = {
+ HeaderTemplateElementType.NEW_LINE, "#define ", //$NON-NLS-1$
+ HeaderTemplateElementType.FORMATTED_TRACE };
+
+ /**
+ * Empty trace macro template switch. This formats the trace using
+ * TraceFormatType.EmptyPreprocessorDefinition and checks if the definition
+ * has already been written using CheckIsTraceFormatDuplicate switch
+ */
+ Object[] EMPTY_TRACE_FUNCTION_TEMPLATE = {
+ TraceFormatType.EMPTY_MACRO,
+ new TemplateChoice(CheckIsTraceFormatDuplicate.class,
+ EMPTY_TEMPLATE, EMPTY_TRACE_FUNCTION_EXISTS_TEMPLATE), };
+
+ /**
+ * Template for trace activation check
+ */
+ Object[] TRACE_FUNCTION_ACTIVATION_CHECK = {
+ "TBool retval = ", //$NON-NLS-1$
+ TraceFormatType.TRACE_ACTIVATION,
+ // Checks if the TraceActivation format exists
+ new TemplateChoice(CheckFormattedTraceExists.class, new Object[] {
+ HeaderTemplateElementType.FORMATTED_TRACE, ";", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE, "if ( retval )", //$NON-NLS-1$
+ HeaderTemplateElementType.OPEN_BRACE }, new Object[] {
+ "EFalse;", HeaderTemplateElementType.NEW_LINE }), //$NON-NLS-1$
+ };
+
+ /**
+ * Template if no activation check is needed
+ */
+ Object[] TRACE_FUNCTION_NO_ACTIVATION_CHECK = { "TBool retval;", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE };
+
+ /**
+ * Template for trace functions
+ */
+ Object[] TRACE_FUNCTION_EXISTS_TEMPLATE = {
+ SET_LINES_PACKED,
+ HeaderTemplateElementType.BUILD_TRACE_BUFFER_CHECK,
+ // If the trace contains TDesC16 parameter, __KERNEL_MODE__ flag is
+ // added to it
+ new TemplateChoice(CheckIsKernelModeFlagNeeded.class, new Object[] {
+ "#ifndef __KERNEL_MODE__", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE }, EMPTY_TEMPLATE),
+ "inline TBool ", //$NON-NLS-1$
+ HeaderTemplateElementType.FORMATTED_TRACE,
+ HeaderTemplateElementType.OPEN_BRACE,
+ // If the trace is buffered activation check is written
+ new TemplateChoice(CheckIsTraceBufferBuilt.class,
+ TRACE_FUNCTION_ACTIVATION_CHECK,
+ TRACE_FUNCTION_NO_ACTIVATION_CHECK),
+ HeaderTemplateElementType.TRACE_FUNCTION_BODY, // Parameters + API
+ HeaderTemplateElementType.CLOSE_EXTRA_BRACES,
+ "return retval;", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE,
+ HeaderTemplateElementType.CLOSE_BRACE,
+ // The __KERNEL_MODE__ #ifdef added above needs to be closed
+ new TemplateChoice(
+ CheckIsKernelModeEndifNeeded.class,
+ new Object[] { "#endif", HeaderTemplateElementType.NEW_LINE }, //$NON-NLS-1$
+ EMPTY_TEMPLATE), SET_LINES_LOOSE,
+ HeaderTemplateElementType.NEW_LINE };
+
+ /**
+ * Trace function template switch. This formats the trace using
+ * TraceFormatType.Header and checks if the definition has already been
+ * written using TRACE_FORMAT_EXISTS_TEMPLATE_INDEX switch
+ */
+ Object[] TRACE_FUNCTION_TEMPLATE = {
+ TraceFormatType.HEADER,
+ new TemplateChoice(CheckIsTraceFormatDuplicate.class,
+ EMPTY_TEMPLATE, TRACE_FUNCTION_EXISTS_TEMPLATE) };
+
+ /**
+ * Template for trace ID's
+ */
+ Object[] TRACE_ID_TEMPLATE = {
+ "#define ", //$NON-NLS-1$
+ HeaderTemplateElementType.TRACE_NAME,
+ " 0x", //$NON-NLS-1$
+ HeaderTemplateElementType.TRACE_ID_HEX,
+ HeaderTemplateElementType.NEW_LINE };
+
+ /**
+ * Main header template
+ */
+ Object[] HEADER_TEMPLATE = {
+ SET_LINES_PACKED,
+ HeaderTemplateElementType.LICENCE_TEXT,
+ HeaderTemplateElementType.NEW_LINE,
+ HEADER_COMMENT_CREATED_BY, " ", //$NON-NLS-1$
+ HeaderTemplateElementType.TRACE_COMPILER_VERSION,
+ HeaderTemplateElementType.NEW_LINE,
+ "// DO NOT EDIT, CHANGES WILL BE LOST", //$NON-NLS-1$
+ SET_LINES_MIDDLE,
+ HeaderTemplateElementType.NEW_LINE,
+ HeaderTemplateElementType.HEADER_GUARD,
+ HeaderTemplateElementType.NEW_LINE,
+ SET_LINES_PACKED,
+ TraceHeaderContributionType.GLOBAL_DEFINES,
+ SET_LINES_MIDDLE,
+ HeaderTemplateElementType.NEW_LINE,
+ SET_LINES_PACKED,
+ TraceHeaderContributionType.GLOBAL_INCLUDES,
+ SET_LINES_MIDDLE,
+ HeaderTemplateElementType.NEW_LINE,
+ SET_LINES_PACKED,
+ new TemplateIterator(IteratorTraces.class, TRACE_ID_TEMPLATE),
+ SET_LINES_LOOSE,
+ HeaderTemplateElementType.NEW_LINE,
+ // Trace functions
+ new TemplateIterator(IteratorComplexTraces.class,
+ TRACE_FUNCTION_TEMPLATE),
+ // End of header guard
+ SET_LINES_MIDDLE, "#endif", HeaderTemplateElementType.NEW_LINE, //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE, "// End of file", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE };
+
+ /**
+ * Template for parameter with fixed size
+ */
+ Object[] FIXED_PARAMETER_TEMPLATE = { "*( ( ", //$NON-NLS-1$
+ HeaderTemplateElementType.PARAMETER_TYPE, "* )ptr ) = ", //$NON-NLS-1$
+ HeaderTemplateElementType.PARAMETER_NAME, ";", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE, "ptr += sizeof ( ", //$NON-NLS-1$
+ HeaderTemplateElementType.PARAMETER_TYPE, " );", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE };
+
+ /**
+ * Template for parameter with fixed size and length check
+ */
+ Object[] FIXED_PARAMETER_TEMPLATE_WITH_LENGTH_CHECK = {
+ "// Check that there are enough space to next parameter", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE,
+ "if ((length + sizeof ( ", //$NON-NLS-1$
+ HeaderTemplateElementType.PARAMETER_TYPE,
+ " )) <= KOstMaxDataLength)", //$NON-NLS-1$
+ HeaderTemplateElementType.OPEN_BRACE,
+ FIXED_PARAMETER_TEMPLATE,
+ "length += sizeof ( ", //$NON-NLS-1$
+ HeaderTemplateElementType.PARAMETER_TYPE,
+ " );", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE,
+ HeaderTemplateElementType.CLOSE_BRACE};
+
+ /**
+ * Template for writing 32-bit alignment for parameters
+ */
+ Object[] DYNAMIC_PARAMETER_ALIGNMENT_TEMPLATE = {
+ "// Fillers are written to get 32-bit alignment", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE,
+ "while ( length", //$NON-NLS-1$
+ HeaderTemplateElementType.PARAMETER_INDEX,
+ "++ < lengthAligned", //$NON-NLS-1$
+ HeaderTemplateElementType.PARAMETER_INDEX,
+ " )", //$NON-NLS-1$
+ HeaderTemplateElementType.OPEN_BRACE,
+ "*ptr++ = 0;", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE,
+ HeaderTemplateElementType.CLOSE_BRACE };
+
+ /**
+ * Template for parameter with dynamic size
+ */
+ Object[] DYNAMIC_PARAMETER_TEMPLATE = {
+ "if (length", //$NON-NLS-1$
+ HeaderTemplateElementType.PARAMETER_INDEX,
+ " > 0)", //$NON-NLS-1$
+ HeaderTemplateElementType.OPEN_BRACE,
+ "// Number of elements is written before data", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE,
+ "// In case of Unicode string, number of elements is half of length", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE,
+ "*( ( TUint32* )ptr ) = length", //$NON-NLS-1$
+ HeaderTemplateElementType.PARAMETER_INDEX,
+ " / (", //$NON-NLS-1$
+ HeaderTemplateElementType.PARAMETER_NAME,
+ ".Size() / ", //$NON-NLS-1$
+ HeaderTemplateElementType.PARAMETER_NAME,
+ ".Length());", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE,
+ "ptr += sizeof ( TUint32 );", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE,
+ "memcpy( ptr, ", //$NON-NLS-1$
+ HeaderTemplateElementType.PARAMETER_NAME,
+ ".Ptr(), length", //$NON-NLS-1$
+ HeaderTemplateElementType.PARAMETER_INDEX,
+ " );", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE,
+ "ptr += length", //$NON-NLS-1$
+ HeaderTemplateElementType.PARAMETER_INDEX,
+ ";", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE,
+ new TemplateChoice(CheckParameterNeedsAlignment.class,
+ DYNAMIC_PARAMETER_ALIGNMENT_TEMPLATE, EMPTY_TEMPLATE),
+ HeaderTemplateElementType.NEW_LINE,
+ "length += sizeof ( TUint32 ) + lengthAligned", //$NON-NLS-1$
+ HeaderTemplateElementType.PARAMETER_INDEX,
+ ";", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE,
+ HeaderTemplateElementType.CLOSE_BRACE,
+ "else if (length + sizeof ( TUint32 ) <= KOstMaxDataLength)", //$NON-NLS-1$
+ HeaderTemplateElementType.OPEN_BRACE,
+ HeaderTemplateElementType.NEW_LINE,
+ "*( ( TUint32* )ptr ) = 0;", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE,
+ "ptr += sizeof ( TUint32 );", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE,
+ "length += sizeof ( TUint32 );", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE,
+ HeaderTemplateElementType.CLOSE_BRACE};
+
+ /**
+ * Template to allocate the buffer for parameters if buffer size is fixed
+ */
+ Object[] FIXED_BUFFER_ALLOCATION_TEMPLATE = { "TUint8 data[ ", //$NON-NLS-1$
+ HeaderTemplateElementType.FIXED_BUFFER_SIZE, " ];", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE, "TUint8* ptr = data;", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE};
+
+ /**
+ * Template to allocate the buffer for parameters if buffer size is dynamic
+ */
+ Object[] DYNAMIC_BUFFER_ALLOCATION_TEMPLATE = {
+ // KOstMaxDataLength is defined in opensystemtrace.h
+ "TUint8 data[ KOstMaxDataLength ];", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE, "TUint8* ptr = data;", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE, "// Set length to zero and calculate it againg", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE, "// when adding parameters", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE, "length = 0;", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE };
+
+ /**
+ * Template to allocate buffer for trace data
+ */
+ Object[] BUFFER_ALLOCATION_TEMPLATE = { new TemplateChoice(
+ CheckIsBufferSizeDynamic.class, DYNAMIC_BUFFER_ALLOCATION_TEMPLATE,
+ FIXED_BUFFER_ALLOCATION_TEMPLATE) };
+
+ /**
+ * Template to length variable definition
+ */
+ Object[] LENGTH_VARIABLE_DEFINITION_TEMPLATE = {
+ "TInt length = 0;", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE };
+
+ /**
+ * Beging template to length variable increase
+ */
+ Object[] LENGTH_VARIABLE_INCREASE_TEMPLATE_BEGIN = {
+ "// Increase length because of fixed size parameters", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE,
+ "length += "}; //$NON-NLS-1$
+
+ /**
+ * End template to length variable increase
+ */
+ Object[] LENGTH_VARIABLE_INCREASE_TEMPLATE_END = {
+ ";", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE };
+
+ /**
+ * Template to calculate the length for a dynamic parameter
+ */
+ Object[] DYNAMIC_PARAMETER_LENGTH_TEMPLATE = {
+ "// Check that parameter lenght is not too long", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE,
+ "TInt length", //$NON-NLS-1$
+ HeaderTemplateElementType.PARAMETER_INDEX,
+ " = ", //$NON-NLS-1$
+ SymbianConstants.PARAMETER_DECLARATION_PREFIX,
+ HeaderTemplateElementType.PARAMETER_INDEX, ".Size();", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE,
+ "if ((length + length", //$NON-NLS-1$
+ HeaderTemplateElementType.PARAMETER_INDEX,
+ " + sizeof ( TUint32 )) > KOstMaxDataLength)", //$NON-NLS-1$
+ HeaderTemplateElementType.OPEN_BRACE,
+ "length", //$NON-NLS-1$
+ HeaderTemplateElementType.PARAMETER_INDEX,
+ " = KOstMaxDataLength - (length + sizeof ( TUint32 ));", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE,
+ HeaderTemplateElementType.CLOSE_BRACE,
+ HeaderTemplateElementType.NEW_LINE,
+ "TInt lengthAligned", //$NON-NLS-1$
+ HeaderTemplateElementType.PARAMETER_INDEX,
+ " = ( length", //$NON-NLS-1$
+ HeaderTemplateElementType.PARAMETER_INDEX,
+ " + 3 ) & ~3;", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE,
+ "if (lengthAligned", //$NON-NLS-1$
+ HeaderTemplateElementType.PARAMETER_INDEX,
+ " > 0)", //$NON-NLS-1$
+ HeaderTemplateElementType.OPEN_BRACE,
+ "length = length + sizeof ( TUint32 ) + lengthAligned", //$NON-NLS-1$
+ HeaderTemplateElementType.PARAMETER_INDEX,
+ ";", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE,
+ HeaderTemplateElementType.CLOSE_BRACE,
+ HeaderTemplateElementType.NEW_LINE };
+
+ /**
+ * Template for the optimized single dynamic parameter case, where buffer is
+ * not needed
+ */
+ Object[] SINGLE_DYNAMIC_PARAMETER_TEMPLATE = {
+ "TInt size = ", //$NON-NLS-1$
+ SymbianConstants.PARAMETER_DECLARATION_PREFIX, "1.Size();", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE,
+ "// BTrace assumes that parameter size is atleast 4 bytes", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE,
+ "if (size % 4 == 0)", //$NON-NLS-1$
+ HeaderTemplateElementType.OPEN_BRACE,
+ "TUint8* ptr = ( TUint8* )aParam1.Ptr();", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE,
+ "// Data is written directly and length is determined from trace message length", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE,
+ "retval = OstSendNBytes( EXTRACT_GROUP_ID(aTraceID), EOstTrace, KOstTraceComponentID, aTraceID, ptr, size );", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE,
+ HeaderTemplateElementType.CLOSE_BRACE,
+ HeaderTemplateElementType.NEW_LINE,
+ "else", //$NON-NLS-1$
+ HeaderTemplateElementType.OPEN_BRACE,
+ "TUint8 data[ KOstMaxDataLength ];", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE,
+ "TUint8* ptr = data;", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE,
+ "if (size > KOstMaxDataLength)", //$NON-NLS-1$
+ HeaderTemplateElementType.OPEN_BRACE,
+ "size = KOstMaxDataLength;", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE,
+ HeaderTemplateElementType.CLOSE_BRACE,
+ HeaderTemplateElementType.NEW_LINE,
+ "TInt sizeAligned = ( size + 3 ) & ~3;", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE,
+ "memcpy( ptr, ", //$NON-NLS-1$
+ SymbianConstants.PARAMETER_DECLARATION_PREFIX, "1.Ptr(), size );", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE,
+ "ptr += size;", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE,
+ "// Fillers are written to get 32-bit alignment", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE,
+ "while ( size++ < sizeAligned )", //$NON-NLS-1$
+ HeaderTemplateElementType.OPEN_BRACE,
+ "*ptr++ = 0;", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE,
+ HeaderTemplateElementType.CLOSE_BRACE,
+ HeaderTemplateElementType.NEW_LINE,
+ "ptr -= sizeAligned;", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE,
+ "size = sizeAligned;", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE,
+ "// Data is written directly and length is determined from trace message length", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE,
+ "retval = OstSendNBytes( EXTRACT_GROUP_ID(aTraceID), EOstTrace, KOstTraceComponentID, aTraceID, ptr, size );", //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE,
+ HeaderTemplateElementType.CLOSE_BRACE,
+ HeaderTemplateElementType.NEW_LINE};
+
+ /**
+ * Template for buffered parameters
+ */
+ Object[] BUFFERED_PARAMETERS_TEMPLATE = { HeaderTemplateElementType.TRACE_FUNCTION_PARAMETERS };
+
+ /**
+ * Template when the trace buffer needs to be allocated
+ */
+ Object[] BUILD_TRACE_BUFFER_TEMPLATE = {
+ new TemplateIterator(IteratorParameters.class,
+ BUFFERED_PARAMETERS_TEMPLATE),
+ "ptr -= ", //$NON-NLS-1$
+ new TemplateChoice(CheckIsBufferSizeDynamic.class,
+ new Object[] { "length;" }, new Object[] { //$NON-NLS-1$
+ HeaderTemplateElementType.FIXED_BUFFER_SIZE, ";" }), //$NON-NLS-1$
+ HeaderTemplateElementType.NEW_LINE };
+
+ /**
+ * Template for trace parameters.
+ */
+ Object[] PARAMETERS_TEMPLATE = { new TemplateChoice(
+ CheckIsTraceBufferBuilt.class, BUILD_TRACE_BUFFER_TEMPLATE,
+ SINGLE_DYNAMIC_PARAMETER_TEMPLATE) };
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/IteratorComplexTraces.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/IteratorComplexTraces.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,55 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Iterator for complex traces
+*
+*/
+package com.nokia.tracecompiler.engine.header;
+
+import java.io.IOException;
+
+import com.nokia.tracecompiler.model.Trace;
+import com.nokia.tracecompiler.model.TraceGroup;
+import com.nokia.tracecompiler.model.TraceModel;
+
+/**
+ * Iterator for complex traces
+ *
+ */
+public final class IteratorComplexTraces extends TemplateIteratorEntry {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.header.TemplateIteratorEntry#
+ * iterate(java.lang.Object[])
+ */
+ @Override
+ void iterate(Object[] template) throws IOException {
+ TraceModel model = writer.getHeader().getOwner().getModel();
+ for (TraceGroup group : model) {
+ for (Trace trace : group) {
+ ComplexHeaderRule rule = trace
+ .getExtension(ComplexHeaderRule.class);
+ if (rule != null && rule.needsFunction()) {
+ if (writer.startTrace(trace)) {
+ writer.writeTemplate(template);
+ }
+ }
+ }
+ }
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/IteratorParameters.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/IteratorParameters.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,46 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Parameter iterator
+*
+*/
+package com.nokia.tracecompiler.engine.header;
+
+import java.io.IOException;
+import java.util.Iterator;
+
+import com.nokia.tracecompiler.model.TraceParameter;
+
+/**
+ * Parameter iterator
+ *
+ */
+public final class IteratorParameters extends TemplateIteratorEntry {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.header.TemplateIteratorEntry#iterate()
+ */
+ @Override
+ public void iterate(Object[] template) throws IOException {
+ Iterator itr = writer.getCurrentTrace().getParameters();
+ while (itr.hasNext()) {
+ writer.startParameter(itr.next());
+ writer.writeTemplate(template);
+ }
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/IteratorTraces.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/IteratorTraces.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,51 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Iterator for all traces
+*
+*/
+package com.nokia.tracecompiler.engine.header;
+
+import java.io.IOException;
+
+import com.nokia.tracecompiler.model.Trace;
+import com.nokia.tracecompiler.model.TraceGroup;
+import com.nokia.tracecompiler.model.TraceModel;
+
+/**
+ * Iterator for all traces
+ *
+ */
+public final class IteratorTraces extends TemplateIteratorEntry {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.header.TemplateIteratorEntry#
+ * iterate(java.lang.Object[])
+ */
+ @Override
+ void iterate(Object[] template) throws IOException {
+ TraceModel model = writer.getHeader().getOwner().getModel();
+ for (TraceGroup group : model) {
+ for (Trace trace : group) {
+ if (writer.startTrace(trace)) {
+ writer.writeTemplate(template);
+ }
+ }
+ }
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/Messages.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/Messages.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,63 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Localization for header package
+*
+*/
+package com.nokia.tracecompiler.engine.header;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+/**
+ * Localization for header package
+ *
+ */
+class Messages {
+
+ /**
+ * Bundle name
+ */
+ private static final String BUNDLE_NAME = "com.nokia.tracecompiler.engine.header.messages"; //$NON-NLS-1$
+
+ /**
+ * Bundle
+ */
+ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
+ .getBundle(BUNDLE_NAME);
+
+ /**
+ * Prevents construction
+ */
+ private Messages() {
+ }
+
+ /**
+ * Gets localized string based on key
+ *
+ * @param key
+ * the resource key
+ * @return the localized resource
+ */
+ public static String getString(String key) {
+ String value;
+ try {
+ value = RESOURCE_BUNDLE.getString(key);
+ } catch (MissingResourceException e) {
+ value = '!' + key + '!';
+ }
+ return value;
+ }
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/SetNewLineCount.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/SetNewLineCount.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,51 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Changes the new line count
+*
+*/
+package com.nokia.tracecompiler.engine.header;
+
+/**
+ * Changes the new line count
+ *
+ */
+public final class SetNewLineCount {
+
+ /**
+ * Line feed count
+ */
+ private int count;
+
+ /**
+ * Constructor
+ *
+ * @param count
+ * the line feed count
+ */
+ SetNewLineCount(int count) {
+ this.count = count;
+ }
+
+ /**
+ * Gets the count
+ *
+ * @return the count
+ */
+ final int getLineCount() {
+ return count;
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/TemplateCheckBase.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/TemplateCheckBase.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,49 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Template iterator
+*
+*/
+package com.nokia.tracecompiler.engine.header;
+
+/**
+ * Check function for TemplateChoice
+ *
+ */
+abstract class TemplateCheckBase {
+
+ /**
+ * Header writer
+ */
+ protected TraceHeaderWriter writer;
+
+ /**
+ * Sets the writer
+ *
+ * @param writer
+ * the writer to set
+ */
+ final void setWriter(TraceHeaderWriter writer) {
+ this.writer = writer;
+ }
+
+ /**
+ * Runs the check
+ *
+ * @return the result
+ */
+ abstract boolean check();
+
+}
\ No newline at end of file
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/TemplateChoice.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/TemplateChoice.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,86 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Template iterator
+*
+*/
+package com.nokia.tracecompiler.engine.header;
+
+/**
+ * If-check in template
+ *
+ */
+class TemplateChoice {
+
+ /**
+ * Templates to be used if check is true
+ */
+ private Object[] templateTrue;
+
+ /**
+ * Templates to be used if check is false
+ */
+ private Object[] templateFalse;
+
+ /**
+ * Choice class
+ */
+ private Class extends TemplateCheckBase> choiceClass;
+
+ /**
+ * Constructors
+ *
+ * @param choiceClass
+ * the class which does the check
+ * @param templateTrue
+ * the template to be used if check is true
+ * @param templateFalse
+ * the template to be used if check is false
+ */
+ TemplateChoice(Class extends TemplateCheckBase> choiceClass,
+ Object[] templateTrue, Object[] templateFalse) {
+ this.choiceClass = choiceClass;
+ this.templateTrue = templateTrue;
+ this.templateFalse = templateFalse;
+ }
+
+ /**
+ * Gets the choice class
+ *
+ * @return the class
+ */
+ Class extends TemplateCheckBase> getChoiceClass() {
+ return choiceClass;
+ }
+
+ /**
+ * Gets the template if choice returns true
+ *
+ * @return the template
+ */
+ Object[] getTrueTemplate() {
+ return templateTrue;
+ }
+
+ /**
+ * Gets the template if choice returns false
+ *
+ * @return the template
+ */
+ Object[] getFalseTemplate() {
+ return templateFalse;
+ }
+
+}
\ No newline at end of file
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/TemplateIterator.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/TemplateIterator.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,69 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Template iterator
+*
+*/
+package com.nokia.tracecompiler.engine.header;
+
+/**
+ * Template iterator
+ *
+ */
+final class TemplateIterator {
+
+ /**
+ * Iterator class
+ */
+ private Class extends TemplateIteratorEntry> iteratorClass;
+
+ /**
+ * Template to be run by the iterator
+ */
+ private Object[] template;
+
+ /**
+ * Constructor
+ *
+ * @param iteratorClass
+ * the iterator class
+ * @param template
+ * the template
+ */
+ TemplateIterator(Class extends TemplateIteratorEntry> iteratorClass,
+ Object[] template) {
+ this.iteratorClass = iteratorClass;
+ this.template = template;
+ }
+
+ /**
+ * Gets the iterator class
+ *
+ * @return the class
+ */
+ final Class extends TemplateIteratorEntry> getIteratorClass() {
+ return iteratorClass;
+ }
+
+ /**
+ * Gets the template
+ *
+ * @return the template
+ */
+ final Object[] getTemplate() {
+ return template;
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/TemplateIteratorEntry.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/TemplateIteratorEntry.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,54 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Iterator base class
+*
+*/
+package com.nokia.tracecompiler.engine.header;
+
+import java.io.IOException;
+
+/**
+ * Iterator base class
+ *
+ */
+abstract class TemplateIteratorEntry {
+
+ /**
+ * Header writer
+ */
+ protected TraceHeaderWriter writer;
+
+ /**
+ * Sets the writer
+ *
+ * @param writer
+ * the writer to set
+ */
+ final void setWriter(TraceHeaderWriter writer) {
+ this.writer = writer;
+ }
+
+ /**
+ * Runs the iterator on given template
+ *
+ * @param template
+ * the template
+ * @throws IOException
+ * if operation fails
+ */
+ abstract void iterate(Object[] template) throws IOException;
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/TraceHeader.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/TraceHeader.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,73 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Representation of a header file that gets included into sources
+*
+*/
+package com.nokia.tracecompiler.engine.header;
+
+import com.nokia.tracecompiler.project.TraceProjectFile;
+
+/**
+ * Representation of a header file that gets included into sources when traces
+ * are added.
+ *
+ */
+final class TraceHeader extends TraceProjectFile {
+
+ /**
+ * Title shown in UI
+ */
+ private static final String TITLE = Messages.getString("TraceHeader.Title"); //$NON-NLS-1$
+
+ /**
+ * Constructor
+ *
+ * @param target
+ * target path
+ * @param hasModelName
+ * true if model name should be used with the file
+ */
+ TraceHeader(String target, boolean hasModelName) {
+ super(target, hasModelName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.project.TraceProjectFile#getFileExtension()
+ */
+ @Override
+ protected String getFileExtension() {
+ String retval;
+ if (hasModelName) {
+ retval = HeaderConstants.TRACE_HEADER_EXTENSION;
+ } else {
+ retval = ""; //$NON-NLS-1$
+ }
+ return retval;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.project.TraceProjectFile#getTitle()
+ */
+ @Override
+ public String getTitle() {
+ return TITLE;
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/TraceHeaderWriter.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/TraceHeaderWriter.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,1401 @@
+/*
+ * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ *
+ * Description:
+ *
+ * Writes the TraceHeader to a file
+ *
+ */
+package com.nokia.tracecompiler.engine.header;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import com.nokia.tracecompiler.TraceCompilerLogger;
+import com.nokia.tracecompiler.engine.LocationListBase;
+import com.nokia.tracecompiler.engine.LocationProperties;
+import com.nokia.tracecompiler.engine.TraceCompilerEngineGlobals;
+import com.nokia.tracecompiler.engine.TraceLocation;
+import com.nokia.tracecompiler.engine.TraceCompilerEngineErrorCodes.TraceCompilerErrorCode;
+import com.nokia.tracecompiler.engine.source.SourceFormatter;
+import com.nokia.tracecompiler.engine.source.TraceFormattingRule;
+import com.nokia.tracecompiler.engine.source.TraceParameterFormattingRule;
+import com.nokia.tracecompiler.file.FileCompareOutputStream;
+import com.nokia.tracecompiler.file.FileUtils;
+import com.nokia.tracecompiler.model.Trace;
+import com.nokia.tracecompiler.model.TraceCompilerException;
+import com.nokia.tracecompiler.model.TraceGroup;
+import com.nokia.tracecompiler.model.TraceModel;
+import com.nokia.tracecompiler.model.TraceParameter;
+import com.nokia.tracecompiler.plugin.TraceFormatConstants;
+import com.nokia.tracecompiler.plugin.TraceHeaderContribution;
+import com.nokia.tracecompiler.plugin.TraceAPIFormatter.TraceFormatType;
+import com.nokia.tracecompiler.plugin.TraceHeaderContribution.TraceHeaderContributionType;
+import com.nokia.tracecompiler.rules.FillerParameterRule;
+import com.nokia.tracecompiler.source.SourceConstants;
+import com.nokia.tracecompiler.source.SourceExcludedArea;
+import com.nokia.tracecompiler.source.SourceParser;
+import com.nokia.tracecompiler.source.SourceUtils;
+import com.nokia.tracecompiler.source.SymbianConstants;
+import com.nokia.tracecompiler.utils.TraceCompilerVersion;
+
+/**
+ * Writes the TraceHeader to a file
+ *
+ */
+final class TraceHeaderWriter {
+
+ /**
+ * return type text of a generated OstTraceGenx function.
+ */
+ private static final String INLINE_TBOOL = "inline TBool";
+
+ /**
+ * open bracket in a type cast
+ */
+ private static final String BEGINCAST = "OBR"; //$NON-NLS-1$
+
+ /**
+ * closing bracket in a type cast
+ */
+ private static final String ENDCAST = "CBR"; //$NON-NLS-1$
+
+ /**
+ * REF replaces & in a function guard
+ */
+ private static final String REF = "REF"; //$NON-NLS-1$
+
+ /**
+ * & character
+ */
+ private static final String AMPERSANT = "&"; //$NON-NLS-1$
+
+ /**
+ * closing bracket
+ */
+ private static final String CLOSING_BRACKET = ")"; //$NON-NLS-1$
+
+ /**
+ * open bracket
+ */
+ private static final String OPEN_BRACKET = "("; //$NON-NLS-1$
+
+ /**
+ * TUint32 definition
+ */
+ private static final String TUINT32_DEF = "TUint32 "; //$NON-NLS-1$
+
+ /**
+ * TInt32 definition
+ */
+ private static final String TINT32_DEF = "TInt32 "; //$NON-NLS-1$
+
+ /**
+ * TUint definition
+ */
+ private static final String TUINT_DEF = "TUint "; //$NON-NLS-1$
+
+ /**
+ * TInt definition
+ */
+ private static final String TINT_DEF = "TInt "; //$NON-NLS-1$
+
+ /**
+ * Length variable defined flag
+ */
+ private boolean lenghtVariableDefined = false;
+
+
+ /**
+ * List of dynamic elements that can be used from the templates
+ *
+ */
+ enum HeaderTemplateElementType {
+
+ /**
+ * Licence text
+ */
+ LICENCE_TEXT,
+
+ /**
+ * TraceCompiler version number
+ */
+ TRACE_COMPILER_VERSION,
+
+ /**
+ * Header guard based on file name
+ */
+ HEADER_GUARD,
+
+ /**
+ * Opening brace
+ */
+ OPEN_BRACE,
+
+ /**
+ * Closing brace
+ */
+ CLOSE_BRACE,
+
+ /**
+ * New line and indent based on open brace count
+ */
+ NEW_LINE,
+
+ /**
+ * Writes currentTraceFormatted
+ */
+ FORMATTED_TRACE,
+
+ /**
+ * Adds all closing braces except the one that closes the function
+ */
+ CLOSE_EXTRA_BRACES,
+
+ /**
+ * Type of current parameter
+ */
+ PARAMETER_TYPE,
+
+ /**
+ * Name of current parameter
+ */
+ PARAMETER_NAME,
+
+ /**
+ * Name of current trace
+ */
+ TRACE_NAME,
+
+ /**
+ * ID of current trace
+ */
+ TRACE_ID_HEX,
+
+ /**
+ * Calls a function to add the trace buffer initialization code
+ */
+ BUILD_TRACE_BUFFER_CHECK,
+
+ /**
+ * Calls a function to add the function body
+ */
+ TRACE_FUNCTION_BODY,
+
+ /**
+ * Calls a function to add function parameters
+ */
+ TRACE_FUNCTION_PARAMETERS,
+
+ /**
+ * Writes the fixedBufferSize member variable
+ */
+ FIXED_BUFFER_SIZE,
+
+ /**
+ * Writes the dynamicBufferSize member variable
+ */
+ DYNAMIC_BUFFER_SIZE,
+
+ /**
+ * Index of the parameter being processed
+ */
+ PARAMETER_INDEX
+ }
+
+ /**
+ * Group ID shift bits
+ */
+ private static final int GROUP_SHIFT = 16; // CodForChk_Dis_Magic
+
+ /**
+ * Number of bytes in parameter
+ */
+ private static final int BYTES_IN_PARAMETER = 4; // CodForChk_Dis_Magic
+
+ /**
+ * Indent
+ */
+ private static final String INDENT = " "; //$NON-NLS-1$
+
+ /**
+ * The header file to be updated
+ */
+ private TraceHeader header;
+
+ /**
+ * Output stream for the header
+ */
+ private OutputStream headerOutput;
+
+ /**
+ * Temporary flag that specifies if a trace requires a trace buffer or it
+ * can be represented by the default trace macros
+ */
+ private boolean buildTraceBuffer;
+
+ /**
+ * Temporary variable for fixed size
+ */
+ private int fixedBufferSize;
+
+ /**
+ * Dynamic size flag
+ */
+ private boolean dynamicBufferSizeFlag;
+
+ /**
+ * Flag which is set it trace needs #endif for __KERNEL_MODE__
+ */
+ private boolean needsKernelEndif;
+
+ /**
+ * Used via HeaderTemplateElementType.FORMATTED_TRACE
+ */
+ private String currentTraceFormatted;
+
+ /**
+ * Type of current parameter
+ */
+ private String currentParameterType;
+
+ /**
+ * Name of current parameter
+ */
+ private String currentParameterName;
+
+ /**
+ * Index of current parameter
+ */
+ private int currentParameterIndex;
+
+ /**
+ * Number of opened brackets
+ */
+ private int openBraceCount;
+
+ /**
+ * Trace being processed
+ */
+ private Trace currentTrace;
+
+ /**
+ * Parameter being processed
+ */
+ private TraceParameter currentParameter;
+
+ /**
+ * List of trace functions already in the header
+ */
+ private ArrayList traceDeclarations = new ArrayList();
+
+ /**
+ * Number of sequential new lines
+ */
+ private int newLineCount;
+
+ /**
+ * Number of allowed sequential new lines
+ */
+ private int maxNewLines;
+
+ /**
+ * Indicates that writing a function to the header file is going
+ */
+ private boolean firstOpenBraceFound;
+
+ /**
+ * boolean indication that we are buffering a function text
+ */
+ private boolean bufferingFunction;
+
+ /**
+ * While writing a function to the header file, it's gathered to this
+ * member. The member is then checked if the function parameters contain
+ * TInt or TUint values. If so, the function is replicated so that TInt is
+ * replaced by TInt32 and TUint with TUint32.
+ */
+ private StringBuilder functionText = new StringBuilder();
+
+ /**
+ * Number of brackets seen when writing a function. When it gets to 0, the
+ * function in previousFunction variable is complete and can be written.
+ */
+ private int numberOfBrackets;
+
+ /**
+ * string to hold the function guard
+ */
+ private String ostTraceGenxFunGuard;
+
+ /**
+ * Creates a new header writer
+ *
+ * @param header
+ * the header to be written
+ */
+ TraceHeaderWriter(TraceHeader header) {
+ this.header = header;
+ }
+
+ /**
+ * Writes the header
+ *
+ * @return true if header was written, false if it matched the existing
+ * header
+ * @throws TraceCompilerException
+ * if writing fails
+ */
+ boolean write() throws TraceCompilerException {
+ boolean headerWritten = false;
+ try {
+ openBraceCount = 0;
+ createHeader();
+ writeTemplate(HeaderTemplate.HEADER_TEMPLATE);
+ headerWritten = closeHeader();
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new TraceCompilerException(
+ TraceCompilerErrorCode.CANNOT_WRITE_PROJECT_FILE, e);
+ } finally {
+ traceDeclarations.clear();
+ if (headerOutput != null) {
+ try {
+ headerOutput.close();
+ } catch (IOException e) {
+ }
+ }
+ headerOutput = null;
+ }
+ return headerWritten;
+ }
+
+ /**
+ * Creates the header file
+ *
+ * @throws IOException
+ * if creation fails
+ */
+ private void createHeader() throws IOException {
+ File file = new File(header.getAbsolutePath());
+ if (file.exists()) {
+ // If header exists, data is written to a byte array and compared
+ // with existing file. If they are the same, the file is not
+ // updated.
+ headerOutput = new FileCompareOutputStream(file);
+ } else {
+ // If header does not exist, the data is written directly to file
+ headerOutput = FileUtils.createOutputStream(file);
+ }
+ }
+
+ /**
+ * Closes the header file. If data was written to a byte buffer this
+ * compares the contents of the buffer with the existing file and re-writes
+ * the file if contents do not match.
+ *
+ * @return true if header was written, false if it matched the existing
+ * header
+ * @throws IOException
+ * if closing fails
+ */
+ private boolean closeHeader() throws IOException {
+ boolean headerWritten = true;
+ if (headerOutput instanceof FileCompareOutputStream) {
+ headerWritten = ((FileCompareOutputStream) headerOutput)
+ .writeFile();
+ }
+ headerOutput.close();
+ headerOutput = null;
+ return headerWritten;
+ }
+
+ /**
+ * Writes a template to the stream
+ *
+ * @param template
+ * the template
+ * @throws IOException
+ * if writing fails
+ */
+ void writeTemplate(Object[] template) throws IOException {
+ for (Object o : template) {
+ if (o instanceof String) {
+ write((String) o);
+ } else if (o instanceof TraceHeaderContributionType) {
+ writeHeaderContributions((TraceHeaderContributionType) o);
+ } else if (o instanceof HeaderTemplateElementType) {
+ writeTemplateElement((HeaderTemplateElementType) o);
+ } else if (o instanceof Object[]) {
+ // Template within template
+ writeTemplate((Object[]) o);
+ } else if (o instanceof TemplateChoice) {
+ TemplateChoice choice = (TemplateChoice) o;
+ // Gets the array index from template
+ Class extends TemplateCheckBase> c = choice.getChoiceClass();
+ try {
+ // Creates a switch-case object based on array index
+ TemplateCheckBase check = c.newInstance();
+ check.setWriter(this);
+ // Gets the case from the switch-case object and uses it to
+ // get the correct template
+ if (check.check()) {
+ writeTemplate(choice.getTrueTemplate());
+ } else {
+ writeTemplate(choice.getFalseTemplate());
+ }
+ } catch (InstantiationException e) {
+ } catch (IllegalAccessException e) {
+ }
+ } else if (o instanceof TemplateIterator) {
+ Class extends TemplateIteratorEntry> c = ((TemplateIterator) o)
+ .getIteratorClass();
+ try {
+ // Creates an iterator object based on array index
+ TemplateIteratorEntry itr = c.newInstance();
+ itr.setWriter(this);
+ itr.iterate(((TemplateIterator) o).getTemplate());
+ } catch (InstantiationException e) {
+ } catch (IllegalAccessException e) {
+ }
+ } else if (o instanceof SetNewLineCount) {
+ maxNewLines = ((SetNewLineCount) o).getLineCount();
+ } else if (o instanceof TraceFormatType) {
+ // Stores the formatted trace, but does not write anything
+ // HeaderTemplateElementType.FORMATTED_TRACE writes the trace
+ currentTraceFormatted = SourceFormatter.formatTrace(
+ currentTrace, (TraceFormatType) o);
+ }
+ }
+ }
+
+ /**
+ * Writes an element from the HeaderTemplateElementType enumeration
+ *
+ * @param type
+ * the element type
+ * @throws IOException
+ * if writing fails
+ */
+ private void writeTemplateElement(HeaderTemplateElementType type)
+ throws IOException { // CodForChk_Dis_ComplexFunc
+ switch (type) {
+ case NEW_LINE:
+ writeNewLine();
+ break;
+ case OPEN_BRACE:
+ writeOpenBrace();
+ break;
+ case CLOSE_BRACE:
+ writeCloseBrace();
+ break;
+ case PARAMETER_INDEX:
+ write(String.valueOf(currentParameterIndex));
+ break;
+ case PARAMETER_TYPE:
+ write(currentParameterType);
+ break;
+ case PARAMETER_NAME:
+ write(currentParameterName);
+ break;
+ case FORMATTED_TRACE:
+ writeFormattedTrace(currentTraceFormatted);
+ break;
+ case TRACE_NAME:
+ write(currentTrace.getName());
+ break;
+ case TRACE_ID_HEX:
+ writeTraceID();
+ break;
+ case FIXED_BUFFER_SIZE:
+ write(String.valueOf(fixedBufferSize));
+ break;
+ case TRACE_FUNCTION_BODY:
+ writeFunctionBody(currentTrace);
+ break;
+ case TRACE_FUNCTION_PARAMETERS:
+ writeParameter(currentParameter);
+ break;
+ case BUILD_TRACE_BUFFER_CHECK:
+ buildTraceBuffer = traceNeedsBuffer(currentTrace);
+ break;
+ case HEADER_GUARD:
+ write(SourceUtils.createHeaderGuard(header.getFileName()));
+ break;
+ case TRACE_COMPILER_VERSION:
+ write(TraceCompilerVersion.getVersion());
+ break;
+ case CLOSE_EXTRA_BRACES:
+ while (openBraceCount > 1) {
+ writeCloseBrace();
+ }
+ break;
+ case LICENCE_TEXT:
+ writeLicence();
+ break;
+ }
+ }
+
+ /**
+ * Writes the trace ID to header
+ *
+ * @throws IOException
+ * if writing fails
+ */
+ private void writeTraceID() throws IOException {
+ int gid = currentTrace.getGroup().getID() << GROUP_SHIFT;
+ write(Integer.toHexString(gid | currentTrace.getID()));
+ ComplexHeaderRule rule = currentTrace
+ .getExtension(ComplexHeaderRule.class);
+ if (rule != null) {
+ String ext = rule.getTraceIDDefineExtension();
+ if (ext != null) {
+ write(ext);
+ }
+ }
+ }
+
+ /**
+ * Writes the header contributions from plug-in's
+ *
+ * @param type
+ * the contribution type
+ * @throws IOException
+ * if writing fails
+ */
+ private void writeHeaderContributions(TraceHeaderContributionType type)
+ throws IOException {
+ Iterator contributions = getContributions(type);
+ boolean written = false;
+ while (contributions.hasNext()) {
+ writeContribution(contributions.next(), type);
+ written = true;
+ }
+ if (written) {
+ writeNewLine();
+ }
+ }
+
+ /**
+ * Gets a list of contributions from plug-in's
+ *
+ * @param type
+ * the contribution type
+ * @return the contributions
+ */
+ private Iterator getContributions(TraceHeaderContributionType type) {
+ Iterator contributions = header.getOwner()
+ .getExtensions(TraceHeaderContribution.class);
+ ArrayList list = new ArrayList();
+ while (contributions.hasNext()) {
+ String[] s = contributions.next().getContribution(type);
+ if (s != null) {
+ for (String element : s) {
+ list.add(element);
+ }
+ }
+ }
+ return list.iterator();
+ }
+
+ /**
+ * Writes a contribution to the stream
+ *
+ * @param contribution
+ * the contribution
+ * @param type
+ * the contribution type
+ * @throws IOException
+ * if writing fails
+ */
+ private void writeContribution(String contribution,
+ TraceHeaderContributionType type) throws IOException {
+ switch (type) {
+ case GLOBAL_DEFINES:
+ writeDefine(contribution);
+ break;
+ case GLOBAL_INCLUDES:
+ writeSystemInclude(contribution);
+ break;
+ case MAIN_HEADER_CONTENT:
+ // Handled by HeaderEngine
+ break;
+ }
+ }
+
+ /**
+ * write start of function guard
+ * @throws IOException
+ */
+ private void writeStartFunctionGuard() throws IOException {
+ Pattern p = Pattern.compile("inline\\s+TBool\\s+([^\\(]+)\\s*\\((.*)\\)\\s*\\{"); //$NON-NLS-1$
+ String guard = null;
+ String functionName = null;
+
+ // Get the function definition line
+ int startIndex = functionText.indexOf(SourceConstants.OPENING_BRACE) + 1;
+ String funcDef = functionText.substring(0, startIndex);
+
+ Matcher m = p.matcher(funcDef);
+ if (m.matches()) {
+ //get function name
+ functionName = m.group(1);
+ if (functionName == null || functionName.length() == 0) {
+ throw new IOException(Messages.getString("TraceHeader.internalError1")); //$NON-NLS-1$
+ }
+ //get raw parameters
+ String parameters = m.group(2);
+ if (parameters == null || parameters.length() == 0) {//there must be at least TraceID
+ throw new IOException(Messages.getString("TraceHeader.internalError2")); //$NON-NLS-1$
+ }
+
+ functionName = functionName.trim();
+ parameters = parameters.trim();
+ //remove parameters names
+ guard = parameters.replaceAll("(\\S+,)|(\\S+\\s*$)", ""); //$NON-NLS-1$ //$NON-NLS-2$
+ //replace repeated spaces by one space
+ guard = guard.replaceAll("\\s+", SourceConstants.SPACE).trim(); //$NON-NLS-1$
+ //replace space by underscore
+ guard = guard.replace(SourceConstants.SPACE, SourceConstants.UNDERSCORE);
+ //replace ampersant by REF
+ guard = guard.replace(AMPERSANT, REF);
+ //replace ( by OBR
+ guard = guard.replace(OPEN_BRACKET, BEGINCAST);
+ //replace ) by CBR
+ guard = guard.replace(CLOSING_BRACKET, ENDCAST);
+ } else {
+ throw new IOException(Messages.getString("TraceHeader.internalError3")); //$NON-NLS-1$
+ }
+
+ guard = SourceConstants.DOUBLE_UNDERSCORE
+ + functionName.toUpperCase()
+ + SourceConstants.UNDERSCORE
+ + guard.toUpperCase()
+ + SourceConstants.DOUBLE_UNDERSCORE;
+
+ ostTraceGenxFunGuard = guard;
+ write( SourceConstants.IFNDEF + SourceConstants.SPACE_CHAR + ostTraceGenxFunGuard);
+ write(SourceConstants.LINE_FEED);
+ write( SourceConstants.DEFINE +SourceConstants.SPACE_CHAR + ostTraceGenxFunGuard);
+ write(SourceConstants.LINE_FEED);
+ write(SourceConstants.LINE_FEED);
+ }
+
+ /**
+ * write end of function guard
+ * @throws IOException
+ */
+ private void writeEndFunctionGuard() throws IOException {
+ if (ostTraceGenxFunGuard != null) {
+ write(SourceConstants.LINE_FEED);
+ write(SourceConstants.LINE_FEED);
+ write(SourceConstants.ENDIF
+ + SourceConstants.SPACE_CHAR
+ + SourceConstants.FORWARD_SLASH_CHAR
+ + SourceConstants.FORWARD_SLASH_CHAR
+ + SourceConstants.SPACE_CHAR
+ + ostTraceGenxFunGuard);
+ write(SourceConstants.LINE_FEED);
+ }
+ }
+ /**
+ * Writes the function body to the stream
+ *
+ * @param trace
+ * the trace to be written
+ * @throws IOException
+ * if writing fails
+ */
+ private void writeFunctionBody(Trace trace) throws IOException {
+ writeTraceBufferAllocation(trace);
+ writeTemplate(HeaderTemplate.PARAMETERS_TEMPLATE);
+ // If buffer is not used (single descriptor parameter), trace line is
+ // already written in template
+ if (isTraceBufferBuilt()) {
+ writeTraceLine(trace);
+ }
+ }
+
+ /**
+ * Writes trace buffer allocation code to the function
+ *
+ * @param trace
+ * the trace to be written
+ * @throws IOException
+ * if writing fails
+ */
+ private void writeTraceBufferAllocation(Trace trace) throws IOException {
+ // If buffer is not used (single descriptor parameter), this function
+ // does nothing
+ if (isTraceBufferBuilt()) {
+ Iterator parameters = trace.getParameters();
+ lenghtVariableDefined = false;
+ int fixedSizeParametersTotalSize = 0;
+ while (parameters.hasNext()) {
+ TraceParameter parameter = parameters.next();
+ TraceParameterFormattingRule sourceRule = parameter
+ .getExtension(TraceParameterFormattingRule.class);
+ if (sourceRule == null || sourceRule.isShownInSource()
+ || sourceRule instanceof FillerParameterRule) {
+ // Fillers do not increment parameter index
+ if (!(sourceRule instanceof FillerParameterRule)) {
+ currentParameterIndex++;
+ }
+ int paramSize = SourceUtils
+ .mapParameterTypeToSize(parameter);
+ // calculateParameterSize returns 0 for dynamic parameters,
+ // but 4 extra bytes need to be reserved for the length
+ if (paramSize == 0) {
+ paramSize = BYTES_IN_PARAMETER;
+ }
+ fixedBufferSize += paramSize;
+ fixedSizeParametersTotalSize += paramSize;
+ if (SourceUtils.isParameterSizeDynamic(parameter)) {
+
+ // Define length variable only once
+ if (lenghtVariableDefined == false) {
+ writeTemplate(HeaderTemplate.LENGTH_VARIABLE_DEFINITION_TEMPLATE);
+ lenghtVariableDefined = true;
+ }
+
+ // Increase length variable if needed
+ // This is needed in case that there has been fixed size
+ // parameter
+ // before dynamic parameter
+ if (fixedSizeParametersTotalSize - paramSize > 0) {
+ fixedSizeParametersTotalSize -= paramSize;
+ writeTemplate(HeaderTemplate.LENGTH_VARIABLE_INCREASE_TEMPLATE_BEGIN);
+ write(String.valueOf(fixedSizeParametersTotalSize));
+ writeTemplate(HeaderTemplate.LENGTH_VARIABLE_INCREASE_TEMPLATE_END);
+ }
+
+ fixedSizeParametersTotalSize = 0;
+
+ writeTemplate(HeaderTemplate.DYNAMIC_PARAMETER_LENGTH_TEMPLATE);
+ dynamicBufferSizeFlag = true;
+ }
+ }
+ }
+ writeTemplate(HeaderTemplate.BUFFER_ALLOCATION_TEMPLATE);
+ currentParameterIndex = 0;
+ }
+ }
+
+ /**
+ * Writes the given parameter to the header
+ *
+ * @param parameter
+ * the parameter
+ * @throws IOException
+ * if writing fails
+ */
+ void writeParameter(TraceParameter parameter) throws IOException {
+ TraceParameterFormattingRule sourceRule = parameter
+ .getExtension(TraceParameterFormattingRule.class);
+ if (sourceRule == null || sourceRule.isShownInSource()
+ || sourceRule instanceof FillerParameterRule) {
+ String paramType = SourceUtils
+ .mapParameterTypeToSymbianType(parameter);
+ if (SourceUtils.isParameterSizeDynamic(parameter)) {
+ currentParameterIndex++;
+ currentParameterName = SymbianConstants.PARAMETER_DECLARATION_PREFIX
+ + currentParameterIndex;
+ writeTemplate(HeaderTemplate.DYNAMIC_PARAMETER_TEMPLATE);
+ } else {
+ currentParameterType = paramType;
+ if (sourceRule instanceof FillerParameterRule) {
+ currentParameterName = "0"; //$NON-NLS-1$
+ writeTemplate(HeaderTemplate.FIXED_PARAMETER_TEMPLATE);
+ } else {
+ currentParameterIndex++;
+ currentParameterName = SymbianConstants.PARAMETER_DECLARATION_PREFIX
+ + currentParameterIndex;
+ if (lenghtVariableDefined == true) {
+ writeTemplate(HeaderTemplate.FIXED_PARAMETER_TEMPLATE_WITH_LENGTH_CHECK);
+ } else {
+ writeTemplate(HeaderTemplate.FIXED_PARAMETER_TEMPLATE);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Writes the trace line to the function
+ *
+ * @param trace
+ * the trace to be written
+ * @throws IOException
+ * if writing fails
+ */
+ private void writeTraceLine(Trace trace) throws IOException {
+ StringBuffer sb;
+ StringBuffer bufferData = new StringBuffer();
+ StringBuffer lengthData = new StringBuffer();
+ if (isBufferSizeDynamic()) {
+ sb = writeBufferedTraceLine(trace, bufferData, lengthData);
+ } else {
+ // If buffer size is 4, the buffer can be traced using the
+ // the 32-bit parameter trace macro instead of data macro
+ if (fixedBufferSize / BYTES_IN_PARAMETER == 1) {
+ sb = writePackedTraceLine(trace, bufferData);
+ } else {
+ sb = writeBufferedTraceLine(trace, bufferData, lengthData);
+ }
+ }
+ int index = sb.indexOf(TraceFormatConstants.DATA_BUFFER_FORMAT);
+ if (index >= 0) {
+ sb.replace(index, index
+ + TraceFormatConstants.DATA_BUFFER_FORMAT.length(),
+ bufferData.toString());
+ }
+ index = sb.indexOf(TraceFormatConstants.DATA_LENGTH_FORMAT);
+ if (index >= 0) {
+ sb.replace(index, index
+ + TraceFormatConstants.DATA_LENGTH_FORMAT.length(),
+ lengthData.toString());
+ }
+ String s = sb.toString();
+ write("retval = "); //$NON-NLS-1$
+ writeFormattedTrace(s);
+ writeNewLine();
+ }
+
+ /**
+ * Writes a trace line when the parameters can be fitted into a direct API
+ * call
+ *
+ * @param trace
+ * the trace
+ * @param bufferData
+ * the buffer
+ * @return formatted trace
+ */
+ private StringBuffer writePackedTraceLine(Trace trace,
+ StringBuffer bufferData) {
+ StringBuffer sb;
+ // The formatting rule is used to get the API macro
+ sb = new StringBuffer(SourceFormatter.formatTrace(trace,
+ TraceFormatType.TRACE_PACKED));
+ TraceFormattingRule rule = trace
+ .getExtension(TraceFormattingRule.class);
+ if (rule == null) {
+ rule = trace.getModel().getExtension(TraceFormattingRule.class);
+ }
+ int index = sb.indexOf(TraceFormatConstants.PARAM_COUNT_FORMAT);
+ if (index >= 0) {
+ // Single parameter is supported
+ sb.replace(index, index
+ + TraceFormatConstants.PARAM_COUNT_FORMAT.length(), rule
+ .mapParameterCountToSource(trace, 1));
+ }
+ bufferData.append("*( ( TUint32* )ptr )"); //$NON-NLS-1$
+ return sb;
+ }
+
+ /**
+ * Writes a trace line when the trace contains more data that the API
+ * supports
+ *
+ * @param trace
+ * the trace
+ * @param bufferData
+ * the trace buffer
+ * @param lengthData
+ * the trace length buffer
+ * @return the formatted trace
+ */
+ private StringBuffer writeBufferedTraceLine(Trace trace,
+ StringBuffer bufferData, StringBuffer lengthData) {
+ StringBuffer sb;
+ // Buffer parameter
+ // *( ( TUint32* )ptr ), *( ( TUint32* )( ptr + 4 ) ), ..., ptr + x
+ sb = new StringBuffer(SourceFormatter.formatTrace(trace,
+ TraceFormatType.TRACE_BUFFER));
+ if (isTraceBufferBuilt()) {
+ bufferData.append("ptr"); //$NON-NLS-1$
+ if (isBufferSizeDynamic()) {
+ // In case of dynamic buffer, the length has been calculated
+ // into length variable
+ lengthData.append("length"); //$NON-NLS-1$
+ } else {
+ // Fixed size case
+ lengthData.append(String.valueOf(fixedBufferSize));
+ }
+ } else {
+ // In case of no-buffer, the size variable contain the data size
+ bufferData.append("ptr"); //$NON-NLS-1$
+ lengthData.append("size"); //$NON-NLS-1$
+ }
+ return sb;
+ }
+
+ /**
+ * Writes a formatted trace to the stream. This removes the newline from the
+ * trace if it exists
+ *
+ * @param trace
+ * the trace
+ * @throws IOException
+ * if writing fails
+ */
+ private void writeFormattedTrace(String trace) throws IOException {
+ if (trace.endsWith(SourceConstants.LINE_FEED)) {
+ write(trace.substring(0, trace.length()
+ - SourceConstants.LINE_FEED.length()));
+ } else {
+ write(trace);
+ }
+ }
+
+ /**
+ * Increases indent and writes a new line, brace, new line combination
+ *
+ * @throws IOException
+ * if writing fails
+ */
+ private void writeOpenBrace() throws IOException {
+ openBraceCount++;
+ writeNewLine();
+ write(SourceConstants.OPENING_BRACE);
+ writeNewLine();
+ }
+
+ /**
+ * Write brace, decreases indent and writes a new line
+ *
+ * @throws IOException
+ * if writing fails
+ */
+ private void writeCloseBrace() throws IOException {
+ write(SourceConstants.CLOSING_BRACE);
+ openBraceCount--;
+ writeNewLine();
+ }
+
+ /**
+ * write licence Text
+ * @throws IOException if write fails
+ */
+ private void writeLicence() throws IOException {
+ String licence = null;
+ SourceParser parser = null;
+ //first get any of the traces belonging to this header
+ TraceModel model = header.getOwner().getModel();
+ for (TraceGroup group : model) {
+ for (Trace trace : group) {
+ Iterator itr = trace.getExtensions(LocationListBase.class);
+ // The trace must have at least one location that belong to this header
+ while (itr.hasNext() && parser == null) {
+ LocationListBase list = itr.next();
+ for (LocationProperties loc : list) {
+ if (isValidTraceForHeader(loc.getFileName())) {
+ parser = ((TraceLocation)loc).getParser();
+ break;
+ }
+ }
+ }
+ if (parser!= null) {
+ break;
+ }
+ }
+ if (parser != null) {
+ break;
+ }
+ }
+
+ if (parser!= null) {
+ List excludedAreas = parser.getExcludedAreas();
+ //try to find licence from the source
+ if (!excludedAreas.isEmpty()) {
+ SourceExcludedArea sourceExcludedArea = excludedAreas.get(0);
+ int offset = sourceExcludedArea.getOffset();
+ int type = sourceExcludedArea.getType();
+ int length = sourceExcludedArea.getLength();
+ if (offset == 0 && type == SourceExcludedArea.MULTILINE_COMMENT) {
+ String data = sourceExcludedArea.getParser().getData(offset, length);
+ if (data.contains("Copyright")) { //$NON-NLS-1$
+ // licence found write it
+ TraceCompilerLogger.printInfo("Add Licence text from: " + sourceExcludedArea.getFileName() + " to : " + header.getAbsolutePath()); //$NON-NLS-1$
+ licence = data;
+ write(licence);
+ }
+ }
+ }
+ }
+
+ if (licence == null) {
+ //get default licence from the licence file
+ licence = TraceCompilerEngineGlobals.getDefaultLicence(true);
+
+ if(licence != null) {
+ TraceCompilerLogger.printInfo("Add default EPL Licence to : " + header.getAbsolutePath()); //$NON-NLS-1$
+ write(licence);
+ }
+ }
+ }
+
+ /**
+ * Writes a new line and indent to the stream
+ *
+ * @throws IOException
+ * if writing fails
+ */
+ private void writeNewLine() throws IOException {
+ int newLines = newLineCount;
+ while (newLines < maxNewLines) {
+ write(SourceConstants.LINE_FEED);
+ for (int i = 0; i < openBraceCount; i++) {
+ write(INDENT);
+ }
+ newLines++;
+ }
+ newLineCount = maxNewLines;
+ }
+
+ /**
+ * Writes a define to stream
+ *
+ * @param name
+ * the name for the define
+ * @throws IOException
+ * if writing fails
+ */
+ private void writeDefine(String name) throws IOException {
+ write(SourceConstants.DEFINE);
+ write(SourceConstants.SPACE);
+ write(name);
+ writeNewLine();
+ }
+
+ /**
+ * Writes include to header
+ *
+ * @param name
+ * the header name
+ * @throws IOException
+ * if writing fails
+ */
+ private void writeSystemInclude(String name) throws IOException {
+ write(SourceConstants.INCLUDE);
+ write(SourceConstants.SPACE);
+ write("<"); //$NON-NLS-1$
+ write(name);
+ write(">"); //$NON-NLS-1$
+ writeNewLine();
+ }
+
+ /**
+ * Writes data to a stream
+ *
+ * @param data
+ * the string of data
+ * @throws IOException
+ * if writing fails
+ */
+ private void write(String data) throws IOException {
+ // Check if function starts
+ if (data.contains(INLINE_TBOOL) || bufferingFunction) {
+ bufferingFunction = true;
+ functionText.append(data);
+ } else {
+ headerOutput.write(data.getBytes());
+ }
+ newLineCount = 0;
+
+ //try to duplicate function if the current function processing is complete and duplicate is needed.
+ writeAndDuplicateFunction(data);
+ }
+
+ /**
+ * Duplicates the function if needed
+ *
+ * @param data
+ * data String
+ * @throws IOException
+ * if writing fails
+ */
+ private void writeAndDuplicateFunction(String data) throws IOException {
+ // This assumes there is only one start or end bracket in one line!
+ if (data.contains(SourceConstants.OPENING_BRACE)) {
+ firstOpenBraceFound = true;
+ numberOfBrackets++;
+ } else if (data.contains(SourceConstants.CLOSING_BRACE)) {
+ numberOfBrackets--;
+
+ // Function ends
+ if (numberOfBrackets == 0 && firstOpenBraceFound) {
+ firstOpenBraceFound = false;
+ bufferingFunction = false;
+ //write start function guard
+ writeStartFunctionGuard();
+ //write the function
+ headerOutput.write(functionText.toString().getBytes());
+ //write end function guard
+ writeEndFunctionGuard();
+
+ //process duplicate if needed
+ // Get the function definition line
+ int startIndex = functionText.indexOf(SourceConstants.OPENING_BRACE);
+ String funcDef = functionText.substring(0, startIndex);
+
+ // Replace TInt with TInt32 and TUint with TUint32 from the
+ // header and write the function back again
+ if (funcDef.contains(TINT_DEF)
+ || funcDef.contains(TUINT_DEF)) {
+ //replace and duplicate
+ funcDef = funcDef.replace(TINT_DEF, TINT32_DEF);
+ funcDef = funcDef.replace(TUINT_DEF, TUINT32_DEF);
+ functionText.replace(0, startIndex, funcDef);
+
+ //write start function guard for duplicate
+ write(SourceConstants.LINE_FEED);
+ write(SourceConstants.LINE_FEED);
+ writeStartFunctionGuard();
+
+ //write duplicate function
+ headerOutput.write(functionText.toString().getBytes());
+
+ //write end function guard for duplicate
+ writeEndFunctionGuard();
+ }
+
+ functionText.setLength(0);
+ }
+ }
+ }
+
+ /**
+ * Checks if a trace needs a buffer or it can be represented with regular
+ * trace macros.
+ *
+ * @param trace
+ * the trace
+ * @return true if trace needs a buffer
+ */
+ private boolean traceNeedsBuffer(Trace trace) {
+ // A single dynamic parameter can be passed through the regular
+ // API macros. In that case the parameter length is determined
+ // by the trace message length
+ Iterator parameters = trace.getParameters();
+ boolean needsBuffer = false;
+ boolean dynamicFound = false;
+ while (parameters.hasNext() && !needsBuffer) {
+ TraceParameter parameter = parameters.next();
+ if (isParameterVisible(parameter)) {
+ if (SourceUtils.isParameterSizeDynamic(parameter)) {
+ if (dynamicFound) {
+ needsBuffer = true;
+ } else {
+ dynamicFound = true;
+ }
+ } else {
+ needsBuffer = true;
+ }
+ }
+ }
+ return needsBuffer;
+ }
+
+ /**
+ * Checks if a parameter is visible
+ *
+ * @param parameter
+ * the parameter to be checked
+ * @return true if visible, false if not
+ */
+ private boolean isParameterVisible(TraceParameter parameter) {
+ boolean retval;
+ TraceParameterFormattingRule sourceRule = parameter
+ .getExtension(TraceParameterFormattingRule.class);
+ if (sourceRule == null || sourceRule.isShownInSource()) {
+ retval = true;
+ } else {
+ retval = false;
+ }
+ return retval;
+ }
+
+ /**
+ * Gets the formatted trace
+ *
+ * @return the trace
+ */
+ String getCurrentTraceFormatted() {
+ return currentTraceFormatted;
+ }
+
+ /**
+ * Checks if trace is already formatted to header
+ *
+ * @return true if formatted
+ */
+ boolean isTraceFormatDuplicate() {
+ boolean retval;
+ if (traceDeclarations.contains(currentTraceFormatted)) {
+ retval = true;
+ } else {
+ traceDeclarations.add(currentTraceFormatted);
+ retval = false;
+ }
+ return retval;
+ }
+
+ /**
+ * Checks if the buffer size for current trace is fixed
+ *
+ * @return the flag
+ */
+ boolean isTraceBufferFixed() {
+ return fixedBufferSize != 0;
+ }
+
+ /**
+ * Checks if the buffer is built
+ *
+ * @return the flag
+ */
+ boolean isTraceBufferBuilt() {
+ return buildTraceBuffer;
+ }
+
+ /**
+ * Gets the current trace
+ *
+ * @return the trace
+ */
+ Trace getCurrentTrace() {
+ return currentTrace;
+ }
+
+ /**
+ * Gets the header
+ *
+ * @return the header
+ */
+ TraceHeader getHeader() {
+ return header;
+ }
+
+ /**
+ * Starts writing a trace
+ *
+ * @param trace
+ * the trace
+ * @return true if trace can be written, false if not
+ */
+ boolean startTrace(Trace trace) {
+ boolean validTrace = false;
+ Iterator itr = trace
+ .getExtensions(LocationListBase.class);
+ // The trace must have at least one location that belong to this header
+ while (itr.hasNext() && !validTrace) {
+ LocationListBase list = itr.next();
+ for (LocationProperties loc : list) {
+ validTrace = isValidTraceForHeader(loc.getFileName());
+ if (validTrace) {
+ break;
+ }
+ }
+ }
+ if (validTrace) {
+ currentTrace = trace;
+ fixedBufferSize = 0;
+ dynamicBufferSizeFlag = false;
+ buildTraceBuffer = false;
+ currentTraceFormatted = null;
+ currentParameterName = null;
+ currentParameterType = null;
+ currentParameterIndex = 0;
+ }
+ return validTrace;
+ }
+
+ /**
+ * Checks if the location belongs to this header
+ *
+ * @param locFileName
+ * the location
+ * @return true if location belongs here
+ */
+ private boolean isValidTraceForHeader(String locFileName) {
+ boolean valid = false;
+ if (locFileName != null) {
+ int index = locFileName.lastIndexOf('.');
+ if (index >= 0) {
+ locFileName = locFileName.substring(0, index);
+ }
+ if (locFileName.equals(header.getProjectName())) {
+ valid = true;
+ }
+ }
+ return valid;
+ }
+
+ /**
+ * Starts writing a parameter
+ *
+ * @param parameter
+ * the parameter
+ */
+ void startParameter(TraceParameter parameter) {
+ currentParameterName = null;
+ currentParameterType = null;
+ currentParameter = parameter;
+ }
+
+ /**
+ * Sets the kernel mode #endif needed flag
+ *
+ * @param flag
+ * the flag
+ */
+ void setKernelModeEndifNeeded(boolean flag) {
+ needsKernelEndif = flag;
+ }
+
+ /**
+ * Gets the kernel mode endif needed flag
+ *
+ * @return the flag
+ */
+ boolean isKernelModeEndifNeeded() {
+ return needsKernelEndif;
+ }
+
+ /**
+ * Returns the dynamic buffer size flag
+ *
+ * @return true if buffer size is dynamic
+ */
+ boolean isBufferSizeDynamic() {
+ return dynamicBufferSizeFlag;
+ }
+
+ /**
+ * Checks if current parameter needs alignment
+ *
+ * @return true if needed
+ */
+ boolean isParameterAlignmentNeeded() {
+ return SourceUtils.isParameterAlignementNeeded(currentParameter
+ .getType());
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/messages.properties
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/messages.properties Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,8 @@
+TraceHeader.Title=Trace Header
+HeaderEngine.TraceHeaderNotChangedPrefix=No changes were made to
+HeaderEngine.FailedToAttachHeader=Failed to attach trace header to project
+TraceHeader.internalError1=TraceCompiler internal: Error parsing OstTraceGenx function name.
+TraceHeader.internalError2=TraceCompiler internal: Error parsing OstTraceGenx function parameters.
+TraceHeader.internalError3=TraceCompiler internal: TraceCompiler could not identify OstTraceGenx function.
+
+
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/package.html
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/header/package.html Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,4 @@
+
+Maintains the trace header, which contains inline functions
+for traces that cannot be represented by the normal trace API.
+
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/messages.properties
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/messages.properties Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,110 @@
+TraceCompiler.UnknownTypeWarning=Parameter type is unknown. Hex, 32-bit used
+TraceLocationConverter.GroupIdValueError=TC has detected a fixed_id.defintions using different Group Id values. This file will be regenerated with the correct values.
+TraceLocationConverter.DeprecatedGroupIdWarningStart=Deprecated group
+TraceLocationConverter.DeprecatedGroupIdWarningMiddle=detected. Updating to
+TraceLocationConverter.DeprecatedGroupIdWarningEnd=in dictionary. Please update source code!
+TraceLocationConverter.FixedIdProblemWarningBeginText=Found problems with the old fixed id message :
+TraceLocationConverter.FixedIdProblemWarningMiddleText=. Therfore deleting it.
+TraceLocationMap.SourceWithTraceRemoved=Source file with traces was removed
+TraceCompilerErrorMessages.SourceNotEditable=Source cannot be edited
+TraceCompilerErrorMessages.DuplicateGroupID=Group ID conflict. Please close all the source files, delete traceid and tracecompiler cache files. Then reopen source file.
+TraceCompilerErrorMessages.DuplicateTraceID=Trace ID is already in use
+TraceCompilerErrorMessages.DuplicateGroupName=Group name is already in use
+TraceCompilerErrorMessages.DuplicateTraceName=Trace name is already in use
+TraceCompilerErrorMessages.DuplicateConstantValue=Enum text is already in use
+TraceCompilerErrorMessages.DuplicateConstantID=Enum value is already in use
+TraceCompilerErrorMessages.DuplicateConstantTableName=Enum type is already in use
+TraceCompilerErrorMessages.DuplicateConstantTableID=Enum ID is already in use
+TraceCompilerErrorMessages.DuplicateParameterName=Parameter name is already in use
+TraceCompilerErrorMessages.DuplicateParameterID=Parameter ID is already in use
+TraceCompilerErrorMessages.InvalidGroupName=Invalid group name
+TraceCompilerErrorMessages.InvalidTraceName=Invalid trace name
+TraceCompilerErrorMessages.InvalidGroupID=Invalid group ID
+TraceCompilerErrorMessages.InvalidGroupIDStart=Group ID must be between
+TraceCompilerErrorMessages.InvalidGroupIDMiddle=\ and
+TraceCompilerErrorMessages.InvalidGroupIDEnd=
+TraceCompilerErrorMessages.InvalidTraceID=Invalid trace ID
+TraceCompilerErrorMessages.InvalidTraceIDStart=Trace ID must be between
+TraceCompilerErrorMessages.InvalidTraceIDMiddle=\ and
+TraceCompilerErrorMessages.InvalidTraceIDEnd=
+TraceCompilerErrorMessages.InvalidModelPropertiesForExport=Before exporting, the trace compiler needs to be run once to generate UID and name for the component.
+TraceCompilerErrorMessages.InvalidProjectName=Project name is not valid
+TraceCompilerErrorMessages.InvalidSourceLocation=Cursor location is not valid
+TraceCompilerErrorMessages.InvalidParameterName=Parameter name is not valid
+TraceCompilerErrorMessages.InvalidParameterNameInReturnValue=Return parameter name is not valid. Parameter was not added to exit trace.
+TraceCompilerErrorMessages.InvalidConstantValue=Enum text is not valid
+TraceCompilerErrorMessages.InvalidParameterType=Parameter type is not supported
+TraceCompilerErrorMessages.InvalidParameterTypePrefix=Parameter type
+TraceCompilerErrorMessages.InvalidParameterTypePostfix=\ is not supported
+TraceCompilerErrorMessages.InvalidDirectoryPrefix=
+TraceCompilerErrorMessages.InvalidDirectoryPostfix=\ is not a valid directory
+TraceCompilerErrorMessages.InvalidDirectory=Directory is not valid
+TraceCompilerErrorMessages.InvalidConstantTableName=Enum type is not valid. Please select a valid enum from the source code and try again.
+TraceCompilerErrorMessages.ConstantTableNotPartOfProject=The file where enum exist is not part of project. You can parse enums only from files that are part of the project. If you want parse enum from external file, you can copy and paste that enum to some file in your project and parse it from there. After you have parsed enum you can delete it from your project.
+TraceCompilerErrorMessages.FileDoesNotExistPrefix=
+TraceCompilerErrorMessages.FileDoesNotExistPostfix=\ does not exist
+TraceCompilerErrorMessages.InvalidTraceData=Invalid trace text
+TraceCompilerErrorMessages.InvalidTraceFile=Trace project file is not valid
+TraceCompilerErrorMessages.GroupNotSelected=Group was not selected
+TraceCompilerErrorMessages.NoFunctionsToInstrumentPrefix=None of the functions from open files could be instrumented with
+TraceCompilerErrorMessages.NoFunctionsToInstrument=Currently open files do not have any functions that can be instrumented
+TraceCompilerErrorMessages.NoFunctionsToInstrumentPostfix=\ template
+TraceCompilerErrorMessages.ParameterFormatMismatch=Parameter count does not match the format specification
+TraceCompilerErrorMessages.ParameterFormatNotSupported=Parameter format is not supported
+TraceCompilerErrorMessages.ParameterFormatNotSupportedPrefix=Parameter format
+TraceCompilerErrorMessages.ParameterFormatNotSupportedPostfix=\ is not supported
+TraceCompilerErrorMessages.MultipleErrorsInOperation=Multiple errors during operation. See event viewer for details
+TraceCompilerErrorMessages.ParameterAddNotAllowed=Parameters cannot be added to the trace
+TraceCompilerErrorMessages.EmptyParameterName=Parameter did not have a name and was not added to trace
+TraceCompilerErrorMessages.SourceNotOpen=Source file needs to be opened first
+TraceCompilerErrorMessages.ParameterRemoveNotAllowed=The parameter cannot be removed
+TraceCompilerErrorMessages.ConstantTableNotSelected=Enum was not selected
+TraceCompilerErrorMessages.ConstantTableParseFailed=Failed to parse enum
+TraceCompilerErrorMessages.CannotDeleteSelectedObject=The selected object cannot be deleted
+TraceCompilerErrorMessages.CannotUpdateTraceIntoSource=Trace could not be updated to source code
+TraceCompilerErrorMessages.CannotParseFunctionParameters=None of the function parameters could be added to the function entry trace
+TraceCompilerErrorMessages.CannotOpenProjectFile=Cannot open project file. Check that the directory is not read-only
+TraceCompilerErrorMessages.CannotWriteProjectFile=Cannot write project file. Check that the directory is not read-only
+TraceCompilerErrorMessages.CannotOpenSourceFile=Source file could not be opened
+TraceCompilerErrorMessages.ParameterTemplateInUse=Another parameter already uses the selected template
+TraceCompilerErrorMessages.InvalidTraceTextFormat=Trace text format is not valid
+TraceCompilerErrorMessages.InvalidTraceNameFormat=Trace name format is not valid
+TraceCompilerErrorMessages.InsertTraceDoesNotWork=Data traces cannot be inserted to source
+TraceCompilerErrorMessages.TraceLocationNotSelected=Source location was not selected
+TraceCompilerErrorMessages.TraceHasMultipleLocations=Trace is used from multiple places
+TraceCompilerErrorMessages.LocationCouldNotBeParsed=Location could not be parsed
+TraceCompilerErrorMessages.UnreachableTraceLocation=Trace is in unreachable part of the code
+TraceCompilerErrorMessages.NameFormatMissingFunction=Missing function name tag {$FN} from trace name
+TraceCompilerErrorMessages.TraceNotSelected=Trace was not selected
+TraceCompilerErrorMessages.TraceProjectNotOpen=Trace project is not open
+TraceCompilerErrorMessages.TraceHasNoLocations=Trace is not used from source files and will be removed when a source is saved
+TraceCompilerErrorMessages.NoTracesToDelete=No traces to delete
+TraceCompilerErrorMessages.NoTracesToExport=Project does not have any traces -> No files were written
+TraceCompilerErrorMessages.FileDoesNotExist=File does not exist
+TraceCompilerErrorMessages.NoTraceGroups=Cannot add a new trace before a trace group has been created
+TraceCompilerErrorMessages.UnexpectedException=Unknown error occurred
+TraceCompilerErrorMessages.NotEnoughParameters=Trace does not have enough parameters
+TraceCompilerErrorMessages.NoContextForLocation=Class / function name for trace could not be determined
+TraceCompilerErrorMessages.TraceDoesNotExist=Trace will be created when the source file is saved
+TraceCompilerErrorMessages.TraceNeedsConversionPrefix=Trace needs conversion
+TraceCompilerErrorMessages.ParameterCountMismatch=Parameter count in source does not match the parameter count in trace
+TraceCompilerErrorMessages.ParameterCountDoesNotMatchApi=The number of parameters in source does not match the API macro
+TraceCompilerErrorMessages.ParameterFormatNotSupportedInMacro=Extension macro needs to be used with this parameter format type
+TraceCompilerErrorMessages.ParameterFormatUnnecessaryExtMacro=Trace does not need to use extension macro
+TraceCompilerErrorMessages.ParameterFormatNotSupportedInMacroPrefix=Extension macro needs to be used with parameter
+TraceCompilerErrorMessages.ParameterFormatNotSupportedInMacroPostfix=
+TraceCompilerErrorMessages.ParameterFormatNotSupportedInArrayPrefix=Parameter format
+TraceCompilerErrorMessages.ParameterFormatNotSupportedInArrayPostfix=\ cannot be used as an array
+TraceCompilerErrorMessages.ParameterFormatNotSupportedInArray=Parameter format cannot be used as an array
+TraceCompilerErrorMessages.PropertyFileElementNotSupportedPrefix=Property file element
+TraceCompilerErrorMessages.PropertyFileElementNotSupportedPostfix=\ is not supported and was ignored
+TraceCompilerErrorMessages.PropertyFileElementMisplacedPrefix=Property file element
+TraceCompilerErrorMessages.PropertyFileElementMisplacedPostfix=\ was unexpected
+TraceCompilerErrorMessages.PropertyFileAttributeInvalidPrefix=Property file attribute
+TraceCompilerErrorMessages.PropertyFileAttributeInvalidPostfix=\ did not have a valid value
+TraceCompilerErrorMessages.RunOutOfGroupIDs=Run out of Group IDs. You can try to reuse unused group ids by deleting fixed id definition file.
+TraceCompilerErrorMessages.RunOutOfTraceIDs=Run out of Trace IDs. You can try to reuse unused trace ids by deleting fixed id definition file.
+TraceCompilerErrorMessages.VarArgListParameterFound=Parameters were not added to the trace because one of the variables is a variable argument list.
+TraceCompilerErrorMessages.InvalidUsageOfTraceStateGroupName=Invalid group name. TRACE_STATE group name is reserved for state traces only.
+TraceCompilerErrorMessages.InvalidUsageOfTracePerformanceGroupName=Invalid group name. TRACE_PERFORMANCE group name is reserved for performance traces only.
+TraceCompilerErrorMessages.LicenceFileError=Failed to read licence file.
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/package.html
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/package.html Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,3 @@
+
+Contains the main control logic of TraceCompiler.
+
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/plugin/PluginEngine.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/plugin/PluginEngine.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,198 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Export plugin manager, which delegates calls to plug-ins
+*
+*/
+package com.nokia.tracecompiler.engine.plugin;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import com.nokia.tracecompiler.engine.TraceCompilerEngineBase;
+import com.nokia.tracecompiler.engine.TraceCompilerEngineConfiguration;
+import com.nokia.tracecompiler.engine.TraceCompilerEngineErrorMessages;
+import com.nokia.tracecompiler.engine.TraceCompilerEngineGlobals;
+import com.nokia.tracecompiler.engine.TraceCompilerEngineErrorCodes.TraceCompilerErrorCode;
+import com.nokia.tracecompiler.model.TraceCompilerException;
+import com.nokia.tracecompiler.model.TraceModel;
+import com.nokia.tracecompiler.model.TraceObjectPropertyVerifier;
+import com.nokia.tracecompiler.plugin.TraceAPIPlugin;
+import com.nokia.tracecompiler.plugin.TraceCompilerExport;
+import com.nokia.tracecompiler.plugin.TraceCompilerPlugin;
+
+/**
+ * Plugin engine, which delegates calls to plug-ins
+ *
+ */
+public final class PluginEngine extends TraceCompilerEngineBase {
+
+ /**
+ * List of plug-ins
+ */
+ private ArrayList plugins = new ArrayList();
+
+ /**
+ * Property verifier
+ */
+ private PluginTracePropertyVerifier verifier = new PluginTracePropertyVerifier(
+ this);
+
+ /**
+ * Trace model
+ */
+ private TraceModel model;
+
+ /**
+ * Project open flag
+ */
+ private boolean projectOpen;
+
+ /**
+ * Sets the trace model. This is not set in constructor, since plug-in
+ * engine is created before the model
+ *
+ * @param model
+ * the trace model
+ */
+ public void setModel(TraceModel model) {
+ this.model = model;
+ }
+
+ /**
+ * Gets the started flag
+ *
+ * @return true if started, false if not
+ */
+ public boolean isProjectOpen() {
+ return projectOpen;
+ }
+
+ /**
+ * Adds a plugin
+ *
+ * @param plugin
+ * the plugin to be added
+ */
+ public void add(TraceCompilerPlugin plugin) {
+ plugins.add(plugin);
+ if (plugin instanceof TraceAPIPlugin) {
+ TraceAPIPlugin api = (TraceAPIPlugin) plugin;
+ TraceAPIPluginManager manager = model
+ .getExtension(TraceAPIPluginManager.class);
+ manager.addFormatters(api.getFormatters());
+ manager.addParsers(api.getParsers());
+ }
+ }
+
+ /**
+ * Removes a plugin
+ *
+ * @param plugin
+ * the plugin to be removed
+ */
+ public void remove(TraceCompilerPlugin plugin) {
+ // Formatters / parsers are not removed. Currently this is not a
+ // problem since plug-in's are removed only on shutdown
+ plugins.remove(plugin);
+ }
+
+ /**
+ * Gets the property verifier interface
+ *
+ * @return the verifier
+ */
+ public TraceObjectPropertyVerifier getVerifier() {
+ return verifier;
+ }
+
+ /**
+ * Checks if there are plug-ins
+ *
+ * @return true if plug-ins exist
+ */
+ public boolean hasPlugins() {
+ return !plugins.isEmpty();
+ }
+
+ /**
+ * Gets the plug-ins
+ *
+ * @return the plug-ins
+ */
+ Iterator getPlugins() {
+ return plugins.iterator();
+ }
+
+ /* (non-Javadoc)
+ * @see com.nokia.tracecompiler.engine.TraceCompilerEngineBase#exportProject()
+ */
+ @Override
+ public void exportProject() throws TraceCompilerException {
+ if (model.hasTraces()) {
+ for (TraceCompilerPlugin plugin : plugins) {
+ if (plugin instanceof TraceCompilerExport) {
+ try {
+ ((TraceCompilerExport) plugin).exportTraceProject();
+ } catch (TraceCompilerException e) {
+ TraceCompilerEngineGlobals.getEvents().postError(e);
+ throw e;
+ }
+ }
+ }
+ } else {
+ TraceCompilerEngineGlobals.getEvents().postInfoMessage(
+ TraceCompilerEngineErrorMessages.getErrorMessage(
+ TraceCompilerErrorCode.NO_TRACES_TO_EXPORT, null),
+ null);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.TraceCompilerEngine#projectOpened()
+ */
+ @Override
+ public void projectOpened() {
+ if (!projectOpen) {
+ for (TraceCompilerPlugin plugin : plugins) {
+ plugin.traceProjectOpened(model);
+ }
+ projectOpen = true;
+ } else {
+ if (TraceCompilerEngineConfiguration.ASSERTIONS_ENABLED) {
+ TraceCompilerEngineGlobals.getEvents().postAssertionFailed(
+ "PluginEngine.traceProjectOpened", null); //$NON-NLS-1$
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.TraceCompilerEngine#projectClosing()
+ */
+ @Override
+ public void projectClosed() {
+ if (projectOpen) {
+ for (TraceCompilerPlugin plugin : plugins) {
+ plugin.traceProjectClosed();
+ }
+ projectOpen = false;
+ }
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/plugin/PluginTracePropertyVerifier.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/plugin/PluginTracePropertyVerifier.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,336 @@
+/*
+* Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Property verifier for trace objects
+*
+*/
+package com.nokia.tracecompiler.engine.plugin;
+
+import java.util.Iterator;
+
+import com.nokia.tracecompiler.engine.TraceCompilerEngineGlobals;
+import com.nokia.tracecompiler.engine.TraceCompilerEngineErrorCodes.RangeErrorParameters;
+import com.nokia.tracecompiler.engine.TraceCompilerEngineErrorCodes.TraceCompilerErrorCode;
+import com.nokia.tracecompiler.model.Trace;
+import com.nokia.tracecompiler.model.TraceCompilerException;
+import com.nokia.tracecompiler.model.TraceConstantTable;
+import com.nokia.tracecompiler.model.TraceConstantTableEntry;
+import com.nokia.tracecompiler.model.TraceGroup;
+import com.nokia.tracecompiler.model.TraceModel;
+import com.nokia.tracecompiler.model.TraceObjectPropertyVerifier;
+import com.nokia.tracecompiler.model.TraceParameter;
+import com.nokia.tracecompiler.plugin.TraceCompilerPlugin;
+import com.nokia.tracecompiler.source.SourceConstants;
+import com.nokia.tracecompiler.source.SourceUtils;
+import com.nokia.tracecompiler.project.*;
+
+/**
+ * Property verifier for trace objects
+ *
+ */
+public final class PluginTracePropertyVerifier implements TraceObjectPropertyVerifier {
+
+ /**
+ * Valid data character range start
+ */
+ private static final int DATA_CHAR_START = 0x20; // CodForChk_Dis_Magic
+
+ /**
+ * Valid data character range end
+ */
+ private static final int DATA_CHAR_END = 0x7E; // CodForChk_Dis_Magic
+ /**
+ * TAB character
+ */
+ private static final int TAB = 0x9; // CodForChk_Dis_Magic
+
+ /**
+ * Plugin engine
+ */
+ private PluginEngine pluginEngine;
+
+ /**
+ * Constructor. Empty public constructor is needed by test class.
+ */
+ public PluginTracePropertyVerifier() {
+
+ }
+
+ /**
+ * Constructor
+ *
+ * @param engine
+ * plug-in engine
+ */
+ PluginTracePropertyVerifier(PluginEngine engine) {
+ this.pluginEngine = engine;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.model.TraceObjectPropertyVerifier#
+ * checkConstantProperties(com.nokia.tracecompiler.model.TraceConstantTable,
+ * com.nokia.tracecompiler.model.TraceConstantTableEntry, int,
+ * java.lang.String)
+ */
+ public void checkConstantProperties(TraceConstantTable table,
+ TraceConstantTableEntry entry, int id, String value)
+ throws TraceCompilerException {
+ if (!SourceUtils.isValidName(value)) {
+ throw new TraceCompilerException(
+ TraceCompilerErrorCode.INVALID_CONSTANT_VALUE);
+ }
+ if (table != null) {
+ // If table exists, the value and ID must be unique
+ TraceConstantTableEntry old = table.findEntryByID(id);
+ if (old != null && old != entry) {
+ throw new TraceCompilerException(
+ TraceCompilerErrorCode.DUPLICATE_CONSTANT_ID);
+ }
+ old = table.findEntryByName(value);
+ if (old != null && old != entry) {
+ throw new TraceCompilerException(
+ TraceCompilerErrorCode.DUPLICATE_CONSTANT_VALUE);
+ }
+ }
+ Iterator itr = pluginEngine.getPlugins();
+ while (itr.hasNext()) {
+ TraceCompilerPlugin provider = itr.next();
+ if (provider instanceof TraceObjectPropertyVerifier) {
+ ((TraceObjectPropertyVerifier) provider)
+ .checkConstantProperties(table, entry, id, value);
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.model.TraceObjectPropertyVerifier#
+ * checkConstantTableProperties(com.nokia.tracecompiler.model.TraceModel,
+ * com.nokia.tracecompiler.model.TraceConstantTable, int,
+ * java.lang.String)
+ */
+ public void checkConstantTableProperties(TraceModel model,
+ TraceConstantTable table, int id, String tableName)
+ throws TraceCompilerException {
+ if (!SourceUtils.isValidName(tableName)) {
+ throw new TraceCompilerException(
+ TraceCompilerErrorCode.INVALID_CONSTANT_TABLE_NAME, false);
+ }
+ TraceConstantTable old = model.findConstantTableByID(id);
+ if (old != null && old != table) {
+ throw new TraceCompilerException(
+ TraceCompilerErrorCode.DUPLICATE_CONSTANT_TABLE_ID);
+ }
+ old = model.findConstantTableByName(tableName);
+ if (old != null && old != table) {
+ throw new TraceCompilerException(
+ TraceCompilerErrorCode.DUPLICATE_CONSTANT_TABLE_NAME);
+ }
+ Iterator itr = pluginEngine.getPlugins();
+ while (itr.hasNext()) {
+ TraceCompilerPlugin provider = itr.next();
+ if (provider instanceof TraceObjectPropertyVerifier) {
+ ((TraceObjectPropertyVerifier) provider)
+ .checkConstantTableProperties(model, table, id,
+ tableName);
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.model.TraceObjectPropertyVerifier#
+ * checkTraceGroupProperties(com.nokia.tracecompiler.model.TraceModel,
+ * com.nokia.tracecompiler.model.TraceGroup, int, java.lang.String)
+ */
+ public void checkTraceGroupProperties(TraceModel model, TraceGroup group,
+ int id, String name) throws TraceCompilerException {
+ if (!SourceUtils.isValidName(name)) {
+ throw new TraceCompilerException(
+ TraceCompilerErrorCode.INVALID_GROUP_NAME);
+ } else if ((id < 0) || (id > TraceCompilerEngineGlobals.MAX_GROUP_ID)) {
+ RangeErrorParameters params = new RangeErrorParameters();
+ params.start = 0;
+ params.end = TraceCompilerEngineGlobals.MAX_GROUP_ID;
+ params.isHex = true;
+ throw new TraceCompilerException(
+ TraceCompilerErrorCode.INVALID_GROUP_ID, params);
+ } else {
+ TraceGroup old = model.findGroupByID(id);
+ // this condition is to check that user defined group ids are unique.
+ // system defined group ids at present are not required to be unique.
+ if ((old != null) && (old != group) && (id >= GroupNames.USER_GROUP_ID_FIRST ) && (id <= GroupNames.USER_GROUP_ID_LAST )) {
+ throw new TraceCompilerException(
+ TraceCompilerErrorCode.DUPLICATE_GROUP_ID);
+ }
+ old = model.findGroupByName(name);
+ if (old != null && old != group) {
+ throw new TraceCompilerException(
+ TraceCompilerErrorCode.DUPLICATE_GROUP_NAME);
+ }
+ }
+ Iterator itr = pluginEngine.getPlugins();
+ while (itr.hasNext()) {
+ TraceCompilerPlugin provider = itr.next();
+ if (provider instanceof TraceObjectPropertyVerifier) {
+ ((TraceObjectPropertyVerifier) provider)
+ .checkTraceGroupProperties(model, group, id, name);
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.model.TraceObjectPropertyVerifier#
+ * checkTraceModelProperties(com.nokia.tracecompiler.model.TraceModel,
+ * int, java.lang.String, java.lang.String)
+ */
+ public void checkTraceModelProperties(TraceModel model, int id,
+ String name, String path) throws TraceCompilerException {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.model.TraceObjectPropertyVerifier#
+ * checkTraceParameterProperties(com.nokia.tracecompiler.model.Trace,
+ * com.nokia.tracecompiler.model.TraceParameter, int, java.lang.String,
+ * java.lang.String)
+ */
+ public void checkTraceParameterProperties(Trace owner,
+ TraceParameter parameter, int id, String name, String type)
+ throws TraceCompilerException {
+ if (!SourceUtils.isValidParameterName(name)) {
+ throw new TraceCompilerException(
+ TraceCompilerErrorCode.INVALID_PARAMETER_NAME);
+ }
+ TraceParameter old = owner.findParameterByID(id);
+ if (old != null && old != parameter) {
+ throw new TraceCompilerException(
+ TraceCompilerErrorCode.DUPLICATE_PARAMETER_ID);
+ }
+ old = owner.findParameterByName(name);
+ if (old != null && old != parameter) {
+ throw new TraceCompilerException(
+ TraceCompilerErrorCode.DUPLICATE_PARAMETER_NAME);
+ }
+ Iterator itr = pluginEngine.getPlugins();
+ while (itr.hasNext()) {
+ TraceCompilerPlugin provider = itr.next();
+ if (provider instanceof TraceObjectPropertyVerifier) {
+ ((TraceObjectPropertyVerifier) provider)
+ .checkTraceParameterProperties(owner, parameter, id,
+ name, type);
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.model.TraceObjectPropertyVerifier#
+ * checkTraceProperties(com.nokia.tracecompiler.model.TraceGroup,
+ * com.nokia.tracecompiler.model.Trace, int, java.lang.String,
+ * java.lang.String)
+ */
+ public void checkTraceProperties(TraceGroup group, Trace trace, int id,
+ String name, String data) throws TraceCompilerException {
+ if (!isValidData(data)) {
+ throw new TraceCompilerException(
+ TraceCompilerErrorCode.INVALID_TRACE_DATA);
+ } else if (!SourceUtils.isValidName(name)) {
+ throw new TraceCompilerException(
+ TraceCompilerErrorCode.INVALID_TRACE_NAME);
+ } else if ((id < 0) || (id > TraceCompilerEngineGlobals.MAX_TRACE_ID)) {
+ RangeErrorParameters params = new RangeErrorParameters();
+ params.start = 0;
+ params.end = TraceCompilerEngineGlobals.MAX_TRACE_ID;
+ params.isHex = true;
+ throw new TraceCompilerException(
+ TraceCompilerErrorCode.INVALID_TRACE_ID, params);
+ } else {
+ // Verifies the trace name is globally unique
+ Trace old = TraceCompilerEngineGlobals.getTraceModel().findTraceByName(
+ name);
+ if (old != trace && old != null) {
+ throw new TraceCompilerException(
+ TraceCompilerErrorCode.DUPLICATE_TRACE_NAME);
+ }
+ if (group != null) {
+ // If group exists, the trace ID and text must be unique within
+ // the group
+ old = group.findTraceByID(id);
+ if (old != trace && old != null) {
+ // Trace ID's must be unique within group
+ throw new TraceCompilerException(
+ TraceCompilerErrorCode.DUPLICATE_TRACE_ID);
+ }
+ }
+ }
+ Iterator itr = pluginEngine.getPlugins();
+ while (itr.hasNext()) {
+ TraceCompilerPlugin provider = itr.next();
+ if (provider instanceof TraceObjectPropertyVerifier) {
+ ((TraceObjectPropertyVerifier) provider).checkTraceProperties(
+ group, trace, id, name, data);
+ }
+ }
+ }
+
+ /**
+ * Checks the validity of data
+ *
+ * @param data
+ * the data
+ * @return true if valid
+ */
+ private boolean isValidData(String data) {
+ boolean retval;
+ if (data != null) {
+ retval = true;
+ for (int i = 0; i < data.length() && retval; i++) {
+ char c = data.charAt(i);
+ // Unescaped quotes are not allowed
+ if (c == SourceConstants.QUOTE_CHAR
+ && (i == 0 || data.charAt(i - 1) != SourceConstants.BACKSLASH_CHAR)) {
+ retval = false;
+ } else {
+ retval = isValidDataChar(c);
+ }
+ }
+ } else {
+ retval = false;
+ }
+ return retval;
+ }
+
+ /**
+ * Checks data character validity
+ *
+ * @param c
+ * character
+ * @return true if valid
+ */
+ private boolean isValidDataChar(char c) {
+ // Special and extended characters are not allowed, except TAB
+ return c >= DATA_CHAR_START && c <= DATA_CHAR_END || c == TAB;
+ }
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/plugin/TraceAPIPluginManager.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/plugin/TraceAPIPluginManager.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,52 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Trace API plug-in manager interface
+*
+*/
+package com.nokia.tracecompiler.engine.plugin;
+
+import com.nokia.tracecompiler.model.TraceModelExtension;
+import com.nokia.tracecompiler.plugin.TraceAPIFormatter;
+import com.nokia.tracecompiler.plugin.TraceAPIParser;
+
+/**
+ * Trace API plug-in manager interface
+ *
+ */
+public interface TraceAPIPluginManager extends TraceModelExtension {
+
+ /**
+ * Adds the formatter API's from the plug-in
+ *
+ * @param formatters
+ * the formatters
+ */
+ public void addFormatters(TraceAPIFormatter[] formatters);
+
+ /**
+ * Adds the parser API's from the plug-in
+ *
+ * @param parsers
+ * the parsers
+ */
+ public void addParsers(TraceAPIParser[] parsers);
+
+ /**
+ * Sets the default API to the model.
+ */
+ public void createDefaultAPI();
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/plugin/package.html
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/plugin/package.html Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,3 @@
+
+Plug-in manager and related classes
+
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/project/Messages.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/project/Messages.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,63 @@
+/*
+* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Localization for project package
+*
+*/
+package com.nokia.tracecompiler.engine.project;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+/**
+ * Localization for project package
+ *
+ */
+class Messages {
+
+ /**
+ * Bundle name
+ */
+ private static final String BUNDLE_NAME = "com.nokia.tracecompiler.engine.project.messages"; //$NON-NLS-1$
+
+ /**
+ * Bundle
+ */
+ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
+ .getBundle(BUNDLE_NAME);
+
+ /**
+ * Prevents construction
+ */
+ private Messages() {
+ }
+
+ /**
+ * Gets localized string based on key
+ *
+ * @param key
+ * the resource key
+ * @return the localized resource
+ */
+ public static String getString(String key) {
+ String value;
+ try {
+ value = RESOURCE_BUNDLE.getString(key);
+ } catch (MissingResourceException e) {
+ value = '!' + key + '!';
+ }
+ return value;
+ }
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/project/ProjectConstants.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/project/ProjectConstants.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,168 @@
+/*
+* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Constant values related to project files
+*
+*/
+package com.nokia.tracecompiler.engine.project;
+
+/**
+ * Constant values related to project files
+ *
+ */
+public interface ProjectConstants {
+
+ /**
+ * Title of the cache file
+ */
+ String FIXED_ID_DEFINITION_FILE_TITLE = Messages
+ .getString("ProjectConstants.FixedIdDefinitionFileTitle"); //$NON-NLS-1$
+
+ /**
+ * Cache file extension
+ */
+ String CACHE_FILE_NAME = "tracecompiler.cache"; //$NON-NLS-1$
+
+ /**
+ * Fixed ID file extension
+ */
+ String FIXED_ID_DEFINITIONS_FILE_NAME = "fixed_id.definitions"; //$NON-NLS-1$
+
+ /**
+ * Extension for the file within zip file
+ */
+ String FILE_EXTENSION = ".xml"; //$NON-NLS-1$
+
+ /**
+ * Less than escape sequence
+ */
+ String LT = "<"; //$NON-NLS-1$
+
+ /**
+ * Greater than escape sequence
+ */
+ String GT = ">"; //$NON-NLS-1$
+
+ /**
+ * Indent
+ */
+ String INDENT = " "; //$NON-NLS-1$
+
+ /**
+ * End a tag
+ */
+ String END_TAG = ">"; //$NON-NLS-1$
+
+ /**
+ * Start of end tag
+ */
+ String START_END_TAG = ""; //$NON-NLS-1$
+
+ /**
+ * End tag with line feed
+ */
+ String END_TAG_LF = ">\r\n"; //$NON-NLS-1$
+
+ /**
+ * Start a tag
+ */
+ String START_TAG = "<"; //$NON-NLS-1$
+
+ /**
+ * Extension tag
+ */
+ String EXTENSION_TAG = "extension"; //$NON-NLS-1$
+
+ /**
+ * Data tag
+ */
+ String DATA_TAG = "data"; //$NON-NLS-1$
+
+ /**
+ * Name tag
+ */
+ String NAME_TAG = "name"; //$NON-NLS-1$
+
+ /**
+ * Object ID tag
+ */
+ String ID_TAG = "id"; //$NON-NLS-1$
+
+ /**
+ * Constant table entry tag
+ */
+ String CONSTANT_TABLE_ENTRY_TAG = "entry"; //$NON-NLS-1$
+
+ /**
+ * Parameter tag
+ */
+ String PARAMETER_TAG = "parameter"; //$NON-NLS-1$
+
+ /**
+ * Trace text tag
+ */
+ String TRACE_TEXT_TAG = "text"; //$NON-NLS-1$
+
+ /**
+ * Trace tag
+ */
+ String TRACE_TAG = "trace"; //$NON-NLS-1$
+
+ /**
+ * Parameter type tag
+ */
+ String PARAMETER_TYPE_TAG = "type"; //$NON-NLS-1$
+
+ /**
+ * Constant table tag
+ */
+ String CONSTANT_TABLE_TAG = "table"; //$NON-NLS-1$
+
+ /**
+ * Group tag
+ */
+ String GROUP_TAG = "group"; //$NON-NLS-1$
+
+ /**
+ * Model tag
+ */
+ String MODEL_TAG = "model"; //$NON-NLS-1$
+
+ /**
+ * Location tag
+ */
+ String LOCATION_TAG = "location"; //$NON-NLS-1$
+
+ /**
+ * File tag
+ */
+ String LOCATION_FILE_TAG = "file"; //$NON-NLS-1$
+
+ /**
+ * Line tag
+ */
+ String LOCATION_LINE_TAG = "line"; //$NON-NLS-1$
+
+ /**
+ * Class name tag
+ */
+ String LOCATION_CLASS_NAME_TAG = "class"; //$NON-NLS-1$
+
+ /**
+ * Function name tag
+ */
+ String LOCATION_FUNCTION_NAME_TAG = "function"; //$NON-NLS-1$
+
+}
diff -r 813b186005b6 -r 838cdffd57ce tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/project/ProjectEngine.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tracefw/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/engine/project/ProjectEngine.java Mon Aug 23 15:29:36 2010 +0300
@@ -0,0 +1,294 @@
+/*
+* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+* Trace project file manager
+*
+*/
+package com.nokia.tracecompiler.engine.project;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Enumeration;
+
+import com.nokia.tracecompiler.engine.TraceCompilerEngineBase;
+import com.nokia.tracecompiler.engine.TraceCompilerEngineErrorCodes.TraceCompilerErrorCode;
+import com.nokia.tracecompiler.engine.plugin.TraceAPIPluginManager;
+import com.nokia.tracecompiler.file.FileUtils;
+import com.nokia.tracecompiler.model.TraceCompilerException;
+import com.nokia.tracecompiler.model.TraceModel;
+import com.nokia.tracecompiler.project.GroupNames;
+import com.nokia.tracecompiler.project.ProjectUtils;
+
+/**
+ * Trace project engine
+ *
+ */
+public final class ProjectEngine extends TraceCompilerEngineBase {
+
+ /**
+ * Parameters for create project
+ */
+ private class CreateProjectParameters {
+
+ /**
+ * Trace project path
+ */
+ String traceProjectPath;
+
+ /**
+ * Trace project name
+ */
+ String traceProjectName;
+
+ /**
+ * Trace project ID
+ */
+ int traceProjectID;
+
+ }
+
+ /**
+ * Default project ID
+ */
+ private static final int DEFAULT_PROJECT_ID = 0x0; // CodForChk_Dis_Magic
+
+ /**
+ * Trace model
+ */
+ private TraceModel model;
+
+ /**
+ * Trace directory name
+ */
+ public static String traceFolderName;
+
+ /**
+ * Constructor
+ *
+ * @param model
+ * the trace model
+ */
+ public ProjectEngine(TraceModel model) {
+ this.model = model;
+ }
+
+ /**
+ * Opens trace project
+ *
+ * @param projectPath
+ * the path to the project to be opened
+ * @param modelName
+ * the name for the model or null to use directory name
+ * @throws TraceCompilerException
+ * if opening fails
+ */
+ public void openTraceProject(String projectPath, String modelName)
+ throws TraceCompilerException {
+ if (projectPath != null) {
+ CreateProjectParameters parameters = createParameters(projectPath,
+ modelName);
+
+ // Create empty project
+ if (model.getExtension(TraceCompilerProject.class) == null) {
+ createEmptyProjectFile(parameters);
+ }
+ } else {
+
+ // If fileName is null, there's no open source files. In
+ // that the project cannot be created
+ throw new TraceCompilerException(
+ TraceCompilerErrorCode.SOURCE_NOT_OPEN);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.TraceCompilerEngine#projectOpened()
+ */
+ @Override
+ public void projectOpened() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.TraceCompilerEngine#projectClosed()
+ */
+ @Override
+ public void projectClosed() {
+ model.removeExtensions(TraceCompilerProject.class);
+ model.removeExtensions(TraceIDCache.class);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.nokia.tracecompiler.engine.TraceCompilerEngine#exportProject()
+ */
+ @Override
+ public void exportProject() {
+ try {
+
+ // The fixed id definitions file is updated even there are no traces
+ // in case that old fixed id definitions file exist
+ syncFixedIdDefinitionsFile();
+ } catch (TraceCompilerException e) {
+ }
+ }
+
+ /**
+ * Updated fixed id definitions file
+ *
+ * @throws TraceCompilerException
+ * if update fails
+ */
+ private void syncFixedIdDefinitionsFile() throws TraceCompilerException {
+ TraceIDCache cache = model.getExtension(TraceIDCache.class);
+ // Create trace Id cache if it does not exist
+ if (cache == null) {
+ String path = ProjectUtils.getLocationForFile(model,
+ ProjectEngine.traceFolderName,
+ ProjectConstants.FIXED_ID_DEFINITIONS_FILE_NAME, false);
+ if (path != null) {
+ cache = new TraceIDCache(new File(path).getParent());
+ model.addExtension(cache);
+ }
+ }
+ if (cache != null) {
+ File cacheFile = new File(cache.getAbsolutePath());
+
+ // The fixed id definitions file is updated in case that there are
+ // traces in model
+ if (model.hasTraces()) {
+ // Try to save Ids to fixed Id definition file
+ try {
+ SortedProperties ids = new SortedProperties();
+ // Save Ids from model to fixed Id properties
+ model.saveIDs(ids);
+
+ // If there are some fixed Ids in that are not used anymore,
+ // keep also those Ids in defininiton file, but mark those
+ // ids as obsolete
+ ids = handleObsoleteIds(ids);
+
+ // Rewrites the trace Id cache file
+ OutputStream fos = FileUtils.createOutputStream(cacheFile);
+ ids.store(fos,
+ ProjectConstants.FIXED_ID_DEFINITION_FILE_TITLE);
+ fos.close();
+ cache.postFileWrittenEvent(cache.getAbsolutePath());
+ } catch (IOException e) {
+ cacheFile.delete();
+ }
+ }
+ }
+ }
+
+ /**
+ * Handle obsolete Ids
+ *
+ * @param ids
+ * Ids
+ */
+ private SortedProperties handleObsoleteIds(SortedProperties ids) {
+ SortedProperties fixedIds = model.getFixedIds();
+ if (fixedIds != null) {
+ Enumeration