Add multi-host support
This refactoring includes:
- added multi-host mode support;
- added support for graceful shutdown of the service;
- added support to flush the log buffer as it fills;
- D-Bus service xyz.openbmc_project.HostLogger replaced with SIGUSR1
signal handler;
- self diagnostic messages now registered via phosphor-logging;
- added unit tests;
- build system migrated from autotools to meson;
- source code aligned with OpenBMC conventions.
Change-Id: If6c1dfde278af685d8563450543a6587a282c7e4
Signed-off-by: Artem Senichev <a.senichev@yadro.com>
diff --git a/src/zlib_file.cpp b/src/zlib_file.cpp
new file mode 100644
index 0000000..042dafb
--- /dev/null
+++ b/src/zlib_file.cpp
@@ -0,0 +1,69 @@
+// SPDX-License-Identifier: Apache-2.0
+// Copyright (C) 2020 YADRO
+
+#include "zlib_file.hpp"
+
+#include "zlib_exception.hpp"
+
+ZlibFile::ZlibFile(const std::string& fileName)
+{
+ fd = gzopen(fileName.c_str(), "w");
+ if (fd == Z_NULL)
+ {
+ throw ZlibException(ZlibException::create, Z_ERRNO, fd, fileName);
+ }
+ this->fileName = fileName;
+}
+
+ZlibFile::~ZlibFile()
+{
+ if (fd != Z_NULL)
+ {
+ gzclose_w(fd);
+ }
+}
+
+void ZlibFile::close()
+{
+ if (fd != Z_NULL)
+ {
+ const int rc = gzclose_w(fd);
+ if (rc != Z_OK)
+ {
+ throw ZlibException(ZlibException::close, rc, fd, fileName);
+ }
+ fd = Z_NULL;
+ fileName.clear();
+ }
+}
+
+void ZlibFile::write(const tm& timeStamp, const std::string& message) const
+{
+ int rc;
+
+ // Write time stamp
+ rc = gzprintf(fd, "[ %02i:%02i:%02i ] ", timeStamp.tm_hour,
+ timeStamp.tm_min, timeStamp.tm_sec);
+ if (rc <= 0)
+ {
+ throw ZlibException(ZlibException::write, rc, fd, fileName);
+ }
+
+ // Write message
+ const size_t len = message.length();
+ if (len)
+ {
+ rc = gzwrite(fd, message.data(), static_cast<unsigned int>(len));
+ if (rc <= 0)
+ {
+ throw ZlibException(ZlibException::write, rc, fd, fileName);
+ }
+ }
+
+ // Write EOL
+ rc = gzputc(fd, '\n');
+ if (rc <= 0)
+ {
+ throw ZlibException(ZlibException::write, rc, fd, fileName);
+ }
+}