#pragma once #include #include #include #include #include namespace phosphor::software::cpld { class CPLDInterface { public: CPLDInterface(sdbusplus::async::context& ctx, const std::string& chipname, uint16_t bus, uint8_t address) : ctx(ctx), chipname(chipname), bus(bus), address(address) {} virtual ~CPLDInterface() = default; CPLDInterface(const CPLDInterface&) = delete; CPLDInterface& operator=(const CPLDInterface&) = delete; CPLDInterface(CPLDInterface&&) = delete; CPLDInterface& operator=(CPLDInterface&&) = delete; virtual sdbusplus::async::task updateFirmware( bool force, const uint8_t* image, size_t imageSize, std::function progress = nullptr) = 0; virtual sdbusplus::async::task getVersion(std::string& version) = 0; protected: sdbusplus::async::context& ctx; std::string chipname; uint16_t bus; uint8_t address; }; class CPLDFactory { public: using Creator = std::function( sdbusplus::async::context& ctx, const std::string& chipName, uint16_t bus, uint8_t address)>; using ConfigProvider = std::function()>; static CPLDFactory& instance(); void registerCPLD(const std::string& vendorName, Creator creator); std::unique_ptr create( const std::string& vendorName, sdbusplus::async::context& ctx, const std::string& chipName, uint16_t bus, uint8_t address) const; std::vector getConfigs(); private: std::unordered_map creators; }; } // namespace phosphor::software::cpld