crashanalysercmd/Libraries/Engine/CrashDebuggerLib/Structures/KernelObjects/DObjectCon.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 
       
    22 namespace CrashDebuggerLib.Structures.KernelObjects
       
    23 {
       
    24     public class DObjectCon : DBase, IEnumerable<DObject>
       
    25     {
       
    26         #region Constructors
       
    27         public DObjectCon( CrashDebuggerInfo aCrashDebugger, DObject.TObjectType aType )
       
    28             : base( aCrashDebugger )
       
    29         {
       
    30             iType = aType;
       
    31         }
       
    32         #endregion
       
    33 
       
    34         #region API
       
    35         internal void Add( DObject aObject )
       
    36         {
       
    37             if ( aObject.Type != Type )
       
    38             {
       
    39                 throw new ArgumentException( "Object is not of the correct type" );
       
    40             }
       
    41             
       
    42             // Add it to the address-based index.
       
    43             iObjectsInOriginalOrder.Add( aObject.KernelAddress, aObject );
       
    44 
       
    45             try
       
    46             {
       
    47                 // Must munge in the address, because name is not sufficiently unique. For example
       
    48                 // there can be dead threads or processes (or anything really) with the same name
       
    49                 // but since one is dead and the other is not, then they have different addresses.
       
    50                 string sortedByName = string.Format( "{0}_{1:x8}", aObject, aObject.KernelAddress );
       
    51                 iObjectsInSortedOrder.Add( sortedByName, aObject );
       
    52             }
       
    53             catch ( Exception )
       
    54             {
       
    55                 // Keep the two synchronised...
       
    56                 iObjectsInOriginalOrder.Remove( aObject.KernelAddress );
       
    57             }
       
    58         }
       
    59 
       
    60         public bool Contains( DObject aObject )
       
    61         {
       
    62             bool exists = iObjectsInOriginalOrder.ContainsKey( aObject.KernelAddress );
       
    63             return exists;
       
    64         }
       
    65         #endregion
       
    66 
       
    67         #region Properties
       
    68         public int Count
       
    69         {
       
    70             get { return iObjectsInSortedOrder.Count; }
       
    71         }
       
    72 
       
    73         public int ExpectedCount
       
    74         {
       
    75             get { return iExpectedCount; }
       
    76             set { iExpectedCount = value; }
       
    77         }
       
    78 
       
    79         public int Index
       
    80         {
       
    81             get { return iIndex; }
       
    82             set { iIndex = value; }
       
    83         }
       
    84 
       
    85         public DObject this[ uint aAddress ]
       
    86         {
       
    87             get
       
    88             {
       
    89                 DObject ret = null;
       
    90                 iObjectsInOriginalOrder.TryGetValue( aAddress, out ret );
       
    91                 return ret;
       
    92             }
       
    93         }
       
    94 
       
    95         public DObject.TObjectType Type
       
    96         {
       
    97             get { return iType; }
       
    98         }
       
    99 
       
   100         public string TypeDescription
       
   101         {
       
   102             get
       
   103             {
       
   104                 string ret = DObject.AsTypeDescription( iType );
       
   105                 return ret;
       
   106             }
       
   107         }
       
   108         #endregion
       
   109 
       
   110         #region Internal methods
       
   111         #endregion
       
   112 
       
   113         #region Internal constants
       
   114         #endregion
       
   115 
       
   116         #region From IEnumerable<DObject>
       
   117         public IEnumerator<DObject> GetEnumerator()
       
   118         {
       
   119             foreach ( KeyValuePair<string, DObject> pair in iObjectsInSortedOrder )
       
   120             {
       
   121                 yield return pair.Value;
       
   122             }
       
   123         }
       
   124 
       
   125         System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
       
   126         {
       
   127             foreach ( KeyValuePair<string, DObject> pair in iObjectsInSortedOrder )
       
   128             {
       
   129                 yield return pair.Value;
       
   130             }
       
   131         }
       
   132         #endregion
       
   133 
       
   134         #region From System.Object
       
   135         public override string ToString()
       
   136         {
       
   137             StringBuilder ret = new StringBuilder();
       
   138             ret.AppendFormat( "[{0:d4}] {1} objects", Count, TypeDescription );
       
   139             return ret.ToString();
       
   140         }
       
   141         #endregion
       
   142 
       
   143         #region Data members
       
   144         private readonly DObject.TObjectType iType;
       
   145         private int iIndex = 0;
       
   146         private int iExpectedCount = 0;
       
   147         private Dictionary<uint, DObject> iObjectsInOriginalOrder = new Dictionary<uint, DObject>();
       
   148         private SortedList<string, DObject> iObjectsInSortedOrder = new SortedList<string, DObject>();
       
   149         #endregion
       
   150     }
       
   151 }