libsf3
Loading...
Searching...
No Matches
sf3_log.h
Go to the documentation of this file.
1#ifndef __SF3_LOG__
2#define __SF3_LOG__
3#include "sf3_core.h"
4
6#define SF3_FORMAT_ID_LOG 0x04
7
14 uint32_t size;
17 uint64_t time;
20 uint8_t severity;
22};
23
27 uint64_t size;
29 uint32_t entry_count;
31 uint64_t entry_offset[];
32};
33
38 struct sf3_identifier identifier;
39 int64_t start;
40 int64_t end;
41 uint16_t chunk_count;
42 struct sf3_log_chunk chunks[];
43};
44
46SF3_INLINE const char *sf3_log_entry_source(const struct sf3_log_entry *entry){
47 return entry->source.str;
48}
49
51SF3_INLINE const char *sf3_log_entry_category(const struct sf3_log_entry *entry){
52 return ((sf3_str8 *)SF3_SKIP_STR(entry->source))->str;
53}
54
56SF3_INLINE const char *sf3_log_entry_message(const struct sf3_log_entry *entry){
57 return ((sf3_str16 *)SF3_SKIP_STRP((sf3_str8 *)SF3_SKIP_STR(entry->source)))->str;
58}
59
64SF3_INLINE const struct sf3_log_entry *sf3_log_next_entry(const struct sf3_log_entry *entry){
65 return (const struct sf3_log_entry*)(((char*)entry)+entry->size);
66}
67
69SF3_INLINE const struct sf3_log_entry *sf3_log_first_entry(const struct sf3_log_chunk *chunk){
70 return (const struct sf3_log_entry*)chunk->entry_offset+chunk->entry_count;
71}
72
76SF3_INLINE const struct sf3_log_entry *sf3_log_entry(const struct sf3_log_chunk *chunk, uint32_t entry){
77 if(chunk->entry_count <= entry) return 0;
78 return (const struct sf3_log_entry *)(((char*)chunk)+chunk->entry_offset[entry]);
79}
80
85SF3_INLINE const struct sf3_log_chunk *sf3_log_next_chunk(const struct sf3_log_chunk *chunk){
86 return (const struct sf3_log_chunk *)(((char*)chunk)+chunk->size);
87}
88
90SF3_INLINE uint32_t sf3_log_chunk_capacity(const struct sf3_log_chunk *chunk){
91 uint64_t end_of_offsets = chunk->entry_offset[0];
92 uint64_t offsets_size = (end_of_offsets - 4 - 8);
93 return offsets_size / sizeof(uint64_t);
94}
95
98SF3_INLINE uint32_t sf3_log_chunk_remaining(const struct sf3_log_chunk *chunk){
99 return sf3_log_chunk_capacity(chunk) - chunk->entry_count;
100}
101
103SF3_EXPORT size_t sf3_log_size(const struct sf3_log *log){
104 if(log->chunk_count == 0) return sizeof(struct sf3_log);
105 const struct sf3_log_chunk *last = &log->chunks[0];
106 for(uint16_t i=0; i<=log->chunk_count; ++i){
107 last = sf3_log_next_chunk(last);
108 }
109 const void *start = (const void *)log;
110 const void *end = (const void *)last;
111 return (end-start);
112}
113#endif
#define SF3_INLINE
Definition sf3_core.h:16
#define SF3_EXPORT
Definition sf3_core.h:13
#define SF3_PACK
Definition sf3_core.h:9
#define SF3_SKIP_STR(STR)
Macro to retrieve a pointer past the variable size of an SF3 string.
Definition sf3_core.h:59
#define SF3_SKIP_STRP(STR)
Definition sf3_core.h:64
SF3_INLINE const struct sf3_log_chunk * sf3_log_next_chunk(const struct sf3_log_chunk *chunk)
Definition sf3_log.h:85
SF3_INLINE const char * sf3_log_entry_source(const struct sf3_log_entry *entry)
Returns the string of the "source" for the entry.
Definition sf3_log.h:46
SF3_INLINE const char * sf3_log_entry_category(const struct sf3_log_entry *entry)
Returns the string of the "category" for the entry.
Definition sf3_log.h:51
SF3_INLINE const struct sf3_log_entry * sf3_log_first_entry(const struct sf3_log_chunk *chunk)
Returns the first entry of the chunk.
Definition sf3_log.h:69
SF3_INLINE uint32_t sf3_log_chunk_remaining(const struct sf3_log_chunk *chunk)
Definition sf3_log.h:98
SF3_INLINE const char * sf3_log_entry_message(const struct sf3_log_entry *entry)
Returns the string of the message for the entry.
Definition sf3_log.h:56
SF3_INLINE const struct sf3_log_entry * sf3_log_next_entry(const struct sf3_log_entry *entry)
Definition sf3_log.h:64
SF3_EXPORT size_t sf3_log_size(const struct sf3_log *log)
Computes the size of the log file in bytes.
Definition sf3_log.h:103
SF3_INLINE uint32_t sf3_log_chunk_capacity(const struct sf3_log_chunk *chunk)
Returns the number of log entries that can be stored in the chunk.
Definition sf3_log.h:90
The basic header structure of every SF3 file.
Definition sf3_core.h:70
A chunk of log entries in a log file.
Definition sf3_log.h:25
uint64_t entry_offset[]
The offsets to the log entries.
Definition sf3_log.h:31
uint32_t entry_count
The number of registered log entries.
Definition sf3_log.h:29
uint64_t size
The size of the chunk structure in bytes.
Definition sf3_log.h:27
Definition sf3_log.h:12
uint32_t size
The size of the log entry structure in bytes.
Definition sf3_log.h:14
uint8_t severity
Definition sf3_log.h:20
uint64_t time
Definition sf3_log.h:17
sf3_str8 source
Definition sf3_log.h:21
uint16_t chunk_count
Definition sf3_log.h:41
struct sf3_log_chunk chunks[]
Definition sf3_log.h:42
int64_t start
Definition sf3_log.h:39
int64_t end
Definition sf3_log.h:40
char str[]
Definition sf3_core.h:31