Skip to content

Commit aa363f2

Browse files
committed
sys/log: Fix FCB log and unittests
1 parent 64aa51e commit aa363f2

File tree

6 files changed

+221
-139
lines changed

6 files changed

+221
-139
lines changed

sys/log/common/include/log_common/log_common.h

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -138,74 +138,6 @@ typedef void log_append_cb(struct log *log, uint32_t idx);
138138
*/
139139
typedef void log_notify_rotate_cb(const struct log *log);
140140

141-
/** @typedef log_trailer_append_cb
142-
* @brief Callback that is executed each time the corresponding log entry is
143-
* appended to
144-
*
145-
* @param log The log that was just appended to
146-
* @param buf Buffer to append trailer to
147-
* @param buflen Pointer to the length of the trailer to be filled up
148-
* optionally
149-
* @param loc Argument pointing to the location of
150-
* the entry
151-
* @param f_offset Pointer to the offset(optional) at which append should
152-
* happen
153-
*
154-
* @return 0 on success, non-zero on failure
155-
*/
156-
typedef int log_trailer_append_cb(struct log *log, uint8_t *buf,
157-
uint16_t *buflen, void *loc,
158-
uint16_t *f_offset);
159-
160-
/** @typedef log_mbuf_trailer_append_cb
161-
* @brief Callback that is executed each time the corresponding log entry is
162-
* appended to
163-
*
164-
* @param log The log that was just appended to
165-
* @param om Pointer to the mbuf that contains the log entry
166-
* @param loc Argument pointing to the location of
167-
* the entry
168-
* @param f_offset The offset(optional) at which append should
169-
* happen
170-
*
171-
* @return 0 on success, non-zero on failure
172-
*/
173-
typedef int log_trailer_mbuf_append_cb(struct log *log, struct os_mbuf *om,
174-
void *loc, uint16_t f_offset);
175-
176-
/** @typedef log_process_trailer_cb
177-
* @brief Callback that is executed each time a trailer is processed
178-
*
179-
* @param log The log that was just appended to
180-
* @param arg Void pointer for a custom arg
181-
* @param dptr Pointer to the data buffer
182-
* @param len Length of the trailer
183-
*
184-
* @return 0 on success, non-zero on failure
185-
*/
186-
typedef int log_process_trailer_cb(struct log *log, void *arg, const void *dptr,
187-
uint16_t len);
188-
189-
/** @typedef log_trailer_len_cb
190-
* @brief Callback used to read length of trailer in a log entry
191-
*
192-
* @param log The log the trailer is to be read from
193-
* @param hdr Log entry header of the log entry the log is
194-
* read from
195-
* @return Length of the appended trailer
196-
*/
197-
typedef uint16_t log_trailer_len_cb(struct log *log, const struct log_entry_hdr *hdr);
198-
199-
/** @typedef log_trailer_data_len_cb
200-
* @brief Callback used to read length of trailer data in a log entry
201-
*
202-
* @param log The log the trailer is to be read from
203-
* @param hdr Log entry header of the log entry the log is
204-
* read from
205-
* @return Length of the appended trailer data
206-
*/
207-
typedef uint16_t log_trailer_data_len_cb(struct log *log, const struct log_entry_hdr *hdr);
208-
209141
#ifdef __cplusplus
210142
}
211143
#endif

sys/log/full/include/log/log.h

Lines changed: 94 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,74 @@ struct log_storage_info {
7777
};
7878
#endif
7979

80+
/** @typedef log_trailer_append_func_t
81+
* @brief Callback that is executed each time the corresponding log entry is
82+
* appended to
83+
*
84+
* @param log The log that was just appended to
85+
* @param buf Buffer to append trailer to
86+
* @param buflen Pointer to the length of the trailer to be filled up
87+
* optionally
88+
* @param loc Argument pointing to the location of
89+
* the entry
90+
* @param f_offset Pointer to the offset(optional) at which append should
91+
* happen
92+
*
93+
* @return 0 on success, non-zero on failure
94+
*/
95+
typedef int log_trailer_append_func_t(struct log *log, uint8_t *buf,
96+
uint16_t *buflen, void *loc,
97+
uint16_t *f_offset);
98+
99+
/** @typedef log_mbuf_trailer_append_func_t
100+
* @brief Callback that is executed each time the corresponding log entry is
101+
* appended to
102+
*
103+
* @param log The log that was just appended to
104+
* @param om Pointer to the mbuf that contains the log entry
105+
* @param loc Argument pointing to the location of
106+
* the entry
107+
* @param f_offset The offset(optional) at which append should
108+
* happen
109+
*
110+
* @return 0 on success, non-zero on failure
111+
*/
112+
typedef int log_trailer_mbuf_append_func_t(struct log *log, struct os_mbuf *om,
113+
void *loc, uint16_t f_offset);
114+
115+
/** @typedef log_process_trailer_func_t
116+
* @brief Callback that is executed each time a trailer is processed
117+
*
118+
* @param log The log that was just appended to
119+
* @param arg Void pointer for a custom arg
120+
* @param dptr Pointer to the data buffer
121+
* @param len Length of the trailer
122+
*
123+
* @return 0 on success, non-zero on failure
124+
*/
125+
typedef int log_process_trailer_func_t(struct log *log, void *arg, const void *dptr,
126+
uint16_t len);
127+
128+
/** @typedef log_trailer_len_func_t
129+
* @brief Callback used to read length of trailer in a log entry
130+
*
131+
* @param log The log the trailer is to be read from
132+
* @param hdr Log entry header of the log entry the log is
133+
* read from
134+
* @return Length of the appended trailer
135+
*/
136+
typedef uint16_t log_trailer_len_func_t(struct log *log, const struct log_entry_hdr *hdr);
137+
138+
/** @typedef log_trailer_data_len_func_t
139+
* @brief Callback used to read length of trailer data in a log entry
140+
*
141+
* @param log The log the trailer is to be read from
142+
* @param hdr Log entry header of the log entry the log is
143+
* read from
144+
* @return Length of the appended trailer data
145+
*/
146+
typedef uint16_t log_trailer_data_len_func_t(struct log *log, const struct log_entry_hdr *hdr);
147+
80148
typedef int (*log_walk_func_t)(struct log *log, struct log_offset *log_offset,
81149
const void *dptr, uint16_t len);
82150

@@ -137,8 +205,8 @@ struct log_handler {
137205
#define LOG_IMG_HASHLEN 4
138206

139207
/* Flags used to indicate type of data in reserved payload */
140-
#define LOG_FLAGS_IMG_HASH (1 << 0)
141-
#define LOG_FLAGS_TRAILER_SUPPORT (1 << 1)
208+
#define LOG_FLAGS_IMG_HASH (1 << 0)
209+
#define LOG_FLAGS_TRAILER_SUPPORT (1 << 1)
142210

143211
#if MYNEWT_VAL(LOG_VERSION) == 3
144212
struct log_entry_hdr {
@@ -232,6 +300,15 @@ STATS_SECT_END
232300
#define LOG_STATS_INCN(log, name, cnt)
233301
#endif
234302

303+
struct log_trailer_handler {
304+
/* Trailer support callbacks */
305+
log_trailer_len_func_t *log_trailer_len;
306+
log_trailer_data_len_func_t *log_trailer_data_len;
307+
log_trailer_append_func_t *log_trailer_append;
308+
log_process_trailer_func_t *log_process_trailer;
309+
log_trailer_mbuf_append_func_t *log_trailer_mbuf_append;
310+
};
311+
235312
struct log {
236313
const char *l_name;
237314
const struct log_handler *l_log;
@@ -244,14 +321,13 @@ struct log {
244321
#if !MYNEWT_VAL(LOG_GLOBAL_IDX)
245322
uint32_t l_idx;
246323
#endif
247-
log_trailer_len_cb *l_trailer_len_cb;
248-
log_trailer_data_len_cb *l_trailer_data_len_cb;
249-
log_trailer_append_cb *l_trailer_append_cb;
250-
log_process_trailer_cb *l_process_trailer_cb;
251-
log_trailer_mbuf_append_cb *l_trailer_mbuf_append_cb;
252-
void *l_trailer_arg;
253324
#if MYNEWT_VAL(LOG_STATS)
254325
STATS_SECT_DECL(logs) l_stats;
326+
#endif
327+
/* Gets set when trailer callbacks are registered */
328+
struct log_trailer_handler *l_th;
329+
#if MYNEWT_VAL(LOG_FLAGS_TRAILER_SUPPORT)
330+
void *l_trailer_arg;
255331
#endif
256332
};
257333

@@ -858,15 +934,15 @@ int log_read_last_hdr_trailer(struct log *log, struct log_entry_hdr *out_hdr,
858934
* @param lptc Pointer to the log process trailer callback
859935
*/
860936
static inline void
861-
log_register_trailer_cbs(struct log *log, log_trailer_append_cb *ltac,
862-
log_trailer_len_cb *ltlc,
863-
log_trailer_data_len_cb *ltdlc,
864-
log_process_trailer_cb *lptc)
937+
log_register_trailer_cbs(struct log *log, log_trailer_append_func_t *ltac,
938+
log_trailer_len_func_t *ltlc,
939+
log_trailer_data_len_func_t *ltdlc,
940+
log_process_trailer_func_t *lptc)
865941
{
866-
log->l_trailer_append_cb = ltac;
867-
log->l_trailer_len_cb = ltlc;
868-
log->l_trailer_data_len_cb = ltdlc;
869-
log->l_process_trailer_cb = lptc;
942+
log->l_th->log_trailer_append = ltac;
943+
log->l_th->log_trailer_len = ltlc;
944+
log->l_th->log_trailer_data_len = ltdlc;
945+
log->l_th->log_process_trailer = lptc;
870946
}
871947

872948
/**
@@ -877,9 +953,9 @@ log_register_trailer_cbs(struct log *log, log_trailer_append_cb *ltac,
877953
*/
878954
static inline void
879955
log_register_mbuf_trailer_cbs(struct log *log,
880-
log_trailer_mbuf_append_cb *ltmac)
956+
log_trailer_mbuf_append_func_t *ltmac)
881957
{
882-
log->l_trailer_mbuf_append_cb = ltmac;
958+
log->l_th->log_trailer_mbuf_append = ltmac;
883959
}
884960
#endif
885961

0 commit comments

Comments
 (0)