1 #include "cpld_interface.hpp" 2 3 namespace phosphor::software::cpld 4 { 5 6 CPLDFactory& CPLDFactory::instance() 7 { 8 static CPLDFactory factory; 9 return factory; 10 } 11 12 void CPLDFactory::registerCPLD(const std::string& chipType, Creator creator) 13 { 14 creators[chipType] = std::move(creator); 15 } 16 17 std::unique_ptr<CPLDInterface> CPLDFactory::create( 18 const std::string& chipType, sdbusplus::async::context& ctx, 19 const std::string& chipName, uint16_t bus, uint8_t address) const 20 { 21 auto it = creators.find(chipType); 22 if (it != creators.end()) 23 { 24 return (it->second)(ctx, chipName, bus, address); 25 } 26 return nullptr; 27 } 28 29 std::vector<std::string> CPLDFactory::getConfigs() 30 { 31 std::vector<std::string> configs; 32 configs.reserve(creators.size()); 33 34 std::transform(creators.begin(), creators.end(), 35 std::back_inserter(configs), 36 [](const auto& pair) { return pair.first; }); 37 38 return configs; 39 } 40 41 } // namespace phosphor::software::cpld 42