SMF uses a data structure of type struct smf_ctx to track the current state of the state machine. This structure is embedded within a larger structure called the state object that holds the following:
- SMF's context structure.
- The zbus channel of the latest message received.
- The contents of the latest message received.
- Any extended state variables needed by the module.
For example, the FOTA module defines its state object structure:
struct fota_state_object {
/* This must be first */
struct smf_ctx ctx;
/* Last channel type that a message was received on */
const struct zbus_channel *chan;
/* Buffer for last zbus message */
uint8_t msg_buf[MAX_MSG_SIZE];
/* Extended state variable: nRF Cloud FOTA poll context */
struct nrf_cloud_fota_poll_ctx fota_ctx;
};
The structure is allocated in the module's thread and passed to all SMF functions.