1 /*
2  * Copyright (c) 2022 Rodrigo Peixoto <rodrigopex@gmail.com>
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 #include <zephyr/logging/log.h>
6 #include <zephyr/sys/iterable_sections.h>
7 #include <zephyr/zbus/zbus.h>
8 LOG_MODULE_DECLARE(zbus, CONFIG_ZBUS_LOG_LEVEL);
9 
zbus_iterate_over_channels(bool (* iterator_func)(const struct zbus_channel * chan))10 bool zbus_iterate_over_channels(bool (*iterator_func)(const struct zbus_channel *chan))
11 {
12 	STRUCT_SECTION_FOREACH(zbus_channel, chan) {
13 		if (!(*iterator_func)(chan)) {
14 			return false;
15 		}
16 	}
17 	return true;
18 }
19 
zbus_iterate_over_channels_with_user_data(bool (* iterator_func)(const struct zbus_channel * chan,void * user_data),void * user_data)20 bool zbus_iterate_over_channels_with_user_data(
21 	bool (*iterator_func)(const struct zbus_channel *chan, void *user_data), void *user_data)
22 {
23 	STRUCT_SECTION_FOREACH(zbus_channel, chan) {
24 		if (!(*iterator_func)(chan, user_data)) {
25 			return false;
26 		}
27 	}
28 	return true;
29 }
30 
zbus_iterate_over_observers(bool (* iterator_func)(const struct zbus_observer * obs))31 bool zbus_iterate_over_observers(bool (*iterator_func)(const struct zbus_observer *obs))
32 {
33 	STRUCT_SECTION_FOREACH(zbus_observer, obs) {
34 		if (!(*iterator_func)(obs)) {
35 			return false;
36 		}
37 	}
38 	return true;
39 }
40 
zbus_iterate_over_observers_with_user_data(bool (* iterator_func)(const struct zbus_observer * obs,void * user_data),void * user_data)41 bool zbus_iterate_over_observers_with_user_data(
42 	bool (*iterator_func)(const struct zbus_observer *obs, void *user_data), void *user_data)
43 {
44 	STRUCT_SECTION_FOREACH(zbus_observer, obs) {
45 		if (!(*iterator_func)(obs, user_data)) {
46 			return false;
47 		}
48 	}
49 	return true;
50 }
51