net: lwm2m: Add path generation macro

Currently, the Zephyr LwM2M code base is littered with hard-coded
object- and resource IDs, such as

    /* Mark 1st instance of security object as a bootstrap server */
    lwm2m_engine_set_u8("0/0/1", 1);

The purpose of this LoC is extremely opaque without the accompanying
comment. Each use of a resource path requires constantly checking
headers or the object registry to ensure you're not misremembering IDs.

To alleviate this, this commit introduces a variadic LwM2M path
expansion macro which performs preprocessor stringification on each
argument. For instance, "0/0/1" can now be written as

    LWM2M_PATH(LWM2M_OBJECT_SECURITY_ID, 0, SECURITY_BOOTSTRAP_FLAG_ID)

which, while albeit lengthier, avoids the use of hard-coded string
literals, thus making the code much more immediately understandable.

Signed-off-by: Benjamin Lindqvist <benjamin.lindqvist@endian.se>
2 files changed