xref: /openbmc/phosphor-modbus/rtu/device/device_factory.cpp (revision 7184805ae4ede906935133e3e0f8ee2468bc781b)
1 #include "device_factory.hpp"
2 
3 #include "reservoir_pump_unit.hpp"
4 
5 #include <string>
6 #include <vector>
7 
8 namespace phosphor::modbus::rtu::device
9 {
10 
11 using ReservoirPumpUnitIntf = phosphor::modbus::rtu::device::ReservoirPumpUnit;
12 
getInterfaces()13 auto DeviceFactory::getInterfaces() -> std::vector<std::string>
14 {
15     std::vector<std::string> interfaces{};
16 
17     auto rpuInterfaces = ReservoirPumpUnitIntf::getInterfaces();
18     interfaces.insert(interfaces.end(), rpuInterfaces.begin(),
19                       rpuInterfaces.end());
20 
21     return interfaces;
22 }
23 
getConfig(sdbusplus::async::context & ctx,const sdbusplus::message::object_path & objectPath,const std::string & interfaceName)24 auto DeviceFactory::getConfig(sdbusplus::async::context& ctx,
25                               const sdbusplus::message::object_path& objectPath,
26                               const std::string& interfaceName)
27     -> sdbusplus::async::task<std::optional<config::DeviceFactoryConfig>>
28 {
29     auto rpuInterfaces = ReservoirPumpUnitIntf::getInterfaces();
30     if (rpuInterfaces.find(interfaceName) != rpuInterfaces.end())
31     {
32         co_return co_await ReservoirPumpUnitIntf::getConfig(ctx, objectPath,
33                                                             interfaceName);
34     }
35 
36     co_return std::nullopt;
37 }
38 
create(sdbusplus::async::context & ctx,const config::DeviceFactoryConfig & config,PortIntf & serialPort,EventIntf::Events & events)39 auto DeviceFactory::create(sdbusplus::async::context& ctx,
40                            const config::DeviceFactoryConfig& config,
41                            PortIntf& serialPort, EventIntf::Events& events)
42     -> std::unique_ptr<BaseDevice>
43 {
44     switch (config.deviceType)
45     {
46         case config::DeviceType::reservoirPumpUnit:
47             return std::make_unique<ReservoirPumpUnit>(ctx, config, serialPort,
48                                                        events);
49         default:
50             break;
51     }
52 
53     return nullptr;
54 }
55 
56 } // namespace phosphor::modbus::rtu::device
57