Using a struct[enum] as an sdbusplus D-Bus method arg?

Patrick Williams patrick at stwcx.xyz
Wed Jan 15 04:41:17 AEDT 2020


On Mon, Jan 13, 2020 at 12:59:26PM -0600, Matt Spinler wrote:
> To go from enums to strings, there is a convertForMessage() function, but to
> go from
> strings back to the enums, which is what we need, the function has the enum
> name in it:
>      convert<enum name>FromString(const std::string& s);
> 
> I don't think it's possible for message::read() to know that?

This needs a pretty simple refactoring to rename the
convert<enum>FromString function to a template function.

    // in a header somewhere to forward declare.
    template <typename T> T convertFromString() = delete;

    // in the generated code for each enum.
    template <> enum_type convertFromString<enum_type>() { ... }

The message::read will be able map message::read<enum_type> to
convertFromString<enum_type>.  There is probably some SFINAE needed
using is_enum[1] so that we don't need to generate each
message::<enum_type> specialization but can use a generic one for all
enums.

[1] https://en.cppreference.com/w/cpp/types/is_enum
-- 
Patrick Williams
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.ozlabs.org/pipermail/openbmc/attachments/20200114/2e64ff7b/attachment-0001.sig>


More information about the openbmc mailing list