1 2 #include <dirent.h> 3 #include <time.h> 4 5 #ifdef __cplusplus 6 #include <cstdint> 7 #include <string> 8 9 using namespace std; 10 #else 11 #include <stdint.h> 12 #endif 13 14 #ifdef __cplusplus 15 struct event_record_t { 16 #else 17 typedef struct _event_record_t { 18 #endif 19 char *message; 20 char *severity; 21 char *association; 22 char *reportedby; 23 uint8_t *p; 24 size_t n; 25 26 // These get filled in for you 27 time_t timestamp; 28 int16_t logid; 29 #ifdef __cplusplus 30 }; 31 32 #else 33 } event_record_t; 34 #endif 35 36 37 #ifdef __cplusplus 38 39 class event_manager { 40 uint16_t latestid; 41 string eventpath; 42 DIR *dirp; 43 uint16_t logcount; 44 uint16_t maxlogs; 45 size_t maxsize; 46 size_t currentsize; 47 48 public: 49 event_manager(string path, size_t reqmaxsize, uint16_t reqmaxlogs); 50 ~event_manager(); 51 52 uint16_t next_log(void); 53 void next_log_refresh(void); 54 55 uint16_t latest_log_id(void); 56 uint16_t log_count(void); 57 size_t get_managed_size(void); 58 59 int open(uint16_t logid, event_record_t **rec); // must call close 60 void close(event_record_t *rec); 61 62 uint16_t create(event_record_t *rec); 63 int remove(uint16_t logid); 64 65 private: 66 bool is_file_a_log(string str); 67 uint16_t create_log_event(event_record_t *rec); 68 uint16_t new_log_id(void); 69 bool is_logid_a_log(uint16_t logid); 70 }; 71 #else 72 typedef struct event_manager event_manager; 73 #endif 74 75 #ifdef __cplusplus 76 extern "C" { 77 #endif 78 uint16_t message_create_new_log_event(event_manager *em, event_record_t *rec); 79 int message_load_log(event_manager *em, uint16_t logid, event_record_t **rec); 80 void message_free_log(event_manager *em, event_record_t *rec); 81 int message_delete_log(event_manager *em, uint16_t logid); 82 void message_refresh_events(event_manager *em); 83 uint16_t message_next_event(event_manager *em); 84 #ifdef __cplusplus 85 } 86 #endif 87 88 89