Channels

Serial Modem Host Applications

tags
Serial Modem Host Applications

Each module declares and defines a channel using zbus macros. For example, in the src/modules/network/network.h file, the Network module declares the network_chan channel:

ZBUS_CHAN_DECLARE(network_chan);

The channel is defined in src/modules/network/network.c:

ZBUS_CHAN_DEFINE(network_chan,          /* Channel name, derived from module name */
         struct network_msg,    /* Message data type */
         NULL,                  /* Optional validator function */
         NULL,                  /* Optional pointer to user data */
         ZBUS_OBSERVERS_EMPTY,  /* Initial observers */
         ZBUS_MSG_INIT(.type = NETWORK_DISCONNECTED)); /* Message initialization */

The fields of the ZBUS_CHAN_DEFINE macro are populated in a similar way across modules:

  • Channel name: The name of the channel, derived from the module name.
  • Message data type: The data type used to hold message data. The name comes from the channel name.
  • Validator function and User data: Not used.
  • Initial observers: The initial observer list is empty. Observers are added in the relevant modules later.
  • Message initialization: The initial value stored in the channel. Not used, and therefore set either to the module's disconnected message type or to ZBUS_MSG_INIT(0).

Important

In the context of zbus, you can use the term "message type" to refer to the data type or structure containing the message data for a given channel, in this case struct network_msg. In this architecture, "message type" is used to mean the enumerated value that distinguishes different kinds of messages sent on the same channel, in this case the type field of struct network_msg.