}
}
-void bus_match_dump(struct bus_match_node *node, unsigned level) {
+void bus_match_dump(FILE *out, struct bus_match_node *node, unsigned level) {
_cleanup_free_ char *pfx = NULL;
char buf[32];
return;
pfx = strrep(" ", level);
- printf("%s[%s]", strempty(pfx), bus_match_node_type_to_string(node->type, buf, sizeof(buf)));
+ fprintf(out, "%s[%s]", strempty(pfx), bus_match_node_type_to_string(node->type, buf, sizeof(buf)));
if (node->type == BUS_MATCH_VALUE) {
if (node->parent->type == BUS_MATCH_MESSAGE_TYPE)
- printf(" <%u>\n", node->value.u8);
+ fprintf(out, " <%u>\n", node->value.u8);
else
- printf(" <%s>\n", node->value.str);
+ fprintf(out, " <%s>\n", node->value.str);
} else if (node->type == BUS_MATCH_ROOT)
- puts(" root");
+ fputs(" root\n", out);
else if (node->type == BUS_MATCH_LEAF)
- printf(" %p/%p\n", node->leaf.callback->callback,
- container_of(node->leaf.callback, sd_bus_slot, match_callback)->userdata);
+ fprintf(out, " %p/%p\n", node->leaf.callback->callback,
+ container_of(node->leaf.callback, sd_bus_slot, match_callback)->userdata);
else
- putchar('\n');
+ putc('\n', out);
if (BUS_MATCH_CAN_HASH(node->type)) {
struct bus_match_node *c;
HASHMAP_FOREACH(c, node->compare.children)
- bus_match_dump(c, level + 1);
+ bus_match_dump(out, c, level + 1);
}
for (struct bus_match_node *c = node->child; c; c = c->next)
- bus_match_dump(c, level + 1);
+ bus_match_dump(out, c, level + 1);
}
enum bus_match_scope bus_match_get_scope(const struct bus_match_component *components, unsigned n_components) {
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
+#include <stdio.h>
+
#include "sd-bus.h"
#include "hashmap.h"
void bus_match_free(struct bus_match_node *node);
-void bus_match_dump(struct bus_match_node *node, unsigned level);
+void bus_match_dump(FILE *out, 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);
assert_se(match_add(slots, &root, "arg4has='po'", 17) >= 0);
assert_se(match_add(slots, &root, "arg4='pi'", 18) >= 0);
- bus_match_dump(&root, 0);
+ bus_match_dump(stdout, &root, 0);
assert_se(sd_bus_message_new_signal(bus, &m, "/foo/bar", "bar.x", "waldo") >= 0);
assert_se(sd_bus_message_append(m, "ssssas", "one", "two", "/prefix/three", "prefix.four", 3, "pi", "pa", "po") >= 0);
assert_se(bus_match_remove(&root, &slots[8].match_callback) >= 0);
assert_se(bus_match_remove(&root, &slots[13].match_callback) >= 0);
- bus_match_dump(&root, 0);
+ bus_match_dump(stdout, &root, 0);
zero(mask);
assert_se(bus_match_run(NULL, &root, m) == 0);