crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbianSymbolLib/Plugins/SLPluginSymbol/Data/SymbolFileSegment.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.IO;
       
    20 using System.Collections.Generic;
       
    21 using System.Text;
       
    22 using System.Text.RegularExpressions;
       
    23 using SymbianStructuresLib.Debug.Symbols;
       
    24 using SymbianSymbolLib.SourceManagement.Source;
       
    25 using SymbianSymbolLib.SourceManagement.Provisioning;
       
    26 using SymbianUtils;
       
    27 using SymbianUtils.Tracer;
       
    28 using SymbianUtils.FileTypes;
       
    29 using SLPluginSymbol.Source;
       
    30 
       
    31 namespace SLPluginSymbol.Data
       
    32 {
       
    33     internal class SymbolFileSegment : DisposableObject, IEnumerable<SymbolCollectionSegment>
       
    34     {
       
    35         #region Delegates & events
       
    36         public delegate void CompletionHandler( SymbolFileSegment aSegment );
       
    37         public event CompletionHandler Completed = null;
       
    38         #endregion
       
    39 
       
    40         #region Constructors
       
    41         public SymbolFileSegment( SymbolFileData aData, int aOffset, int aLength )
       
    42 		{
       
    43             iData = aData;
       
    44             iOffset = aOffset;
       
    45             iLength = aLength;
       
    46 		}
       
    47         #endregion
       
    48 
       
    49         #region API
       
    50         public void PerformInitialCollectionIdentification()
       
    51         {
       
    52             SymbolCollectionSegment current = null;
       
    53             //
       
    54             long lineCount = 0;
       
    55             //
       
    56             using ( StreamReader reader = NewStream() )
       
    57             {
       
    58                 string line = reader.ReadLine();
       
    59                 while ( line != null )
       
    60                 {
       
    61                     ++lineCount;
       
    62                     if ( line.StartsWith( "From    " ) )
       
    63                     {
       
    64                         string hostFileName = line.Substring( 4 ).Trim();
       
    65                         UpdateLineCount( current );
       
    66                         current = NewCollectionSegment( hostFileName );
       
    67                     }
       
    68                     else if ( current != null && line != string.Empty )
       
    69                     {
       
    70                         current.AddLine( line );
       
    71                     }
       
    72 
       
    73                     line = reader.ReadLine();
       
    74                 }
       
    75             }
       
    76 
       
    77             UpdateLineCount( current );
       
    78             iIsReady = true;
       
    79 
       
    80             if ( Completed != null )
       
    81             {
       
    82                 Completed( this );
       
    83             }
       
    84         }
       
    85         #endregion
       
    86 
       
    87         #region Properties
       
    88         public bool IsReady
       
    89         {
       
    90             get { return iIsReady; }
       
    91         }
       
    92 
       
    93         public long NumberOfLines
       
    94         {
       
    95             get { return iNumberOfLines; }
       
    96         }
       
    97 
       
    98         public int Count
       
    99         {
       
   100             get { return iCollectionSegments.Count; }
       
   101         }
       
   102 
       
   103         public SymbolCollectionSegment this[ int aIndex ]
       
   104         {
       
   105             get { return iCollectionSegments[ aIndex ]; }
       
   106         }
       
   107 
       
   108         public SymbolSource Source
       
   109         {
       
   110             get { return iData.Source; }
       
   111         }
       
   112         #endregion
       
   113 
       
   114         #region Internal constants
       
   115         #endregion
       
   116 
       
   117         #region Internal methods
       
   118         private void UpdateLineCount( SymbolCollectionSegment aFinalisedSegment )
       
   119         {
       
   120             if ( aFinalisedSegment != null )
       
   121             {
       
   122                 iNumberOfLines += aFinalisedSegment.Count;
       
   123             }
       
   124         }
       
   125 
       
   126         private SymbolCollectionSegment NewCollectionSegment( string aFileNameInHost )
       
   127         {
       
   128             SymbolCollectionSegment ret = new SymbolCollectionSegment( iData.Source.Provider.IdAllocator, aFileNameInHost );
       
   129             iCollectionSegments.Add( ret );
       
   130             return ret;
       
   131         }
       
   132 
       
   133         private StreamReader NewStream()
       
   134         {
       
   135             return new StreamReader( new MemoryStream( iData, iOffset, iLength ) );
       
   136         }
       
   137         #endregion
       
   138 
       
   139         #region From IEnumerable<SymbolCollectionSegment>
       
   140         public IEnumerator<SymbolCollectionSegment> GetEnumerator()
       
   141         {
       
   142             foreach ( SymbolCollectionSegment segment in iCollectionSegments )
       
   143             {
       
   144                 yield return segment;
       
   145             }
       
   146         }
       
   147 
       
   148         System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
       
   149         {
       
   150             foreach ( SymbolCollectionSegment segment in iCollectionSegments )
       
   151             {
       
   152                 yield return segment;
       
   153             }
       
   154         }
       
   155         #endregion
       
   156 
       
   157         #region From DisposableObject
       
   158         protected override void CleanupManagedResources()
       
   159         {
       
   160             try
       
   161             {
       
   162                 base.CleanupManagedResources();
       
   163             }
       
   164             finally
       
   165             {
       
   166                 foreach ( SymbolCollectionSegment segment in iCollectionSegments )
       
   167                 {
       
   168                     segment.Dispose();
       
   169                 }
       
   170                 iCollectionSegments.Clear();
       
   171                 iCollectionSegments = null;
       
   172             }
       
   173         }
       
   174         #endregion
       
   175 
       
   176         #region Data members
       
   177         private readonly SymbolFileData iData;
       
   178         private readonly int iOffset;
       
   179         private readonly int iLength;
       
   180         private bool iIsReady = false;
       
   181         private long iNumberOfLines = 0;
       
   182         private List<SymbolCollectionSegment> iCollectionSegments = new List<SymbolCollectionSegment>();
       
   183         #endregion
       
   184     }
       
   185 }