xref: /openbmc/phosphor-modbus/rtu/port/port_factory.cpp (revision b62e3dfe5505fdb8c2ab96156b62e3bfb878b7a6)
17f9d41ddSJagpal Singh Gill #include "port_factory.hpp"
27f9d41ddSJagpal Singh Gill 
37f9d41ddSJagpal Singh Gill #include "usb_port.hpp"
47f9d41ddSJagpal Singh Gill 
57f9d41ddSJagpal Singh Gill #include <xyz/openbmc_project/Configuration/USBPort/client.hpp>
67f9d41ddSJagpal Singh Gill 
77f9d41ddSJagpal Singh Gill namespace phosphor::modbus::rtu::port
87f9d41ddSJagpal Singh Gill {
97f9d41ddSJagpal Singh Gill 
107f9d41ddSJagpal Singh Gill using USBPortConfigIntf =
117f9d41ddSJagpal Singh Gill     sdbusplus::client::xyz::openbmc_project::configuration::USBPort<>;
127f9d41ddSJagpal Singh Gill 
getInterfaces()137f9d41ddSJagpal Singh Gill auto PortFactory::getInterfaces() -> std::vector<std::string>
147f9d41ddSJagpal Singh Gill {
157f9d41ddSJagpal Singh Gill     return {USBPortConfigIntf::interface};
167f9d41ddSJagpal Singh Gill }
177f9d41ddSJagpal Singh Gill 
getConfig(sdbusplus::async::context & ctx,const sdbusplus::message::object_path & objectPath,const std::string & interfaceName)187f9d41ddSJagpal Singh Gill auto PortFactory::getConfig(sdbusplus::async::context& ctx,
197f9d41ddSJagpal Singh Gill                             const sdbusplus::message::object_path& objectPath,
207f9d41ddSJagpal Singh Gill                             const std::string& interfaceName)
21*b62e3dfeSJagpal Singh Gill     -> sdbusplus::async::task<std::unique_ptr<config::PortFactoryConfig>>
227f9d41ddSJagpal Singh Gill {
237f9d41ddSJagpal Singh Gill     if (interfaceName == USBPortConfigIntf::interface)
247f9d41ddSJagpal Singh Gill     {
25*b62e3dfeSJagpal Singh Gill         co_return co_await USBPort::getConfig(ctx, objectPath);
267f9d41ddSJagpal Singh Gill     }
277f9d41ddSJagpal Singh Gill 
28*b62e3dfeSJagpal Singh Gill     co_return std::nullptr_t();
297f9d41ddSJagpal Singh Gill }
307f9d41ddSJagpal Singh Gill 
create(sdbusplus::async::context & ctx,const config::PortFactoryConfig & config)317f9d41ddSJagpal Singh Gill auto PortFactory::create(sdbusplus::async::context& ctx,
32*b62e3dfeSJagpal Singh Gill                          const config::PortFactoryConfig& config)
337f9d41ddSJagpal Singh Gill     -> std::unique_ptr<BasePort>
347f9d41ddSJagpal Singh Gill {
357f9d41ddSJagpal Singh Gill     if (config.portType == config::PortType::usb)
367f9d41ddSJagpal Singh Gill     {
377f9d41ddSJagpal Singh Gill         return std::make_unique<USBPort>(ctx, config);
387f9d41ddSJagpal Singh Gill     }
397f9d41ddSJagpal Singh Gill 
407f9d41ddSJagpal Singh Gill     return nullptr;
417f9d41ddSJagpal Singh Gill }
427f9d41ddSJagpal Singh Gill 
437f9d41ddSJagpal Singh Gill } // namespace phosphor::modbus::rtu::port
44