xref: /openbmc/phosphor-modbus/rtu/device/device_factory.cpp (revision e92aba4516471f5a01d4ab1f93eb9919ec05c21f)
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 
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 
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 
39 auto DeviceFactory::create(sdbusplus::async::context& ctx,
40                            const config::DeviceFactoryConfig& config,
41                            PortIntf& serialPort) -> std::unique_ptr<BaseDevice>
42 {
43     switch (config.deviceType)
44     {
45         case config::DeviceType::reservoirPumpUnit:
46             return std::make_unique<ReservoirPumpUnit>(ctx, config, serialPort);
47         default:
48             break;
49     }
50 
51     return nullptr;
52 }
53 
54 } // namespace phosphor::modbus::rtu::device
55