/* OUBO platform-independent C99 state machine illustration.
 * No device registers, SDK or real hardware operations are included.
 * Replace callbacks with validated application-specific implementations.
 * This example is not a safety-qualified software component. */
#include <stdbool.h>
#include <stddef.h>
typedef enum { APP_INIT, APP_RUNNING, APP_FAULT } app_state;
typedef struct {
    bool (*initialize)(void);
    bool (*healthy)(void);
    void (*run_once)(void);
    void (*safe_output)(void);
} app_callbacks;
typedef struct { app_state state; bool reset_requested; } app_context;
void app_step(app_context *app, const app_callbacks *cb) {
    if (app == NULL || cb == NULL || cb->initialize == NULL ||
        cb->healthy == NULL || cb->run_once == NULL || cb->safe_output == NULL) return;
    switch (app->state) {
    case APP_INIT:
        cb->safe_output();
        app->state = cb->initialize() ? APP_RUNNING : APP_FAULT;
        break;
    case APP_RUNNING:
        if (!cb->healthy()) { cb->safe_output(); app->state = APP_FAULT; }
        else cb->run_once();
        break;
    case APP_FAULT:
    default:
        cb->safe_output();
        app->state = APP_FAULT;
        if (app->reset_requested) { app->reset_requested = false; app->state = APP_INIT; }
        break;
    }
}
