lg2: commit: add stubs to support new sdbusplus events
Create empty stubs for the commit functions from the new event
log design[1].
[1]: https://github.com/openbmc/docs/blob/master/designs/event-logging.md
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I8c0232858f41b875e78d5e41f17c065ca727429d
diff --git a/lib/include/phosphor-logging/commit.hpp b/lib/include/phosphor-logging/commit.hpp
new file mode 100644
index 0000000..aa34df3
--- /dev/null
+++ b/lib/include/phosphor-logging/commit.hpp
@@ -0,0 +1,38 @@
+#pragma once
+
+#include <phosphor-logging/lg2/commit.hpp>
+#include <sdbusplus/async.hpp>
+#include <sdbusplus/exception.hpp>
+
+namespace lg2
+{
+/** Commit a generated event/error.
+ *
+ * @param t - The event to commit.
+ * @return The object path of the resulting event.
+ *
+ * Note: Similar to elog(), this will use the default dbus connection to
+ * perform the operation.
+ */
+template <typename T>
+ requires std::is_base_of_v<sdbusplus::exception::generated_event_base, T>
+auto commit(T&& t) -> sdbusplus::message::object_path
+{
+ return details::commit(std::forward<T>(t));
+}
+
+/** Commit a generated event/error (using async context).
+ *
+ * @param ctx - The async context to use.
+ * @param t - The event to commit.
+ * @return The object path of the resulting event.
+ */
+template <typename T>
+ requires std::is_base_of_v<sdbusplus::exception::generated_event_base, T>
+auto commit(sdbusplus::async::context& ctx,
+ T&& t) -> sdbusplus::async::task<sdbusplus::message::object_path>
+{
+ return details::commit(ctx, std::forward<T>(t));
+}
+
+} // namespace lg2
diff --git a/lib/include/phosphor-logging/lg2/commit.hpp b/lib/include/phosphor-logging/lg2/commit.hpp
new file mode 100644
index 0000000..47c5be1
--- /dev/null
+++ b/lib/include/phosphor-logging/lg2/commit.hpp
@@ -0,0 +1,18 @@
+#pragma once
+
+#include <sdbusplus/async.hpp>
+#include <sdbusplus/exception.hpp>
+
+namespace lg2::details
+{
+
+/* Non-template versions of the commit functions */
+
+auto commit(sdbusplus::exception::generated_event_base&& t)
+ -> sdbusplus::message::object_path;
+
+auto commit(sdbusplus::async::context& ctx,
+ sdbusplus::exception::generated_event_base&& t)
+ -> sdbusplus::async::task<sdbusplus::message::object_path>;
+
+} // namespace lg2::details
diff --git a/lib/lg2_commit.cpp b/lib/lg2_commit.cpp
new file mode 100644
index 0000000..2c20311
--- /dev/null
+++ b/lib/lg2_commit.cpp
@@ -0,0 +1,21 @@
+#include <phosphor-logging/lg2/commit.hpp>
+#include <sdbusplus/async.hpp>
+#include <sdbusplus/exception.hpp>
+
+namespace lg2::details
+{
+
+auto commit([[maybe_unused]] sdbusplus::exception::generated_event_base&& t)
+ -> sdbusplus::message::object_path
+{
+ return {};
+}
+
+auto commit([[maybe_unused]] sdbusplus::async::context& ctx,
+ [[maybe_unused]] sdbusplus::exception::generated_event_base&& t)
+ -> sdbusplus::async::task<sdbusplus::message::object_path>
+{
+ co_return {};
+}
+
+} // namespace lg2::details
diff --git a/lib/meson.build b/lib/meson.build
index 1e2f51f..3c7e3fc 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -16,6 +16,7 @@
phosphor_logging_lib = library(
'phosphor_logging',
'elog.cpp',
+ 'lg2_commit.cpp',
'lg2_logger.cpp',
'sdjournal.cpp',
phosphor_logging_gen,
diff --git a/test/basic_event_commit.cpp b/test/basic_event_commit.cpp
new file mode 100644
index 0000000..fc454d9
--- /dev/null
+++ b/test/basic_event_commit.cpp
@@ -0,0 +1,23 @@
+#include <phosphor-logging/commit.hpp>
+#include <xyz/openbmc_project/Logging/event.hpp>
+
+#include <gtest/gtest.h>
+
+namespace phosphor::logging::test
+{
+
+using LoggingCleared = sdbusplus::event::xyz::openbmc_project::Logging::Cleared;
+
+TEST(TestBasicEventCommit, GenerateSimpleEvent)
+{
+ EXPECT_THROW(
+ { throw LoggingCleared("NUMBER_OF_LOGS", 1); }, LoggingCleared);
+ return;
+}
+
+TEST(TestBasicEventCommit, CallCommit)
+{
+ lg2::commit(LoggingCleared("NUMBER_OF_LOGS", 3));
+}
+
+} // namespace phosphor::logging::test
diff --git a/test/meson.build b/test/meson.build
index 9bf34ed..bdf3cdb 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -24,6 +24,7 @@
endif
tests = [
+ 'basic_event_commit',
'extensions_test',
'remote_logging_test_address',
'remote_logging_test_config',
@@ -45,6 +46,7 @@
gmock_dep,
gtest_dep,
log_manager_deps,
+ pdi_dep,
phosphor_logging_dep,
],
include_directories: include_directories('..', '../gen'),