trace/traceviewer/com.nokia.traceviewer/src/com/nokia/traceviewer/engine/dataprocessor/Decoder.java
changeset 11 5b9d4d8641ce
equal deleted inserted replaced
10:ed1c9f64298a 11:5b9d4d8641ce
       
     1 /*
       
     2  * Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies). 
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:
       
    15  *
       
    16  * Decoder class
       
    17  *
       
    18  */
       
    19 package com.nokia.traceviewer.engine.dataprocessor;
       
    20 
       
    21 import com.nokia.traceviewer.TraceViewerPlugin;
       
    22 import com.nokia.traceviewer.action.OpenDecodeFileAction;
       
    23 import com.nokia.traceviewer.engine.DecodeProvider;
       
    24 import com.nokia.traceviewer.engine.TraceProperties;
       
    25 import com.nokia.traceviewer.engine.TraceViewerGlobals;
       
    26 import com.nokia.traceviewer.engine.preferences.PreferenceConstants;
       
    27 
       
    28 /**
       
    29  * Decoder class
       
    30  * 
       
    31  */
       
    32 public class Decoder implements DataProcessor {
       
    33 
       
    34 	/**
       
    35 	 * Interval how often to update progressbar
       
    36 	 */
       
    37 	private static final int PROGRESSBAR_UPDATE_INTERVAL = 100;
       
    38 
       
    39 	/**
       
    40 	 * Decoder got from decodeProvider
       
    41 	 */
       
    42 	private DecodeProvider decoder;
       
    43 
       
    44 	/**
       
    45 	 * Offset where decoding of traces after decode file opening is so long that
       
    46 	 * we can start showing traces
       
    47 	 */
       
    48 	private int startShowingTracesAgainFromCount;
       
    49 
       
    50 	/**
       
    51 	 * Determines if Btrace variables (Thread ID, CPU ID) should be shown
       
    52 	 */
       
    53 	private boolean showBtraceVariables;
       
    54 
       
    55 	/**
       
    56 	 * Constructor
       
    57 	 */
       
    58 	public Decoder() {
       
    59 
       
    60 		// Get show BTrace variables option
       
    61 		showBtraceVariables = TraceViewerPlugin.getDefault()
       
    62 				.getPreferenceStore().getBoolean(
       
    63 						PreferenceConstants.SHOW_BTRACE_VARIABLES_CHECKBOX);
       
    64 	}
       
    65 
       
    66 	/*
       
    67 	 * (non-Javadoc)
       
    68 	 * 
       
    69 	 * @see
       
    70 	 * com.nokia.traceviewer.engine.DataProcessor#processData(com.nokia.traceviewer
       
    71 	 * .engine.TraceProperties)
       
    72 	 */
       
    73 	public void processData(TraceProperties properties) {
       
    74 		TraceViewerGlobals.debug("processData in Decoder", //$NON-NLS-1$
       
    75 				TraceViewerGlobals.DebugLevel.TEST);
       
    76 		if (decoder == null && TraceViewerGlobals.getDecodeProvider() != null) {
       
    77 			decoder = TraceViewerGlobals.getDecodeProvider();
       
    78 		}
       
    79 
       
    80 		// Needs to be binary trace to be decoded
       
    81 		if (properties.binaryTrace && decoder != null
       
    82 				&& decoder.isModelLoadedAndValid()) {
       
    83 			decoder.decodeTrace(properties.byteBuffer, properties);
       
    84 		}
       
    85 
       
    86 		// Insert BTrace variables if there is any
       
    87 		if (showBtraceVariables
       
    88 				&& properties.bTraceInformation.hasInformation()
       
    89 				&& properties.traceString != null) {
       
    90 
       
    91 			StringBuilder tmp = new StringBuilder(properties.traceString
       
    92 					.length() * 2);
       
    93 
       
    94 			// CPU ID
       
    95 			if (properties.bTraceInformation.getCpuId() != -1) {
       
    96 				tmp.append(Messages.getString("Decoder.CpuIdText")); //$NON-NLS-1$
       
    97 				tmp.append(properties.bTraceInformation.getCpuId());
       
    98 				tmp.append(Messages.getString("Decoder.CpuTextDelimeter"));//$NON-NLS-1$
       
    99 			}
       
   100 
       
   101 			tmp.append(properties.traceString);
       
   102 
       
   103 			// Thread ID
       
   104 			if (properties.bTraceInformation.getThreadId() != 0) {
       
   105 				tmp.append(Messages.getString("Decoder.ThreadIdText")); //$NON-NLS-1$
       
   106 				tmp.append(Integer.toHexString(properties.bTraceInformation
       
   107 						.getThreadId()));
       
   108 			}
       
   109 			properties.traceString = tmp.toString();
       
   110 		}
       
   111 
       
   112 		// Update progressBar
       
   113 		if (TraceViewerGlobals.getTraceViewer().getView() != null) {
       
   114 			updateProgressBar(properties);
       
   115 		}
       
   116 	}
       
   117 
       
   118 	/**
       
   119 	 * Updates progressBar if needed
       
   120 	 * 
       
   121 	 * @param properties
       
   122 	 *            trace properties
       
   123 	 */
       
   124 	private void updateProgressBar(TraceProperties properties) {
       
   125 		// Update possible progressBar
       
   126 		OpenDecodeFileAction decodeAction = ((OpenDecodeFileAction) TraceViewerGlobals
       
   127 				.getTraceViewer().getView().getActionFactory()
       
   128 				.getOpenDecodeFileAction());
       
   129 		int traceCount = TraceViewerGlobals.getTraceViewer()
       
   130 				.getDataReaderAccess().getCurrentDataReader().getTraceCount();
       
   131 
       
   132 		if (decodeAction.isDecodingTraces()) {
       
   133 			if (traceCount % PROGRESSBAR_UPDATE_INTERVAL == 0) {
       
   134 				decodeAction.getProgressBarDialog().updateProgressBar(
       
   135 						TraceViewerGlobals.getTraceViewer()
       
   136 								.getDataReaderAccess().getCurrentDataReader()
       
   137 								.getTraceCount());
       
   138 			}
       
   139 
       
   140 			// Start showing traces again
       
   141 			if (traceCount >= startShowingTracesAgainFromCount) {
       
   142 				properties.traceConfiguration.setShowInView(true);
       
   143 				startShowingTracesAgainFromCount = Integer.MAX_VALUE;
       
   144 			}
       
   145 		}
       
   146 	}
       
   147 
       
   148 	/**
       
   149 	 * Set startShowingTracesAgainFromCount
       
   150 	 * 
       
   151 	 * @param offset
       
   152 	 *            offset
       
   153 	 */
       
   154 	public void setStartShowingTracesAgainOffset(int offset) {
       
   155 		startShowingTracesAgainFromCount = offset;
       
   156 	}
       
   157 
       
   158 	/**
       
   159 	 * Sets show BTrace variables boolean
       
   160 	 * 
       
   161 	 * @param showVariables
       
   162 	 *            if true, show BTrace variables
       
   163 	 */
       
   164 	public void setShowBTraceVariables(boolean showVariables) {
       
   165 		this.showBtraceVariables = showVariables;
       
   166 	}
       
   167 
       
   168 }