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