1 /* SPDX-License-Identifier: LGPL-2.1+ */
10 typedef enum ConditionType
{
11 CONDITION_ARCHITECTURE
,
12 CONDITION_VIRTUALIZATION
,
14 CONDITION_KERNEL_COMMAND_LINE
,
15 CONDITION_KERNEL_VERSION
,
20 CONDITION_NEEDS_UPDATE
,
23 CONDITION_PATH_EXISTS
,
24 CONDITION_PATH_EXISTS_GLOB
,
25 CONDITION_PATH_IS_DIRECTORY
,
26 CONDITION_PATH_IS_SYMBOLIC_LINK
,
27 CONDITION_PATH_IS_MOUNT_POINT
,
28 CONDITION_PATH_IS_READ_WRITE
,
29 CONDITION_DIRECTORY_NOT_EMPTY
,
30 CONDITION_FILE_NOT_EMPTY
,
31 CONDITION_FILE_IS_EXECUTABLE
,
38 CONDITION_CONTROL_GROUP_CONTROLLER
,
41 _CONDITION_TYPE_INVALID
= -1
44 typedef enum ConditionResult
{
49 _CONDITION_RESULT_MAX
,
50 _CONDITION_RESULT_INVALID
= -1
53 typedef struct Condition
{
59 ConditionResult result
:6;
63 LIST_FIELDS(struct Condition
, conditions
);
66 Condition
* condition_new(ConditionType type
, const char *parameter
, bool trigger
, bool negate
);
67 void condition_free(Condition
*c
);
68 Condition
* condition_free_list_type(Condition
*first
, ConditionType type
);
69 static inline Condition
* condition_free_list(Condition
*first
) {
70 return condition_free_list_type(first
, _CONDITION_TYPE_INVALID
);
73 int condition_test(Condition
*c
);
74 typedef int (*condition_test_logger_t
)(void *userdata
, int level
, int error
, const char *file
, int line
, const char *func
, const char *format
, ...) _printf_(7, 8);
75 bool condition_test_list(Condition
*first
, const char *(*to_string
)(ConditionType t
), condition_test_logger_t logger
, void *userdata
);
77 void condition_dump(Condition
*c
, FILE *f
, const char *prefix
, const char *(*to_string
)(ConditionType t
));
78 void condition_dump_list(Condition
*c
, FILE *f
, const char *prefix
, const char *(*to_string
)(ConditionType t
));
80 const char* condition_type_to_string(ConditionType t
) _const_
;
81 ConditionType
condition_type_from_string(const char *s
) _pure_
;
83 const char* assert_type_to_string(ConditionType t
) _const_
;
84 ConditionType
assert_type_from_string(const char *s
) _pure_
;
86 const char* condition_result_to_string(ConditionResult r
) _const_
;
87 ConditionResult
condition_result_from_string(const char *s
) _pure_
;
89 static inline bool condition_takes_path(ConditionType t
) {
91 CONDITION_PATH_EXISTS
,
92 CONDITION_PATH_EXISTS_GLOB
,
93 CONDITION_PATH_IS_DIRECTORY
,
94 CONDITION_PATH_IS_SYMBOLIC_LINK
,
95 CONDITION_PATH_IS_MOUNT_POINT
,
96 CONDITION_PATH_IS_READ_WRITE
,
97 CONDITION_DIRECTORY_NOT_EMPTY
,
98 CONDITION_FILE_NOT_EMPTY
,
99 CONDITION_FILE_IS_EXECUTABLE
,
100 CONDITION_NEEDS_UPDATE
);