Host C Specs


Directory: src/c/
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 14 / 0 / 14
Functions: 100.0% 2 / 0 / 2
Branches: 100.0% 10 / 0 / 10

core/io/callback_list.c
Line Branch Exec Source
1 /**
2 * @file callback_list.c
3 * @brief Adding to and running a callback list.
4 *
5 * @ingroup lib_core
6 */
7 #include "io/callback_list.h"
8
9 #include <stddef.h>
10
11 21 bool callback_list_add(CallbackList *list, CallbackListFn cb)
12 {
13
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 19 times.
21 if (!cb)
14 {
15 2 return true;
16 }
17
18
2/2
✓ Branch 0 taken 57 times.
✓ Branch 1 taken 16 times.
73 for (int i = 0; i < list->count; i++)
19 {
20
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 54 times.
57 if (list->entries[i] == cb)
21 {
22 3 return true;
23 }
24 }
25
26
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 12 times.
16 if (list->count >= list->max)
27 {
28 4 return false;
29 }
30
31 12 list->entries[list->count++] = cb;
32 12 return true;
33 }
34
35 11 void callback_list_fire(const CallbackList *list)
36 {
37
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 11 times.
32 for (int i = 0; i < list->count; i++)
38 {
39 21 list->entries[i]();
40 }
41 11 }
42