Skip to content

Commit

Permalink
sys/log: Add API to get log entry count
Browse files Browse the repository at this point in the history
This adds log_entry_count() function that can be used to
retrieve number of entries in log.

Signed-off-by: Jerzy Kasenberg <[email protected]>
  • Loading branch information
kasjer committed Jul 31, 2024
1 parent 1cf9b42 commit a4ce0da
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 12 deletions.
12 changes: 12 additions & 0 deletions sys/log/full/include/log/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ typedef int (*lh_append_mbuf_body_func_t)(struct log *log,
struct os_mbuf *om);
typedef int (*lh_walk_func_t)(struct log *,
log_walk_func_t walk_func, struct log_offset *log_offset);
typedef int (*lh_get_entry_count_func_t)(struct log *log, uint32_t *entry_count);
typedef int (*lh_flush_func_t)(struct log *);
#if MYNEWT_VAL(LOG_STORAGE_INFO)
typedef int (*lh_storage_info_func_t)(struct log *, struct log_storage_info *);
Expand All @@ -116,6 +117,7 @@ struct log_handler {
lh_walk_func_t log_walk;
lh_walk_func_t log_walk_sector;
lh_flush_func_t log_flush;
lh_get_entry_count_func_t log_get_entry_count;
#if MYNEWT_VAL(LOG_STORAGE_INFO)
lh_storage_info_func_t log_storage_info;
#endif
Expand Down Expand Up @@ -592,6 +594,16 @@ int log_walk_body(struct log *log, log_walk_body_func_t walk_body_func,
struct log_offset *log_offset);
int log_flush(struct log *log);

/**
* Returns number of entries in log.
*
* @param log - The log to return number of entries from
* @param entry_count - The pointer to variable to store number of entries.
*
* @return 0 on success, error code otherwise
*/
int log_get_entry_count(struct log *log, uint32_t *entry_count);

/**
* @brief Walking a section of FCB.
*
Expand Down
16 changes: 16 additions & 0 deletions sys/log/full/src/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,22 @@ log_flush(struct log *log)
return (rc);
}

int
log_get_entry_count(struct log *log, uint32_t *entry_count)
{
int rc;

if (entry_count == NULL) {
rc = SYS_EINVAL;
} else if (log->l_log->log_get_entry_count == NULL) {
rc = SYS_ENOTSUP;
} else {
rc = log->l_log->log_get_entry_count(log, entry_count);
}

return rc;
}

#if MYNEWT_VAL(LOG_STORAGE_INFO)
int
log_storage_info(struct log *log, struct log_storage_info *info)
Expand Down
39 changes: 27 additions & 12 deletions sys/log/full/src/log_fcb.c
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,20 @@ log_fcb_flush(struct log *log)
return fcb_clear(fcb);
}

static int
log_fcb_get_entry_count(struct log *log, uint32_t *entry_count)
{
struct fcb_log *fcb_log;
struct fcb *fcb;

fcb_log = (struct fcb_log *)log->l_arg;
fcb = &fcb_log->fl_fcb;

*entry_count = fcb_get_entry_count(fcb, NULL);

return 0;
}

static int
log_fcb_registered(struct log *log)
{
Expand Down Expand Up @@ -972,23 +986,24 @@ log_fcb_rtr_erase(struct log *log)
}

const struct log_handler log_fcb_handler = {
.log_type = LOG_TYPE_STORAGE,
.log_read = log_fcb_read,
.log_read_mbuf = log_fcb_read_mbuf,
.log_append = log_fcb_append,
.log_append_body = log_fcb_append_body,
.log_append_mbuf = log_fcb_append_mbuf,
.log_type = LOG_TYPE_STORAGE,
.log_read = log_fcb_read,
.log_read_mbuf = log_fcb_read_mbuf,
.log_append = log_fcb_append,
.log_append_body = log_fcb_append_body,
.log_append_mbuf = log_fcb_append_mbuf,
.log_append_mbuf_body = log_fcb_append_mbuf_body,
.log_walk = log_fcb_walk,
.log_walk_sector = log_fcb_walk_area,
.log_flush = log_fcb_flush,
.log_walk = log_fcb_walk,
.log_walk_sector = log_fcb_walk_area,
.log_flush = log_fcb_flush,
.log_get_entry_count = log_fcb_get_entry_count,
#if MYNEWT_VAL(LOG_STORAGE_INFO)
.log_storage_info = log_fcb_storage_info,
.log_storage_info = log_fcb_storage_info,
#endif
#if MYNEWT_VAL(LOG_STORAGE_WATERMARK)
.log_set_watermark = log_fcb_set_watermark,
.log_set_watermark = log_fcb_set_watermark,
#endif
.log_registered = log_fcb_registered,
.log_registered = log_fcb_registered,
};

#endif

0 comments on commit a4ce0da

Please sign in to comment.