| Jagpal Singh Gill | e92aba4 | 2025-10-16 00:00:13 -0700 | [diff] [blame] | 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, |
| Jagpal Singh Gill | 7184805 | 2025-10-16 00:28:58 -0700 | [diff] [blame] | 41 | PortIntf& serialPort, EventIntf::Events& events) |
| 42 | -> std::unique_ptr<BaseDevice> |
| Jagpal Singh Gill | e92aba4 | 2025-10-16 00:00:13 -0700 | [diff] [blame] | 43 | { |
| 44 | switch (config.deviceType) |
| 45 | { |
| 46 | case config::DeviceType::reservoirPumpUnit: |
| Jagpal Singh Gill | 7184805 | 2025-10-16 00:28:58 -0700 | [diff] [blame] | 47 | return std::make_unique<ReservoirPumpUnit>(ctx, config, serialPort, |
| 48 | events); |
| Jagpal Singh Gill | e92aba4 | 2025-10-16 00:00:13 -0700 | [diff] [blame] | 49 | default: |
| 50 | break; |
| 51 | } |
| 52 | |
| 53 | return nullptr; |
| 54 | } |
| 55 | |
| 56 | } // namespace phosphor::modbus::rtu::device |