crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbianDebugLib/Entity/Configurations/DbgEntityConfigManager.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.IO;
       
    19 using System.Collections.Generic;
       
    20 using System.Text;
       
    21 using System.Threading;
       
    22 using SymbianUtils;
       
    23 using SymbianUtils.PluginManager;
       
    24 using SymbianUtils.FileSystem;
       
    25 using SymbianUtils.Settings;
       
    26 using SymbianDebugLib.Engine;
       
    27 
       
    28 namespace SymbianDebugLib.Entity.Configurations
       
    29 {
       
    30     public class DbgEntityConfigManager : DisposableObject
       
    31     {
       
    32         #region Constructors
       
    33         internal DbgEntityConfigManager( DbgEngine aEngine )
       
    34         {
       
    35             iEngine = aEngine;
       
    36         }
       
    37         #endregion
       
    38 
       
    39         #region API
       
    40         public void Clear()
       
    41         {
       
    42             lock ( iConfigurations )
       
    43             {
       
    44                 iConfigurations.Clear();
       
    45             }
       
    46         }
       
    47 
       
    48         public void Add( DbgEntityConfig aConfiguration )
       
    49         {
       
    50             lock ( iConfigurations )
       
    51             {
       
    52                 iConfigurations.Add( aConfiguration );
       
    53             }
       
    54         }
       
    55 
       
    56         public void SwitchConfigurationSynchronously( DbgEntityConfigIdentifier aId )
       
    57         {
       
    58             // Try to find a config that matches the specified value
       
    59             DbgEntityConfig config = ConfigById( aId );
       
    60             if ( config == null )
       
    61             {
       
    62                 // Unload any old data and return
       
    63                 iEngine.Clear();
       
    64                 iEngine.Trace( "WARNING: DbgEntityConfigManager could not load config id: " + aId.ToString() );
       
    65             }
       
    66             else
       
    67             {
       
    68                 if ( config == iEngine.CurrentConfiguration )
       
    69                 {
       
    70                     // Nothing to do
       
    71                 }
       
    72                 else
       
    73                 {
       
    74                     // Unload any old data
       
    75                     iEngine.Clear();
       
    76 
       
    77                     // Prepare list of files
       
    78                     List<string> files = new List<string>();
       
    79                     foreach ( DbgEntityConfig.CfgSet set in config )
       
    80                     {
       
    81                         foreach ( DbgEntityConfig.CfgFile file in set )
       
    82                         {
       
    83                             files.Add( file.FileNameAndPath );
       
    84                         }
       
    85                     }
       
    86                     iEngine.AddRange( files );
       
    87                     iEngine.Prime( TSynchronicity.ESynchronous );
       
    88                 }
       
    89             }
       
    90         }
       
    91         #endregion
       
    92 
       
    93         #region Event handlers
       
    94         #endregion
       
    95 
       
    96         #region Properties
       
    97         public int Count
       
    98         {
       
    99             get 
       
   100             {
       
   101                 lock ( iConfigurations )
       
   102                 {
       
   103                     return iConfigurations.Count;
       
   104                 }
       
   105             }
       
   106         }
       
   107 
       
   108         internal DbgEngine Engine
       
   109         {
       
   110             get { return iEngine; }
       
   111         }
       
   112         #endregion
       
   113 
       
   114         #region Internal methods
       
   115         private DbgEntityConfig ConfigById( DbgEntityConfigIdentifier aId )
       
   116         {
       
   117             DbgEntityConfig ret = null;
       
   118             //
       
   119             lock ( iConfigurations )
       
   120             {
       
   121                 foreach ( DbgEntityConfig cfg in iConfigurations )
       
   122                 {
       
   123                     if ( cfg.Contains( aId ) )
       
   124                     {
       
   125                         ret = cfg;
       
   126                         break;
       
   127                     }
       
   128                 }
       
   129             }
       
   130             //
       
   131             return ret;
       
   132         }
       
   133         #endregion
       
   134 
       
   135         #region Data members
       
   136         private readonly DbgEngine iEngine;
       
   137         private List<DbgEntityConfig> iConfigurations = new List<DbgEntityConfig>();
       
   138         #endregion
       
   139     }
       
   140 }