]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/condition-util.h
condition: add more test cases
[thirdparty/systemd.git] / src / shared / condition-util.h
CommitLineData
b77c08e0
TG
1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3#pragma once
4
5/***
6 This file is part of systemd.
7
8 Copyright 2010 Lennart Poettering
9
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22***/
23
24#include <stdbool.h>
25#include <stdio.h>
26
27#include "list.h"
28#include "macro.h"
29
30typedef enum ConditionType {
31 CONDITION_PATH_EXISTS,
32 CONDITION_PATH_EXISTS_GLOB,
33 CONDITION_PATH_IS_DIRECTORY,
34 CONDITION_PATH_IS_SYMBOLIC_LINK,
35 CONDITION_PATH_IS_MOUNT_POINT,
36 CONDITION_PATH_IS_READ_WRITE,
37 CONDITION_DIRECTORY_NOT_EMPTY,
38 CONDITION_FILE_NOT_EMPTY,
39 CONDITION_FILE_IS_EXECUTABLE,
40 CONDITION_KERNEL_COMMAND_LINE,
41 CONDITION_VIRTUALIZATION,
42 CONDITION_SECURITY,
43 CONDITION_CAPABILITY,
44 CONDITION_HOST,
45 CONDITION_AC_POWER,
099524d7 46 CONDITION_ARCHITECTURE,
a55654d5 47 CONDITION_NEEDS_UPDATE,
e2680723 48 CONDITION_FIRST_BOOT,
b77c08e0
TG
49 CONDITION_NULL,
50 _CONDITION_TYPE_MAX,
51 _CONDITION_TYPE_INVALID = -1
52} ConditionType;
53
592fd144
LP
54#define CONDITION_STATE_IS_SUCCEEDED(state) ((state) > 0)
55#define CONDITION_STATE_IS_UNKNOWN(state) ((state) == 0)
56#define CONDITION_STATE_IS_FAILED(state) ((state) < 0)
57
58enum {
59 CONDITION_STATE_SUCCEEDED = -1,
60 CONDITION_STATE_UNKNOWN = 0,
61 CONDITION_STATE_FAILED = 1
62};
63
b77c08e0
TG
64typedef struct Condition {
65 ConditionType type;
66
67 bool trigger:1;
68 bool negate:1;
69
70 char *parameter;
b77c08e0
TG
71 int state;
72
73 LIST_FIELDS(struct Condition, conditions);
74} Condition;
75
76Condition* condition_new(ConditionType type, const char *parameter, bool trigger, bool negate);
77void condition_free(Condition *c);
78void condition_free_list(Condition *c);
79
d1bddcec
LP
80int condition_test(Condition *c);
81
b77c08e0
TG
82void condition_dump(Condition *c, FILE *f, const char *prefix);
83void condition_dump_list(Condition *c, FILE *f, const char *prefix);
84
85const char* condition_type_to_string(ConditionType t) _const_;
86int condition_type_from_string(const char *s) _pure_;