2 MemoryDatabaseManager class.
4 Database hold all PCD information comes from SPD, MSA, FPD file in memory.
6 Copyright (c) 2006, Intel Corporation
7 All rights reserved. This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 package org
.tianocore
.build
.pcd
.entity
;
18 import java
.util
.ArrayList
;
19 import java
.util
.HashMap
;
20 import java
.util
.List
;
22 import java
.util
.UUID
;
24 import org
.tianocore
.build
.pcd
.exception
.EntityException
;
26 /** Database hold all PCD information comes from SPD, MSA, FPD file in memory.
28 public class MemoryDatabaseManager
{
30 /// Memory database. The string "cName + SpaceNameGuid" is primary key.
31 /// memory database is in global scope, and it will be used for others PCD tools.
33 private static Map
<String
, Token
> memoryDatabase
= null;
36 /// Before build a module, the used libary will be build firstly, the PCD of these
37 /// libarry is inheritted by the module, so stored module's PCD information as PCD
38 /// context of building libary.
40 public static List
<UsageInstance
> UsageInstanceContext
= null;
44 public static String CurrentModuleName
= null;
45 public static String PcdPeimHString
= "";
46 public static String PcdPeimCString
= "";
47 public static String PcdDxeHString
= "";
48 public static String PcdDxeCString
= "";
53 public MemoryDatabaseManager() {
55 // Allocate memory for new database in global scope.
57 if (memoryDatabase
== null) {
58 memoryDatabase
= new HashMap
<String
, Token
>();
63 Judege whether token exists in memory database
65 @param primaryKey the primaryKey for searching token
67 @retval TRUE - token already exist in database.
68 @retval FALSE - token does not exist in database.
70 public boolean isTokenInDatabase(String primaryKey
) {
71 return (memoryDatabase
.get(primaryKey
) != null);
75 Add a pcd token into memory database.
77 @param primaryKey the primary key for searching token
78 @param token token instance
80 public void addTokenToDatabase(String primaryKey
, Token token
) {
81 memoryDatabase
.put(primaryKey
, token
);
85 Get a token instance from memory database with primary key.
87 @param primaryKey the primary key for searching token
89 @return token instance.
91 public Token
getTokenByKey(String primaryKey
) {
92 return memoryDatabase
.get(primaryKey
);
96 Get the number of PCD token record in memory database.
98 @return the number of PCD token record in memory database.
100 public int getDBSize() {
101 return memoryDatabase
.size();
105 Get the token record array contained all PCD token in memory database.
107 @return the token record array contained all PCD token in memory database.
109 public Token
[] getRecordArray() {
110 Token
[] tokenArray
= null;
111 Object
[] dataArray
= null;
112 Map
.Entry entry
= null;
115 if (memoryDatabase
== null) {
119 dataArray
= memoryDatabase
.entrySet().toArray();
120 tokenArray
= new Token
[memoryDatabase
.size()];
121 for (index
= 0; index
< memoryDatabase
.size(); index
++) {
122 entry
=(Map
.Entry
) dataArray
[index
];
123 tokenArray
[index
] =(Token
) entry
.getValue();
130 Get record array only contains DYNAMIC or DYNAMIC_EX type PCD.
134 private ArrayList
getDynamicRecordArray() {
135 Token
[] tokenArray
= getRecordArray();
137 ArrayList
<Token
> al
= new ArrayList
<Token
>();
139 for (index
= 0; index
< tokenArray
.length
; index
++) {
140 if (tokenArray
[index
].isDynamicPCD
) {
141 al
.add(tokenArray
[index
]);
150 Get the token record array contained all PCD token referenced by PEI phase.
151 The output array is sorted based on descending order of the size of alignment for each feilds.
153 @return the token record array contained all PCD token referenced in PEI phase.
154 * @throws EntityException
156 public void getTwoPhaseDynamicRecordArray(ArrayList
<Token
> pei
, ArrayList
<Token
> dxe
)
157 throws EntityException
{
158 int usageInstanceIndex
= 0;
160 ArrayList tokenArrayList
= getDynamicRecordArray();
161 Object
[] usageInstanceArray
= null;
162 UsageInstance usageInstance
= null;
164 //pei = new ArrayList<Token>();
165 //dxe = new ArrayList<Token>();
167 for (index
= 0; index
< tokenArrayList
.size(); index
++) {
168 boolean found
= false;
169 Token token
= (Token
) tokenArrayList
.get(index
);
170 if (token
.consumers
!= null) {
171 usageInstanceArray
= token
.consumers
.entrySet().toArray();
172 for (usageInstanceIndex
= 0; usageInstanceIndex
< token
.consumers
.size(); usageInstanceIndex
++) {
173 usageInstance
=(UsageInstance
) (((Map
.Entry
)usageInstanceArray
[usageInstanceIndex
]).getValue());
174 if (usageInstance
.isPeiPhaseComponent()) {
183 // If no PEI components reference the PCD entry,
184 // we check if it is referenced in DXE driver.
187 if (token
.consumers
!= null) {
188 usageInstanceArray
= token
.consumers
.entrySet().toArray();
189 for (usageInstanceIndex
= 0; usageInstanceIndex
< token
.consumers
.size(); usageInstanceIndex
++) {
190 usageInstance
=(UsageInstance
) (((Map
.Entry
)usageInstanceArray
[usageInstanceIndex
]).getValue());
191 if (usageInstance
.isDxePhaseComponent()) {
200 if (token
.isDynamicPCD
&& token
.consumers
.size() == 0) {
204 // We only support Dynamice(EX) type for PEI and DXE phase.
205 // If it is not referenced in either PEI or DXE, throw exception now.
207 throw new EntityException("Dynamic(EX) PCD Entries are referenced in module that is not in PEI phase nor in DXE phase.");
217 Get all PCD record for a module according to module's name, module's GUID,
218 package name, package GUID, arch, version information.
220 @param moduleName the name of module.
222 @return all usage instance for this module in memory database.
224 public List
<UsageInstance
> getUsageInstanceArrayByModuleName(String moduleName
,
231 String primaryKey
= UsageInstance
.getPrimaryKey(moduleName
,
238 return getUsageInstanceArrayByKeyString(primaryKey
);
242 Get all PCD token for a usage instance according to primary key.
244 @param primaryKey the primary key of usage instance.
246 @return List<UsageInstance>
248 public List
<UsageInstance
> getUsageInstanceArrayByKeyString(String primaryKey
) {
249 Token
[] tokenArray
= null;
251 UsageInstance usageInstance
= null;
252 List
<UsageInstance
> returnArray
= new ArrayList
<UsageInstance
>();
254 tokenArray
= getRecordArray();
257 // Loop to find all PCD record related to current module
259 for (recordIndex
= 0; recordIndex
< getDBSize(); recordIndex
++) {
260 if (tokenArray
[recordIndex
].consumers
.size() != 0) {
261 usageInstance
= tokenArray
[recordIndex
].consumers
.get(primaryKey
);
262 if (usageInstance
!= null) {
263 returnArray
.add(usageInstance
);
272 Get all modules name who contains PCD information
274 @return Array for module name
276 public List
<String
> getAllModuleArray()
281 Token
[] tokenArray
= null;
282 Object
[] usageInstanceArray
= null;
283 List
<String
> moduleNames
= new ArrayList
<String
>();
284 UsageInstance usageInstance
= null;
285 boolean bFound
= false;
287 tokenArray
= getRecordArray();
289 // Find all consumer usage instance for retrieving module's name
291 for (indexToken
= 0; indexToken
< getDBSize(); indexToken
++) {
292 usageInstanceArray
= tokenArray
[indexToken
].consumers
.entrySet().toArray();
293 for (usageIndex
= 0; usageIndex
< tokenArray
[indexToken
].consumers
.size(); usageIndex
++) {
294 usageInstance
= (UsageInstance
)((Map
.Entry
)usageInstanceArray
[usageIndex
]).getValue();
296 for (moduleIndex
= 0; moduleIndex
< moduleNames
.size(); moduleIndex
++) {
297 if (moduleNames
.get(moduleIndex
).equalsIgnoreCase(usageInstance
.getPrimaryKey())) {
303 moduleNames
.add(usageInstance
.getPrimaryKey());