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