|
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 System.Collections; |
|
20 using System.Collections.Generic; |
|
21 using System.Text; |
|
22 using CrashItemLib.PluginAPI; |
|
23 using CrashItemLib.Crash.Source; |
|
24 using CrashItemLib.Engine.Sources; |
|
25 |
|
26 namespace CrashItemLib.Engine.Primer |
|
27 { |
|
28 internal class CIPrimerWorkingSet |
|
29 { |
|
30 #region Constructors |
|
31 public CIPrimerWorkingSet( CIEngine aEngine ) |
|
32 { |
|
33 iEngine = aEngine; |
|
34 } |
|
35 #endregion |
|
36 |
|
37 #region API |
|
38 public void Clear() |
|
39 { |
|
40 iEntries.Clear(); |
|
41 } |
|
42 |
|
43 public void Add( CFFSourceAndConfidence aEntry ) |
|
44 { |
|
45 // For every single source file we might actually have multiple |
|
46 // plugins that claim they can interpet the contents. |
|
47 // |
|
48 // Therefore we maintain a dictionary that is keyed by the file name |
|
49 // and contains a list of plugin handlers (and their associatied |
|
50 // confidence level for handling the source file). |
|
51 List<CFFSourceAndConfidence> entries = null; |
|
52 // |
|
53 FileInfo file = aEntry.MasterFile; |
|
54 System.Diagnostics.Debug.Assert( file != null ); |
|
55 // |
|
56 if ( !iEntries.ContainsKey( file ) ) |
|
57 { |
|
58 entries = new List<CFFSourceAndConfidence>(); |
|
59 iEntries.Add( file, entries ); |
|
60 } |
|
61 else |
|
62 { |
|
63 entries = iEntries[ file ]; |
|
64 } |
|
65 // |
|
66 entries.Add( aEntry ); |
|
67 } |
|
68 |
|
69 public void Add( IEnumerable<CFFSourceAndConfidence> aEntries ) |
|
70 { |
|
71 foreach ( CFFSourceAndConfidence level in aEntries ) |
|
72 { |
|
73 Add( level ); |
|
74 } |
|
75 } |
|
76 |
|
77 public void Rationalise() |
|
78 { |
|
79 // At this point we're ready to decide how we will process the source |
|
80 // files. Some may be trace files, in which case we probably need to multiple |
|
81 // the various plugin handlers (that support trace-based content) so that they |
|
82 // can each have a stab at handling the trace content. |
|
83 // |
|
84 // For native (non-trace) handlers, we only let the handler with the highest |
|
85 // confidence ultimately read the file. |
|
86 // |
|
87 // 1) For any native entries, sort them by priority and discard |
|
88 // everything but the highest priority entry. |
|
89 // |
|
90 // 2) For any trace entries, then we basically don't need to do anything |
|
91 // because all entries will require processing via a trace reader. |
|
92 foreach ( KeyValuePair<FileInfo, List<CFFSourceAndConfidence>> kvp in iEntries ) |
|
93 { |
|
94 // For native entries relating to this file |
|
95 List<CFFSourceAndConfidence> listNative = new List<CFFSourceAndConfidence>(); |
|
96 |
|
97 // For trace entries relating to this file |
|
98 List<CFFSourceAndConfidence> listTrace = new List<CFFSourceAndConfidence>(); |
|
99 |
|
100 FileInfo file = kvp.Key; |
|
101 List<CFFSourceAndConfidence> entries = kvp.Value; |
|
102 foreach ( CFFSourceAndConfidence conf in entries ) |
|
103 { |
|
104 if ( conf.OpType == CFFSource.TReaderOperationType.EReaderOpTypeNative ) |
|
105 { |
|
106 listNative.Add( conf ); |
|
107 } |
|
108 else if ( conf.OpType == CFFSource.TReaderOperationType.EReaderOpTypeTrace ) |
|
109 { |
|
110 listTrace.Add( conf ); |
|
111 } |
|
112 else |
|
113 { |
|
114 // Not supported |
|
115 } |
|
116 } |
|
117 |
|
118 // Sort the native list based upon confidence level |
|
119 Comparison<CFFSourceAndConfidence> comparer = delegate( CFFSourceAndConfidence aLeft, CFFSourceAndConfidence aRight ) |
|
120 { |
|
121 return aLeft.CompareTo( aRight ); |
|
122 }; |
|
123 listNative.Sort( comparer ); |
|
124 |
|
125 // Save highest priority native entry - only try to treat the source file as a |
|
126 // trace entry if no native entries claim to be able to read it. |
|
127 if ( listNative.Count > 0 ) |
|
128 { |
|
129 CFFSourceAndConfidence highestConfidence = listNative[ 0 ]; |
|
130 CIEngineSource sourceNative = CIEngineSource.NewNative( iEngine, highestConfidence ); |
|
131 iEngine.Sources.Add( sourceNative ); |
|
132 } |
|
133 else if ( listTrace.Count > 0 ) |
|
134 { |
|
135 // If we found some trace entries, then immediately store the trace source. |
|
136 // The listTrace array contains all of the plugins that claim to be able to |
|
137 // read the trace-based source file. |
|
138 CIEngineSource sourceTrace = CIEngineSource.NewTrace( iEngine, listTrace.ToArray() ); |
|
139 iEngine.Sources.Add( sourceTrace ); |
|
140 } |
|
141 } |
|
142 } |
|
143 #endregion |
|
144 |
|
145 #region Properties |
|
146 #endregion |
|
147 |
|
148 #region Data members |
|
149 private readonly CIEngine iEngine; |
|
150 private Dictionary< FileInfo, List<CFFSourceAndConfidence> > iEntries = new Dictionary< FileInfo, List<CFFSourceAndConfidence> >(); |
|
151 #endregion |
|
152 } |
|
153 } |