|
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 System.IO; |
|
22 using SymbianUtils; |
|
23 using SymbianUtils.Tracer; |
|
24 using SymbianUtils.FileTypes; |
|
25 using SymbianUtils.PluginManager; |
|
26 using SymbianStructuresLib.Debug.Common.Interfaces; |
|
27 using SymbianInstructionLib.Arm.Library; |
|
28 using SymbianInstructionLib.Arm.Instructions.Common; |
|
29 using SymbianCodeLib.DbgEnginePlugin; |
|
30 using SymbianCodeLib.SourceManagement.Source; |
|
31 |
|
32 namespace SymbianCodeLib.SourceManagement.Provisioning |
|
33 { |
|
34 public class CodeSourceProviderManager : DisposableObject, IEnumerable<CodeSourceProvider>, ITracer |
|
35 { |
|
36 #region Constructors |
|
37 internal CodeSourceProviderManager( CodePlugin aPlugin, IPlatformIdAllocator aIdAllocator ) |
|
38 { |
|
39 iPlugin = aPlugin; |
|
40 iIdAllocator = aIdAllocator; |
|
41 iInstructionLibrary = new ArmLibrary(); |
|
42 // |
|
43 iProviders.Load( new object[] { this } ); |
|
44 } |
|
45 #endregion |
|
46 |
|
47 #region API |
|
48 public SymFileTypeList SupportedFileTypes() |
|
49 { |
|
50 SymFileTypeList ret = new SymFileTypeList(); |
|
51 // |
|
52 foreach ( CodeSourceProvider provider in iProviders ) |
|
53 { |
|
54 SymFileTypeList list = provider.FileTypes; |
|
55 ret.AddRange( list ); |
|
56 } |
|
57 // |
|
58 return ret; |
|
59 } |
|
60 |
|
61 public CodeSourceProvider GetProvider( string aFileName ) |
|
62 { |
|
63 CodeSourceProvider ret = null; |
|
64 // |
|
65 foreach ( CodeSourceProvider provider in iProviders ) |
|
66 { |
|
67 bool canRead = provider.IsSupported( aFileName ); |
|
68 if ( canRead ) |
|
69 { |
|
70 ret = provider; |
|
71 break; |
|
72 } |
|
73 } |
|
74 // |
|
75 return ret; |
|
76 } |
|
77 |
|
78 public IEnumerator<CodeSource> GetSourceEnumerator() |
|
79 { |
|
80 return iPlugin.SourceManager.GetEnumerator(); |
|
81 } |
|
82 |
|
83 public void PrepareToCreateSources( IEnumerable<string> aFileNames ) |
|
84 { |
|
85 foreach ( CodeSourceProvider provider in iProviders ) |
|
86 { |
|
87 provider.PrepareToCreateSources( aFileNames ); |
|
88 } |
|
89 } |
|
90 #endregion |
|
91 |
|
92 #region Properties |
|
93 public int Count |
|
94 { |
|
95 get { return iProviders.Count; } |
|
96 } |
|
97 |
|
98 public IPlatformIdAllocator IdAllocator |
|
99 { |
|
100 get { return iIdAllocator; } |
|
101 } |
|
102 |
|
103 public ArmLibrary InstructionLibrary |
|
104 { |
|
105 get |
|
106 { |
|
107 return iInstructionLibrary; |
|
108 } |
|
109 } |
|
110 |
|
111 public CodeSourceProvider this[ string aName ] |
|
112 { |
|
113 get |
|
114 { |
|
115 CodeSourceProvider ret = null; |
|
116 // |
|
117 foreach ( CodeSourceProvider prov in iProviders ) |
|
118 { |
|
119 if ( prov.Name == aName ) |
|
120 { |
|
121 ret = prov; |
|
122 break; |
|
123 } |
|
124 } |
|
125 // |
|
126 return ret; |
|
127 } |
|
128 } |
|
129 |
|
130 public CodeSourceProvider this[ int aIndex ] |
|
131 { |
|
132 get { return iProviders[ aIndex ]; } |
|
133 } |
|
134 |
|
135 internal CodePlugin Plugin |
|
136 { |
|
137 get { return iPlugin; } |
|
138 } |
|
139 #endregion |
|
140 |
|
141 #region Internal methods |
|
142 #endregion |
|
143 |
|
144 #region From IEnumerable<CodeSourceProvider> |
|
145 public IEnumerator<CodeSourceProvider> GetEnumerator() |
|
146 { |
|
147 foreach ( CodeSourceProvider prov in iProviders ) |
|
148 { |
|
149 yield return prov; |
|
150 } |
|
151 } |
|
152 |
|
153 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() |
|
154 { |
|
155 foreach ( CodeSourceProvider prov in iProviders ) |
|
156 { |
|
157 yield return prov; |
|
158 } |
|
159 } |
|
160 #endregion |
|
161 |
|
162 #region From ITracer |
|
163 public void Trace( string aMessage ) |
|
164 { |
|
165 iPlugin.Trace( aMessage ); |
|
166 } |
|
167 |
|
168 public void Trace( string aFormat, params object[] aParams ) |
|
169 { |
|
170 iPlugin.Trace( aFormat, aParams ); |
|
171 } |
|
172 #endregion |
|
173 |
|
174 #region From DisposableObject |
|
175 protected override void CleanupManagedResources() |
|
176 { |
|
177 try |
|
178 { |
|
179 base.CleanupManagedResources(); |
|
180 } |
|
181 finally |
|
182 { |
|
183 iProviders.Unload(); |
|
184 iProviders.Dispose(); |
|
185 } |
|
186 } |
|
187 #endregion |
|
188 |
|
189 #region Data members |
|
190 private readonly CodePlugin iPlugin; |
|
191 private readonly IPlatformIdAllocator iIdAllocator; |
|
192 private readonly ArmLibrary iInstructionLibrary; |
|
193 private PluginManager<CodeSourceProvider> iProviders = new PluginManager<CodeSourceProvider>(); |
|
194 #endregion |
|
195 } |
|
196 } |