xref: /openbmc/phosphor-modbus/rtu/port/port_factory.cpp (revision b62e3dfe5505fdb8c2ab96156b62e3bfb878b7a6)
1 #include "port_factory.hpp"
2 
3 #include "usb_port.hpp"
4 
5 #include <xyz/openbmc_project/Configuration/USBPort/client.hpp>
6 
7 namespace phosphor::modbus::rtu::port
8 {
9 
10 using USBPortConfigIntf =
11     sdbusplus::client::xyz::openbmc_project::configuration::USBPort<>;
12 
getInterfaces()13 auto PortFactory::getInterfaces() -> std::vector<std::string>
14 {
15     return {USBPortConfigIntf::interface};
16 }
17 
getConfig(sdbusplus::async::context & ctx,const sdbusplus::message::object_path & objectPath,const std::string & interfaceName)18 auto PortFactory::getConfig(sdbusplus::async::context& ctx,
19                             const sdbusplus::message::object_path& objectPath,
20                             const std::string& interfaceName)
21     -> sdbusplus::async::task<std::unique_ptr<config::PortFactoryConfig>>
22 {
23     if (interfaceName == USBPortConfigIntf::interface)
24     {
25         co_return co_await USBPort::getConfig(ctx, objectPath);
26     }
27 
28     co_return std::nullptr_t();
29 }
30 
create(sdbusplus::async::context & ctx,const config::PortFactoryConfig & config)31 auto PortFactory::create(sdbusplus::async::context& ctx,
32                          const config::PortFactoryConfig& config)
33     -> std::unique_ptr<BasePort>
34 {
35     if (config.portType == config::PortType::usb)
36     {
37         return std::make_unique<USBPort>(ctx, config);
38     }
39 
40     return nullptr;
41 }
42 
43 } // namespace phosphor::modbus::rtu::port
44