@@ -77,6 +77,74 @@ struct log_storage_info {
77
77
};
78
78
#endif
79
79
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
+
80
148
typedef int (* log_walk_func_t )(struct log * log , struct log_offset * log_offset ,
81
149
const void * dptr , uint16_t len );
82
150
@@ -137,8 +205,8 @@ struct log_handler {
137
205
#define LOG_IMG_HASHLEN 4
138
206
139
207
/* 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)
142
210
143
211
#if MYNEWT_VAL (LOG_VERSION ) == 3
144
212
struct log_entry_hdr {
@@ -232,6 +300,15 @@ STATS_SECT_END
232
300
#define LOG_STATS_INCN (log , name , cnt )
233
301
#endif
234
302
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
+
235
312
struct log {
236
313
const char * l_name ;
237
314
const struct log_handler * l_log ;
@@ -244,14 +321,13 @@ struct log {
244
321
#if !MYNEWT_VAL (LOG_GLOBAL_IDX )
245
322
uint32_t l_idx ;
246
323
#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 ;
253
324
#if MYNEWT_VAL (LOG_STATS )
254
325
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 ;
255
331
#endif
256
332
};
257
333
@@ -858,15 +934,15 @@ int log_read_last_hdr_trailer(struct log *log, struct log_entry_hdr *out_hdr,
858
934
* @param lptc Pointer to the log process trailer callback
859
935
*/
860
936
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 )
865
941
{
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 ;
870
946
}
871
947
872
948
/**
@@ -877,9 +953,9 @@ log_register_trailer_cbs(struct log *log, log_trailer_append_cb *ltac,
877
953
*/
878
954
static inline void
879
955
log_register_mbuf_trailer_cbs (struct log * log ,
880
- log_trailer_mbuf_append_cb * ltmac )
956
+ log_trailer_mbuf_append_func_t * ltmac )
881
957
{
882
- log -> l_trailer_mbuf_append_cb = ltmac ;
958
+ log -> l_th -> log_trailer_mbuf_append = ltmac ;
883
959
}
884
960
#endif
885
961
0 commit comments