Skip to content

Commit 2bd49bb

Browse files
JordanYateskartben
authored andcommitted
doc: zbus: document ZBUS_CHAN_DEFINE_WITH_ID
Add documentation for the `ZBUS_CHAN_DEFINE_WITH_ID` feature. Signed-off-by: Jordan Yates <[email protected]>
1 parent 50cdc17 commit 2bd49bb

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

doc/services/zbus/index.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,34 @@ the defined channels and observers.
636636
ZBUS_CHAN_DECLARE(acc_chan, version_chan);
637637
638638
639+
Unique channel identifiers
640+
--------------------------
641+
642+
To simplify integrations with external entities, it is possible to assign a unique numeric identifier
643+
to a channel. Users can then retrieve the channel reference by using the identifier with
644+
:c:func:`zbus_chan_from_id`, rather than needing to obtain the reference at compile time with
645+
:c:macro:`ZBUS_CHAN_DECLARE`. Channels using this feature are declared with
646+
:c:func:`ZBUS_CHAN_DEFINE_WITH_ID`.
647+
648+
.. code-block:: c
649+
650+
ZBUS_CHAN_DEFINE_WITH_ID(control_chan, /* Name */
651+
0x12345678, /* Unique channel identifier */
652+
struct control_msg, /* Message type */
653+
control_validator, /* Validator */
654+
&message_count, /* User data */
655+
ZBUS_OBSERVERS_EMPTY, /* observers */
656+
ZBUS_MSG_INIT(.move = 0) /* Initial value */
657+
);
658+
659+
static void channel_retrieve(void)
660+
{
661+
const struct zbus_channel *chan = zbus_chan_from_id(0x12345678);
662+
663+
...
664+
}
665+
666+
639667
Iterating over channels and observers
640668
=====================================
641669

0 commit comments

Comments
 (0)