crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbolLib/CodeSeg/Resolver/CodeSegResolverOperation.cs
changeset 0 818e61de6cd1
equal deleted inserted replaced
-1:000000000000 0:818e61de6cd1
       
     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 */
       
    17 using System;
       
    18 using System.IO;
       
    19 using System.Threading;
       
    20 using System.Text;
       
    21 using System.Text.RegularExpressions;
       
    22 using System.Collections.Specialized;
       
    23 using System.Collections.Generic;
       
    24 using System.ComponentModel;
       
    25 using SymbianUtils;
       
    26 using SymbianUtils.SerializedOperations;
       
    27 using SymbolLib.Sources.Map.Parser;
       
    28 
       
    29 namespace SymbolLib.CodeSegDef
       
    30 {
       
    31 	public abstract class CodeSegResolverOperation : SerializedOperation
       
    32     {
       
    33         #region Events
       
    34         public delegate void LocatedFileNameHandler( string aFileName );
       
    35         public event LocatedFileNameHandler LocatedFile;
       
    36         public delegate void RawTextHandler( string aText );
       
    37         public event RawTextHandler RawText;
       
    38         #endregion
       
    39 
       
    40         #region Constructors
       
    41         protected CodeSegResolverOperation( CodeSegResolver aResolver, bool aResetResolver )
       
    42             : base( false )
       
    43 		{
       
    44             iResolver = aResolver;
       
    45             iResetResolver = aResetResolver;
       
    46 		}
       
    47 		#endregion
       
    48 
       
    49         #region From SerializedOperation
       
    50         protected override void PerformOperation()
       
    51         {
       
    52             base.Trace( "" );
       
    53             base.Trace( " => => => => => => => => => => => => => => => => => => => => => " );
       
    54             base.Trace( "" );
       
    55             base.Trace( "PerformOperation() - START - this: " + this.GetType().Name );
       
    56 
       
    57             if ( iResetResolver )
       
    58             {
       
    59                 iResolver.Clear();
       
    60             }
       
    61 
       
    62             this.NotifyRawText( "Scanning..." );
       
    63             Scan();
       
    64 
       
    65             base.Trace( "PerformOperation() - END - this: " + this.GetType().Name );
       
    66         }
       
    67         #endregion
       
    68 
       
    69         #region API - new framework
       
    70         protected abstract void Scan();
       
    71         #endregion
       
    72 
       
    73         #region API
       
    74         protected void Add( CodeSegResolverEntry aEntry )
       
    75         {
       
    76             NotifyFile( aEntry.ImageFileNameAndPath );
       
    77             base.Trace( "[{0}] device: {1}, host: {2}", this.GetType().Name, aEntry.ImageFileNameAndPath, aEntry.EnvironmentFileNameAndPath );
       
    78             //
       
    79             iResolver.Add( aEntry );
       
    80         }
       
    81         #endregion
       
    82 
       
    83         #region Properties
       
    84         protected string DriveLetter
       
    85         {
       
    86             get { return iResolver.DriveLetter; }
       
    87             set { iResolver.DriveLetter = value; }
       
    88         }
       
    89         #endregion
       
    90 
       
    91         #region Internal methods
       
    92         protected void NotifyRawText( string aMessage )
       
    93         {
       
    94             if ( RawText != null )
       
    95             {
       
    96                 RawText( aMessage );
       
    97             }
       
    98         }
       
    99 
       
   100         protected void NotifyFile( string aFileName )
       
   101         {
       
   102             if ( LocatedFile != null )
       
   103             {
       
   104                 LocatedFile( aFileName );
       
   105             }
       
   106         }
       
   107 
       
   108         protected static string RemoveMapExtension( string aFileName )
       
   109         {
       
   110             StringBuilder ret = new StringBuilder( aFileName );
       
   111             //
       
   112             int pos = aFileName.LastIndexOf( CodeSegResolver.KMapFileExtension );
       
   113             if ( pos >= 1 )
       
   114             {
       
   115                 ret.Remove( pos, CodeSegResolver.KMapFileExtension.Length );
       
   116             }
       
   117             //
       
   118             return ret.ToString().ToLower();
       
   119         }
       
   120 
       
   121         protected static string GeneratePhoneBinaryNameAndPath( string aFileName )
       
   122         {
       
   123             StringBuilder ret = new StringBuilder();
       
   124             //
       
   125             ret.Append( CodeSegResolver.KROMBinaryPath );
       
   126             ret.Append( Path.GetFileName( aFileName ).ToLower() );
       
   127             //
       
   128             return ret.ToString();
       
   129         }
       
   130 
       
   131         protected string CombineWithDriveLetter( string aFileName )
       
   132 		{
       
   133 			string ret = string.Empty;
       
   134 			lock( this )
       
   135 			{
       
   136 				ret = Path.Combine( iResolver.DriveLetter, aFileName ).ToLower();
       
   137 			}
       
   138 			return ret;
       
   139 		}
       
   140         #endregion
       
   141 
       
   142         #region Data members
       
   143         private readonly CodeSegResolver iResolver;
       
   144         private readonly bool iResetResolver;
       
   145 		#endregion
       
   146 	}
       
   147 }