Add the stream mode

The stream mode behaves differently in versus the existing buffer mode.

1. It leverages rsyslog to persist logs;
2. It leverages logrotate to rotate and compress logs;
3. It persists logs as soon as they are collected.

Add configuration options to choose modes at start up time. When stream
mode is disabled, no difference compared to the existing service.

See README.md for details.

This change also adds mock classes for unit test purpose.

Change-Id: Ic7d02e826c7d9372621c096c6e768e6216974150
Signed-off-by: Nan Zhou <nanzhoumails@gmail.com>
diff --git a/src/buffer_service.hpp b/src/buffer_service.hpp
new file mode 100644
index 0000000..a03ef3b
--- /dev/null
+++ b/src/buffer_service.hpp
@@ -0,0 +1,70 @@
+// SPDX-License-Identifier: Apache-2.0
+// Copyright (C) 2020 YADRO
+
+#pragma once
+
+#include "config.hpp"
+#include "dbus_loop.hpp"
+#include "file_storage.hpp"
+#include "host_console.hpp"
+#include "log_buffer.hpp"
+#include "service.hpp"
+
+#include <sys/un.h>
+
+/**
+ * @class BufferService
+ * @brief Buffer based log service: watches for events and handles them.
+ */
+class BufferService : public Service
+{
+  public:
+    /**
+     * @brief Constructor for buffer-only mode or buffer + stream mode.  All
+     * arguments should outlive this class.
+     *
+     * @param config service configuration.
+     * @param dbusLoop the DbusLoop instance.
+     * @param hostConsole the HostConsole instance.
+     * @param logBuffer the logBuffer instance.
+     * @param fileStorage the fileStorage instance.
+     *
+     * @throw std::exception in case of errors
+     */
+    BufferService(const Config& config, DbusLoop& dbusLoop,
+                  HostConsole& hostConsole, LogBuffer& logBuffer,
+                  FileStorage& fileStorage);
+
+    ~BufferService() override = default;
+
+    /**
+     * @brief Run the service.
+     *
+     * @throw std::exception in case of errors
+     */
+    void run() override;
+
+  protected:
+    /**
+     * @brief Flush log buffer to a file.
+     */
+    virtual void flush();
+
+    /**
+     * @brief Read data from host console and perform actions according to
+     * modes.
+     */
+    virtual void readConsole();
+
+  private:
+    /** @brief Service configuration. */
+    const Config& config;
+    /** @brief D-Bus event loop. */
+    DbusLoop* dbusLoop;
+    /** @brief Host console connection. */
+    HostConsole* hostConsole;
+    /** @brief Intermediate storage: container for parsed log messages. */
+    LogBuffer* logBuffer;
+    /** @brief Persistent storage. */
+    FileStorage* fileStorage;
+};