Lines Matching refs:node
60 static void bus_match_node_free(struct bus_match_node *node) { in bus_match_node_free() argument
61 assert(node); in bus_match_node_free()
62 assert(node->parent); in bus_match_node_free()
63 assert(!node->child); in bus_match_node_free()
64 assert(node->type != BUS_MATCH_ROOT); in bus_match_node_free()
65 assert(node->type < _BUS_MATCH_NODE_TYPE_MAX); in bus_match_node_free()
67 if (node->parent->child) { in bus_match_node_free()
70 if (node->prev) { in bus_match_node_free()
71 assert(node->prev->next == node); in bus_match_node_free()
72 node->prev->next = node->next; in bus_match_node_free()
74 assert(node->parent->child == node); in bus_match_node_free()
75 node->parent->child = node->next; in bus_match_node_free()
78 if (node->next) in bus_match_node_free()
79 node->next->prev = node->prev; in bus_match_node_free()
82 if (node->type == BUS_MATCH_VALUE) { in bus_match_node_free()
86 if (node->parent->type == BUS_MATCH_MESSAGE_TYPE) in bus_match_node_free()
87 hashmap_remove(node->parent->compare.children, UINT_TO_PTR(node->value.u8)); in bus_match_node_free()
88 else if (BUS_MATCH_CAN_HASH(node->parent->type) && node->value.str) in bus_match_node_free()
89 hashmap_remove(node->parent->compare.children, node->value.str); in bus_match_node_free()
91 free(node->value.str); in bus_match_node_free()
94 if (BUS_MATCH_IS_COMPARE(node->type)) { in bus_match_node_free()
95 assert(hashmap_isempty(node->compare.children)); in bus_match_node_free()
96 hashmap_free(node->compare.children); in bus_match_node_free()
99 free(node); in bus_match_node_free()
102 static bool bus_match_node_maybe_free(struct bus_match_node *node) { in bus_match_node_maybe_free() argument
103 assert(node); in bus_match_node_maybe_free()
105 if (node->type == BUS_MATCH_ROOT) in bus_match_node_maybe_free()
108 if (node->child) in bus_match_node_maybe_free()
111 if (BUS_MATCH_IS_COMPARE(node->type) && !hashmap_isempty(node->compare.children)) in bus_match_node_maybe_free()
114 bus_match_node_free(node); in bus_match_node_maybe_free()
119 struct bus_match_node *node, in value_node_test() argument
126 assert(node); in value_node_test()
127 assert(node->type == BUS_MATCH_VALUE); in value_node_test()
135 return node->value.u8 == value_u8; in value_node_test()
138 if (streq_ptr(node->value.str, value_str)) in value_node_test()
147 if (streq_ptr(node->value.str, *i)) in value_node_test()
157 if (node->value.str[0] != ':' && value_str && value_str[0] == ':') in value_node_test()
170 return streq_ptr(node->value.str, value_str); in value_node_test()
176 if (streq_ptr(node->value.str, *i)) in value_node_test()
184 return namespace_simple_pattern(node->value.str, value_str); in value_node_test()
189 return path_simple_pattern(node->value.str, value_str); in value_node_test()
193 return path_complex_pattern(node->value.str, value_str); in value_node_test()
203 struct bus_match_node *node, in value_node_same() argument
212 assert(node); in value_node_same()
213 assert(node->type == BUS_MATCH_VALUE); in value_node_same()
218 return node->value.u8 == value_u8; in value_node_same()
230 return streq(node->value.str, value_str); in value_node_same()
239 struct bus_match_node *node, in bus_match_run() argument
249 if (!node) in bus_match_run()
262 switch (node->type) { in bus_match_run()
270 return bus_match_run(bus, node->child, m); in bus_match_run()
279 assert(node->child); in bus_match_run()
280 return bus_match_run(bus, node->child, m); in bus_match_run()
291 if (node->leaf.callback->install_slot || in bus_match_run()
292 m->read_counter <= node->leaf.callback->after || in bus_match_run()
293 node->leaf.callback->last_iteration == bus->iteration_counter) in bus_match_run()
294 return bus_match_run(bus, node->next, m); in bus_match_run()
296 node->leaf.callback->last_iteration = bus->iteration_counter; in bus_match_run()
304 if (node->leaf.callback->callback) { in bus_match_run()
308 slot = container_of(node->leaf.callback, sd_bus_slot, match_callback); in bus_match_run()
311 bus->current_handler = node->leaf.callback->callback; in bus_match_run()
314 r = node->leaf.callback->callback(m, slot->userdata, &error_buffer); in bus_match_run()
329 return bus_match_run(bus, node->next, m); in bus_match_run()
358 (void) bus_message_get_arg(m, node->type - BUS_MATCH_ARG, &test_str); in bus_match_run()
362 (void) bus_message_get_arg(m, node->type - BUS_MATCH_ARG_PATH, &test_str); in bus_match_run()
366 (void) bus_message_get_arg(m, node->type - BUS_MATCH_ARG_NAMESPACE, &test_str); in bus_match_run()
370 (void) bus_message_get_arg_strv(m, node->type - BUS_MATCH_ARG_HAS, &test_strv); in bus_match_run()
377 if (BUS_MATCH_CAN_HASH(node->type)) { in bus_match_run()
383 found = hashmap_get(node->compare.children, test_str); in bus_match_run()
386 found = hashmap_get(node->compare.children, *i); in bus_match_run()
395 } else if (node->type == BUS_MATCH_MESSAGE_TYPE) in bus_match_run()
396 found = hashmap_get(node->compare.children, UINT_TO_PTR(test_u8)); in bus_match_run()
407 for (struct bus_match_node *c = node->child; c; c = c->next) { in bus_match_run()
408 if (!value_node_test(c, node->type, test_u8, test_str, test_strv, m)) in bus_match_run()
423 return bus_match_run(bus, node->next, m); in bus_match_run()
910 struct bus_match_node *node, *pp; in bus_match_remove() local
915 node = callback->match_node; in bus_match_remove()
916 if (!node) in bus_match_remove()
919 assert(node->type == BUS_MATCH_LEAF); in bus_match_remove()
924 pp = node->parent; in bus_match_remove()
925 bus_match_node_free(node); in bus_match_remove()
929 node = pp; in bus_match_remove()
930 pp = node->parent; in bus_match_remove()
932 if (!bus_match_node_maybe_free(node)) in bus_match_remove()
939 void bus_match_free(struct bus_match_node *node) { in bus_match_free() argument
942 if (!node) in bus_match_free()
945 if (BUS_MATCH_CAN_HASH(node->type)) { in bus_match_free()
947 HASHMAP_FOREACH(c, node->compare.children) in bus_match_free()
950 assert(hashmap_isempty(node->compare.children)); in bus_match_free()
953 while ((c = node->child)) in bus_match_free()
956 if (node->type != BUS_MATCH_ROOT) in bus_match_free()
957 bus_match_node_free(node); in bus_match_free()
1010 void bus_match_dump(FILE *out, struct bus_match_node *node, unsigned level) { in bus_match_dump() argument
1013 if (!node) in bus_match_dump()
1016 …fprintf(out, "%*s[%s]", 2 * level, "", bus_match_node_type_to_string(node->type, buf, sizeof(buf))… in bus_match_dump()
1018 if (node->type == BUS_MATCH_VALUE) { in bus_match_dump()
1019 if (node->parent->type == BUS_MATCH_MESSAGE_TYPE) in bus_match_dump()
1020 fprintf(out, " <%u>\n", node->value.u8); in bus_match_dump()
1022 fprintf(out, " <%s>\n", node->value.str); in bus_match_dump()
1023 } else if (node->type == BUS_MATCH_ROOT) in bus_match_dump()
1025 else if (node->type == BUS_MATCH_LEAF) in bus_match_dump()
1026 fprintf(out, " %p/%p\n", node->leaf.callback->callback, in bus_match_dump()
1027 container_of(node->leaf.callback, sd_bus_slot, match_callback)->userdata); in bus_match_dump()
1031 if (BUS_MATCH_CAN_HASH(node->type)) { in bus_match_dump()
1033 HASHMAP_FOREACH(c, node->compare.children) in bus_match_dump()
1037 for (struct bus_match_node *c = node->child; c; c = c->next) in bus_match_dump()