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
.io
.BufferedWriter
;
20 import java
.io
.FileWriter
;
21 import java
.io
.IOException
;
22 import java
.util
.ArrayList
;
23 import java
.util
.Collections
;
24 import java
.util
.Comparator
;
25 import java
.util
.HashMap
;
26 import java
.util
.Hashtable
;
27 import java
.util
.List
;
29 import java
.util
.UUID
;
31 import org
.tianocore
.build
.pcd
.action
.ActionMessage
;
33 /** Database hold all PCD information comes from SPD, MSA, FPD file in memory.
35 public class MemoryDatabaseManager
{
37 /// Memory database. The string "cName + SpaceNameGuid" is primary key.
38 /// memory database is in global scope, and it will be used for others PCD tools.
40 private static Map
<String
, Token
> memoryDatabase
= null;
43 /// Before build a module, the used libary will be build firstly, the PCD of these
44 /// libarry is inheritted by the module, so stored module's PCD information as PCD
45 /// context of building libary.
47 public static List
<UsageInstance
> UsageInstanceContext
= null;
51 public static String CurrentModuleName
= null;
52 public static String PcdPeimHString
= "";
53 public static String PcdPeimCString
= "";
54 public static String PcdDxeHString
= "";
55 public static String PcdDxeCString
= "";
60 public MemoryDatabaseManager() {
62 // Allocate memory for new database in global scope.
64 if (memoryDatabase
== null) {
65 memoryDatabase
= new HashMap
<String
, Token
>();
70 Judege whether token exists in memory database
72 @param primaryKey the primaryKey for searching token
74 @retval TRUE - token already exist in database.
75 @retval FALSE - token does not exist in database.
77 public boolean isTokenInDatabase(String primaryKey
) {
78 return (memoryDatabase
.get(primaryKey
) != null);
82 Add a pcd token into memory database.
84 @param primaryKey the primary key for searching token
85 @param token token instance
87 public void addTokenToDatabase(String primaryKey
, Token token
) {
88 memoryDatabase
.put(primaryKey
, token
);
92 Get a token instance from memory database with primary key.
94 @param primaryKey the primary key for searching token
96 @return token instance.
98 public Token
getTokenByKey(String primaryKey
) {
99 return memoryDatabase
.get(primaryKey
);
103 Get the number of PCD token record in memory database.
105 @return the number of PCD token record in memory database.
107 public int getDBSize() {
108 return memoryDatabase
.size();
112 Get the token record array contained all PCD token in memory database.
114 @return the token record array contained all PCD token in memory database.
116 public Token
[] getRecordArray() {
117 Token
[] tokenArray
= null;
118 Object
[] dataArray
= null;
119 Map
.Entry entry
= null;
122 if (memoryDatabase
== null) {
126 dataArray
= memoryDatabase
.entrySet().toArray();
127 tokenArray
= new Token
[memoryDatabase
.size()];
128 for (index
= 0; index
< memoryDatabase
.size(); index
++) {
129 entry
=(Map
.Entry
) dataArray
[index
];
130 tokenArray
[index
] =(Token
) entry
.getValue();
137 Get record array only contains DYNAMIC or DYNAMIC_EX type PCD.
141 private ArrayList
getDynamicRecordArray() {
142 Token
[] tokenArray
= getRecordArray();
145 ArrayList
<Token
> al
= new ArrayList
<Token
>();
147 for (index
= 0; index
< tokenArray
.length
; index
++) {
148 if (tokenArray
[index
].pcdType
== Token
.PCD_TYPE
.DYNAMIC
||
149 tokenArray
[index
].pcdType
== Token
.PCD_TYPE
.DYNAMIC_EX
) {
150 al
.add(tokenArray
[index
]);
159 Get the token record array contained all PCD token referenced by PEI phase.
160 The output array is sorted based on descending order of the size of alignment for each feilds.
162 @return the token record array contained all PCD token referenced in PEI phase.
164 public void getTwoPhaseDynamicRecordArray(ArrayList
<Token
> pei
, ArrayList
<Token
> dxe
) {
165 int usageInstanceIndex
= 0;
167 ArrayList tokenArrayList
= getDynamicRecordArray();
168 Object
[] usageInstanceArray
= null;
169 UsageInstance usageInstance
= null;
171 //pei = new ArrayList<Token>();
172 //dxe = new ArrayList<Token>();
174 for (index
= 0; index
< tokenArrayList
.size(); index
++) {
175 boolean found
= false;
176 Token token
= (Token
) tokenArrayList
.get(index
);
177 if (token
.consumers
!= null) {
178 usageInstanceArray
= token
.consumers
.entrySet().toArray();
179 for (usageInstanceIndex
= 0; usageInstanceIndex
< token
.consumers
.size(); usageInstanceIndex
++) {
180 usageInstance
=(UsageInstance
) (((Map
.Entry
)usageInstanceArray
[usageInstanceIndex
]).getValue());
181 if (usageInstance
.isPeiPhaseComponent()) {
189 // If no PEI components reference the PCD entry, we insert it to DXE list
200 Get all PCD record for a module according to module's name, module's GUID,
201 package name, package GUID, arch, version information.
203 @param moduleName the name of module.
205 @return all usage instance for this module in memory database.
207 public List
<UsageInstance
> getUsageInstanceArrayByModuleName(String moduleName
,
214 String primaryKey
= UsageInstance
.getPrimaryKey(moduleName
,
221 return getUsageInstanceArrayByKeyString(primaryKey
);
225 Get all PCD token for a usage instance according to primary key.
227 @param primaryKey the primary key of usage instance.
229 @return List<UsageInstance>
231 public List
<UsageInstance
> getUsageInstanceArrayByKeyString(String primaryKey
) {
232 Token
[] tokenArray
= null;
234 UsageInstance usageInstance
= null;
235 List
<UsageInstance
> returnArray
= new ArrayList
<UsageInstance
>();
237 tokenArray
= getRecordArray();
240 // Loop to find all PCD record related to current module
242 for (recordIndex
= 0; recordIndex
< getDBSize(); recordIndex
++) {
243 if (tokenArray
[recordIndex
].consumers
.size() != 0) {
244 usageInstance
= tokenArray
[recordIndex
].consumers
.get(primaryKey
);
245 if (usageInstance
!= null) {
246 returnArray
.add(usageInstance
);
255 Get all modules name who contains PCD information
257 @return Array for module name
259 public List
<String
> getAllModuleArray()
264 Token
[] tokenArray
= null;
265 Object
[] usageInstanceArray
= null;
266 List
<String
> moduleNames
= new ArrayList
<String
>();
267 UsageInstance usageInstance
= null;
268 boolean bFound
= false;
270 tokenArray
= getRecordArray();
272 // Find all consumer usage instance for retrieving module's name
274 for (indexToken
= 0; indexToken
< getDBSize(); indexToken
++) {
275 usageInstanceArray
= tokenArray
[indexToken
].consumers
.entrySet().toArray();
276 for (usageIndex
= 0; usageIndex
< tokenArray
[indexToken
].consumers
.size(); usageIndex
++) {
277 usageInstance
= (UsageInstance
)((Map
.Entry
)usageInstanceArray
[usageIndex
]).getValue();
279 for (moduleIndex
= 0; moduleIndex
< moduleNames
.size(); moduleIndex
++) {
280 if (moduleNames
.get(moduleIndex
).equalsIgnoreCase(usageInstance
.getPrimaryKey())) {
286 moduleNames
.add(usageInstance
.getPrimaryKey());