crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbianSymbolLib/SourceManagement/Provisioning/SymSourceProviderManager.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.Collections.Generic;
       
    20 using System.Text;
       
    21 using System.IO;
       
    22 using SymbianUtils;
       
    23 using SymbianUtils.Tracer;
       
    24 using SymbianUtils.FileTypes;
       
    25 using SymbianUtils.PluginManager;
       
    26 using SymbianStructuresLib.Debug.Common.Interfaces;
       
    27 using SymbianSymbolLib.DbgEnginePlugin;
       
    28 using SymbianSymbolLib.SourceManagement.Source;
       
    29 
       
    30 namespace SymbianSymbolLib.SourceManagement.Provisioning
       
    31 {
       
    32     public class SymSourceProviderManager : DisposableObject, IEnumerable<SymSourceProvider>, ITracer
       
    33     {
       
    34         #region Constructors
       
    35         internal SymSourceProviderManager( SymbolPlugin aPlugin, IPlatformIdAllocator aIdAllocator )
       
    36         {
       
    37             iPlugin = aPlugin;
       
    38             iIdAllocator = aIdAllocator;
       
    39             //
       
    40             iProviders.Load( new object[] { this } );
       
    41         }
       
    42         #endregion
       
    43 
       
    44         #region API
       
    45         public SymFileTypeList SupportedFileTypes()
       
    46         {
       
    47             SymFileTypeList ret = new SymFileTypeList();
       
    48             //
       
    49             foreach ( SymSourceProvider provider in iProviders )
       
    50             {
       
    51                 SymFileTypeList list = provider.FileTypes;
       
    52                 ret.AddRange( list );
       
    53             }
       
    54             //
       
    55             return ret;
       
    56         }
       
    57 
       
    58         public SymSourceProvider GetProvider( string aFileName )
       
    59         {
       
    60             SymSourceProvider ret = null;
       
    61             //
       
    62             foreach ( SymSourceProvider provider in iProviders )
       
    63             {
       
    64                 bool canRead = provider.IsSupported( aFileName );
       
    65                 if ( canRead )
       
    66                 {
       
    67                     ret = provider;
       
    68                     break;
       
    69                 }
       
    70             }
       
    71             //
       
    72             return ret;
       
    73         }
       
    74 
       
    75         public IEnumerator<SymSource> GetSourceEnumerator()
       
    76         {
       
    77             return iPlugin.SourceManager.GetEnumerator();
       
    78         }
       
    79 
       
    80         public void PrepareToCreateSources()
       
    81         {
       
    82             foreach ( SymSourceProvider provider in iProviders )
       
    83             {
       
    84                 provider.PrepareToCreateSources();
       
    85             }
       
    86         }
       
    87         #endregion
       
    88 
       
    89         #region Properties
       
    90         public int Count
       
    91         {
       
    92             get { return iProviders.Count; }
       
    93         }
       
    94 
       
    95         public SymSourceProvider this[ string aName ]
       
    96         {
       
    97             get
       
    98             {
       
    99                 SymSourceProvider ret = null;
       
   100                 //
       
   101                 foreach ( SymSourceProvider prov in iProviders )
       
   102                 {
       
   103                     if ( prov.Name == aName )
       
   104                     {
       
   105                         ret = prov;
       
   106                         break;
       
   107                     }
       
   108                 }
       
   109                 //
       
   110                 return ret;
       
   111             }
       
   112         }
       
   113 
       
   114         public IPlatformIdAllocator IdAllocator
       
   115         {
       
   116             get { return iIdAllocator; }
       
   117         }
       
   118 
       
   119         public SymSourceProvider this[ int aIndex ]
       
   120         {
       
   121             get { return iProviders[ aIndex ]; }
       
   122         }
       
   123         #endregion
       
   124 
       
   125         #region Internal methods
       
   126         internal SymbolPlugin Plugin
       
   127         {
       
   128             get { return iPlugin; }
       
   129         }
       
   130         #endregion
       
   131 
       
   132         #region From IEnumerable<SymSourceProvider>
       
   133         public IEnumerator<SymSourceProvider> GetEnumerator()
       
   134         {
       
   135             foreach ( SymSourceProvider prov in iProviders )
       
   136             {
       
   137                 yield return prov;
       
   138             }
       
   139         }
       
   140 
       
   141         System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
       
   142         {
       
   143             foreach ( SymSourceProvider prov in iProviders )
       
   144             {
       
   145                 yield return prov;
       
   146             }
       
   147         }
       
   148         #endregion
       
   149 
       
   150         #region From ITracer
       
   151         public void Trace( string aMessage )
       
   152         {
       
   153             iPlugin.Trace( aMessage );
       
   154         }
       
   155 
       
   156         public void Trace( string aFormat, params object[] aParams )
       
   157         {
       
   158             iPlugin.Trace( aFormat, aParams );
       
   159         }
       
   160         #endregion
       
   161 
       
   162         #region From DisposableObject
       
   163         protected override void CleanupManagedResources()
       
   164         {
       
   165             try
       
   166             {
       
   167                 base.CleanupManagedResources();
       
   168             }
       
   169             finally
       
   170             {
       
   171                 iProviders.Unload();
       
   172                 iProviders.Dispose();
       
   173             }
       
   174         }
       
   175         #endregion
       
   176 
       
   177         #region Data members
       
   178         private readonly SymbolPlugin iPlugin;
       
   179         private readonly IPlatformIdAllocator iIdAllocator;
       
   180         private PluginManager<SymSourceProvider> iProviders = new PluginManager<SymSourceProvider>();
       
   181         #endregion
       
   182     }
       
   183 }