xref: /openbmc/bmcweb/redfish-core/include/filesystem_log_watcher.hpp (revision fda37f9b6d12ff0852cba4dcdecfd633436e6152)
12185ddeaSEd Tanous #pragma once
22185ddeaSEd Tanous 
37b669723SEd Tanous #include <boost/asio/posix/stream_descriptor.hpp>
47b669723SEd Tanous 
57b669723SEd Tanous #include <optional>
67b669723SEd Tanous #include <string_view>
72185ddeaSEd Tanous namespace redfish
82185ddeaSEd Tanous {
97b669723SEd Tanous 
107b669723SEd Tanous constexpr const char* redfishEventLogFile = "/var/log/redfish";
117b669723SEd Tanous 
127b669723SEd Tanous class FilesystemLogWatcher
137b669723SEd Tanous {
147b669723SEd Tanous   private:
157b669723SEd Tanous     std::streampos redfishLogFilePosition{0};
167b669723SEd Tanous 
177b669723SEd Tanous     int dirWatchDesc = -1;
187b669723SEd Tanous     int fileWatchDesc = -1;
197b669723SEd Tanous     void onINotify(const boost::system::error_code& ec,
207b669723SEd Tanous                    std::size_t bytesTransferred);
217b669723SEd Tanous 
227b669723SEd Tanous     void resetRedfishFilePosition();
237b669723SEd Tanous 
247b669723SEd Tanous     void watchRedfishEventLogFile();
257b669723SEd Tanous 
267b669723SEd Tanous     void readEventLogsFromFile();
277b669723SEd Tanous 
287b669723SEd Tanous     void cacheRedfishLogFile();
297b669723SEd Tanous 
307b669723SEd Tanous     std::array<char, 1024> readBuffer{};
31*fda37f9bSEd Tanous     // Explicit make the last item so it is canceled before the buffer goes out
32*fda37f9bSEd Tanous     // of scope.
33*fda37f9bSEd Tanous     boost::asio::posix::stream_descriptor inotifyConn;
347b669723SEd Tanous 
357b669723SEd Tanous   public:
367b669723SEd Tanous     explicit FilesystemLogWatcher(boost::asio::io_context& iocIn);
377b669723SEd Tanous };
382185ddeaSEd Tanous } // namespace redfish
39