crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbianDebugLib/Engine/DbgEngine.cs
changeset 0 818e61de6cd1
child 2 0c91f0baec58
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.Collections.Generic;
       
    19 using System.Text;
       
    20 using System.IO;
       
    21 using SymbianUtils;
       
    22 using SymbianUtils.Tracer;
       
    23 using SymbianUtils.FileSystem;
       
    24 using SymbianUtils.Settings;
       
    25 using SymbianStructuresLib.Debug.Common.Id;
       
    26 using SymbianStructuresLib.Debug.Common.Interfaces;
       
    27 using SymbianStructuresLib.CodeSegments;
       
    28 using SymbianDebugLib.Entity;
       
    29 using SymbianDebugLib.Entity.Manager;
       
    30 using SymbianDebugLib.Entity.Descriptors;
       
    31 using SymbianDebugLib.Entity.Configurations;
       
    32 using SymbianDebugLib.PluginAPI;
       
    33 using SymbianDebugLib.PluginAPI.Types.Code;
       
    34 using SymbianDebugLib.PluginAPI.Types.Trace;
       
    35 using SymbianDebugLib.PluginAPI.Types.Symbol;
       
    36 using SymbianDebugLib.PluginAPI.Types.KeyBindings;
       
    37 using SymbianDebugLib.PluginAPI.Types.MetaDataConfig;
       
    38 using SymbianDebugLib.ValidationRules;
       
    39 
       
    40 namespace SymbianDebugLib.Engine
       
    41 {
       
    42     public class DbgEngine : DisposableObject, IEnumerable<DbgEntity>, ITracer
       
    43     {
       
    44         #region Enumerations
       
    45         public enum TEvent
       
    46         {
       
    47             EPrimingStarted = 0,
       
    48             EPrimingComplete
       
    49         }
       
    50         #endregion
       
    51 
       
    52         #region Delegates & events
       
    53         public delegate void OperationHandler( DbgEngine aEngine, TEvent aEvent );
       
    54         public delegate void EventHandler( DbgEngine aEngine, DbgEntity aEntity, object aContext );
       
    55         //
       
    56         public event EventHandler EntityAdded;
       
    57         public event EventHandler EntityRemoved;
       
    58         public event EventHandler EntitiesCleared;
       
    59         public event EventHandler EntityPrimingStarted;
       
    60         public event EventHandler EntityPrimingProgress;
       
    61         public event EventHandler EntityPrimingComplete;
       
    62         public event OperationHandler EngineOperation;
       
    63         #endregion
       
    64 
       
    65         #region Constructors
       
    66         public DbgEngine()
       
    67             : this( null )
       
    68         {
       
    69         }
       
    70 
       
    71         public DbgEngine( ITracer aTracer )
       
    72         {
       
    73             iTracer = aTracer;
       
    74  
       
    75             // Initialise the settings object
       
    76             iSettings = new XmlSettings( KDbgEngineXmlSettingsFileName );
       
    77             iSettings.Restore();
       
    78 
       
    79             iEntityManager = new DbgEntityManager( this );
       
    80             iPluginManager = new DbgPluginManager( this );
       
    81             iConfigManager = new DbgEntityConfigManager( this );
       
    82             iValidationManager = new DbgValidationManager( this );
       
    83             iDescriptorManager = new DbgEntityDescriptorManager( this );
       
    84         }
       
    85         #endregion
       
    86 
       
    87         #region API - setup phase
       
    88         public void Clear()
       
    89         {
       
    90             iCurrentConfig = null;
       
    91             iEntityManager.Clear();
       
    92         }
       
    93 
       
    94         public DbgEntity Add( string aEntityFullName )
       
    95         {
       
    96             return Add( new FileInfo( aEntityFullName ) );
       
    97         }
       
    98 
       
    99         public DbgEntity Add( FileInfo aFile )
       
   100         {
       
   101             return iEntityManager.AddFile( aFile );
       
   102         }
       
   103 
       
   104         public void AddRange( IEnumerable<FileInfo> aEntities )
       
   105         {
       
   106             foreach ( FileInfo entity in aEntities )
       
   107             {
       
   108                 Add( entity );
       
   109             }
       
   110         }
       
   111 
       
   112         public void AddRange( IEnumerable<string> aFiles )
       
   113         {
       
   114             foreach ( string file in aFiles )
       
   115             {
       
   116                 Add( file );
       
   117             }
       
   118         }
       
   119 
       
   120         public bool Contains( string aEntityFullName )
       
   121         {
       
   122             FSEntity entity = FSEntity.New( aEntityFullName );
       
   123             return Contains( entity );
       
   124         }
       
   125 
       
   126         public bool Contains( FSEntity aFSEntity )
       
   127         {
       
   128             return iEntityManager.Contains( aFSEntity );
       
   129         }
       
   130 
       
   131         public void Remove( DbgEntity aEntity )
       
   132         {
       
   133             EntityManager.Remove( aEntity );
       
   134         }
       
   135 
       
   136         public void Prime( TSynchronicity aSynchronicity )
       
   137         {
       
   138             if ( EngineOperation != null )
       
   139             {
       
   140                 EngineOperation( this, TEvent.EPrimingStarted );
       
   141             }
       
   142 
       
   143             // Reset the plugins
       
   144             Code.Clear();
       
   145             Symbols.Clear();
       
   146 
       
   147             // Categorise the prime list by plugin
       
   148             Dictionary<DbgPluginEngine, DbgEntityList> list = new Dictionary<DbgPluginEngine, DbgEntityList>();
       
   149             foreach ( DbgEntity entity in iEntityManager )
       
   150             {
       
   151                 // Might be null.
       
   152                 DbgPluginEngine plugin = entity.PluginEngine;
       
   153                 if ( plugin != null )
       
   154                 {
       
   155                     // Find correct list
       
   156                     DbgEntityList pluginEntityList = null;
       
   157                     if ( list.ContainsKey( plugin ) )
       
   158                     {
       
   159                         pluginEntityList = list[ plugin ];
       
   160                     }
       
   161                     else
       
   162                     {
       
   163                         pluginEntityList = new DbgEntityList( this );
       
   164                         list.Add( plugin, pluginEntityList );
       
   165                     }
       
   166 
       
   167                     // Now add the entry
       
   168                     pluginEntityList.Add( entity );
       
   169                 }
       
   170             }
       
   171 
       
   172             // Finally, we can tell all the plugins about the files they are about to receive
       
   173             foreach ( KeyValuePair<DbgPluginEngine, DbgEntityList> kvp in list )
       
   174             {
       
   175                 kvp.Key.PrepareToPrime( kvp.Value );
       
   176             }
       
   177 
       
   178             // Now prime the individual entities
       
   179             foreach ( DbgEntity entity in iEntityManager )
       
   180             {
       
   181                 entity.Prime( aSynchronicity );
       
   182             }
       
   183 
       
   184             if ( EngineOperation != null )
       
   185             {
       
   186                 EngineOperation( this, TEvent.EPrimingComplete );
       
   187             }
       
   188         }
       
   189 
       
   190         public bool IsReadyToPrime( out string aErrorList )
       
   191         {
       
   192             bool valid = iValidationManager.IsValid( DbgValidationRule.TOperation.EOperationPrime, out aErrorList );
       
   193             //
       
   194             if ( valid )
       
   195             {
       
   196                 valid = EntityManager.IsReadyToPrime( out aErrorList );
       
   197             }
       
   198             //
       
   199             return valid;
       
   200         }
       
   201         #endregion
       
   202 
       
   203         #region API - child engine & views
       
   204         public DbgEngineCode Code
       
   205         {
       
   206             get { return iPluginManager.Code; }
       
   207         }
       
   208 
       
   209         public DbgEngineSymbol Symbols
       
   210         {
       
   211             get { return iPluginManager.Symbols; }
       
   212         }
       
   213 
       
   214         public DbgEngineTrace TraceDictionaries
       
   215         {
       
   216             get { return iPluginManager.TraceDictionaries; }
       
   217         }
       
   218 
       
   219         public DbgEngineKeyBindings KeyBindings
       
   220         {
       
   221             get { return iPluginManager.KeyBindings; }
       
   222         }
       
   223 
       
   224         public DbgEngineMetaDataConfig MetaDataConfig
       
   225         {
       
   226             get { return iPluginManager.MetaDataConfig; }
       
   227         }
       
   228 
       
   229         public DbgEngineView CreateView( string aName )
       
   230         {
       
   231             return CreateView( aName, new CodeSegDefinitionCollection() );
       
   232         }
       
   233 
       
   234         public DbgEngineView CreateView( string aName, CodeSegDefinitionCollection aCodeSegments )
       
   235         {
       
   236             return CreateView( aName, aCodeSegments, TDbgViewDeactivationType.EDoNothing );
       
   237         }
       
   238 
       
   239         public DbgEngineView CreateView( string aName, CodeSegDefinitionCollection aCodeSegments, TDbgViewDeactivationType aDeactivationType )
       
   240         {
       
   241             DbgEngineView ret = new DbgEngineView( this, aName, aCodeSegments, aDeactivationType );
       
   242             return ret;
       
   243         }
       
   244         #endregion
       
   245 
       
   246         #region API - settings
       
   247         public void XmlSettingsSave()
       
   248         {
       
   249             iSettings.Save( KDbgEngineXmlSettingsRootNodeName, iEntityManager );
       
   250             iSettings.Store();
       
   251         }
       
   252 
       
   253         public void XmlSettingsLoad()
       
   254         {
       
   255             iSettings.Load( KDbgEngineXmlSettingsRootNodeName, iEntityManager );
       
   256         }
       
   257         #endregion
       
   258 
       
   259         #region Properties
       
   260         public int Count
       
   261         {
       
   262             get { return iEntityManager.Count; }
       
   263         }
       
   264 
       
   265         public bool Verbose
       
   266         {
       
   267             get { return iVerbose; }
       
   268             set { iVerbose = value; }
       
   269         }
       
   270 
       
   271         public DbgEntity this[ int aIndex ]
       
   272         {
       
   273             get { return iEntityManager[ aIndex ]; }
       
   274         }
       
   275 
       
   276         public DbgEntityManager EntityManager
       
   277         {
       
   278             get { return iEntityManager; }
       
   279         }
       
   280 
       
   281         public DbgEntityConfigManager ConfigManager
       
   282         {
       
   283             get { return iConfigManager; }
       
   284         }
       
   285 
       
   286         public DbgEntityDescriptorManager DescriptorManager
       
   287         {
       
   288             get { return iDescriptorManager; }
       
   289         }
       
   290 
       
   291         public bool IsUsingConfiguration
       
   292         {
       
   293             get { return iCurrentConfig != null; }
       
   294         }
       
   295 
       
   296         public DbgEntityConfig CurrentConfiguration
       
   297         {
       
   298             get { return iCurrentConfig; }
       
   299             internal set { iCurrentConfig = value; }
       
   300         }
       
   301 
       
   302         public TDbgUiMode UiMode
       
   303         {
       
   304             get { return iDescriptorManager.UiMode; }
       
   305             set
       
   306             {
       
   307                 iDescriptorManager.UiMode = value;
       
   308             }
       
   309         }
       
   310 
       
   311         public FSExtensionList FileTypeExtensions
       
   312         {
       
   313             get { return DescriptorManager.Extensions; }
       
   314         }
       
   315 
       
   316         public XmlSettings Settings
       
   317         {
       
   318             get { return iSettings; }
       
   319         }
       
   320 
       
   321         public FSEntity[] FileSystemEntities
       
   322         {
       
   323             get { return EntityManager.FileSystemEntities; }
       
   324         }
       
   325 
       
   326         public IPlatformIdAllocator IdAllocator
       
   327         {
       
   328             get { return iIdAllocator; }
       
   329         }
       
   330         #endregion
       
   331 
       
   332         #region Internal constants
       
   333         private const string KDbgEngineXmlSettingsFileName = "DbgEngineSettings.xml";
       
   334         private const string KDbgEngineXmlSettingsRootNodeName = "DbgEngine";
       
   335         #endregion
       
   336 
       
   337         #region Internal event propagation methods
       
   338         internal void OnAdded( DbgEntity aEntity )
       
   339         {
       
   340             try
       
   341             {
       
   342                 if ( EntityAdded != null )
       
   343                 {
       
   344                     EntityAdded( this, aEntity, null );
       
   345                 }
       
   346             }
       
   347             catch ( Exception )
       
   348             {
       
   349             }
       
   350         }
       
   351 
       
   352         internal void OnRemoved( DbgEntity aEntity )
       
   353         {
       
   354             try
       
   355             {
       
   356                 if ( EntityRemoved != null )
       
   357                 {
       
   358                     EntityRemoved( this, aEntity, null );
       
   359                 }
       
   360             }
       
   361             catch ( Exception )
       
   362             {
       
   363             }
       
   364         }
       
   365 
       
   366         internal void OnPrimingStarted( DbgEntity aEntity )
       
   367         {
       
   368             try
       
   369             {
       
   370                 if ( EntityPrimingStarted != null )
       
   371                 {
       
   372                     EntityPrimingStarted( this, aEntity, null );
       
   373                 }
       
   374             }
       
   375             catch ( Exception )
       
   376             {
       
   377             }
       
   378         }
       
   379 
       
   380         internal void OnPrimingProgress( DbgEntity aEntity, int aValue )
       
   381         {
       
   382             try
       
   383             {
       
   384                 if ( EntityPrimingProgress != null )
       
   385                 {
       
   386                     EntityPrimingProgress( this, aEntity, aValue );
       
   387                 }
       
   388             }
       
   389             catch ( Exception )
       
   390             {
       
   391             }
       
   392         }
       
   393 
       
   394         internal void OnPrimingComplete( DbgEntity aEntity )
       
   395         {
       
   396             try
       
   397             {
       
   398                 if ( EntityPrimingComplete != null )
       
   399                 {
       
   400                     EntityPrimingComplete( this, aEntity, null );
       
   401                 }
       
   402             }
       
   403             catch ( Exception )
       
   404             {
       
   405             }
       
   406         }
       
   407 
       
   408         internal void OnCleared()
       
   409         {
       
   410             try
       
   411             {
       
   412                 if ( EntitiesCleared != null )
       
   413                 {
       
   414                     EntitiesCleared( this, null, null );
       
   415                 }
       
   416             }
       
   417             catch ( Exception )
       
   418             {
       
   419             }
       
   420         }
       
   421         #endregion
       
   422 
       
   423         #region From IEnumerable<DbgEntity>
       
   424         public IEnumerator<DbgEntity> GetEnumerator()
       
   425         {
       
   426             foreach ( DbgEntity e in iEntityManager )
       
   427             {
       
   428                 yield return e;
       
   429             }
       
   430         }
       
   431 
       
   432         System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
       
   433         {
       
   434             foreach ( DbgEntity e in iEntityManager )
       
   435             {
       
   436                 yield return e;
       
   437             }
       
   438         }
       
   439         #endregion
       
   440 
       
   441         #region From ITracer
       
   442         public void Trace( string aMessage )
       
   443         {
       
   444             if ( iTracer != null )
       
   445             {
       
   446                 iTracer.Trace( aMessage );
       
   447             }
       
   448         }
       
   449 
       
   450         public void Trace( string aFormat, params object[] aParams )
       
   451         {
       
   452             Trace( string.Format( aFormat, aParams ) );
       
   453         }
       
   454         #endregion
       
   455 
       
   456         #region From DisposableObject
       
   457         protected override void CleanupManagedResources()
       
   458         {
       
   459             try
       
   460             {
       
   461                 base.CleanupManagedResources();
       
   462             }
       
   463             finally
       
   464             {
       
   465                 iPluginManager.Dispose();
       
   466                 iConfigManager.Dispose();
       
   467             }
       
   468         }
       
   469         #endregion
       
   470 
       
   471         #region Data members
       
   472         private readonly ITracer iTracer;
       
   473         private readonly XmlSettings iSettings;
       
   474         private readonly DbgEntityManager iEntityManager;
       
   475         private readonly DbgPluginManager iPluginManager;
       
   476         private readonly DbgEntityConfigManager iConfigManager;
       
   477         private readonly DbgValidationManager iValidationManager;
       
   478         private readonly DbgEntityDescriptorManager iDescriptorManager;
       
   479         private PlatformIdAllocator iIdAllocator = new PlatformIdAllocator();
       
   480         private DbgEntityConfig iCurrentConfig = null;
       
   481         private bool iVerbose;
       
   482         #endregion
       
   483     }
       
   484 }