|
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.IO; |
|
20 using System.Collections.Generic; |
|
21 using System.Text; |
|
22 using System.ComponentModel; |
|
23 using SymbianUtils; |
|
24 using SymbianUtils.Tracer; |
|
25 using SymbianUtils.Threading; |
|
26 using SymbianUtils.FileTypes; |
|
27 using SymbianUtils.TextUtilities.Readers.Types.Array; |
|
28 using SymbianStructuresLib.Debug.Symbols; |
|
29 using SymbianSymbolLib.SourceManagement.Source; |
|
30 using SymbianSymbolLib.SourceManagement.Provisioning; |
|
31 using SLPluginSymbol.Data; |
|
32 using SLPluginSymbol.Source; |
|
33 |
|
34 namespace SLPluginSymbol.Reader |
|
35 { |
|
36 internal class SymbolFileReader : MultiThreadedProcessor<SymbolFileSegment> |
|
37 { |
|
38 #region Constructors |
|
39 public SymbolFileReader( SymbolSource aSource, SymbolFileData aData ) |
|
40 : base( aData, System.Threading.ThreadPriority.Lowest ) |
|
41 { |
|
42 iSource = aSource; |
|
43 iData = aData; |
|
44 |
|
45 // Count the total number of lines - this enables us to report progress |
|
46 foreach ( SymbolFileSegment segment in iData ) |
|
47 { |
|
48 iTotalNumberOfLines += segment.NumberOfLines; |
|
49 } |
|
50 } |
|
51 #endregion |
|
52 |
|
53 #region API |
|
54 public void Read( TSynchronicity aSynchronicity ) |
|
55 { |
|
56 base.Start( aSynchronicity ); |
|
57 } |
|
58 #endregion |
|
59 |
|
60 #region Properties |
|
61 #endregion |
|
62 |
|
63 #region Event handlers |
|
64 private void SymbolFileSegmentReader_Progress( SymbolFileSegmentReader aReader, long aTotalNumberOfLines, long aChunkSizeProcessed ) |
|
65 { |
|
66 bool report = false; |
|
67 int progress = 0; |
|
68 // |
|
69 lock ( iSyncRoot ) |
|
70 { |
|
71 iProgressSoFar += aChunkSizeProcessed; |
|
72 // |
|
73 float progressF = (float) iProgressSoFar / (float) iTotalNumberOfLines; |
|
74 progress = (int) ( progressF * 100.0f ); |
|
75 // |
|
76 if ( iProgressLastReported != progress ) |
|
77 { |
|
78 iProgressLastReported = progress; |
|
79 report = true; |
|
80 } |
|
81 // |
|
82 if ( report ) |
|
83 { |
|
84 System.Diagnostics.Debug.WriteLine( "SymbolFileReader - progress: " + progress ); |
|
85 iSource.ReportEvent( SymSource.TEvent.EReadingProgress, progress ); |
|
86 } |
|
87 } |
|
88 } |
|
89 #endregion |
|
90 |
|
91 #region Internal methods |
|
92 #endregion |
|
93 |
|
94 #region From MultiThreadedProcessor |
|
95 protected override void OnEvent( MultiThreadedProcessor<SymbolFileSegment>.TEvent aEvent ) |
|
96 { |
|
97 base.OnEvent( aEvent ); |
|
98 // |
|
99 switch ( aEvent ) |
|
100 { |
|
101 case MultiThreadedProcessor<SymbolFileSegment>.TEvent.EEventStarting: |
|
102 iSource.ReportEvent( SymSource.TEvent.EReadingStarted ); |
|
103 break; |
|
104 case MultiThreadedProcessor<SymbolFileSegment>.TEvent.EEventCompleted: |
|
105 iSource.ReportEvent( SymSource.TEvent.EReadingComplete ); |
|
106 this.Dispose(); |
|
107 System.Diagnostics.Debug.WriteLine( string.Format( "[Symbol Memory] END -> {0:d12}, source: {1}", System.GC.GetTotalMemory( true ), iSource.FileName ) ); |
|
108 break; |
|
109 default: |
|
110 break; |
|
111 } |
|
112 } |
|
113 |
|
114 protected override bool Process( SymbolFileSegment aItem ) |
|
115 { |
|
116 SymbolFileSegmentReader reader = new SymbolFileSegmentReader( aItem ); |
|
117 reader.Progress += new SymbolFileSegmentReader.ProgressHandler( SymbolFileSegmentReader_Progress ); |
|
118 reader.Read( TSynchronicity.ESynchronous ); |
|
119 return true; |
|
120 } |
|
121 #endregion |
|
122 |
|
123 #region From DisposableObject |
|
124 protected override void CleanupManagedResources() |
|
125 { |
|
126 try |
|
127 { |
|
128 base.CleanupManagedResources(); |
|
129 } |
|
130 finally |
|
131 { |
|
132 iData.Dispose(); |
|
133 |
|
134 // Since we've just flushed a large portion of file data (symbol files are BIG) |
|
135 // ensure that disposed objects are released in order to reduce memory footprint. |
|
136 GC.Collect(); |
|
137 GC.WaitForPendingFinalizers(); |
|
138 } |
|
139 } |
|
140 #endregion |
|
141 |
|
142 #region Data members |
|
143 private readonly SymbolSource iSource; |
|
144 private readonly SymbolFileData iData; |
|
145 private readonly long iTotalNumberOfLines; |
|
146 private long iProgressSoFar = 0; |
|
147 private object iSyncRoot = new object(); |
|
148 private int iProgressLastReported = -1; |
|
149 #endregion |
|
150 } |
|
151 } |