Artem Senichev | e8837d5 | 2020-06-07 11:59:04 +0300 | [diff] [blame^] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright (C) 2020 YADRO |
| 3 | |
| 4 | #pragma once |
| 5 | |
| 6 | #include "config.hpp" |
| 7 | #include "dbus_loop.hpp" |
| 8 | #include "file_storage.hpp" |
| 9 | #include "host_console.hpp" |
| 10 | #include "log_buffer.hpp" |
| 11 | |
| 12 | /** |
| 13 | * @class Service |
| 14 | * @brief Log service: watches for events and handles them. |
| 15 | */ |
| 16 | class Service |
| 17 | { |
| 18 | public: |
| 19 | /** |
| 20 | * @brief Constructor. |
| 21 | * |
| 22 | * @param[in] config service configuration |
| 23 | * |
| 24 | * @throw std::exception in case of errors |
| 25 | */ |
| 26 | Service(const Config& config); |
| 27 | |
| 28 | /** |
| 29 | * @brief Run the service. |
| 30 | * |
| 31 | * @throw std::exception in case of errors |
| 32 | */ |
| 33 | void run(); |
| 34 | |
| 35 | private: |
| 36 | /** |
| 37 | * @brief Flush log buffer to a file. |
| 38 | */ |
| 39 | void flush(); |
| 40 | |
| 41 | /** |
| 42 | * @brief Read data from host console and put it into the log buffer. |
| 43 | */ |
| 44 | void readConsole(); |
| 45 | |
| 46 | private: |
| 47 | /** @brief Service configuration. */ |
| 48 | const Config& config; |
| 49 | /** @brief D-Bus event loop. */ |
| 50 | DbusLoop dbusLoop; |
| 51 | /** @brief Host console connection. */ |
| 52 | HostConsole hostConsole; |
| 53 | /** @brief Intermediate storage: container for parsed log messages. */ |
| 54 | LogBuffer logBuffer; |
| 55 | /** @brief Persistent storage. */ |
| 56 | FileStorage fileStorage; |
| 57 | }; |