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