|
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.Text; |
|
19 using System.IO; |
|
20 using System.Collections.Generic; |
|
21 using CrashAnalyserEngine.Plugins; |
|
22 using CrashItemLib.Crash.Container; |
|
23 using CrashItemLib.Engine.Sources; |
|
24 |
|
25 namespace CAPCrashAnalysis.CommandLine |
|
26 { |
|
27 internal class CACmdLineFileSource : CACmdLineFSEntity, IEnumerable<CIContainer> |
|
28 { |
|
29 #region Constructors |
|
30 public CACmdLineFileSource() |
|
31 { |
|
32 } |
|
33 #endregion |
|
34 |
|
35 #region API |
|
36 public OutputEntry AddOutput( CIContainer aContainer, string aFileName, TOutputStatus aStatus ) |
|
37 { |
|
38 OutputEntry output = new OutputEntry( aContainer, aFileName, aStatus ); |
|
39 iOutputs.Add( output ); |
|
40 return output; |
|
41 } |
|
42 |
|
43 public void Add( CIContainer aContainer ) |
|
44 { |
|
45 // If we're adding a container, then it must be because |
|
46 // there wasn't a source associated with this file (crash engine |
|
47 // could not understand input file). |
|
48 System.Diagnostics.Debug.Assert( iSource == null ); |
|
49 |
|
50 if ( iContainers == null ) |
|
51 { |
|
52 iContainers = new CIContainerCollection(); |
|
53 } |
|
54 iContainers.Add( aContainer ); |
|
55 } |
|
56 #endregion |
|
57 |
|
58 #region Properties |
|
59 public CIEngineSource Source |
|
60 { |
|
61 get { return iSource; } |
|
62 set { iSource = value; } |
|
63 } |
|
64 |
|
65 public int OutputCount |
|
66 { |
|
67 get { return iOutputs.Count; } |
|
68 } |
|
69 |
|
70 public OutputEntry this[ int aIndex ] |
|
71 { |
|
72 get { return iOutputs[ aIndex ]; } |
|
73 } |
|
74 |
|
75 public OutputEntry[] Outputs |
|
76 { |
|
77 get { return iOutputs.ToArray(); } |
|
78 } |
|
79 |
|
80 public int ContainerCount |
|
81 { |
|
82 get |
|
83 { |
|
84 int ret = 0; |
|
85 // |
|
86 if ( Source != null ) |
|
87 { |
|
88 ret = Source.ContainerCount; |
|
89 } |
|
90 else if ( iContainers != null ) |
|
91 { |
|
92 ret = iContainers.Count; |
|
93 } |
|
94 // |
|
95 return ret; |
|
96 } |
|
97 } |
|
98 |
|
99 public IEnumerable<CIContainer> Containers |
|
100 { |
|
101 get |
|
102 { |
|
103 CIContainerCollection ret = iContainers; |
|
104 // |
|
105 if ( Source != null ) |
|
106 { |
|
107 return Source; |
|
108 } |
|
109 else if ( ret == null ) |
|
110 { |
|
111 ret = new CIContainerCollection(); |
|
112 } |
|
113 // |
|
114 return ret; |
|
115 } |
|
116 } |
|
117 #endregion |
|
118 |
|
119 #region Internal methods |
|
120 #endregion |
|
121 |
|
122 #region Output class |
|
123 public class OutputEntry : CACmdLineMessageList |
|
124 { |
|
125 #region Constructors |
|
126 internal OutputEntry( CIContainer aContainer, string aOutputFileName, TOutputStatus aXmlOutputStatus ) |
|
127 { |
|
128 iContainer = aContainer; |
|
129 iXmlOutputStatus = aXmlOutputStatus; |
|
130 iOutputFileName = aOutputFileName; |
|
131 } |
|
132 #endregion |
|
133 |
|
134 #region Properties |
|
135 public CIContainer Container |
|
136 { |
|
137 get { return iContainer; } |
|
138 } |
|
139 |
|
140 public TOutputStatus Status |
|
141 { |
|
142 get |
|
143 { |
|
144 // There are two different statuses. One is the container-level status, |
|
145 // i.e. whether the container refers to a 'real' crash or just a dummy (i.e. a 'failed' xml file). |
|
146 // |
|
147 // Then, there is the actual success associated with whether or not we could write |
|
148 // the xml output. |
|
149 TOutputStatus ret = iXmlOutputStatus; |
|
150 // |
|
151 if ( ret == TOutputStatus.ESuccess ) |
|
152 { |
|
153 // Check container level status then... |
|
154 if ( Container.Status == CIContainer.TStatus.EStatusDefault ) |
|
155 { |
|
156 ret = TOutputStatus.ESuccess; |
|
157 } |
|
158 else if ( Container.Status == CIContainer.TStatus.EStatusErrorContainer ) |
|
159 { |
|
160 ret = TOutputStatus.EFailed; |
|
161 } |
|
162 } |
|
163 // |
|
164 return ret; |
|
165 } |
|
166 } |
|
167 |
|
168 public string OutputFileName |
|
169 { |
|
170 get { return iOutputFileName; } |
|
171 } |
|
172 #endregion |
|
173 |
|
174 #region Data members |
|
175 private readonly TOutputStatus iXmlOutputStatus; |
|
176 private readonly CIContainer iContainer; |
|
177 private readonly string iOutputFileName; |
|
178 #endregion |
|
179 } |
|
180 #endregion |
|
181 |
|
182 #region From IEnumerable<CIContainer> |
|
183 public new IEnumerator<CIContainer> GetEnumerator() |
|
184 { |
|
185 foreach ( CIContainer container in Containers ) |
|
186 { |
|
187 yield return container; |
|
188 } |
|
189 } |
|
190 |
|
191 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() |
|
192 { |
|
193 foreach ( CIContainer container in Containers ) |
|
194 { |
|
195 yield return container; |
|
196 } |
|
197 } |
|
198 #endregion |
|
199 |
|
200 #region Data members |
|
201 private CIEngineSource iSource = null; |
|
202 private List<OutputEntry> iOutputs = new List<OutputEntry>(); |
|
203 private CIContainerCollection iContainers = null; |
|
204 #endregion |
|
205 } |
|
206 |
|
207 public enum TOutputStatus |
|
208 { |
|
209 ESuccess = 0, |
|
210 EFailed |
|
211 } |
|
212 } |