Host C Specs


Directory: src/c/
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 17 / 0 / 17
Functions: 100.0% 4 / 0 / 4
Branches: 100.0% 16 / 0 / 16

pebble/system/settings/settings_chain.h
Line Branch Exec Source
1 /**
2 * @file settings_chain.h
3 * @brief The walk over a face's settings schemas, and the checks a launch makes over them.
4 *
5 * Every load, save, read, and write walks the face's chain through each schema's companion, and then
6 * the framework's own schema, when it keeps one. The walk is one helper, so no loop can leave the
7 * framework's schema out. It touches no SDK call, which is what lets the host specs walk it.
8 *
9 * @ingroup lib_settings
10 */
11 #pragma once
12 #include "system/settings/settings.h"
13
14 /**
15 * @addtogroup lib_settings
16 * @{
17 */
18
19 /**
20 * @brief Where the walk starts.
21 *
22 * @param head The face's first schema, or NULL for a face with no settings of its own.
23 * @param tail The framework's schema, or NULL when it keeps none.
24 * @return The first schema, or NULL when there is nothing to walk.
25 */
26 6 static inline const SettingsSchema *settings_chain_first(const SettingsSchema *head, const SettingsSchema *tail)
27 {
28
2/2
✓ Branch 2 → 3 taken 5 times.
✓ Branch 2 → 4 taken 1 time.
6 return head ? head : tail;
29 }
30
31 /**
32 * @brief The schema after this one in the walk.
33 *
34 * That is the face's own companion. After the face's last schema it is the framework's, and the walk
35 * ends there.
36 *
37 * @param schema The schema the walk is on.
38 * @param tail The framework's schema, or NULL when it keeps none.
39 * @return The next schema, or NULL at the end.
40 */
41 15 static inline const SettingsSchema *settings_chain_next(const SettingsSchema *schema, const SettingsSchema *tail)
42 {
43
2/2
✓ Branch 2 → 3 taken 5 times.
✓ Branch 2 → 4 taken 10 times.
15 if (schema == tail)
44 {
45 5 return NULL;
46 }
47
48
2/2
✓ Branch 4 → 5 taken 5 times.
✓ Branch 4 → 6 taken 5 times.
10 return schema->companion ? schema->companion : tail;
49 }
50
51 /**
52 * @brief Walks the face's schemas and then the framework's, for a `for` loop's header.
53 *
54 * @param schema The name the loop's schema goes by.
55 * @param head The face's first schema, or NULL for a face with no settings of its own.
56 * @param tail The framework's schema, or NULL when it keeps none.
57 */
58 #define SETTINGS_CHAIN_EACH(schema, head, tail) \
59 for (const SettingsSchema *schema = settings_chain_first((head), (tail)); schema; \
60 schema = settings_chain_next(schema, (tail)))
61
62 /**
63 * @brief Whether a schema in the face's own chain has a field on a message key.
64 *
65 * Only the face's chain is walked, not the framework's schema.
66 *
67 * @param head The face's first schema, or NULL.
68 * @param message_key The `MESSAGE_KEY_*` to look for, by address.
69 * @return True when a face field rides on it.
70 */
71 2 static inline bool settings_chain_has_field(const SettingsSchema *head, const uint32_t *message_key)
72 {
73
2/2
✓ Branch 9 → 3 taken 4 times.
✓ Branch 9 → 10 taken 1 time.
5 for (const SettingsSchema *schema = head; schema; schema = schema->companion)
74 {
75
2/2
✓ Branch 7 → 4 taken 4 times.
✓ Branch 7 → 8 taken 3 times.
7 for (uint8_t i = 0; i < schema->field_count; i++)
76 {
77
2/2
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 6 taken 3 times.
4 if (schema->fields[i].message_key == message_key)
78 {
79 1 return true;
80 }
81 }
82 }
83
84 1 return false;
85 }
86
87 /**
88 * @brief Whether a schema in the face's own chain is saved under a persist key.
89 *
90 * Only the face's chain is walked, not the framework's schema.
91 *
92 * @param head The face's first schema, or NULL.
93 * @param key The persist key to look for.
94 * @return True when a face schema uses it.
95 */
96 2 static inline bool settings_chain_has_key(const SettingsSchema *head, uint32_t key)
97 {
98
2/2
✓ Branch 6 → 3 taken 2 times.
✓ Branch 6 → 7 taken 1 time.
3 for (const SettingsSchema *schema = head; schema; schema = schema->companion)
99 {
100
2/2
✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 5 taken 1 time.
2 if (schema->key == key)
101 {
102 1 return true;
103 }
104 }
105
106 1 return false;
107 }
108
109 /** @} */
110