tracesrv/tracecompiler/src/com.nokia.tracecompiler/src/com/nokia/tracecompiler/model/TraceParameter.java
changeset 56 aa2539c91954
equal deleted inserted replaced
54:a151135b0cf9 56:aa2539c91954
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 * All trace objects may contain parameters
       
    17 *
       
    18 */
       
    19 package com.nokia.tracecompiler.model;
       
    20 
       
    21 /**
       
    22  * Traces may contain parameters
       
    23  * 
       
    24  */
       
    25 public class TraceParameter extends TraceObject {
       
    26 
       
    27 	/**
       
    28 	 * The type of this parameter
       
    29 	 */
       
    30 	private String type;
       
    31 
       
    32 	/**
       
    33 	 * Hexadecimal (%p), pointer type
       
    34 	 */
       
    35 	public static final String POINTER = "void*"; //$NON-NLS-1$
       
    36 	
       
    37 	/**
       
    38 	 * Signed decimal (%d), 32-bit type
       
    39 	 */
       
    40 	public static final String SDEC32 = "int32"; //$NON-NLS-1$
       
    41 
       
    42 	/**
       
    43 	 * Hexadecimal (%x), 32-bit type
       
    44 	 */
       
    45 	public static final String HEX32 = "hex32"; //$NON-NLS-1$
       
    46 
       
    47 	/**
       
    48 	 * Unsigned decimal (%u), 32-bit type
       
    49 	 */
       
    50 	public static final String UDEC32 = "uint32"; //$NON-NLS-1$
       
    51 	
       
    52 	/**
       
    53 	 * Octal (%o), 32-bit type
       
    54 	 */
       
    55 	public static final String OCT32 = "oct32"; //$NON-NLS-1$	
       
    56 
       
    57 	/**
       
    58 	 * Signed decimal (%hd), 16-bit type
       
    59 	 */
       
    60 	public static final String SDEC16 = "int16"; //$NON-NLS-1$
       
    61 
       
    62 	/**
       
    63 	 * Hexadecimal (%hx), 16-bit type
       
    64 	 */
       
    65 	public static final String HEX16 = "hex16"; //$NON-NLS-1$
       
    66 
       
    67 	/**
       
    68 	 * Unsigned decimal (%hu), 16-bit type
       
    69 	 */
       
    70 	public static final String UDEC16 = "uint16"; //$NON-NLS-1$
       
    71 	
       
    72 	/**
       
    73 	 * Octal (%ho), 16-bit type
       
    74 	 */
       
    75 	public static final String OCT16 = "oct16"; //$NON-NLS-1$	
       
    76 
       
    77 	/**
       
    78 	 * Signed decimal (%hhd), 8-bit type
       
    79 	 */
       
    80 	public static final String SDEC8 = "int8"; //$NON-NLS-1$
       
    81 
       
    82 	/**
       
    83 	 * Hexadecimal (%hhx), 8-bit type
       
    84 	 */
       
    85 	public static final String HEX8 = "hex8"; //$NON-NLS-1$
       
    86 
       
    87 	/**
       
    88 	 * Unsigned decimal (%hhu), 8-bit type
       
    89 	 */
       
    90 	public static final String UDEC8 = "uint8"; //$NON-NLS-1$
       
    91 	
       
    92 	/**
       
    93 	 * Octal (%hho), 8-bit type
       
    94 	 */
       
    95 	public static final String OCT8 = "oct8"; //$NON-NLS-1$
       
    96 
       
    97 	/**
       
    98 	 * Signed decimal (%ld), 64-bit type
       
    99 	 */
       
   100 	public static final String SDEC64 = "int64"; //$NON-NLS-1$
       
   101 
       
   102 	/**
       
   103 	 * Time, 64-bit type
       
   104 	 */
       
   105 	public static final String TIME = "time"; //$NON-NLS-1$	
       
   106 	
       
   107 	/**
       
   108 	 * Hexadecimal (%lx), 64-bit type
       
   109 	 */
       
   110 	public static final String HEX64 = "hex64"; //$NON-NLS-1$
       
   111 
       
   112 	/**
       
   113 	 * Unsigned decimal (%lu), 64-bit type
       
   114 	 */
       
   115 	public static final String UDEC64 = "uint64"; //$NON-NLS-1$
       
   116 	
       
   117 	/**
       
   118 	 * Octal (%lo), 64-bit type
       
   119 	 */
       
   120 	public static final String OCT64 = "oct64"; //$NON-NLS-1$	
       
   121 
       
   122 	/**
       
   123 	 * Ascii string (%s) type
       
   124 	 */
       
   125 	public static final String ASCII = "ascii"; //$NON-NLS-1$
       
   126 
       
   127 	/**
       
   128 	 * Unicode string (%S) type
       
   129 	 */
       
   130 	public static final String UNICODE = "unicode"; //$NON-NLS-1$
       
   131 
       
   132 	/**
       
   133 	 * Fixed floating point (%f), 64-bit
       
   134 	 */
       
   135 	public static final String FLOAT_FIX = "ffix"; //$NON-NLS-1$
       
   136 
       
   137 	/**
       
   138 	 * Exponent floating point (%e), 64-bit
       
   139 	 */
       
   140 	public static final String FLOAT_EXP = "fexp"; //$NON-NLS-1$
       
   141 
       
   142 	/**
       
   143 	 * Fixed / exponential floating point (%g), 64-bit
       
   144 	 */
       
   145 	public static final String FLOAT_OPT = "fopt"; //$NON-NLS-1$
       
   146 
       
   147 	/**
       
   148 	 * The trace this parameter belongs to
       
   149 	 */
       
   150 	private Trace owner;
       
   151 
       
   152 	/**
       
   153 	 * Constructor
       
   154 	 * 
       
   155 	 * @param owner
       
   156 	 *            the object owning this parameter
       
   157 	 */
       
   158 	public TraceParameter(Trace owner) {
       
   159 		setModel(owner.getModel());
       
   160 		owner.addParameter(this);
       
   161 		this.owner = owner;
       
   162 	}
       
   163 
       
   164 	/**
       
   165 	 * Constructor, which inserts the parameter into specified index
       
   166 	 * 
       
   167 	 * @param owner
       
   168 	 *            the object owning this parameter
       
   169 	 * @param index
       
   170 	 *            the parameter index
       
   171 	 */
       
   172 	TraceParameter(Trace owner, int index) {
       
   173 		setModel(owner.getModel());
       
   174 		owner.insertParameter(index, this);
       
   175 		this.owner = owner;
       
   176 	}
       
   177 
       
   178 	/**
       
   179 	 * Gets the trace this parameter is associated to.
       
   180 	 * 
       
   181 	 * @return the trace
       
   182 	 */
       
   183 	public Trace getTrace() {
       
   184 		return owner;
       
   185 	}
       
   186 
       
   187 	/**
       
   188 	 * Sets the parameter type. Generates propertyUpdated event to model
       
   189 	 * listeners if type changes
       
   190 	 * 
       
   191 	 * @see TraceModelListener#propertyUpdated(TraceObject, int)
       
   192 	 * @param type
       
   193 	 *            the parameter type
       
   194 	 * @throws TraceCompilerException 
       
   195 	 */
       
   196 	public void setType(String type) throws TraceCompilerException {
       
   197 		if (!type.equals(this.type)) {
       
   198 			removeTableReference();
       
   199 			this.type = type;
       
   200 			addTableReference();
       
   201 			getModel().notifyPropertyUpdated(this, TraceModelListener.TYPE);
       
   202 		}
       
   203 	}
       
   204 
       
   205 	/**
       
   206 	 * Gets the parameter type
       
   207 	 * 
       
   208 	 * @return the parameter type
       
   209 	 */
       
   210 	public String getType() {
       
   211 		return type;
       
   212 	}
       
   213 
       
   214 	/*
       
   215 	 * (non-Javadoc)
       
   216 	 * 
       
   217 	 * @see com.nokia.tracecompiler.model.TraceObject#reset()
       
   218 	 */
       
   219 	@Override
       
   220 	void reset() {
       
   221 		removeTableReference();
       
   222 		super.reset();
       
   223 	}
       
   224 
       
   225 	/**
       
   226 	 * Adds a constant table reference
       
   227 	 */
       
   228 	private void addTableReference() {
       
   229 		if (type != null) {
       
   230 			TraceConstantTable table = getModel().findConstantTableByName(type);
       
   231 			if (table != null) {
       
   232 				table.addParameterReference(this);
       
   233 			}
       
   234 		}
       
   235 	}
       
   236 
       
   237 	/**
       
   238 	 * Removes the constant table reference
       
   239 	 */
       
   240 	private void removeTableReference() {
       
   241 		if (type != null) {
       
   242 			TraceConstantTable table = getModel().findConstantTableByName(type);
       
   243 			if (table != null) {
       
   244 				table.removeParameterReference(this);
       
   245 			}
       
   246 		}
       
   247 	}
       
   248 
       
   249 }