|
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 SymbolLib.CodeSegDef; |
|
20 using SymbolLib.Engines.Common; |
|
21 using SymbolLib.Sources.Map.Engine; |
|
22 using SymbolLib.Sources.Map.Parser; |
|
23 using SymbolLib.Sources.Map.File; |
|
24 using SymbolLib.Sources.Symbol.Engine; |
|
25 using SymbolLib.Sources.Symbol.File; |
|
26 using SymbolLib.Generics; |
|
27 using SymbianUtils; |
|
28 using SymbianUtils.Range; |
|
29 using SymbianUtils.Tracer; |
|
30 |
|
31 namespace SymbolLib.Engines.ROM |
|
32 { |
|
33 public class ROMEngine : SymbolEngineBase |
|
34 { |
|
35 #region Constructor & destructor |
|
36 internal ROMEngine( ITracer aTracer ) |
|
37 : base( aTracer ) |
|
38 { |
|
39 iEngineSymbol = new SymbolFileEngine( this, SymbolFileEngine.TActivationType.EImmediate, false ); |
|
40 iEngineSymbol.Observer += new SymbianUtils.AsyncReaderBase.Observer( SymbolEngine_Observer ); |
|
41 } |
|
42 #endregion |
|
43 |
|
44 #region API |
|
45 public static TFileType IsSupported( string aFileName ) |
|
46 { |
|
47 TFileType ret = TFileType.EFileNotSupported; |
|
48 // |
|
49 try |
|
50 { |
|
51 string extension = Path.GetExtension( aFileName ).ToLower(); |
|
52 if ( extension == ".symbol" ) |
|
53 { |
|
54 SymbolFileEngine tempEngine = new SymbolFileEngine( null, SymbolFileEngine.TActivationType.EOnDemand, false ); |
|
55 SymbolsForBinary symbols = tempEngine.ReadFirstCollection( aFileName ); |
|
56 |
|
57 // For a valid ROFS symbol file, the first symbol should have an address of zero. |
|
58 bool containedNonZeroFirstSymbolCollection = ( symbols != null && symbols.Count > 0 && symbols[ 0 ].Address != 0 ); |
|
59 if ( containedNonZeroFirstSymbolCollection ) |
|
60 { |
|
61 ret = TFileType.EFileRomSymbol; |
|
62 } |
|
63 } |
|
64 } |
|
65 catch ( Exception ) |
|
66 { |
|
67 } |
|
68 // |
|
69 return ret; |
|
70 } |
|
71 #endregion |
|
72 |
|
73 #region Properties |
|
74 #endregion |
|
75 |
|
76 #region From SymbolEngineBase |
|
77 public override bool AddressInRange( long aAddress ) |
|
78 { |
|
79 bool ret = iEngineSymbol.Range.Contains( aAddress ); |
|
80 return ret; |
|
81 } |
|
82 |
|
83 public override int FileNameCount |
|
84 { |
|
85 get |
|
86 { |
|
87 return 1; |
|
88 } |
|
89 } |
|
90 |
|
91 public override string FileName( int aIndex ) |
|
92 { |
|
93 string ret = string.Empty; |
|
94 // |
|
95 if ( aIndex == 0 ) |
|
96 { |
|
97 ret = iEngineSymbol.SymbolFileName; |
|
98 } |
|
99 // |
|
100 return ret; |
|
101 } |
|
102 |
|
103 public override void LoadFromFile( string aFileName, TSynchronicity aSynchronicity ) |
|
104 { |
|
105 string extn = Path.GetExtension( aFileName ).ToLower(); |
|
106 if ( extn == ".symbol" ) |
|
107 { |
|
108 // ROM engine only supports loading a single symbol file |
|
109 // at once. First unload any old file, then load new one. |
|
110 UnloadAll(); |
|
111 iEngineSymbol.LoadFromFile( aFileName, aSynchronicity ); |
|
112 } |
|
113 else |
|
114 { |
|
115 throw new NotSupportedException(); |
|
116 } |
|
117 } |
|
118 |
|
119 public override void UnloadAll() |
|
120 { |
|
121 Reset(); |
|
122 } |
|
123 |
|
124 public override bool IsLoaded( CodeSegDefinition aDefinition ) |
|
125 { |
|
126 bool loaded = iEngineSymbol.IsLoaded( aDefinition ); |
|
127 return loaded; |
|
128 } |
|
129 #endregion |
|
130 |
|
131 #region From GenericSymbolEngine |
|
132 public override bool IsReady |
|
133 { |
|
134 get |
|
135 { |
|
136 return iEngineSymbol.IsReady; |
|
137 } |
|
138 } |
|
139 |
|
140 public override void Reset() |
|
141 { |
|
142 iEngineSymbol.Reset(); |
|
143 } |
|
144 |
|
145 public override bool IsLoaded( string aFileName ) |
|
146 { |
|
147 bool loaded = iEngineSymbol.IsLoaded( aFileName ); |
|
148 return loaded; |
|
149 } |
|
150 |
|
151 public override GenericSymbolCollection this[ int aIndex ] |
|
152 { |
|
153 get |
|
154 { |
|
155 GenericSymbolCollection ret = iEngineSymbol[ aIndex ]; |
|
156 return ret; |
|
157 } |
|
158 } |
|
159 |
|
160 public override AddressRange Range |
|
161 { |
|
162 get |
|
163 { |
|
164 return iEngineSymbol.Range; |
|
165 } |
|
166 } |
|
167 |
|
168 internal override void UnloadUntagged() |
|
169 { |
|
170 |
|
171 } |
|
172 #endregion |
|
173 |
|
174 #region From IGenericSymbolCollectionStatisticsInterface |
|
175 public override int NumberOfCollections |
|
176 { |
|
177 get |
|
178 { |
|
179 return iEngineSymbol.NumberOfCollections; |
|
180 } |
|
181 } |
|
182 #endregion |
|
183 |
|
184 #region Event handlers |
|
185 private void SymbolEngine_Observer( SymbianUtils.AsyncReaderBase.TEvent aEvent, SymbianUtils.AsyncReaderBase aSender ) |
|
186 { |
|
187 switch( aEvent ) |
|
188 { |
|
189 case SymbianUtils.AsyncReaderBase.TEvent.EReadingStarted: |
|
190 OnParsingStarted( iEngineSymbol.SymbolFileName ); |
|
191 break; |
|
192 case SymbianUtils.AsyncReaderBase.TEvent.EReadingProgress: |
|
193 OnParsingProgress( iEngineSymbol.SymbolFileName, aSender.Progress ); |
|
194 break; |
|
195 case SymbianUtils.AsyncReaderBase.TEvent.EReadingComplete: |
|
196 OnParsingCompleted( iEngineSymbol.SymbolFileName ); |
|
197 break; |
|
198 } |
|
199 } |
|
200 #endregion |
|
201 |
|
202 #region Internal methods |
|
203 #endregion |
|
204 |
|
205 #region Data members |
|
206 private readonly SymbolFileEngine iEngineSymbol; |
|
207 #endregion |
|
208 } |
|
209 } |