|
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 using SymbianUtils; |
|
22 using SymbianParserLib.Engine; |
|
23 using SymbianParserLib.Elements; |
|
24 using CrashDebuggerLib.Parsers.State; |
|
25 using CrashDebuggerLib.Structures; |
|
26 |
|
27 namespace CrashDebuggerLib.Parsers |
|
28 { |
|
29 public class CrashDebuggerParser : AsyncTextFileReader |
|
30 { |
|
31 #region Constructors |
|
32 public CrashDebuggerParser( CrashDebuggerInfo aCrashDebugger, string aFileName ) |
|
33 : base( aFileName ) |
|
34 { |
|
35 iCrashDebugger = aCrashDebugger; |
|
36 // |
|
37 iCommandParser.ParagraphComplete += new SymbianParserLib.BaseStructures.ParserElementBase.ElementCompleteHandler( CommandParser_ParagraphComplete ); |
|
38 PrepareCommandParser(); |
|
39 |
|
40 // We need to preserve white space |
|
41 TrimLine = false; |
|
42 } |
|
43 #endregion |
|
44 |
|
45 #region API |
|
46 public void ParseCrashData() |
|
47 { |
|
48 base.AsyncRead(); |
|
49 } |
|
50 #endregion |
|
51 |
|
52 #region Properties |
|
53 public CrashDebuggerInfo CrashDebugger |
|
54 { |
|
55 get { return iCrashDebugger; } |
|
56 } |
|
57 #endregion |
|
58 |
|
59 #region Internal methods |
|
60 private void PrepareCommandParser() |
|
61 { |
|
62 StateFactory.RegisterCommands( iCommandParser ); |
|
63 } |
|
64 #endregion |
|
65 |
|
66 #region Internal constants |
|
67 #endregion |
|
68 |
|
69 #region Event handlers |
|
70 void CommandParser_ParagraphComplete( SymbianParserLib.BaseStructures.ParserElementBase aElement ) |
|
71 { |
|
72 TState state = (TState) aElement.Tag; |
|
73 State.State nextState = StateFactory.Create( state, this ); |
|
74 // |
|
75 if ( iStateObject != null ) |
|
76 { |
|
77 iStateObject.Finalise(); |
|
78 iStateObject = null; |
|
79 } |
|
80 // |
|
81 if ( nextState == null ) |
|
82 { |
|
83 throw new ArgumentException( "Invalid state: " + state ); |
|
84 } |
|
85 // |
|
86 iStateObject = nextState; |
|
87 iCurrentState = state; |
|
88 // |
|
89 #if DEBUG |
|
90 System.Diagnostics.Debug.WriteLine( "SWITCHING STATE: => " + iStateObject.GetType().ToString() ); |
|
91 #endif |
|
92 } |
|
93 #endregion |
|
94 |
|
95 #region From AsyncTextFileReader |
|
96 protected override void HandleReadStarted() |
|
97 { |
|
98 iCrashDebugger.Clear(); |
|
99 base.HandleReadStarted(); |
|
100 } |
|
101 |
|
102 protected override void HandleReadCompleted() |
|
103 { |
|
104 try |
|
105 { |
|
106 if ( iStateObject != null ) |
|
107 { |
|
108 iStateObject.Finalise(); |
|
109 iStateObject = null; |
|
110 } |
|
111 |
|
112 // Start the async op queue |
|
113 iCrashDebugger.AsyncOperationManager.Start(); |
|
114 } |
|
115 finally |
|
116 { |
|
117 base.HandleReadCompleted(); |
|
118 } |
|
119 |
|
120 System.Diagnostics.Debug.WriteLine( "TOTAL REGEX TICKS - " + SymbianParserLib.RegExTranslators.TheTickCounter.TickCount.ToString( "d12" ) ); |
|
121 } |
|
122 |
|
123 protected override void HandleFilteredLine( string aLine ) |
|
124 { |
|
125 string line = aLine; |
|
126 bool consumed = iCommandParser.OfferLine( ref line ); |
|
127 if ( !consumed && iStateObject != null ) |
|
128 { |
|
129 ParserEngine stateParser = iStateObject.ParserEngine; |
|
130 stateParser.OfferLine( ref line ); |
|
131 } |
|
132 } |
|
133 #endregion |
|
134 |
|
135 #region From System.Object |
|
136 public override string ToString() |
|
137 { |
|
138 return base.ToString(); |
|
139 } |
|
140 #endregion |
|
141 |
|
142 #region Internal LUT |
|
143 #endregion |
|
144 |
|
145 #region Data members |
|
146 private readonly CrashDebuggerInfo iCrashDebugger; |
|
147 private ParserEngine iCommandParser = new ParserEngine(); |
|
148 private State.State iStateObject = null; |
|
149 private TState iCurrentState = TState.EStateIdle; |
|
150 #endregion |
|
151 } |
|
152 } |