SctApiConfigCache.cxx

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::recursive_mutex::scoped_lock lock(cache_mutex);
00016   m_map[mid] = banks;
00017 }
00018 
00019 void SctApiConfigCache::clearMid(const UINT32 mid){
00020   boost::recursive_mutex::scoped_lock lock(cache_mutex);
00021   std::map<UINT32, boost::shared_ptr<ModuleBanks> >::iterator mit=m_map.find(mid);
00022   if (mit != m_map.end() ) m_map.erase(mit);
00023 }
00024 
00025 void SctApiConfigCache::clearAll(){
00026   boost::recursive_mutex::scoped_lock lock(cache_mutex);
00027   m_map.clear();
00028 }
00029 
00030 shared_ptr<SctApi::SctApiConfigCache::ModuleBanks> SctApiConfigCache::getFromMid(const UINT32 mid){
00031   boost::recursive_mutex::scoped_lock lock(cache_mutex);
00032   shared_ptr<ModuleBanks> banks;
00033   if (m_map.find(mid)!=m_map.end()) banks = m_map[mid];
00034   return banks;
00035 }
00036 
00037 shared_ptr<const SctApi::SctApiConfigCache::ModuleBanks> SctApiConfigCache::getFromMid(const UINT32 mid) const {
00038   boost::recursive_mutex::scoped_lock lock(cache_mutex);
00039   boost::shared_ptr<const ModuleBanks> banks;
00040   std::map<UINT32, boost::shared_ptr<ModuleBanks> >::const_iterator it=m_map.find(mid);
00041   if (it!=m_map.end()) banks = (*it).second;
00042   return banks;
00043 }
00044 
00045 void SctApiConfigCache::copyAllModules(BankType from, BankType to){
00046   for (std::map<UINT32, boost::shared_ptr<ModuleBanks> >::const_iterator it=m_map.begin(); it!= m_map.end(); ++it){
00047     shared_ptr<ModuleBanks> banks = it->second;
00048     if (!banks.get()) throw SctApiException("Internal error - null pointer in SctApiConfigCache copyAllModules");
00049     banks->copy(from, to);
00050   }
00051 }
00052 
00053 void SctApiConfigCache::copyAllModules(BankType from, std::list<BankType> to){
00054   for (std::list<BankType>::const_iterator i = to.begin(); i!= to.end(); ++i){
00055     copyAllModules(from, *i);
00056   }
00057 }
00058 
00059 boost::shared_ptr<ABCDModule> SctApiConfigCache::ModuleBanks::get(BankType b){
00060   boost::recursive_mutex::scoped_lock lock(bank_mutex);
00061   boost::shared_ptr<ABCDModule> config;
00062   std::map<BankType, boost::shared_ptr<ABCDModule> >::iterator it=m_map.find(b);
00063   if (it!=m_map.end()) config=(*it).second;
00064   return config;
00065 }
00066 
00067 boost::shared_ptr<const ABCDModule> SctApiConfigCache::ModuleBanks::get(BankType b) const{
00068   boost::recursive_mutex::scoped_lock lock(bank_mutex);
00069   boost::shared_ptr<const ABCDModule> config;
00070   std::map<BankType, boost::shared_ptr<ABCDModule> >::const_iterator it=m_map.find(b);
00071   if (it!=m_map.end()) config=(*it).second;
00072   return config;
00073 }
00074 
00075 void SctApiConfigCache::ModuleBanks::set(BankType bank, boost::shared_ptr<ABCDModule> config){
00076   boost::recursive_mutex::scoped_lock lock(bank_mutex);
00077   m_map[bank]=config;
00078 }
00079 
00080 void SctApiConfigCache::ModuleBanks::copy(BankType from, std::list<BankType> to){
00081   for (std::list<BankType>::const_iterator i = to.begin(); i!= to.end(); ++i){
00082     copy(from, *i);
00083   }
00084 }
00085 
00086 void SctApiConfigCache::ModuleBanks::copy(BankType from, BankType to){
00087   boost::recursive_mutex::scoped_lock lock(bank_mutex);
00088   boost::shared_ptr<ABCDModule> copyme=get(from);
00089   if (!copyme.get()) {
00090     std::string message("Attempt to copy null bank");
00091     message += __FILE__;
00092     message += __LINE__;
00093     throw SctApiException(message);
00094   }
00095   std::auto_ptr<ABCDModule> copy=ConfigUtility::clone(*copyme);
00096   m_map[to]=copy;
00097 }

Generated on Mon Feb 6 14:01:28 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6