@@ -22,21 +22,21 @@ struct acc_msg {
22
22
int z ;
23
23
};
24
24
25
- ZBUS_CHAN_DEFINE (version_chan , /* Name */
25
+ ZBUS_CHAN_DEFINE (version_chan , /* Name */
26
26
struct version_msg , /* Message type */
27
27
28
- NULL , /* Validator */
29
- NULL , /* User data */
28
+ NULL , /* Validator */
29
+ NULL , /* User data */
30
30
ZBUS_OBSERVERS_EMPTY , /* observers */
31
31
ZBUS_MSG_INIT (.major = 0 , .minor = 1 ,
32
32
.build = 2 ) /* Initial value major 0, minor 1, build 2 */
33
33
);
34
34
35
- ZBUS_CHAN_DEFINE (acc_data_chan , /* Name */
35
+ ZBUS_CHAN_DEFINE (acc_data_chan , /* Name */
36
36
struct acc_msg , /* Message type */
37
37
38
- NULL , /* Validator */
39
- NULL , /* User data */
38
+ NULL , /* Validator */
39
+ NULL , /* User data */
40
40
ZBUS_OBSERVERS (foo_lis , bar_sub ), /* observers */
41
41
ZBUS_MSG_INIT (.x = 0 , .y = 0 , .z = 0 ) /* Initial value */
42
42
);
@@ -55,12 +55,12 @@ static bool simple_chan_validator(const void *msg, size_t msg_size)
55
55
}
56
56
57
57
ZBUS_CHAN_DEFINE (simple_chan , /* Name */
58
- int , /* Message type */
58
+ int , /* Message type */
59
59
60
60
simple_chan_validator , /* Validator */
61
- NULL , /* User data */
62
- ZBUS_OBSERVERS_EMPTY , /* observers */
63
- 0 /* Initial value is 0 */
61
+ NULL , /* User data */
62
+ ZBUS_OBSERVERS_EMPTY , /* observers */
63
+ 0 /* Initial value is 0 */
64
64
);
65
65
66
66
static void listener_callback_example (const struct zbus_channel * chan )
@@ -89,34 +89,51 @@ static void subscriber_task(void)
89
89
}
90
90
}
91
91
92
- K_THREAD_DEFINE (subscriber_task_id , CONFIG_MAIN_STACK_SIZE ,
93
- subscriber_task , NULL , NULL , NULL , 3 , 0 , 0 );
92
+ K_THREAD_DEFINE (subscriber_task_id , CONFIG_MAIN_STACK_SIZE , subscriber_task , NULL , NULL , NULL , 3 , 0 ,
93
+ 0 );
94
94
95
- #if defined(CONFIG_ZBUS_STRUCTS_ITERABLE_ACCESS )
96
- static int count ;
97
-
98
- static bool print_channel_data_iterator (const struct zbus_channel * chan )
95
+ static bool print_channel_data_iterator (const struct zbus_channel * chan , void * user_data )
99
96
{
100
- LOG_INF ("%d - Channel %s:" , count , zbus_chan_name (chan ));
97
+ int * count = user_data ;
98
+
99
+ LOG_INF ("%d - Channel %s:" , * count , zbus_chan_name (chan ));
101
100
LOG_INF (" Message size: %d" , zbus_chan_msg_size (chan ));
102
- ++ count ;
103
101
LOG_INF (" Observers:" );
104
- for (const struct zbus_observer * const * obs = chan -> observers ; * obs != NULL ; ++ obs ) {
105
- LOG_INF (" - %s" , (* obs )-> name );
102
+
103
+ ++ (* count );
104
+
105
+ struct zbus_channel_observation * observation ;
106
+
107
+ for (int16_t i = chan -> data -> observers_start_idx , limit = chan -> data -> observers_end_idx ;
108
+ i < limit ; ++ i ) {
109
+ STRUCT_SECTION_GET (zbus_channel_observation , i , & observation );
110
+
111
+ __ASSERT (observation != NULL , "observation must be not NULL" );
112
+
113
+ LOG_INF (" - %s" , observation -> obs -> name );
114
+ }
115
+
116
+ struct zbus_observer_node * obs_nd , * tmp ;
117
+
118
+ SYS_SLIST_FOR_EACH_CONTAINER_SAFE (& chan -> data -> observers , obs_nd , tmp , node ) {
119
+ LOG_INF (" - %s" , obs_nd -> obs -> name );
106
120
}
107
121
108
122
return true;
109
123
}
110
124
111
- static bool print_observer_data_iterator (const struct zbus_observer * obs )
125
+ static bool print_observer_data_iterator (const struct zbus_observer * obs , void * user_data )
112
126
{
113
- LOG_INF ("%d - %s %s" , count , obs -> queue ? "Subscriber" : "Listener" , zbus_obs_name (obs ));
127
+ int * count = user_data ;
128
+
129
+ LOG_INF ("%d - %s %s" , * count ,
130
+ obs -> type == ZBUS_OBSERVER_LISTENER_TYPE ? "Listener" : "Subscriber" ,
131
+ zbus_obs_name (obs ));
114
132
115
- ++ count ;
133
+ ++ ( * count ) ;
116
134
117
135
return true;
118
136
}
119
- #endif /* CONFIG_ZBUS_STRUCTS_ITERABLE_ACCESS */
120
137
121
138
int main (void )
122
139
{
@@ -127,17 +144,15 @@ int main(void)
127
144
LOG_INF ("Sensor sample started raw reading, version %u.%u-%u!" , v -> major , v -> minor ,
128
145
v -> build );
129
146
130
- #if defined(CONFIG_ZBUS_STRUCTS_ITERABLE_ACCESS )
131
- count = 0 ;
147
+ int count = 0 ;
132
148
133
149
LOG_INF ("Channel list:" );
134
- zbus_iterate_over_channels (print_channel_data_iterator );
150
+ zbus_iterate_over_channels_with_user_data (print_channel_data_iterator , & count );
135
151
136
152
count = 0 ;
137
153
138
154
LOG_INF ("Observers list:" );
139
- zbus_iterate_over_observers (print_observer_data_iterator );
140
- #endif
155
+ zbus_iterate_over_observers_with_user_data (print_observer_data_iterator , & count );
141
156
zbus_chan_pub (& acc_data_chan , & acc1 , K_SECONDS (1 ));
142
157
143
158
k_msleep (1000 );
0 commit comments