OpenASIP  2.0
CachedHDBManager.hh
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file CachedHDBManager.hh
26  *
27  * Declaration of CachedHDBManager class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2007 (vjaaskel-no.spam-cs.tut.fi)
30  * @author Esa Määttä 2007 (esa.maattae-no.spam-tut.fi)
31  * @note rating: red
32  */
33 
34 #ifndef TTA_CACHED_HDB_MANAGER_HH
35 #define TTA_CACHED_HDB_MANAGER_HH
36 
37 #include <map>
38 #include "HDBManager.hh"
40 #include "Exception.hh"
41 #include "CostEstimationData.hh"
42 
43 namespace HDB {
44 
45 /**
46  * Cached interface to HDBs.
47  *
48  * HDBManager class queries HDB file every time the manager is queried
49  * for an object in the database. Queries to the database are time consuming,
50  * especially when constructing FU and RF implementation objects based on
51  * data scattered across multiple HDB tables.
52  * CachedHDBManager caches the queried objects in memory, resulting in
53  * significant speedups if the same objects are queried repeatedly without
54  * any modifications to the related data in the HDB.
55  *
56  * IMPORTANT NOTE:
57  *
58  * If a new function which modifies or removes cached objects is added
59  * to the HDBManager, it must be derived here to remove corresponding objects
60  * from the cache! Please check that all functions you are using that
61  * modify cached data are reimplemented to remove cached objects.
62  */
63 class CachedHDBManager : public HDBManager {
64 public:
65  static CachedHDBManager& instance(const std::string& hdbFile);
66 
67  virtual ~CachedHDBManager();
68 
69  static CachedHDBManager& createNew(const std::string& fileName);
70 
71  // Functions invalidating cached objects.
72  virtual void removeFUArchitecture(RowID archID) const;
73 
74  virtual void removeFUImplementation(RowID id) const;
75 
76  virtual void removeRFArchitecture(RowID archID) const;
77 
78  virtual void removeRFImplementation(RowID archID) const;
79 
80  // Functions below may invalidate cost estimation values
81  virtual void modifyCostFunctionPlugin(
82  RowID id, const CostFunctionPlugin& plugin);
83 
84  virtual void removeCostFunctionPlugin(RowID pluginID) const;
85 
86  virtual void removeFUEntry(RowID id) const;
87 
88  virtual void removeRFEntry(RowID id) const;
89 
90  virtual void removeBusEntry(RowID id) const;
91 
92  virtual void removeSocketEntry(RowID id) const;
93 
94  virtual void removeCostEstimationData(RowID id) const;
95 
96  virtual void modifyCostEstimationData(
97  RowID id, const CostEstimationData& data);
98 
99  // Queries using cache.
100  virtual FUArchitecture* fuArchitectureByID(RowID id) const;
101 
102  virtual RFArchitecture* rfArchitectureByID(RowID id) const;
103 
105  const std::string& valueName, const std::string& pluginName) const;
106 
109 
110  // Functions to manually delete stored queries
111  virtual void deleteCostEstimationDataIDsQueries() const;
112 
113  // Queries using query cache
114  virtual std::set<RowID> costEstimationDataIDs(
115  const CostEstimationData& match, bool useCompiledQueries = false,
116  RelationalDBQueryResult* compiledQuery = NULL) const;
117 
118 private:
119  CachedHDBManager(const std::string& hdbFile);
120 
121  // Private queries using cache.
124  FUArchitecture& architecture, RowID id) const;
125 
126  // Checks if cache is invalid.
127  void validateCache() const;
128 
129  /// FU Architecture cache.
130  mutable std::map<RowID, FUArchitecture*> fuArchCache_;
131  /// RF Architecture cache.
132  mutable std::map<RowID, RFArchitecture*> rfArchCache_;
133  /// FU Implementation cache.
134  mutable std::map<RowID, FUImplementation*> fuImplCache_;
135  /// RF Implementation cache.
136  mutable std::map<RowID, RFImplementation*> rfImplCache_;
137  /// Cost estimation plugin value cache (pluginName/valueName)
138  mutable std::map<std::string, std::map<std::string, DataObject> >
140 
141  /// map of cached (compiled) queries for costEstimatioDataIDs function
142  mutable std::map<short int, RelationalDBQueryResult*>
144 
145  /// used to detect modifications to the HDB file (which invalidates cache)
146  mutable std::time_t lastModificationTime_;
147  /// used to detect modifications to the HDB file (which invalidates cache)
148  mutable uintmax_t lastSizeInBytes_;
149 };
150 
151 } // End namespace HDB.
152 #endif
HDB::CachedHDBManager::costEstimationPluginValueCache_
std::map< std::string, std::map< std::string, DataObject > > costEstimationPluginValueCache_
Cost estimation plugin value cache (pluginName/valueName)
Definition: CachedHDBManager.hh:139
HDB::FUArchitecture
Definition: FUArchitecture.hh:55
HDB::CachedHDBManager::lastSizeInBytes_
uintmax_t lastSizeInBytes_
used to detect modifications to the HDB file (which invalidates cache)
Definition: CachedHDBManager.hh:148
HDB::CachedHDBManager::createImplementationOfFU
virtual FUImplementation * createImplementationOfFU(FUArchitecture &architecture, RowID id) const
Definition: CachedHDBManager.cc:461
HDB
Definition: CostDatabase.hh:49
RelationalDBQueryResult.hh
Exception.hh
HDB::CachedHDBManager::removeFUEntry
virtual void removeFUEntry(RowID id) const
Definition: CachedHDBManager.cc:337
HDB::CachedHDBManager::removeRFImplementation
virtual void removeRFImplementation(RowID archID) const
Definition: CachedHDBManager.cc:189
DataObject
Definition: DataObject.hh:50
HDB::CachedHDBManager::fuArchCache_
std::map< RowID, FUArchitecture * > fuArchCache_
FU Architecture cache.
Definition: CachedHDBManager.hh:130
HDB::CachedHDBManager::modifyCostFunctionPlugin
virtual void modifyCostFunctionPlugin(RowID id, const CostFunctionPlugin &plugin)
Definition: CachedHDBManager.cc:307
RowID
int RowID
Type definition of row ID in relational databases.
Definition: DBTypes.hh:37
HDB::CachedHDBManager::fuArchitectureByID
virtual FUArchitecture * fuArchitectureByID(RowID id) const
Definition: CachedHDBManager.cc:218
HDB::CachedHDBManager::removeSocketEntry
virtual void removeSocketEntry(RowID id) const
Definition: CachedHDBManager.cc:376
HDB::CachedHDBManager::createNew
static CachedHDBManager & createNew(const std::string &fileName)
Definition: CachedHDBManager.cc:105
HDB::CachedHDBManager::costEstimationDataIDsQueries_
std::map< short int, RelationalDBQueryResult * > costEstimationDataIDsQueries_
map of cached (compiled) queries for costEstimatioDataIDs function
Definition: CachedHDBManager.hh:143
CostEstimationData.hh
HDB::CachedHDBManager
Definition: CachedHDBManager.hh:63
HDB::CachedHDBManager::fuImplCache_
std::map< RowID, FUImplementation * > fuImplCache_
FU Implementation cache.
Definition: CachedHDBManager.hh:134
HDB::CachedHDBManager::removeCostFunctionPlugin
virtual void removeCostFunctionPlugin(RowID pluginID) const
Definition: CachedHDBManager.cc:322
HDB::CachedHDBManager::createImplementationOfRF
virtual RFImplementation * createImplementationOfRF(RowID id) const
Definition: CachedHDBManager.cc:427
HDB::RFImplementation
Definition: RFImplementation.hh:50
HDB::CachedHDBManager::rfArchCache_
std::map< RowID, RFArchitecture * > rfArchCache_
RF Architecture cache.
Definition: CachedHDBManager.hh:132
RelationalDBQueryResult
Definition: RelationalDBQueryResult.hh:46
HDB::HDBManager
Definition: HDBManager.hh:82
HDB::CachedHDBManager::fuArchitectureByIDConst
const FUArchitecture & fuArchitectureByIDConst(RowID id) const
Definition: CachedHDBManager.cc:484
HDB::CachedHDBManager::~CachedHDBManager
virtual ~CachedHDBManager()
Definition: CachedHDBManager.cc:69
HDB::CachedHDBManager::removeRFEntry
virtual void removeRFEntry(RowID id) const
Definition: CachedHDBManager.cc:350
HDB::CachedHDBManager::removeRFArchitecture
virtual void removeRFArchitecture(RowID archID) const
Definition: CachedHDBManager.cc:167
HDB::CachedHDBManager::costEstimationDataValue
virtual DataObject costEstimationDataValue(const std::string &valueName, const std::string &pluginName) const
Definition: CachedHDBManager.cc:271
CostEstimationData
Definition: CostEstimationData.hh:42
HDB::CachedHDBManager::rfArchitectureByIDConst
const RFArchitecture & rfArchitectureByIDConst(RowID id) const
Definition: CachedHDBManager.cc:498
HDB::CachedHDBManager::removeFUImplementation
virtual void removeFUImplementation(RowID id) const
Definition: CachedHDBManager.cc:141
HDB::HDBManager::fileName
std::string fileName() const
Definition: HDBManager.cc:612
HDB::FUImplementation
Definition: FUImplementation.hh:53
HDB::RFArchitecture
Definition: RFArchitecture.hh:50
HDB::CachedHDBManager::removeFUArchitecture
virtual void removeFUArchitecture(RowID archID) const
Definition: CachedHDBManager.cc:119
HDB::CachedHDBManager::CachedHDBManager
CachedHDBManager(const std::string &hdbFile)
Definition: CachedHDBManager.cc:58
HDB::CachedHDBManager::removeBusEntry
virtual void removeBusEntry(RowID id) const
Definition: CachedHDBManager.cc:363
HDB::CachedHDBManager::costEstimationDataIDs
virtual std::set< RowID > costEstimationDataIDs(const CostEstimationData &match, bool useCompiledQueries=false, RelationalDBQueryResult *compiledQuery=NULL) const
Definition: CachedHDBManager.cc:517
HDB::CachedHDBManager::removeCostEstimationData
virtual void removeCostEstimationData(RowID id) const
Definition: CachedHDBManager.cc:389
HDB::CachedHDBManager::validateCache
void validateCache() const
Definition: CachedHDBManager.cc:572
HDB::CachedHDBManager::deleteCostEstimationDataIDsQueries
virtual void deleteCostEstimationDataIDsQueries() const
Definition: CachedHDBManager.cc:555
HDBManager.hh
HDB::CachedHDBManager::modifyCostEstimationData
virtual void modifyCostEstimationData(RowID id, const CostEstimationData &data)
Definition: CachedHDBManager.cc:405
HDB::CachedHDBManager::rfArchitectureByID
virtual RFArchitecture * rfArchitectureByID(RowID id) const
Definition: CachedHDBManager.cc:244
HDB::CostFunctionPlugin
Definition: CostFunctionPlugin.hh:43
HDB::CachedHDBManager::lastModificationTime_
std::time_t lastModificationTime_
used to detect modifications to the HDB file (which invalidates cache)
Definition: CachedHDBManager.hh:146
HDB::CachedHDBManager::rfImplCache_
std::map< RowID, RFImplementation * > rfImplCache_
RF Implementation cache.
Definition: CachedHDBManager.hh:136
HDB::CachedHDBManager::instance
static CachedHDBManager & instance(const std::string &hdbFile)
Definition: CachedHDBManager.cc:89