File: state.h

package info (click to toggle)
swupdate 2025.12%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 10,004 kB
  • sloc: ansic: 66,621; python: 6,291; makefile: 791; sh: 538; javascript: 229
file content (62 lines) | stat: -rw-r--r-- 1,700 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
 * Author: Christian Storm
 * Copyright (C) 2016, Siemens AG
 *
 * SPDX-License-Identifier:     GPL-2.0-only
 */

#pragma once
#include "util.h"
#include <stdbool.h>

#ifdef CONFIG_UPDATE_STATE_CHOICE_BOOTLOADER
#define EXPANDTOKL2(token) token
#define EXPANDTOK(token) EXPANDTOKL2(token)
#define STATE_KEY EXPANDTOK(CONFIG_UPDATE_STATE_BOOTLOADER)
#else
#define STATE_KEY "none"
#endif

/* (Persistent) Update State Management Functions.
 *
 * The SWUpdate core or a module such as suricatta may want to persistently
 * store the update status to communicate it to the server instance after,
 * e.g., a successful reboot into the new firmware.
 * The `{save,get}_state()` functions are called to manage the update status
 * via, e.g., U-Boot's environment.
 *
 */

typedef enum {
	STATE_OK = '0',
	STATE_INSTALLED = '1',
	STATE_TESTING = '2',
	STATE_FAILED = '3',
	STATE_NOT_AVAILABLE = '4',
	STATE_ERROR = '5',
	STATE_WAIT = '6',
	STATE_IN_PROGRESS = '7',
	STATE_LAST = STATE_IN_PROGRESS
} update_state_t;

static inline bool is_valid_state(update_state_t state) {
	return (state >= STATE_OK && state <= STATE_LAST);
}

static inline char* get_state_string(update_state_t state) {
	switch (state) {
		case STATE_IN_PROGRESS: return (char*)"in_progress";
		case STATE_FAILED: return (char*)"failed";
		case STATE_OK: return (char*)"ok";
		case STATE_INSTALLED: return (char*)"installed";
		case STATE_TESTING: return (char*)"testing";
		case STATE_NOT_AVAILABLE: return (char*)"not_available";
		case STATE_ERROR: return (char*)"error";
		case STATE_WAIT: return (char*)"wait";
		default: break;
	}
	return (char*)"<nil>";
}

int save_state(update_state_t value);
update_state_t get_state(void);