crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbianUtils/TextUtilities/Readers/Types/Text/AsyncTextReader.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.Text;
       
    20 using System.Threading;
       
    21 using System.Collections;
       
    22 using SymbianUtils.Tracer;
       
    23 
       
    24 namespace SymbianUtils
       
    25 {
       
    26 	public abstract class AsyncTextReader : AsyncTextReaderBase
       
    27 	{
       
    28 		#region Constructors
       
    29 		protected AsyncTextReader()
       
    30             : this( new AsyncTextReaderPrefix() )
       
    31         {
       
    32 		}
       
    33 
       
    34         protected AsyncTextReader( ITracer aTracer )
       
    35 		:   this( new AsyncTextReaderPrefix(), aTracer )
       
    36 		{
       
    37 		}
       
    38 
       
    39         protected AsyncTextReader( AsyncTextReaderPrefix aPrefixes )
       
    40 		:	this( aPrefixes, null )
       
    41 		{
       
    42 		}
       
    43    
       
    44         protected AsyncTextReader( AsyncTextReaderPrefix aPrefixes, ITracer aTracer )
       
    45             : this( aPrefixes, false, aTracer )
       
    46         {
       
    47         }
       
    48 
       
    49         protected AsyncTextReader( AsyncTextReaderPrefix aPrefixes, bool aRouteBlankLines, ITracer aTracer )
       
    50             : base( aTracer )
       
    51 		{
       
    52 			iPrefixes = aPrefixes;
       
    53 			iRouteBlankLines = aRouteBlankLines;
       
    54 		}
       
    55 		#endregion
       
    56 
       
    57 		#region API
       
    58 		public void AddFilter( AsyncTextReaderFilter aFilter )
       
    59 		{
       
    60 			iFilters.Add( aFilter );
       
    61 		}
       
    62 		#endregion
       
    63 
       
    64 		#region Properties
       
    65 		public AsyncTextReaderPrefix PrefixDefinition
       
    66 		{
       
    67 			get { return iPrefixes; }
       
    68 		}
       
    69 
       
    70 		public AsyncTextReaderFilterCollection Filters
       
    71 		{
       
    72 			get { return iFilters; }
       
    73 		}
       
    74 
       
    75 		public bool RouteBlankLines
       
    76 		{
       
    77 			get { return iRouteBlankLines; }
       
    78 		}
       
    79 
       
    80         public string OriginalLine
       
    81         {
       
    82             get { return iOriginalLine; }
       
    83         }
       
    84 		#endregion
       
    85 
       
    86 		#region New Framework
       
    87 		protected abstract void HandleFilteredLine( string aLine );
       
    88 		#endregion
       
    89 
       
    90 		#region From AsyncTextReaderBase
       
    91 		protected override void HandleReadLine( string aLine )
       
    92 		{
       
    93             iOriginalLine = ( aLine != null ? aLine : string.Empty );
       
    94 			bool isBlankLine = ( aLine != null && aLine.Length == 0 );
       
    95 			//
       
    96 			if ( aLine != null )
       
    97 			{
       
    98 				if	( ( isBlankLine && RouteBlankLines ) || aLine.Length > 0 )
       
    99 				{
       
   100 					// Clean it
       
   101 					if	( !isBlankLine )
       
   102 					{
       
   103 						iPrefixes.Clean( ref aLine );
       
   104 					}
       
   105 
       
   106 					// Process filter on line
       
   107 					bool propagateLine = true;
       
   108 					if	( iFilters != null && !isBlankLine )
       
   109 					{
       
   110 						propagateLine = iFilters.ProcessFilters( ref aLine );
       
   111 					}
       
   112                 
       
   113 					// Notify derived classes
       
   114 					if	( propagateLine )
       
   115 					{
       
   116 						HandleFilteredLine( aLine );
       
   117 					}
       
   118 				}
       
   119 			}
       
   120 		}
       
   121 		#endregion
       
   122 
       
   123 		#region Data members
       
   124 		private readonly AsyncTextReaderPrefix iPrefixes;
       
   125 		private readonly bool iRouteBlankLines;
       
   126         private string iOriginalLine = string.Empty;
       
   127 		private AsyncTextReaderFilterCollection iFilters = new AsyncTextReaderFilterCollection();
       
   128 		#endregion
       
   129 	}
       
   130 }