|
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 System.Reflection; |
|
22 using SymbianParserLib.Engine; |
|
23 using CrashDebuggerLib.Structures.Fault; |
|
24 using SymbianParserLib.Elements; |
|
25 using CrashDebuggerLib.Parsers.State.Implementation; |
|
26 |
|
27 namespace CrashDebuggerLib.Parsers.State |
|
28 { |
|
29 internal static class StateFactory |
|
30 { |
|
31 #region API |
|
32 public static State Create( TState aState, CrashDebuggerParser aParser ) |
|
33 { |
|
34 CreateDictionary(); |
|
35 // |
|
36 State ret = null; |
|
37 if ( iDictionary.ContainsKey( aState ) ) |
|
38 { |
|
39 ret = CreateState( aState, aParser ); |
|
40 if ( ret != null ) |
|
41 { |
|
42 ret.Prepare(); |
|
43 } |
|
44 } |
|
45 // |
|
46 return ret; |
|
47 } |
|
48 |
|
49 public static void RegisterCommands( ParserEngine aEngine ) |
|
50 { |
|
51 CreateDictionary(); |
|
52 // |
|
53 foreach ( KeyValuePair<TState, TStateMapplet> keyVP in iDictionary ) |
|
54 { |
|
55 string[] commandIds = keyVP.Value.CommandIdentifiers; |
|
56 foreach ( string commandId in commandIds ) |
|
57 { |
|
58 // Create paragraph and associate the state type with the tag so that |
|
59 // we know what type of object to create later on when the line fires. |
|
60 ParserParagraph command = new ParserParagraph( commandId ); |
|
61 command.Tag = keyVP.Key; |
|
62 |
|
63 // Create line to match |
|
64 ParserLine line = ParserLine.New( commandId ); |
|
65 |
|
66 // Make sure that the paragraph and line don't disable themselves whenever |
|
67 // they see a matching line. Some of these objects are needed more than once! |
|
68 command.DisableWhenComplete = false; |
|
69 line.DisableWhenComplete = false; |
|
70 // |
|
71 command.Add( line ); |
|
72 aEngine.Add( command ); |
|
73 } |
|
74 } |
|
75 } |
|
76 #endregion |
|
77 |
|
78 #region Properties |
|
79 #endregion |
|
80 |
|
81 #region Internal methods |
|
82 private static void CreateDictionary() |
|
83 { |
|
84 if ( iDictionary.Count == 0 ) |
|
85 { |
|
86 // State table |
|
87 iDictionary.Add( TState.EStateInfoFault, |
|
88 new TStateMapplet( "*** CMD: Fault_Info", typeof( StateInfoFault ) ) ); |
|
89 iDictionary.Add( TState.EStateInfoCpu, |
|
90 new TStateMapplet( "*** CMD: Cpu_Info", typeof( StateInfoCpu ) ) ); |
|
91 iDictionary.Add( TState.EStateInfoDebugMask, |
|
92 new TStateMapplet( "*** CMD: Debug_Mask_Info", typeof( StateInfoDebugMask ) ) ); |
|
93 iDictionary.Add( TState.EStateInfoScheduler, |
|
94 new TStateMapplet( "*** CMD: Scheduler_Info", typeof( StateInfoScheduler ) ) ); |
|
95 |
|
96 // For compatibility reasons catch either of these entries |
|
97 iDictionary.Add( TState.EStateInfoUserContextTable, |
|
98 new TStateMapplet( typeof( StateInfoUserContextTable ), |
|
99 "*** CMD: UserContextTable_Info", |
|
100 "*** CMD: UserContextTables" ) ); |
|
101 |
|
102 // Other entries... |
|
103 iDictionary.Add( TState.EStateTheCurrentProcess, |
|
104 new TStateMapplet( "*** CMD: The_Current_Process", typeof( StateTheCurrentProcess ) ) ); |
|
105 iDictionary.Add( TState.EStateTheCurrentThread, |
|
106 new TStateMapplet( "*** CMD: The_Current_Thread", typeof( StateTheCurrentThread ) ) ); |
|
107 iDictionary.Add( TState.EStateContainerCodeSegs, |
|
108 new TStateMapplet( "*** CMD: container[CODESEG]", typeof( StateContainerCodeSegs ) ) ); |
|
109 iDictionary.Add( TState.EStateContainerThread, |
|
110 new TStateMapplet( "*** CMD: container[THREAD]", typeof( StateContainerThreads ) ) ); |
|
111 iDictionary.Add( TState.EStateContainerProcess, |
|
112 new TStateMapplet( "*** CMD: container[PROCESS]", typeof( StateContainerProcesses ) ) ); |
|
113 iDictionary.Add( TState.EStateContainerChunk, |
|
114 new TStateMapplet( "*** CMD: container[CHUNK]", typeof( StateContainerChunks ) ) ); |
|
115 iDictionary.Add( TState.EStateContainerLibrary, |
|
116 new TStateMapplet( "*** CMD: container[LIBRARY]", typeof( StateContainerLibraries ) ) ); |
|
117 iDictionary.Add( TState.EStateContainerSemaphore, |
|
118 new TStateMapplet( "*** CMD: container[SEMAPHORE]", typeof( StateContainerSemaphores ) ) ); |
|
119 iDictionary.Add( TState.EStateContainerMutex, |
|
120 new TStateMapplet( "*** CMD: container[MUTEX]", typeof( StateContainerMutexes ) ) ); |
|
121 iDictionary.Add( TState.EStateContainerTimer, |
|
122 new TStateMapplet( "*** CMD: container[TIMER]", typeof( StateContainerTimers ) ) ); |
|
123 iDictionary.Add( TState.EStateContainerServer, |
|
124 new TStateMapplet( "*** CMD: container[SERVER]", typeof( StateContainerServers ) ) ); |
|
125 iDictionary.Add( TState.EStateContainerSession, |
|
126 new TStateMapplet( "*** CMD: container[SESSION]", typeof( StateContainerSessions ) ) ); |
|
127 iDictionary.Add( TState.EStateContainerLogicalDevice, |
|
128 new TStateMapplet( "*** CMD: container[LOGICAL DEVICE]", typeof( StateContainerLogicalDevices ) ) ); |
|
129 iDictionary.Add( TState.EStateContainerPhysicalDevice, |
|
130 new TStateMapplet( "*** CMD: container[PHYSICAL DEVICE]", typeof( StateContainerPhysicalDevices ) ) ); |
|
131 iDictionary.Add( TState.EStateContainerLogicalChannel, |
|
132 new TStateMapplet( "*** CMD: container[LOGICAL CHANNEL]", typeof( StateContainerLogicalChannels ) ) ); |
|
133 iDictionary.Add( TState.EStateContainerChangeNotifier, |
|
134 new TStateMapplet( "*** CMD: container[CHANGE NOTIFIER]", typeof( StateContainerChangeNotifiers ) ) ); |
|
135 iDictionary.Add( TState.EStateContainerUndertaker, |
|
136 new TStateMapplet( "*** CMD: container[UNDERTAKER]", typeof( StateContainerUndertakers ) ) ); |
|
137 iDictionary.Add( TState.EStateContainerMessageQueue, |
|
138 new TStateMapplet( "*** CMD: container[MESSAGE QUEUE]", typeof( StateContainerMessageQueues ) ) ); |
|
139 iDictionary.Add( TState.EStateContainerPropertyRef, |
|
140 new TStateMapplet( "*** CMD: container[PROPERTY REF]", typeof( StateContainerPropertyRefs ) ) ); |
|
141 iDictionary.Add( TState.EStateContainerConditionalVariable, |
|
142 new TStateMapplet( "*** CMD: container[CONDITION VARIABLE]", typeof( StateContainerConditionalVariables ) ) ); |
|
143 iDictionary.Add( TState.EStateThreadStacks, |
|
144 new TStateMapplet( "*** CMD: Stack_Data[", typeof( StateThreadStacks ) ) ); |
|
145 } |
|
146 } |
|
147 |
|
148 private static State CreateState( TState aState, CrashDebuggerParser aParser ) |
|
149 { |
|
150 TStateMapplet maplet = iDictionary[ aState ]; |
|
151 State ret = maplet.CreateInstance( aParser ); |
|
152 return ret; |
|
153 } |
|
154 #endregion |
|
155 |
|
156 #region Data members |
|
157 private static Dictionary<TState, TStateMapplet> iDictionary = new Dictionary<TState, TStateMapplet>(); |
|
158 #endregion |
|
159 } |
|
160 |
|
161 #region Internal structure |
|
162 internal class TStateMapplet |
|
163 { |
|
164 #region Constructors |
|
165 public TStateMapplet( Type aType, params string[] aCommandIdentifiers ) |
|
166 { |
|
167 iCommandIdentifiers = aCommandIdentifiers; |
|
168 iType = aType; |
|
169 } |
|
170 |
|
171 public TStateMapplet( string aCommandIdentifier, Type aType ) |
|
172 { |
|
173 iCommandIdentifiers = new string[] { aCommandIdentifier }; |
|
174 iType = aType; |
|
175 } |
|
176 #endregion |
|
177 |
|
178 #region API |
|
179 public State CreateInstance( CrashDebuggerParser aParser ) |
|
180 { |
|
181 State state = null; |
|
182 // |
|
183 Binder binder = null; |
|
184 BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.CreateInstance; |
|
185 object[] args = { aParser }; |
|
186 object ret = iType.InvokeMember( string.Empty, bindingFlags, binder, null, args ); |
|
187 if ( ret != null ) |
|
188 { |
|
189 state = (State) ret; |
|
190 } |
|
191 // |
|
192 return state; |
|
193 } |
|
194 #endregion |
|
195 |
|
196 #region Properties |
|
197 public string[] CommandIdentifiers |
|
198 { |
|
199 get { return iCommandIdentifiers; } |
|
200 } |
|
201 #endregion |
|
202 |
|
203 #region Data members |
|
204 private readonly string[] iCommandIdentifiers; |
|
205 private readonly Type iType; |
|
206 #endregion |
|
207 } |
|
208 #endregion |
|
209 } |