crashanalysercmd/Libraries/Engine/CrashItemLib/Engine/Sources/Types/CIEngineSourceReaderNative.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;
       
    20 using System.Collections.Generic;
       
    21 using System.Text;
       
    22 using SymbianUtils;
       
    23 using CrashItemLib.PluginAPI;
       
    24 using CrashItemLib.Crash.Source;
       
    25 using CrashItemLib.Crash.Container;
       
    26 
       
    27 namespace CrashItemLib.Engine.Sources.Types
       
    28 {
       
    29     internal sealed class CIEngineSourceReaderNative : CIEngineSourceReader
       
    30     {
       
    31         #region Constructors
       
    32         public CIEngineSourceReaderNative( CIEngineSource aSource, CFFSource aPluginSource )
       
    33             : base( aSource )
       
    34         {
       
    35             iPluginSource = aPluginSource;
       
    36         }
       
    37         #endregion
       
    38 
       
    39         #region From CIEngineSourceReader
       
    40         public override CIEngineSource.TState Read()
       
    41         {
       
    42             CIEngineSource.TState ret = CIEngineSource.TState.EStateReadyCorrupt;
       
    43             CFFReader reader = iPluginSource.Reader;
       
    44             //
       
    45             try
       
    46             {
       
    47                 reader.Observer += new CFFReader.ReaderObserver( CFFReader_Observer );
       
    48                 reader.ExceptionHandler += new CFFReader.ReaderExceptionHandler( CFFReader_ExceptionHandler );
       
    49 
       
    50                 // Perform synchronous read
       
    51                 reader.OnNativeReadInit();
       
    52 
       
    53                 // Decide final state
       
    54                 CFFReader.TState readerState = reader.State;
       
    55                 switch ( readerState )
       
    56                 {
       
    57                 default:
       
    58                 case CFFReader.TState.EStateProcessing:
       
    59                 case CFFReader.TState.EStateUninitialised:
       
    60                     SymbianUtils.SymDebug.SymDebugger.Assert( false );
       
    61                     break;
       
    62                 case CFFReader.TState.EStateCorrupt:
       
    63                     ret = CIEngineSource.TState.EStateReadyCorrupt;
       
    64                     break;
       
    65                 case CFFReader.TState.EStateReady:
       
    66                     if ( base.CrashItemCount > 0 )
       
    67                     {
       
    68                         ret = CIEngineSource.TState.EStateReady;
       
    69                     }
       
    70                     else
       
    71                     {
       
    72                         ret = CIEngineSource.TState.EStateReadyNoItems;
       
    73                     }
       
    74                     break;
       
    75                 }
       
    76             }
       
    77             finally
       
    78             {
       
    79                 reader.Observer -= new CFFReader.ReaderObserver( CFFReader_Observer );
       
    80                 reader.ExceptionHandler -= new CFFReader.ReaderExceptionHandler( CFFReader_ExceptionHandler );
       
    81             }
       
    82             //
       
    83             return ret;
       
    84         }
       
    85 
       
    86         public override CFFSource.TReaderOperationType OpType
       
    87         {
       
    88             get { return CFFSource.TReaderOperationType.EReaderOpTypeNative; }
       
    89         }
       
    90         #endregion
       
    91 
       
    92         #region Properties
       
    93         #endregion
       
    94 
       
    95         #region Event Handlers
       
    96         private void CFFReader_Observer( CFFReader.TEvent aEvent, CFFReader aReader, object aContext )
       
    97         {
       
    98             base.Trace( "[CIEngineSourceNative] CFFReader_Observer() - START - aEvent: " + aEvent + ", file: " + base.Source.FileName );
       
    99 
       
   100             // This method is called for both native and trace based events
       
   101             if ( aEvent == CFFReader.TEvent.EReadingContainerCreated )
       
   102             {
       
   103                 CIContainer container = aContext as CIContainer;
       
   104                 if ( container != null )
       
   105                 {
       
   106                     base.SaveCrash( container );
       
   107                 }
       
   108             }
       
   109             else if ( aEvent == CFFReader.TEvent.EReadingProgress )
       
   110             {
       
   111                 int progress = ( aContext != null && aContext is int ) ? (int) aContext : 0;
       
   112                 base.Source.OnSourceReadingProgress( progress );
       
   113             }
       
   114 
       
   115             base.Trace( "[CIEngineSourceNative] CFFReader_Observer() - END - aEvent: " + aEvent + ", file: " + base.Source.FileName );
       
   116         }
       
   117 
       
   118         private void CFFReader_ExceptionHandler( Exception aException, CFFReader aReader )
       
   119         {
       
   120             base.AddException( aException );
       
   121         }
       
   122         #endregion
       
   123 
       
   124         #region Internal methods
       
   125         #endregion
       
   126 
       
   127         #region Data members
       
   128         private readonly CFFSource iPluginSource;
       
   129         #endregion
       
   130     }
       
   131 }