OpenASIP 2.2
Loading...
Searching...
No Matches
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
43namespace 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 */
64public:
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
118private:
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
int RowID
Type definition of row ID in relational databases.
Definition DBTypes.hh:37
virtual void removeFUEntry(RowID id) const
virtual void removeRFEntry(RowID id) const
std::map< std::string, std::map< std::string, DataObject > > costEstimationPluginValueCache_
Cost estimation plugin value cache (pluginName/valueName)
const RFArchitecture & rfArchitectureByIDConst(RowID id) const
virtual DataObject costEstimationDataValue(const std::string &valueName, const std::string &pluginName) const
virtual void removeSocketEntry(RowID id) const
static CachedHDBManager & createNew(const std::string &fileName)
virtual void deleteCostEstimationDataIDsQueries() const
virtual void modifyCostEstimationData(RowID id, const CostEstimationData &data)
virtual void modifyCostFunctionPlugin(RowID id, const CostFunctionPlugin &plugin)
virtual FUArchitecture * fuArchitectureByID(RowID id) const
std::map< RowID, RFArchitecture * > rfArchCache_
RF Architecture cache.
std::map< RowID, FUImplementation * > fuImplCache_
FU Implementation cache.
std::map< RowID, RFImplementation * > rfImplCache_
RF Implementation cache.
std::time_t lastModificationTime_
used to detect modifications to the HDB file (which invalidates cache)
std::map< RowID, FUArchitecture * > fuArchCache_
FU Architecture cache.
virtual void removeFUImplementation(RowID id) const
uintmax_t lastSizeInBytes_
used to detect modifications to the HDB file (which invalidates cache)
virtual RFArchitecture * rfArchitectureByID(RowID id) const
virtual FUImplementation * createImplementationOfFU(FUArchitecture &architecture, RowID id) const
virtual void removeRFImplementation(RowID archID) const
std::map< short int, RelationalDBQueryResult * > costEstimationDataIDsQueries_
map of cached (compiled) queries for costEstimatioDataIDs function
static CachedHDBManager & instance(const std::string &hdbFile)
const FUArchitecture & fuArchitectureByIDConst(RowID id) const
virtual std::set< RowID > costEstimationDataIDs(const CostEstimationData &match, bool useCompiledQueries=false, RelationalDBQueryResult *compiledQuery=NULL) const
virtual void removeFUArchitecture(RowID archID) const
virtual void removeBusEntry(RowID id) const
virtual void removeCostEstimationData(RowID id) const
virtual RFImplementation * createImplementationOfRF(RowID id) const
virtual void removeRFArchitecture(RowID archID) const
virtual void removeCostFunctionPlugin(RowID pluginID) const
std::string fileName() const