diff options
-rw-r--r-- | src/Makefile.am | 4 | ||||
-rw-r--r-- | src/elog.cpp | 33 | ||||
-rw-r--r-- | src/elog.hpp | 69 | ||||
-rw-r--r-- | src/templates/elog.mako.cpp | 0 |
4 files changed, 106 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index d530b46..211cb9f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -7,13 +7,16 @@ sbin_PROGRAMS = phosphor-dbus-monitor phosphor_dbus_monitor_SOURCES = \ journal.cpp \ + elog.cpp \ main.cpp \ propertywatch.cpp phosphor_dbus_monitor_LDADD = \ $(SDBUSPLUS_LIBS) \ + $(PHOSPHOR_DBUS_INTERFACES_LIBS) \ $(PHOSPHOR_LOGGING_LIBS) phosphor_dbus_monitor_CXXFLAGS = \ $(SDBUSPLUS_CFLAGS) \ + $(PHOSPHOR_DBUS_INTERFACES_CFLAGS) \ $(PHOSPHOR_LOGGING_CFLAGS) BUILT_SOURCES = generated.hpp @@ -25,6 +28,7 @@ TEMPLATES = \ templates/count.mako.cpp \ templates/generated.mako.hpp \ templates/journal.mako.cpp \ + templates/elog.mako.cpp \ templates/method.mako.cpp generated.hpp: $(PDMGEN) $(YAML_PATH) $(TEMPLATES) diff --git a/src/elog.cpp b/src/elog.cpp new file mode 100644 index 0000000..9f937c3 --- /dev/null +++ b/src/elog.cpp @@ -0,0 +1,33 @@ +/** + * Copyright © 2017 IBM Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "elog.hpp" + +namespace phosphor +{ +namespace dbus +{ +namespace monitoring +{ + +void ElogBase::operator()() +{ + log(); +} + + +} // namespace monitoring +} // namespace dbus +} // namespace phosphor diff --git a/src/elog.hpp b/src/elog.hpp new file mode 100644 index 0000000..f138b0b --- /dev/null +++ b/src/elog.hpp @@ -0,0 +1,69 @@ +#pragma once +#include <phosphor-logging/elog-errors.hpp> +#include <phosphor-logging/elog.hpp> +#include "callback.hpp" +#include <sdbusplus/exception.hpp> + +namespace phosphor +{ +namespace dbus +{ +namespace monitoring +{ + +/** @class ElogBase + * @brief Elog callback implementation. + * + * The elog callback logs the elog and + * elog metadata. + */ +class ElogBase : public Callback +{ + public: + ElogBase(const ElogBase&) = delete; + ElogBase(ElogBase&&) = default; + ElogBase& operator=(const ElogBase&) = delete; + ElogBase& operator=(ElogBase&&) = default; + virtual ~ElogBase() = default; + ElogBase() : + Callback(){} + + /** @brief Callback interface implementation. */ + void operator()() override; + + private: + /** @brief Delegate type specific calls to subclasses. */ + virtual void log() const = 0; +}; + + +/** @class Elog + * @brief C++ type specific logic for the elog callback. + * + * @tparam T - Error log type + */ +template <typename T> +class Elog : public ElogBase +{ + public: + Elog(const Elog&) = delete; + Elog(Elog&&) = default; + Elog& operator=(const Elog&) = delete; + Elog& operator=(Elog&&) = default; + ~Elog() = default; + Elog() : + ElogBase() {} + + private: + /** @brief elog interface implementation. */ + void log() const override + { + + using namespace phosphor::logging; + report<T>(); + } +}; + +} // namespace monitoring +} // namespace dbus +} // namespace phosphor diff --git a/src/templates/elog.mako.cpp b/src/templates/elog.mako.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/templates/elog.mako.cpp |