1 #pragma once
2 
3 #include <sys/inotify.h>
4 
5 #include <boost/asio/posix/stream_descriptor.hpp>
6 
7 #include <optional>
8 #include <string_view>
9 namespace redfish
10 {
11 
12 constexpr const char* redfishEventLogFile = "/var/log/redfish";
13 
14 class FilesystemLogWatcher
15 {
16   private:
17     std::streampos redfishLogFilePosition{0};
18 
19     int inotifyFd = -1;
20     int dirWatchDesc = -1;
21     int fileWatchDesc = -1;
22     boost::asio::posix::stream_descriptor inotifyConn;
23     void onINotify(const boost::system::error_code& ec,
24                    std::size_t bytesTransferred);
25 
26     void resetRedfishFilePosition();
27 
28     void watchRedfishEventLogFile();
29 
30     void readEventLogsFromFile();
31 
32     void cacheRedfishLogFile();
33 
34     std::array<char, 1024> readBuffer{};
35 
36   public:
37     explicit FilesystemLogWatcher(boost::asio::io_context& iocIn);
38 };
39 } // namespace redfish
40