chiark / gitweb /
aa59ae484907a766a5921780ae4774b412eaa3ff
[elogind.git] / src / libelogind / sd-bus / bus-match.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 /***
5   This file is part of systemd.
6
7   Copyright 2013 Lennart Poettering
8 ***/
9
10 #include "sd-bus.h"
11
12 #include "hashmap.h"
13
14 enum bus_match_node_type {
15         BUS_MATCH_ROOT,
16         BUS_MATCH_VALUE,
17         BUS_MATCH_LEAF,
18
19         /* The following are all different kinds of compare nodes */
20         BUS_MATCH_SENDER,
21         BUS_MATCH_MESSAGE_TYPE,
22         BUS_MATCH_DESTINATION,
23         BUS_MATCH_INTERFACE,
24         BUS_MATCH_MEMBER,
25         BUS_MATCH_PATH,
26         BUS_MATCH_PATH_NAMESPACE,
27         BUS_MATCH_ARG,
28         BUS_MATCH_ARG_LAST = BUS_MATCH_ARG + 63,
29         BUS_MATCH_ARG_PATH,
30         BUS_MATCH_ARG_PATH_LAST = BUS_MATCH_ARG_PATH + 63,
31         BUS_MATCH_ARG_NAMESPACE,
32         BUS_MATCH_ARG_NAMESPACE_LAST = BUS_MATCH_ARG_NAMESPACE + 63,
33         BUS_MATCH_ARG_HAS,
34         BUS_MATCH_ARG_HAS_LAST = BUS_MATCH_ARG_HAS + 63,
35         _BUS_MATCH_NODE_TYPE_MAX,
36         _BUS_MATCH_NODE_TYPE_INVALID = -1
37 };
38
39 struct bus_match_node {
40         enum bus_match_node_type type;
41         struct bus_match_node *parent, *next, *prev, *child;
42
43         union {
44                 struct {
45                         char *str;
46                         uint8_t u8;
47                 } value;
48                 struct {
49                         struct match_callback *callback;
50                 } leaf;
51                 struct {
52                         /* If this is set, then the child is NULL */
53                         Hashmap *children;
54                 } compare;
55         };
56 };
57
58 struct bus_match_component {
59         enum bus_match_node_type type;
60         uint8_t value_u8;
61         char *value_str;
62 };
63
64 enum bus_match_scope {
65         BUS_MATCH_GENERIC,
66         BUS_MATCH_LOCAL,
67         BUS_MATCH_DRIVER,
68 };
69
70 int bus_match_run(sd_bus *bus, struct bus_match_node *root, sd_bus_message *m);
71
72 int bus_match_add(struct bus_match_node *root, struct bus_match_component *components, unsigned n_components, struct match_callback *callback);
73 int bus_match_remove(struct bus_match_node *root, struct match_callback *callback);
74
75 int bus_match_find(struct bus_match_node *root, struct bus_match_component *components, unsigned n_components, sd_bus_message_handler_t callback, void *userdata, struct match_callback **ret);
76
77 void bus_match_free(struct bus_match_node *node);
78
79 void bus_match_dump(struct bus_match_node *node, unsigned level);
80
81 const char* bus_match_node_type_to_string(enum bus_match_node_type t, char buf[], size_t l);
82 enum bus_match_node_type bus_match_node_type_from_string(const char *k, size_t n);
83
84 int bus_match_parse(const char *match, struct bus_match_component **_components, unsigned *_n_components);
85 void bus_match_parse_free(struct bus_match_component *components, unsigned n_components);
86 #if 0 /// UNNEEDED by elogind
87 char *bus_match_to_string(struct bus_match_component *components, unsigned n_components);
88 #endif // 0
89
90 enum bus_match_scope bus_match_get_scope(const struct bus_match_component *components, unsigned n_components);