crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbianDebugLib/Entity/Descriptor/DbgEntityDescriptorManager.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.Collections.Generic;
       
    20 using System.Text;
       
    21 using SymbianUtils.PluginManager;
       
    22 using SymbianUtils.FileSystem;
       
    23 using SymbianUtils.Settings;
       
    24 using SymbianDebugLib.Engine;
       
    25 
       
    26 namespace SymbianDebugLib.Entity.Descriptors
       
    27 {
       
    28     public class DbgEntityDescriptorManager : IEnumerable<DbgEntityDescriptor>, IComparer<DbgEntityDescriptor>
       
    29     {
       
    30         #region Constructors
       
    31         internal DbgEntityDescriptorManager( DbgEngine aEngine )
       
    32         {
       
    33             iEngine = aEngine;
       
    34             //
       
    35             iDescriptors.Load( new object[] { this } );
       
    36             iDescriptors.Sort( this );
       
    37             //
       
    38             BuildExtensionList();
       
    39         }
       
    40         #endregion
       
    41 
       
    42         #region API
       
    43         internal DbgEntity Create( XmlSettingCategory aSettingsCategory )
       
    44         {
       
    45             DbgEntity ret = null;
       
    46             //
       
    47             foreach ( DbgEntityDescriptor descriptor in iDescriptors )
       
    48             {
       
    49                 try
       
    50                 {
       
    51                     ret = descriptor.Create( aSettingsCategory );
       
    52                     if ( ret != null )
       
    53                     {
       
    54                         break;
       
    55                     }
       
    56                 }
       
    57                 catch ( Exception )
       
    58                 {
       
    59                 }
       
    60             }
       
    61             //
       
    62             return ret;
       
    63         }
       
    64 
       
    65         internal DbgEntity Create( FSEntity aFSEntity )
       
    66         {
       
    67             DbgEntity ret = FindDescriptorAndCreateEntry( aFSEntity );
       
    68             return ret;
       
    69         }
       
    70         #endregion
       
    71 
       
    72         #region Properties
       
    73         public int Count
       
    74         {
       
    75             get { return iDescriptors.Count; }
       
    76         }
       
    77 
       
    78         public TDbgUiMode UiMode
       
    79         {
       
    80             get { return iUiMode; }
       
    81             set
       
    82             {
       
    83                 if ( iUiMode != value )
       
    84                 {
       
    85                     iUiMode = value;
       
    86                     foreach ( DbgEntityDescriptor descriptor in iDescriptors )
       
    87                     {
       
    88                         descriptor.OnUiModeChanged();
       
    89                     }
       
    90                 }
       
    91             }
       
    92         }
       
    93 
       
    94         public FSExtensionList Extensions
       
    95         {
       
    96             get { return iAllExtensions; }
       
    97         }
       
    98 
       
    99         public DbgEngine Engine
       
   100         {
       
   101             get { return iEngine; }
       
   102         }
       
   103 
       
   104         public DbgEntityDescriptor this[ int aIndex ]
       
   105         {
       
   106             get { return iDescriptors[ aIndex ]; }
       
   107         }
       
   108 
       
   109         public DbgEntityDescriptor this[ string aCategoryName ]
       
   110         {
       
   111             get
       
   112             {
       
   113                 DbgEntityDescriptor ret = null;
       
   114                 //
       
   115                 foreach ( DbgEntityDescriptor descriptor in iDescriptors )
       
   116                 {
       
   117                     if ( descriptor.CategoryName.ToUpper() == aCategoryName.ToUpper() )
       
   118                     {
       
   119                         ret = descriptor;
       
   120                         break;
       
   121                     }
       
   122                 }
       
   123                 //
       
   124                 return ret;
       
   125             }
       
   126         }
       
   127         #endregion
       
   128 
       
   129         #region Internal methods
       
   130         private void BuildExtensionList()
       
   131         {
       
   132             foreach ( DbgEntityDescriptor descriptor in iDescriptors )
       
   133             {
       
   134                 FSExtensionList extensions = descriptor.Extensions;
       
   135                 iAllExtensions.AddRange( extensions );
       
   136             }
       
   137         }
       
   138 
       
   139         private DbgEntity FindDescriptorAndCreateEntry( FSEntity aFSEntity )
       
   140         {
       
   141             DbgEntity ret = null;
       
   142             //
       
   143             foreach ( DbgEntityDescriptor descriptor in iDescriptors )
       
   144             {
       
   145                 try
       
   146                 {
       
   147                     ret = descriptor.Create( aFSEntity );
       
   148                     if ( ret != null )
       
   149                     {
       
   150                         break;
       
   151                     }
       
   152                 }
       
   153                 catch ( Exception )
       
   154                 {
       
   155                 }
       
   156             }
       
   157             //
       
   158             return ret;
       
   159         }
       
   160         #endregion
       
   161 
       
   162         #region From IEnumerable<DbgEntityDescriptor>
       
   163         public IEnumerator<DbgEntityDescriptor> GetEnumerator()
       
   164         {
       
   165             foreach ( DbgEntityDescriptor d in iDescriptors )
       
   166             {
       
   167                 yield return d;
       
   168             }
       
   169         }
       
   170 
       
   171         System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
       
   172         {
       
   173             foreach ( DbgEntityDescriptor d in iDescriptors )
       
   174             {
       
   175                 yield return d;
       
   176             }
       
   177         }
       
   178         #endregion
       
   179 
       
   180         #region From IComparer<DbgEntityDescriptor>
       
   181         public int Compare( DbgEntityDescriptor aLeft, DbgEntityDescriptor aRight )
       
   182         {
       
   183             int ret = -1;
       
   184             //
       
   185             if ( aLeft == null || aRight == null )
       
   186             {
       
   187                 if ( aRight == null )
       
   188                 {
       
   189                     ret = 1;
       
   190                 }
       
   191             }
       
   192             else
       
   193             {
       
   194                 ret = ( aLeft.DisplayOrder.CompareTo( aRight.DisplayOrder ) * -1 );
       
   195             }
       
   196             //
       
   197             return ret;
       
   198         }
       
   199         #endregion
       
   200 
       
   201         #region Data members
       
   202         private readonly DbgEngine iEngine;
       
   203         private TDbgUiMode iUiMode = TDbgUiMode.EUiEnabled;
       
   204         private FSExtensionList iAllExtensions = new FSExtensionList();
       
   205         private PluginManager<DbgEntityDescriptor> iDescriptors = new PluginManager<DbgEntityDescriptor>( 2 );
       
   206         #endregion
       
   207     }
       
   208 }