00001 #include "ConfigUpdaterManager.h" 00002 #include "ConfigUpdater.h" 00003 00004 #include "Sct_SctApi/SctApi.hh" 00005 #include "Sct/LogicErrors.h" 00006 #include "SctData/TestResult.h" 00007 #include "Sct/SctNames.h" 00008 00009 using namespace Sct; 00010 using namespace SctData; 00011 00012 namespace SctCalibrationController { 00013 00014 ConfigUpdaterManager::ConfigUpdaterManager() { 00015 } 00016 00017 ConfigUpdaterManager& ConfigUpdaterManager::instance() { 00018 static ConfigUpdaterManager cum; 00019 return cum; 00020 } 00021 00022 void ConfigUpdaterManager::update(const SctData::TestResult& t, Sct_SctApi::SctApiIPC_ptr api, bool force) const { 00023 if (t.getPassed() || force){ 00024 getUpdater(t.getClassName()).update(t, api); 00025 }else{ 00026 std::ostringstream oss; 00027 oss << "Module failed - configuration not updated" << t.getClassName() << " " << t.getUniqueID(); 00028 SctNames::Mrs() << "UPDATE_NOT_DONE" 00029 << MRS_TEXT(oss.str().c_str()) << MRS_DIAGNOSTIC << ENDM; 00030 } 00031 } 00032 00033 ConfigUpdater& ConfigUpdaterManager::getUpdater(const string& className) const { 00034 ConfigUpdaterMap::const_iterator it = updaterMap.find(className); 00035 if ( it == updaterMap.end() ) { 00036 std::cerr << "Calibration Controller: no updater for " << className << std::endl; 00037 std::cerr << "known updaters:" << std::endl ; 00038 for (ConfigUpdaterMap::const_iterator it = updaterMap.begin(); it != updaterMap.end(); ++it) { 00039 std::cerr << (*it).first << std::endl; 00040 } 00041 throw InvalidArgumentError("Calibration Controller: no updater for " + className, __FILE__, __LINE__ ); 00042 } else { 00043 return *(*it).second ; 00044 } 00045 } 00046 00047 bool ConfigUpdaterManager::setUpdater(const string& testName, shared_ptr<ConfigUpdater> updater) { 00048 if (updaterMap.find(testName) == updaterMap.end() ) { 00049 updaterMap[testName] = updater; 00050 return true; 00051 } 00052 return false; 00053 } 00054 00055 } 00056