crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbianSymbolLib/Plugins/SLPluginObey/Provider/ObeySourceProvider.cs
changeset 0 818e61de6cd1
equal deleted inserted replaced
-1:000000000000 0:818e61de6cd1
       
     1 /*
       
     2 * Copyright (c) 2004-2008 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 
       
    18 using System;
       
    19 using System.IO;
       
    20 using System.Collections.Generic;
       
    21 using System.Text;
       
    22 using SymbianStructuresLib.Debug.Symbols;
       
    23 using SymbianSymbolLib.SourceManagement.Source;
       
    24 using SymbianSymbolLib.SourceManagement.Provisioning;
       
    25 using SymbianUtils.FileTypes;
       
    26 using SymbianUtils;
       
    27 using SLPluginObey.Reader;
       
    28 using SLPluginObey.Source;
       
    29 
       
    30 namespace SLPluginObey.Provider
       
    31 {
       
    32     public class ObeySourceProvider : SymSourceProvider
       
    33     {
       
    34         #region Constructors
       
    35         public ObeySourceProvider( SymSourceProviderManager aManager )
       
    36             : base( aManager )
       
    37         {
       
    38         }
       
    39         #endregion
       
    40 
       
    41         #region From SymSourceProvider
       
    42         public override bool IsSupported( string aFileName )
       
    43         {
       
    44             bool ret = base.IsSupported( aFileName );
       
    45             if ( ret )
       
    46             {
       
    47                 FindMapProvider();
       
    48 
       
    49                 // Check that the MAP file source is supported
       
    50                 bool exists = File.Exists( aFileName );
       
    51                 ret = ( iMapProvider != null ) && exists;
       
    52             }
       
    53             //
       
    54             return ret;
       
    55         }
       
    56 
       
    57         public override SymSourceCollection CreateSources( string aFileName )
       
    58         {
       
    59             System.Diagnostics.Debug.Assert( iMapProvider != null );
       
    60 
       
    61             // Read OBY file and resolve to map files in host file system.
       
    62             iTransientSources = new SymSourceCollection();
       
    63             try
       
    64             {
       
    65                 ObeyFileReader reader = new ObeyFileReader( aFileName );
       
    66                 reader.EntryRead += new ObeyFileReader.ObyEntryHandler( Reader_EntryRead );
       
    67                 reader.Read( TSynchronicity.ESynchronous );
       
    68             }
       
    69             catch ( Exception )
       
    70             {
       
    71                 iTransientSources.Clear();
       
    72             }
       
    73 
       
    74             // This source provider doesn't directly create any sources
       
    75             SymSourceCollection ret = iTransientSources;
       
    76             iTransientSources = null;
       
    77             return ret;
       
    78         }
       
    79 
       
    80         public override SymFileTypeList FileTypes
       
    81         {
       
    82             get
       
    83             {
       
    84                 SymFileTypeList ret = new SymFileTypeList();
       
    85                 //
       
    86                 ret.Add( new SymFileType( ".oby", "Symbian OS Obey Files" ) );
       
    87                 //
       
    88                 return ret;
       
    89             }
       
    90         }
       
    91 
       
    92         public override string Name
       
    93         {
       
    94             get { return "OBY"; }
       
    95         }
       
    96         #endregion
       
    97 
       
    98         #region Properties
       
    99         #endregion
       
   100 
       
   101         #region Event handlers
       
   102         private void Reader_EntryRead( ObeyFileReader aReader, string aHost, string aDevice )
       
   103         {
       
   104             // Check if there is a corresponding map file in the host file system.
       
   105             FileInfo mapFile = new FileInfo( aHost + KMapFileExtension );
       
   106             if ( mapFile.Exists )
       
   107             {
       
   108                 bool supported = iMapProvider.IsSupported( mapFile.FullName );
       
   109                 if ( supported )
       
   110                 {
       
   111                     // First get the map provider to create its own concrete list of 
       
   112                     // sources for the specified map file. This should just be a single
       
   113                     // source and a single collection since that is the logical encapsulating
       
   114                     // domain for a given map file.
       
   115                     SymSourceCollection mapSources = iMapProvider.CreateSources( mapFile.FullName );
       
   116 
       
   117                     // Next, we iterate through any sources (probably just one) and then
       
   118                     // extract the collection & provider that was specified for that source.
       
   119                     //
       
   120                     // We want to effectively sit the OBY source plugin in between the symbol
       
   121                     // engine and the map plugin so that it can ensure that we only read a
       
   122                     // given map file at the point when the map file symbol collection is activated.
       
   123                     foreach ( SymSource mapSource in mapSources )
       
   124                     {
       
   125                         SymSource obeySource = new ObeySource( mapSource.URI, this, mapSource );
       
   126                         iTransientSources.Add( obeySource );
       
   127                     }
       
   128                 }
       
   129                 else
       
   130                 {
       
   131                     SymbianUtils.SymDebug.SymDebugger.Break();
       
   132                 }
       
   133             }
       
   134         }
       
   135         #endregion
       
   136 
       
   137         #region Internal constants
       
   138         private const string KMapFileExtension = ".map";
       
   139         #endregion
       
   140 
       
   141         #region Internal methods
       
   142         private void FindMapProvider()
       
   143         {
       
   144             if ( iMapProvider == null )
       
   145             {
       
   146                 iMapProvider = base.ProvisioningManager[ "MAP" ];
       
   147             }
       
   148         }
       
   149         #endregion
       
   150 
       
   151         #region Data members
       
   152         private SymSourceProvider iMapProvider;
       
   153         private SymSourceCollection iTransientSources = null;
       
   154         #endregion
       
   155     }
       
   156 }