|
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.Threading; |
|
18 using SymbianUtils; |
|
19 using SymbianDebugLib.Engine; |
|
20 using SymbianDebugLib.Entity.Configurations; |
|
21 using CrashItemLib.Engine; |
|
22 using System; |
|
23 using CrashItemLib.Crash.Messages; |
|
24 |
|
25 namespace CrashItemLib.Crash.Container |
|
26 { |
|
27 internal class CIContainerIndexProcessor |
|
28 { |
|
29 #region Enumerations |
|
30 public enum TEvent |
|
31 { |
|
32 EEventStarting = 0, |
|
33 EEventCompleted |
|
34 } |
|
35 #endregion |
|
36 |
|
37 #region Delegates & events |
|
38 public delegate void ProcessorEventHandler( TEvent aEvent ); |
|
39 public event ProcessorEventHandler EventHandler = delegate { }; |
|
40 #endregion |
|
41 |
|
42 #region Constructors |
|
43 public CIContainerIndexProcessor( CIContainerIndex aIndex, CIEngine aEngine ) |
|
44 { |
|
45 iIndex = aIndex; |
|
46 iEngine = aEngine; |
|
47 } |
|
48 #endregion |
|
49 |
|
50 #region API |
|
51 public void Start( TSynchronicity aSynchronicity ) |
|
52 { |
|
53 if ( aSynchronicity == TSynchronicity.EAsynchronous ) |
|
54 { |
|
55 ThreadPool.QueueUserWorkItem( new WaitCallback( RunWorker ) ); |
|
56 } |
|
57 else |
|
58 { |
|
59 RunWorker(); |
|
60 } |
|
61 } |
|
62 #endregion |
|
63 |
|
64 #region Properties |
|
65 #endregion |
|
66 |
|
67 #region Internal methods |
|
68 private void RunWorker() |
|
69 { |
|
70 RunWorker(null); |
|
71 } |
|
72 |
|
73 private void RunWorker( object aNotUsed ) |
|
74 { |
|
75 iEngine.Trace( "[CIContainerIndexProcessor] RunWorker() - START - index groupings: {0}", iIndex.Count ); |
|
76 |
|
77 EventHandler( TEvent.EEventStarting ); |
|
78 |
|
79 DbgEngine debugEngine = iEngine.DebugEngine; |
|
80 bool needToPrimeDebugEngine = debugEngine.MetaDataConfig.IsConfigurationDataAvailable; |
|
81 iEngine.Trace( "[CIContainerIndexProcessor] RunWorker() - needToPrimeDebugEngine: {0}", needToPrimeDebugEngine ); |
|
82 |
|
83 // Process the index "buckets" until all are exhausted. |
|
84 for ( CIContainerCollection collection = iIndex.DequeueNextContainer(); collection != null; collection = iIndex.DequeueNextContainer() ) |
|
85 { |
|
86 try |
|
87 { |
|
88 if ( collection.Count > 0 ) |
|
89 { |
|
90 // Get the rom serial number - all containers in the collection share a common serial |
|
91 uint serialNumber = CIContainerIndex.GetRomChecksum( collection[ 0 ] ); |
|
92 iEngine.Trace( "[CIContainerIndexProcessor] RunWorker() - {0} containers for rom checksum: 0x{1:x8}", collection.Count, serialNumber ); |
|
93 |
|
94 // Prepare debug engine meta-data as needed. |
|
95 if ( needToPrimeDebugEngine ) |
|
96 { |
|
97 DbgEntityConfigIdentifier identifier = new DbgEntityConfigIdentifier( serialNumber ); |
|
98 |
|
99 iEngine.Trace( "[CIContainerIndexProcessor] RunWorker() - synchronously switching debug meta-data config..." ); |
|
100 debugEngine.ConfigManager.SwitchConfigurationSynchronously( identifier ); |
|
101 iEngine.Trace( "[CIContainerIndexProcessor] RunWorker() - switch complete." ); |
|
102 } |
|
103 |
|
104 // Process the list of crash item containers in separate threads until all are handled. |
|
105 // This is quite a heavyweight operation since it also potentially primes the debug engine with |
|
106 // the needed symbols and then finalizes every associated crash container. |
|
107 // However, we run this in a separate thread so it will not block the UI. |
|
108 iEngine.Trace( "[CIContainerIndexProcessor] RunWorker() - running finalizer for {0} items with rom checksum: 0x{1:x8}", collection.Count, serialNumber ); |
|
109 |
|
110 // We wait until the finalizer is finished, but we're running in a worker thread so this is OK. |
|
111 CIContainerFinalizer finalizer = new CIContainerFinalizer( collection, iEngine ); |
|
112 finalizer.Start( SymbianUtils.TSynchronicity.ESynchronous ); |
|
113 |
|
114 iEngine.Trace( "[CIContainerIndexProcessor] RunWorker() - finalization complete for {0} items with rom checksum: 0x{1:x8}", collection.Count, serialNumber ); |
|
115 } |
|
116 } |
|
117 catch (Exception e) |
|
118 { |
|
119 iEngine.Trace("Error: RunWorker() hit an unexpected exception!"); |
|
120 |
|
121 foreach (CIContainer container in collection) |
|
122 { |
|
123 CIMessageError error = new CIMessageError(container, "RunWorker failed"); |
|
124 error.AddLine("Unexpected exception encountered during container processing - analysis has failed!"); |
|
125 container.Messages.Add(error); |
|
126 } |
|
127 } |
|
128 } |
|
129 iEngine.Trace( "[CIContainerIndexProcessor] RunWorker() - Notifying about completion..." ); |
|
130 |
|
131 EventHandler( TEvent.EEventCompleted ); |
|
132 |
|
133 iEngine.Trace( "[CIContainerIndexProcessor] RunWorker() - END" ); |
|
134 } |
|
135 #endregion |
|
136 |
|
137 #region Data members |
|
138 private readonly CIContainerIndex iIndex; |
|
139 private readonly CIEngine iEngine; |
|
140 #endregion |
|
141 } |
|
142 } |