#pragma once #include "types.hpp" #include "utils.hpp" #include #include #include #include #include #include namespace sdbusplus { namespace bus { class bus; } } // namespace sdbusplus namespace phosphor { namespace inventory { namespace manager { template struct HasProperties { private: using yes = char; struct no { char array[2]; }; template static constexpr yes test(typename U::PropertiesVariant*); template static constexpr no test(...); public: static constexpr auto value = sizeof(test(0)) == sizeof(yes); }; template struct MakeInterface { static std::any op(sdbusplus::bus::bus& bus, const char* path, const Interface&) { return std::any(std::make_shared(bus, path)); } }; template struct MakeInterface::value>> { static std::any op(sdbusplus::bus::bus& bus, const char* path, const Interface& props) { using InterfaceVariant = std::map; InterfaceVariant v; for (const auto& p : props) { v.emplace(p.first, convertVariant(p.second)); } return std::any(std::make_shared(bus, path, v)); } }; template struct AssignInterface { static void op(const Interface&, std::any&) { } }; template struct AssignInterface::value>> { static void op(const Interface& props, std::any& holder) { auto& iface = *std::any_cast&>(holder); for (const auto& p : props) { iface.setPropertyByName( p.first, convertVariant(p.second)); } } }; template struct SerializeInterface { static void op(const std::string& path, const std::string& iface, const std::any&) { Ops::serialize(path, iface); } }; template struct SerializeInterface::value>> { static void op(const std::string& path, const std::string& iface, const std::any& holder) { const auto& object = *std::any_cast&>(holder); Ops::serialize(path, iface, object); } }; template struct DeserializeInterface { static void op(const std::string& path, const std::string& iface, std::any&) { Ops::deserialize(path, iface); } }; template struct DeserializeInterface::value>> { static void op(const std::string& path, const std::string& iface, std::any& holder) { auto& object = *std::any_cast&>(holder); Ops::deserialize(path, iface, object); } }; struct DummyInterface { }; using MakeInterfaceType = std::add_pointer_t::op)>; using AssignInterfaceType = std::add_pointer_t::op)>; template using SerializeInterfaceType = std::add_pointer_t::op)>; template using DeserializeInterfaceType = std::add_pointer_t::op)>; } // namespace manager } // namespace inventory } // namespace phosphor