blob: 3efdbac2c30db01e049f48216cd0af15291b8107 [file] [log] [blame]
Jagpal Singh Gille92aba42025-10-16 00:00:13 -07001#include "device_factory.hpp"
2
3#include "reservoir_pump_unit.hpp"
4
5#include <string>
6#include <vector>
7
8namespace phosphor::modbus::rtu::device
9{
10
11using ReservoirPumpUnitIntf = phosphor::modbus::rtu::device::ReservoirPumpUnit;
12
13auto 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
24auto 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
39auto DeviceFactory::create(sdbusplus::async::context& ctx,
40 const config::DeviceFactoryConfig& config,
Jagpal Singh Gill71848052025-10-16 00:28:58 -070041 PortIntf& serialPort, EventIntf::Events& events)
42 -> std::unique_ptr<BaseDevice>
Jagpal Singh Gille92aba42025-10-16 00:00:13 -070043{
44 switch (config.deviceType)
45 {
46 case config::DeviceType::reservoirPumpUnit:
Jagpal Singh Gill71848052025-10-16 00:28:58 -070047 return std::make_unique<ReservoirPumpUnit>(ctx, config, serialPort,
48 events);
Jagpal Singh Gille92aba42025-10-16 00:00:13 -070049 default:
50 break;
51 }
52
53 return nullptr;
54}
55
56} // namespace phosphor::modbus::rtu::device