00001 #include "SctApiConfigCache.h" 00002 #include "ConfigurationUtility.h" 00003 #include "SctApiException.h" 00004 00005 using boost::shared_ptr; 00006 using SctApi::SctApiConfigCache; 00007 00008 SctApiConfigCache::SctApiConfigCache(){ 00009 } 00010 00011 SctApiConfigCache::~SctApiConfigCache(){ 00012 } 00013 00014 void SctApiConfigCache::set(UINT32 mid, shared_ptr<ModuleBanks> banks){ 00015 boost::mutex::scoped_lock lock(cache_mutex); 00016 m_map[mid] = banks; 00017 } 00018 00019 shared_ptr<SctApi::SctApiConfigCache::ModuleBanks> SctApiConfigCache::getFromMid(const UINT32 mid){ 00020 boost::mutex::scoped_lock lock(cache_mutex); 00021 shared_ptr<ModuleBanks> banks; 00022 if (m_map.find(mid)!=m_map.end()) banks = m_map[mid]; 00023 return banks; 00024 } 00025 00026 shared_ptr<const SctApi::SctApiConfigCache::ModuleBanks> SctApiConfigCache::getFromMid(const UINT32 mid) const { 00027 boost::mutex::scoped_lock lock(cache_mutex); 00028 boost::shared_ptr<const ModuleBanks> banks; 00029 std::map<UINT32, boost::shared_ptr<ModuleBanks> >::const_iterator it=m_map.find(mid); 00030 if (it!=m_map.end()) banks = (*it).second; 00031 return banks; 00032 } 00033 00034 boost::shared_ptr<ABCDModule> SctApiConfigCache::ModuleBanks::get(BankType b){ 00035 boost::mutex::scoped_lock lock(bank_mutex); 00036 boost::shared_ptr<ABCDModule> config; 00037 std::map<BankType, boost::shared_ptr<ABCDModule> >::iterator it=m_map.find(b); 00038 if (it!=m_map.end()) config=(*it).second; 00039 return config; 00040 } 00041 00042 boost::shared_ptr<const ABCDModule> SctApiConfigCache::ModuleBanks::get(BankType b) const{ 00043 boost::mutex::scoped_lock lock(bank_mutex); 00044 boost::shared_ptr<const ABCDModule> config; 00045 std::map<BankType, boost::shared_ptr<ABCDModule> >::const_iterator it=m_map.find(b); 00046 if (it!=m_map.end()) config=(*it).second; 00047 return config; 00048 } 00049 00050 void SctApiConfigCache::ModuleBanks::set(BankType bank, boost::shared_ptr<ABCDModule> config){ 00051 boost::mutex::scoped_lock lock(bank_mutex); 00052 m_map[bank]=config; 00053 } 00054 00055 void SctApiConfigCache::ModuleBanks::copy(BankType from, BankType to){ 00056 boost::mutex::scoped_lock lock(bank_mutex); 00057 boost::shared_ptr<ABCDModule> copyme=get(from); 00058 if (!copyme.get()) { 00059 std::string message("Attempt to copy null bank"); 00060 message += __FILE__; 00061 message += __LINE__; 00062 throw SctApiException(message); 00063 } 00064 std::auto_ptr<ABCDModule> copy=ConfigUtility::clone(*copyme); 00065 m_map[to]=copy; 00066 }