File: handler.h

package info (click to toggle)
swupdate 2025.12%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,004 kB
  • sloc: ansic: 66,621; python: 6,291; makefile: 791; sh: 538; javascript: 229
file content (85 lines) | stat: -rw-r--r-- 2,208 bytes parent folder | download | duplicates (5)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
 * (C) Copyright 2012-2013
 * Stefano Babic <stefano.babic@swupdate.org>
 *
 * SPDX-License-Identifier:     GPL-2.0-only
 */


#pragma once

#include <stdbool.h>

struct img_type;

/*
 * Identify the type of a script
 * A script can contain functions for several of these
 * entries. For example, it can contain both a pre- and post-
 * install functions.
 */
typedef enum {
	NONE,
	PREINSTALL,	/* Script runs as preinstall */
	POSTINSTALL,	/* Script runs a postinstall */
	POSTFAILURE	/* Script called in case update fails */
} script_fn ;

/*
 * Use enum for mask to easy transfer to Lua
 * scripts
 */
typedef enum {
	IMAGE_HANDLER = 1,
	FILE_HANDLER = 2,
	SCRIPT_HANDLER = 4,
	BOOTLOADER_HANDLER = 8,
	PARTITION_HANDLER = 16,
	NO_DATA_HANDLER = 32
} HANDLER_MASK;

/*
 * Life-cycle for the handler:
 * GLOBAL : handler is instantiated at startup and available for all updates
 * SESSION : handler is part of the SWU and available only for the current update
 */

typedef enum {
	GLOBAL_HANDLER,
	SESSION_HANDLER
} handler_type_t;

#define ANY_HANDLER (IMAGE_HANDLER | FILE_HANDLER | SCRIPT_HANDLER | \
			BOOTLOADER_HANDLER | PARTITION_HANDLER | \
			NO_DATA_HANDLER)

typedef int (*handler)(struct img_type *img, void *data);
struct installer_handler{
	char	desc[64];	/* Name that identifies the handler */
	handler installer;	/* Handler function */
	void	*data;		/* Private data for the handler */
	unsigned int mask;	/* Mask (see HANDLER_MASK) */
	bool	noglobal;	/* true if handler is not global and
				   should be removed after install */
};

struct script_handler_data {
	/*
	 * scriptfn must be first, as script handlers may expect to
	 * receive just a script_fn
	 */
	script_fn scriptfn;
	void	*data;
};

int register_handler(const char *desc, 
		handler installer, HANDLER_MASK mask, void *data);
int register_session_handler(const char *desc,
		handler installer, HANDLER_MASK mask, void *data);
int unregister_handler(const char *desc);
void unregister_session_handlers(void);

struct installer_handler *find_handler(struct img_type *img);
void print_registered_handlers(bool global);
struct installer_handler *get_next_handler(void);
unsigned int get_handler_mask(struct img_type *img);