46 lines
1.0 KiB
C
46 lines
1.0 KiB
C
#include "maze32_health.h"
|
|
|
|
#include <stddef.h>
|
|
|
|
void maze32_health_init(maze32_health_t *health, const char *version)
|
|
{
|
|
if (health == NULL) {
|
|
return;
|
|
}
|
|
|
|
health->version = version;
|
|
health->state = MAZE32_HEALTH_BOOTING;
|
|
health->error_code = 0;
|
|
}
|
|
|
|
void maze32_health_set(maze32_health_t *health, maze32_health_state_t state, int error_code)
|
|
{
|
|
if (health == NULL) {
|
|
return;
|
|
}
|
|
|
|
health->state = state;
|
|
health->error_code = error_code;
|
|
}
|
|
|
|
const char *maze32_health_state_name(maze32_health_state_t state)
|
|
{
|
|
switch (state) {
|
|
case MAZE32_HEALTH_BOOTING:
|
|
return "booting";
|
|
case MAZE32_HEALTH_FILESYSTEM_READY:
|
|
return "filesystem_ready";
|
|
case MAZE32_HEALTH_SERVING:
|
|
return "serving";
|
|
case MAZE32_HEALTH_ERROR:
|
|
return "error";
|
|
default:
|
|
return "unknown";
|
|
}
|
|
}
|
|
|
|
int maze32_health_is_healthy(const maze32_health_t *health)
|
|
{
|
|
return health != NULL && health->state == MAZE32_HEALTH_SERVING;
|
|
}
|