diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-03-31 16:16:37 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-03-31 16:16:37 +0200 |
commit | 392d5b378ceae5e1fd7c91ca545fcf4cd105744a (patch) | |
tree | e231fe77155323de76b535cd509ee5677f1bf28f /src/libsystemd-bus/bus-match.h | |
parent | 11c4c2492083325531aeb3eeb9b041c929677890 (diff) |
bus: parse matches locally and allow registration of callbacks for them
This includes code to parse and split up match strings which will also
be useful to calculate bloom filter masks when the time comes.
Diffstat (limited to 'src/libsystemd-bus/bus-match.h')
-rw-r--r-- | src/libsystemd-bus/bus-match.h | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src/libsystemd-bus/bus-match.h b/src/libsystemd-bus/bus-match.h new file mode 100644 index 0000000000..0a63b55403 --- /dev/null +++ b/src/libsystemd-bus/bus-match.h @@ -0,0 +1,81 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +#pragma once + +/*** + This file is part of systemd. + + Copyright 2013 Lennart Poettering + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see <http://www.gnu.org/licenses/>. +***/ + +#include "hashmap.h" + +#include "sd-bus.h" + +enum bus_match_node_type { + BUS_MATCH_ROOT, + BUS_MATCH_VALUE, + BUS_MATCH_LEAF, + + /* The following are all different kinds of compare nodes */ + BUS_MATCH_MESSAGE_TYPE, + BUS_MATCH_SENDER, + BUS_MATCH_DESTINATION, + BUS_MATCH_INTERFACE, + BUS_MATCH_MEMBER, + BUS_MATCH_PATH, + BUS_MATCH_PATH_NAMESPACE, + BUS_MATCH_ARG, + BUS_MATCH_ARG_LAST = BUS_MATCH_ARG + 63, + BUS_MATCH_ARG_PATH, + BUS_MATCH_ARG_PATH_LAST = BUS_MATCH_ARG_PATH + 63, + BUS_MATCH_ARG_NAMESPACE, + BUS_MATCH_ARG_NAMESPACE_LAST = BUS_MATCH_ARG_NAMESPACE + 63, + _BUS_MATCH_NODE_TYPE_MAX, + _BUS_MATCH_NODE_TYPE_INVALID = -1 +}; + +struct bus_match_node { + enum bus_match_node_type type; + struct bus_match_node *parent, *next, *prev, *child; + + union { + struct { + uint8_t u8; + char *str; + } value; + struct { + sd_message_handler_t callback; + void *userdata; + } leaf; + struct { + /* If this is set, then the child is NULL */ + Hashmap *children; + } compare; + }; +}; + +int bus_match_run(sd_bus *bus, struct bus_match_node *root, int ret, sd_bus_message *m); + +int bus_match_add(struct bus_match_node *root, const char *match, sd_message_handler_t callback, void *userdata, struct bus_match_node **ret); +int bus_match_remove(struct bus_match_node *root, const char *match, sd_message_handler_t callback, void *userdata); + +void bus_match_free(struct bus_match_node *node); + +void bus_match_dump(struct bus_match_node *node, unsigned level); + +const char* bus_match_node_type_to_string(enum bus_match_node_type t, char buf[], size_t l); +enum bus_match_node_type bus_match_node_type_from_string(const char *k, size_t n); |