]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/GenBuild/org/tianocore/build/pcd/entity/MemoryDatabaseManager.java
1) remove some dead code from WinNtBusDriver.c
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / pcd / entity / MemoryDatabaseManager.java
CommitLineData
878ddf1f 1/** @file\r
2 MemoryDatabaseManager class.\r
3\r
4 Database hold all PCD information comes from SPD, MSA, FPD file in memory.\r
5 \r
6Copyright (c) 2006, Intel Corporation\r
7All rights reserved. This program and the accompanying materials\r
8are licensed and made available under the terms and conditions of the BSD License\r
9which accompanies this distribution. The full text of the license may be found at\r
10http://opensource.org/licenses/bsd-license.php\r
11 \r
12THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15**/\r
16package org.tianocore.build.pcd.entity;\r
17\r
878ddf1f 18import java.util.ArrayList;\r
19import java.util.HashMap;\r
20import java.util.List;\r
21import java.util.Map;\r
8840ad58 22import java.util.UUID;\r
878ddf1f 23\r
58f1099f 24import org.tianocore.build.pcd.exception.EntityException;\r
878ddf1f 25\r
26/** Database hold all PCD information comes from SPD, MSA, FPD file in memory.\r
27**/\r
28public class MemoryDatabaseManager {\r
29 ///\r
30 /// Memory database. The string "cName + SpaceNameGuid" is primary key.\r
31 /// memory database is in global scope, and it will be used for others PCD tools.\r
32 ///\r
8840ad58 33 private static Map<String, Token> memoryDatabase = null;\r
34\r
878ddf1f 35 ///\r
8840ad58 36 /// Before build a module, the used libary will be build firstly, the PCD of these\r
37 /// libarry is inheritted by the module, so stored module's PCD information as PCD\r
38 /// context of building libary.\r
39 /// \r
40 public static List<UsageInstance> UsageInstanceContext = null;\r
878ddf1f 41 ///\r
8840ad58 42 /// \r
43 /// \r
44 public static String CurrentModuleName = null;\r
99d2c3c4 45 public static String PcdPeimHString = "";\r
32648c62 46 public static String PcdPeimCString = "";\r
47 public static String PcdDxeHString = "";\r
48 public static String PcdDxeCString = "";\r
99d2c3c4 49\r
878ddf1f 50 /**\r
51 Constructure function\r
52 **/\r
53 public MemoryDatabaseManager() {\r
54 //\r
55 // Allocate memory for new database in global scope.\r
56 //\r
57 if (memoryDatabase == null) {\r
58 memoryDatabase = new HashMap<String, Token>();\r
59 }\r
60 }\r
61\r
878ddf1f 62 /**\r
63 Judege whether token exists in memory database\r
64 \r
65 @param primaryKey the primaryKey for searching token\r
66 \r
67 @retval TRUE - token already exist in database.\r
68 @retval FALSE - token does not exist in database.\r
69 **/\r
70 public boolean isTokenInDatabase(String primaryKey) {\r
71 return (memoryDatabase.get(primaryKey) != null);\r
72 }\r
73\r
74 /**\r
75 Add a pcd token into memory database.\r
76 \r
77 @param primaryKey the primary key for searching token\r
78 @param token token instance\r
79 **/\r
80 public void addTokenToDatabase(String primaryKey, Token token) {\r
81 memoryDatabase.put(primaryKey, token);\r
82 }\r
83\r
84 /**\r
85 Get a token instance from memory database with primary key.\r
86 \r
87 @param primaryKey the primary key for searching token\r
88 \r
89 @return token instance.\r
90 **/\r
91 public Token getTokenByKey(String primaryKey) {\r
92 return memoryDatabase.get(primaryKey);\r
93 }\r
94\r
95 /**\r
96 Get the number of PCD token record in memory database.\r
97 \r
98 @return the number of PCD token record in memory database.\r
99 **/\r
100 public int getDBSize() {\r
101 return memoryDatabase.size();\r
102 }\r
103\r
104 /**\r
105 Get the token record array contained all PCD token in memory database.\r
106 \r
107 @return the token record array contained all PCD token in memory database.\r
108 **/\r
109 public Token[] getRecordArray() {\r
110 Token[] tokenArray = null;\r
111 Object[] dataArray = null;\r
112 Map.Entry entry = null;\r
113 int index = 0;\r
114\r
115 if (memoryDatabase == null) {\r
116 return null;\r
117 }\r
118\r
119 dataArray = memoryDatabase.entrySet().toArray();\r
120 tokenArray = new Token[memoryDatabase.size()];\r
121 for (index = 0; index < memoryDatabase.size(); index ++) {\r
122 entry =(Map.Entry) dataArray [index];\r
123 tokenArray[index] =(Token) entry.getValue();\r
124 }\r
125\r
126 return tokenArray;\r
127 }\r
128\r
8840ad58 129 /**\r
130 Get record array only contains DYNAMIC or DYNAMIC_EX type PCD.\r
131 \r
132 @return ArrayList\r
133 */\r
134 private ArrayList getDynamicRecordArray() {\r
99d2c3c4 135 Token[] tokenArray = getRecordArray();\r
136 int index = 0;\r
6a4cae58 137 ArrayList<Token> al = new ArrayList<Token>();\r
99d2c3c4 138\r
139 for (index = 0; index < tokenArray.length; index++) {\r
6ff7a41c 140 if (tokenArray[index].isDynamicPCD) {\r
99d2c3c4 141 al.add(tokenArray[index]);\r
142 }\r
143 }\r
144\r
145 return al;\r
146 }\r
147\r
148\r
878ddf1f 149 /**\r
99d2c3c4 150 Get the token record array contained all PCD token referenced by PEI phase.\r
151 The output array is sorted based on descending order of the size of alignment for each feilds.\r
152\r
153 @return the token record array contained all PCD token referenced in PEI phase.\r
58f1099f 154 * @throws EntityException \r
99d2c3c4 155 **/\r
58f1099f 156 public void getTwoPhaseDynamicRecordArray(ArrayList<Token> pei, ArrayList<Token> dxe) \r
157 throws EntityException {\r
99d2c3c4 158 int usageInstanceIndex = 0;\r
159 int index = 0;\r
8840ad58 160 ArrayList tokenArrayList = getDynamicRecordArray();\r
161 Object[] usageInstanceArray = null;\r
99d2c3c4 162 UsageInstance usageInstance = null;\r
163\r
8840ad58 164 //pei = new ArrayList<Token>();\r
165 //dxe = new ArrayList<Token>();\r
166\r
99d2c3c4 167 for (index = 0; index < tokenArrayList.size(); index++) {\r
168 boolean found = false;\r
169 Token token = (Token) tokenArrayList.get(index);\r
8840ad58 170 if (token.consumers != null) {\r
171 usageInstanceArray = token.consumers.entrySet().toArray();\r
172 for (usageInstanceIndex = 0; usageInstanceIndex < token.consumers.size(); usageInstanceIndex ++) {\r
173 usageInstance =(UsageInstance) (((Map.Entry)usageInstanceArray[usageInstanceIndex]).getValue());\r
174 if (usageInstance.isPeiPhaseComponent()) {\r
99d2c3c4 175 pei.add(token);\r
176 found = true;\r
177 break;\r
178 }\r
179 }\r
99d2c3c4 180 }\r
181\r
58f1099f 182 //\r
183 // If no PEI components reference the PCD entry, \r
184 // we check if it is referenced in DXE driver. \r
32648c62 185 //\r
186 if (!found) {\r
58f1099f 187 if (token.consumers != null) {\r
188 usageInstanceArray = token.consumers.entrySet().toArray();\r
189 for (usageInstanceIndex = 0; usageInstanceIndex < token.consumers.size(); usageInstanceIndex ++) {\r
190 usageInstance =(UsageInstance) (((Map.Entry)usageInstanceArray[usageInstanceIndex]).getValue());\r
191 if (usageInstance.isDxePhaseComponent()) {\r
192 dxe.add(token);\r
193 found = true;\r
194 break;\r
195 }\r
196 }\r
197 }\r
198 \r
199 if (!found) {\r
200 //\r
201 // We only support Dynamice(EX) type for PEI and DXE phase.\r
202 // If it is not referenced in either PEI or DXE, throw exception now.\r
203 //\r
204 throw new EntityException("Dynamic(EX) PCD Entries are referenced in module that is not in PEI phase nor in DXE phase.");\r
205 }\r
32648c62 206 }\r
99d2c3c4 207 }\r
208\r
32648c62 209 return;\r
99d2c3c4 210 }\r
211\r
32648c62 212 /**\r
8840ad58 213 Get all PCD record for a module according to module's name, module's GUID,\r
214 package name, package GUID, arch, version information.\r
878ddf1f 215 \r
216 @param moduleName the name of module.\r
217 \r
218 @return all usage instance for this module in memory database.\r
219 **/\r
8840ad58 220 public List<UsageInstance> getUsageInstanceArrayByModuleName(String moduleName,\r
221 UUID moduleGuid,\r
222 String packageName,\r
223 UUID packageGuid,\r
224 String arch,\r
225 String version) {\r
226\r
227 String primaryKey = UsageInstance.getPrimaryKey(moduleName, \r
228 moduleGuid,\r
229 packageName,\r
230 packageGuid,\r
231 arch,\r
232 version);\r
233\r
234 return getUsageInstanceArrayByKeyString(primaryKey);\r
235 }\r
236\r
237 /**\r
238 Get all PCD token for a usage instance according to primary key.\r
239 \r
240 @param primaryKey the primary key of usage instance.\r
241 \r
242 @return List<UsageInstance>\r
243 */\r
244 public List<UsageInstance> getUsageInstanceArrayByKeyString(String primaryKey) {\r
878ddf1f 245 Token[] tokenArray = null;\r
246 int recordIndex = 0; \r
878ddf1f 247 UsageInstance usageInstance = null;\r
248 List<UsageInstance> returnArray = new ArrayList<UsageInstance>();\r
249\r
250 tokenArray = getRecordArray();\r
251\r
252 //\r
253 // Loop to find all PCD record related to current module\r
254 //\r
255 for (recordIndex = 0; recordIndex < getDBSize(); recordIndex ++) {\r
8840ad58 256 if (tokenArray[recordIndex].consumers.size() != 0) {\r
257 usageInstance = tokenArray[recordIndex].consumers.get(primaryKey);\r
258 if (usageInstance != null) {\r
259 returnArray.add(usageInstance);\r
878ddf1f 260 }\r
261 }\r
262 }\r
263\r
878ddf1f 264 return returnArray;\r
265 }\r
266\r
267 /**\r
268 Get all modules name who contains PCD information\r
269 \r
270 @return Array for module name\r
271 **/\r
272 public List<String> getAllModuleArray()\r
273 {\r
274 int indexToken = 0;\r
275 int usageIndex = 0;\r
276 int moduleIndex = 0;\r
277 Token[] tokenArray = null;\r
8840ad58 278 Object[] usageInstanceArray = null;\r
878ddf1f 279 List<String> moduleNames = new ArrayList<String>();\r
280 UsageInstance usageInstance = null;\r
281 boolean bFound = false;\r
282\r
8840ad58 283 tokenArray = getRecordArray();\r
878ddf1f 284 //\r
285 // Find all consumer usage instance for retrieving module's name\r
286 //\r
287 for (indexToken = 0; indexToken < getDBSize(); indexToken ++) {\r
8840ad58 288 usageInstanceArray = tokenArray[indexToken].consumers.entrySet().toArray();\r
878ddf1f 289 for (usageIndex = 0; usageIndex < tokenArray[indexToken].consumers.size(); usageIndex ++) {\r
8840ad58 290 usageInstance = (UsageInstance)((Map.Entry)usageInstanceArray[usageIndex]).getValue();\r
878ddf1f 291 bFound = false;\r
292 for (moduleIndex = 0; moduleIndex < moduleNames.size(); moduleIndex ++) {\r
8840ad58 293 if (moduleNames.get(moduleIndex).equalsIgnoreCase(usageInstance.getPrimaryKey())) {\r
878ddf1f 294 bFound = true;\r
295 break;\r
296 }\r
297 }\r
298 if (!bFound) {\r
8840ad58 299 moduleNames.add(usageInstance.getPrimaryKey());\r
878ddf1f 300 }\r
301 }\r
302 }\r
303 return moduleNames;\r
304 }\r
878ddf1f 305}\r