|
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 SymbianUtils.Range; |
|
23 using SymbianStructuresLib.Debug.Symbols; |
|
24 using SymbianStructuresLib.Debug.Symbols.Interfaces; |
|
25 using SymbianStructuresLib.CodeSegments; |
|
26 using SymbianStructuresLib.Debug.Common.FileName; |
|
27 using SymbianSymbolLib.SourceManagement.Provisioning; |
|
28 |
|
29 namespace SymbianSymbolLib.SourceManagement.Source |
|
30 { |
|
31 public class SymSource : DisposableObject, IEnumerable<SymbolCollection>, ISymbolCollectionRelocationHandler |
|
32 { |
|
33 #region Delegates & events |
|
34 public delegate void EventHandlerFunction( TEvent aEvent, SymSource aSource, object aData ); |
|
35 public event EventHandlerFunction EventHandler; |
|
36 #endregion |
|
37 |
|
38 #region Enumerations |
|
39 public enum TEvent |
|
40 { |
|
41 EReadingStarted = 0, |
|
42 EReadingProgress, |
|
43 EReadingComplete |
|
44 } |
|
45 |
|
46 public enum TTimeToRead |
|
47 { |
|
48 EReadWhenPriming = 0, |
|
49 EReadWhenNeeded // i.e. relocated |
|
50 } |
|
51 #endregion |
|
52 |
|
53 #region Constructors |
|
54 public SymSource( string aURI, SymSourceProvider aProvider ) |
|
55 { |
|
56 iURI = aURI; |
|
57 iProvider = aProvider; |
|
58 } |
|
59 |
|
60 public SymSource( string aURI, SymSourceProvider aProvider, SymbolCollection aCollection ) |
|
61 : this( aURI, aProvider ) |
|
62 { |
|
63 Add( aCollection ); |
|
64 } |
|
65 #endregion |
|
66 |
|
67 #region API |
|
68 public virtual void Read( TSynchronicity aSynchronicity ) |
|
69 { |
|
70 iProvider.ReadSource( this, aSynchronicity ); |
|
71 } |
|
72 |
|
73 public virtual void Add( SymbolCollection aCollection ) |
|
74 { |
|
75 // We want to be told if the collection changes it's relocation state. |
|
76 aCollection.RelocationStatusChanged += new SymbolCollection.RelocationStatusChangeHandler( Collection_RelocationStatusChanged ); |
|
77 |
|
78 lock ( iCollectionsAll ) |
|
79 { |
|
80 iCollectionsAll.Add( aCollection ); |
|
81 } |
|
82 |
|
83 CategoriseCollection( aCollection ); |
|
84 } |
|
85 |
|
86 public virtual void Remove( SymbolCollection aCollection ) |
|
87 { |
|
88 aCollection.RelocationStatusChanged -= new SymbolCollection.RelocationStatusChangeHandler( Collection_RelocationStatusChanged ); |
|
89 // |
|
90 lock ( iCollectionsAll ) |
|
91 { |
|
92 iCollectionsAll.Remove( aCollection ); |
|
93 } |
|
94 lock ( iAlwaysActivatedCollections ) |
|
95 { |
|
96 iAlwaysActivatedCollections.Remove( aCollection ); |
|
97 } |
|
98 } |
|
99 |
|
100 public virtual bool Contains( uint aAddress ) |
|
101 { |
|
102 lock ( iAlwaysActivatedCollections ) |
|
103 { |
|
104 return iAlwaysActivatedCollections.Contains( aAddress ); |
|
105 } |
|
106 } |
|
107 |
|
108 public virtual Symbol Lookup( uint aAddress, out SymbolCollection aCollection ) |
|
109 { |
|
110 lock ( iAlwaysActivatedCollections ) |
|
111 { |
|
112 aCollection = null; |
|
113 // |
|
114 Symbol ret = iAlwaysActivatedCollections.Lookup( aAddress, out aCollection ); |
|
115 return ret; |
|
116 } |
|
117 } |
|
118 |
|
119 protected virtual void OnAddedToCollection( SymSourceCollection aCollection ) |
|
120 { |
|
121 ++iReferenceCount; |
|
122 } |
|
123 |
|
124 protected virtual void OnRemovedFromCollection( SymSourceCollection aCollection ) |
|
125 { |
|
126 if ( --iReferenceCount <= 0 ) |
|
127 { |
|
128 this.Dispose(); |
|
129 } |
|
130 } |
|
131 |
|
132 protected virtual void OnPrepareForRelocation( SymbolCollection aCollection, uint aOldBase, uint aNewBase ) |
|
133 { |
|
134 // If we read our data during priming, then we don't need to do anything... otherwise, we should |
|
135 // read the data now. |
|
136 if ( TimeToRead == TTimeToRead.EReadWhenNeeded ) |
|
137 { |
|
138 this.Read( TSynchronicity.ESynchronous ); |
|
139 } |
|
140 } |
|
141 #endregion |
|
142 |
|
143 #region API - framework |
|
144 public void ReportEvent( TEvent aEvent ) |
|
145 { |
|
146 if ( aEvent == TEvent.EReadingComplete ) |
|
147 { |
|
148 iAlwaysActivatedCollections.BuildLookupCache(); |
|
149 } |
|
150 |
|
151 ReportEvent( aEvent, null ); |
|
152 } |
|
153 |
|
154 public void ReportEvent( TEvent aEvent, object aData ) |
|
155 { |
|
156 if ( EventHandler != null ) |
|
157 { |
|
158 EventHandler( aEvent, this, aData ); |
|
159 } |
|
160 } |
|
161 #endregion |
|
162 |
|
163 #region Event handlers |
|
164 private void Collection_RelocationStatusChanged( SymbolCollection aCollection ) |
|
165 { |
|
166 CategoriseCollection( aCollection ); |
|
167 } |
|
168 #endregion |
|
169 |
|
170 #region Properties |
|
171 public int Count |
|
172 { |
|
173 get |
|
174 { |
|
175 lock ( iCollectionsAll ) |
|
176 { |
|
177 return iCollectionsAll.Count; |
|
178 } |
|
179 } |
|
180 } |
|
181 |
|
182 public string URI |
|
183 { |
|
184 get |
|
185 { |
|
186 lock ( iURI ) |
|
187 { |
|
188 return iURI; |
|
189 } |
|
190 } |
|
191 set |
|
192 { |
|
193 lock ( iURI ) |
|
194 { |
|
195 iURI = value; |
|
196 } |
|
197 } |
|
198 |
|
199 } |
|
200 |
|
201 public string FileName |
|
202 { |
|
203 get { return iProvider.GetFileName( this ); } |
|
204 } |
|
205 |
|
206 public TTimeToRead TimeToRead |
|
207 { |
|
208 get { return iTimeToRead; } |
|
209 set |
|
210 { |
|
211 iTimeToRead = value; |
|
212 } |
|
213 } |
|
214 |
|
215 public SymSourceProvider Provider |
|
216 { |
|
217 get |
|
218 { |
|
219 lock ( iProvider ) |
|
220 { |
|
221 return iProvider; |
|
222 } |
|
223 } |
|
224 } |
|
225 |
|
226 public SymbolCollection this[ int aIndex ] |
|
227 { |
|
228 get |
|
229 { |
|
230 lock ( iCollectionsAll ) |
|
231 { |
|
232 return iCollectionsAll[ aIndex ]; |
|
233 } |
|
234 } |
|
235 } |
|
236 |
|
237 public virtual SymbolCollection this[ CodeSegDefinition aCodeSegment ] |
|
238 { |
|
239 get |
|
240 { |
|
241 lock ( iCollectionsAll ) |
|
242 { |
|
243 SymbolCollection ret = iCollectionsAll[ aCodeSegment ]; |
|
244 return ret; |
|
245 } |
|
246 } |
|
247 } |
|
248 |
|
249 public virtual SymbolCollection this[ PlatformFileName aFileName ] |
|
250 { |
|
251 get |
|
252 { |
|
253 lock ( iCollectionsAll ) |
|
254 { |
|
255 SymbolCollection ret = iCollectionsAll[ aFileName ]; |
|
256 return ret; |
|
257 } |
|
258 } |
|
259 } |
|
260 #endregion |
|
261 |
|
262 #region Internal methods |
|
263 internal int CountActivated |
|
264 { |
|
265 get |
|
266 { |
|
267 lock ( iAlwaysActivatedCollections ) |
|
268 { |
|
269 return iAlwaysActivatedCollections.Count; |
|
270 } |
|
271 } |
|
272 } |
|
273 |
|
274 internal void AddedToCollection( SymSourceCollection aCollection ) |
|
275 { |
|
276 OnAddedToCollection( aCollection ); |
|
277 } |
|
278 |
|
279 internal void RemovedFromCollection( SymSourceCollection aCollection ) |
|
280 { |
|
281 OnRemovedFromCollection( aCollection ); |
|
282 } |
|
283 |
|
284 private void CategoriseCollection( SymbolCollection aCollection ) |
|
285 { |
|
286 // Reset state |
|
287 lock ( iAlwaysActivatedCollections ) |
|
288 { |
|
289 iAlwaysActivatedCollections.Remove( aCollection ); |
|
290 aCollection.IfaceRelocationHandler = null; |
|
291 } |
|
292 |
|
293 // Collections which do not move from their pre-determined base address |
|
294 // are transparently "activated" which means that they will be queried |
|
295 // automatically during symbolic look up. |
|
296 if ( aCollection.IsFixed ) |
|
297 { |
|
298 lock ( iAlwaysActivatedCollections ) |
|
299 { |
|
300 iAlwaysActivatedCollections.Add( aCollection ); |
|
301 } |
|
302 } |
|
303 else |
|
304 { |
|
305 aCollection.IfaceRelocationHandler = this; |
|
306 } |
|
307 } |
|
308 #endregion |
|
309 |
|
310 #region From ISymbolCollectionRelocationHandler |
|
311 public void PrepareForRelocation( SymbolCollection aCollection, uint aOldBase, uint aNewBase ) |
|
312 { |
|
313 OnPrepareForRelocation( aCollection, aOldBase, aNewBase ); |
|
314 } |
|
315 #endregion |
|
316 |
|
317 #region From IEnumerable<SymbolCollection> |
|
318 public IEnumerator<SymbolCollection> GetEnumerator() |
|
319 { |
|
320 lock ( iCollectionsAll ) |
|
321 { |
|
322 foreach ( SymbolCollection col in iCollectionsAll ) |
|
323 { |
|
324 yield return col; |
|
325 } |
|
326 } |
|
327 } |
|
328 |
|
329 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() |
|
330 { |
|
331 lock ( iCollectionsAll ) |
|
332 { |
|
333 foreach ( SymbolCollection col in iCollectionsAll ) |
|
334 { |
|
335 yield return col; |
|
336 } |
|
337 } |
|
338 } |
|
339 #endregion |
|
340 |
|
341 #region From DisposableObject |
|
342 protected override void CleanupManagedResources() |
|
343 { |
|
344 try |
|
345 { |
|
346 base.CleanupManagedResources(); |
|
347 } |
|
348 finally |
|
349 { |
|
350 int count = iCollectionsAll.Count; |
|
351 for ( int i = count - 1; i >= 0; i-- ) |
|
352 { |
|
353 SymbolCollection col = iCollectionsAll[ i ]; |
|
354 Remove( col ); |
|
355 col.Dispose(); |
|
356 } |
|
357 |
|
358 // These should both be empty in any case |
|
359 iCollectionsAll.Clear(); |
|
360 iAlwaysActivatedCollections.Clear(); |
|
361 } |
|
362 } |
|
363 #endregion |
|
364 |
|
365 #region From System.Object |
|
366 public override string ToString() |
|
367 { |
|
368 return URI; |
|
369 } |
|
370 |
|
371 public override int GetHashCode() |
|
372 { |
|
373 return URI.GetHashCode(); |
|
374 } |
|
375 |
|
376 public override bool Equals( object aObject ) |
|
377 { |
|
378 if ( aObject is SymSource ) |
|
379 { |
|
380 SymSource other = (SymSource) aObject; |
|
381 bool ret = ( string.Compare( other.URI, this.URI, StringComparison.CurrentCultureIgnoreCase ) == 0 ); |
|
382 return ret; |
|
383 } |
|
384 // |
|
385 return base.Equals( aObject ); |
|
386 } |
|
387 #endregion |
|
388 |
|
389 #region Data members |
|
390 private readonly SymSourceProvider iProvider; |
|
391 private string iURI = string.Empty; |
|
392 private int iReferenceCount = 0; |
|
393 private TTimeToRead iTimeToRead = TTimeToRead.EReadWhenPriming; |
|
394 private SymbolCollectionList iCollectionsAll = new SymbolCollectionList(); |
|
395 private SymbolCollectionList iAlwaysActivatedCollections = new SymbolCollectionList(); |
|
396 #endregion |
|
397 } |
|
398 } |