blob: a03ef3bd8783819802b2296ba60500cba0bbb6a1 [file] [log] [blame]
Nan Zhou042b5ba2021-06-18 09:32:45 -07001// 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#include "service.hpp"
12
13#include <sys/un.h>
14
15/**
16 * @class BufferService
17 * @brief Buffer based log service: watches for events and handles them.
18 */
19class BufferService : public Service
20{
21 public:
22 /**
23 * @brief Constructor for buffer-only mode or buffer + stream mode. All
24 * arguments should outlive this class.
25 *
26 * @param config service configuration.
27 * @param dbusLoop the DbusLoop instance.
28 * @param hostConsole the HostConsole instance.
29 * @param logBuffer the logBuffer instance.
30 * @param fileStorage the fileStorage instance.
31 *
32 * @throw std::exception in case of errors
33 */
34 BufferService(const Config& config, DbusLoop& dbusLoop,
35 HostConsole& hostConsole, LogBuffer& logBuffer,
36 FileStorage& fileStorage);
37
38 ~BufferService() override = default;
39
40 /**
41 * @brief Run the service.
42 *
43 * @throw std::exception in case of errors
44 */
45 void run() override;
46
47 protected:
48 /**
49 * @brief Flush log buffer to a file.
50 */
51 virtual void flush();
52
53 /**
54 * @brief Read data from host console and perform actions according to
55 * modes.
56 */
57 virtual void readConsole();
58
59 private:
60 /** @brief Service configuration. */
61 const Config& config;
62 /** @brief D-Bus event loop. */
63 DbusLoop* dbusLoop;
64 /** @brief Host console connection. */
65 HostConsole* hostConsole;
66 /** @brief Intermediate storage: container for parsed log messages. */
67 LogBuffer* logBuffer;
68 /** @brief Persistent storage. */
69 FileStorage* fileStorage;
70};