internal/utils: Remove performCallback
This logic doesn't need to be maintained separately from the sdevent
source.
Change-Id: I1290a13953c71db06d5a8fd6ed630a690958a4a4
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/sdeventplus/internal/utils.hpp b/src/sdeventplus/internal/utils.hpp
index c078ed6..ec572e4 100644
--- a/src/sdeventplus/internal/utils.hpp
+++ b/src/sdeventplus/internal/utils.hpp
@@ -1,11 +1,8 @@
#pragma once
#include <chrono>
-#include <cstdio>
-#include <exception>
-#include <functional>
+#include <cstdint>
#include <sdeventplus/exception.hpp>
-#include <stdexcept>
#include <stdplus/util/cexec.hpp>
#include <utility>
@@ -19,28 +16,6 @@
namespace internal
{
-/** @brief Handle sd_event callback exception gracefully
- * @details A generic wrapper that turns exceptions into
- * error messages and return codes.
- */
-template <typename... Args>
-inline int performCallback(const char* name, Args&&... args)
-{
- try
- {
- std::invoke(std::forward<Args>(args)...);
- }
- catch (const std::exception& e)
- {
- fprintf(stderr, "sdeventplus: %s: %s\n", name, e.what());
- }
- catch (...)
- {
- fprintf(stderr, "sdeventplus: %s: Unknown error\n", name);
- }
- return 0;
-}
-
/** @brief Constructs an SdEventError for stdplus cexec
*/
inline SdEventError makeError(int error, const char* msg)
diff --git a/src/sdeventplus/source/base.hpp b/src/sdeventplus/source/base.hpp
index 0807fb1..914cf36 100644
--- a/src/sdeventplus/source/base.hpp
+++ b/src/sdeventplus/source/base.hpp
@@ -7,7 +7,6 @@
#include <functional>
#include <memory>
#include <sdeventplus/event.hpp>
-#include <sdeventplus/internal/utils.hpp>
#include <sdeventplus/types.hpp>
#include <stdplus/handle/copyable.hpp>
#include <systemd/sd-bus.h>
@@ -207,8 +206,19 @@
Data& data =
static_cast<Data&>(*reinterpret_cast<detail::BaseData*>(userdata));
Callback& callback = std::invoke(getter, data);
- return internal::performCallback(name, callback, std::ref(data),
- std::forward<Args>(args)...);
+ try
+ {
+ std::invoke(callback, data, std::forward<Args>(args)...);
+ }
+ catch (const std::exception& e)
+ {
+ fprintf(stderr, "sdeventplus: %s: %s\n", name, e.what());
+ }
+ catch (...)
+ {
+ fprintf(stderr, "sdeventplus: %s: Unknown error\n", name);
+ }
+ return 0;
}
private:
diff --git a/test/internal/utils.cpp b/test/internal/utils.cpp
deleted file mode 100644
index 3836c57..0000000
--- a/test/internal/utils.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-#include <functional>
-#include <gtest/gtest.h>
-#include <memory>
-#include <sdeventplus/internal/utils.hpp>
-#include <stdexcept>
-#include <system_error>
-#include <utility>
-
-namespace sdeventplus
-{
-namespace internal
-{
-namespace
-{
-
-TEST(UtilsTest, PerformCallbackSuccess)
-{
- EXPECT_EQ(0, performCallback(nullptr, []() {}));
-}
-
-TEST(UtilsTest, PerformCallbackAcceptsReference)
-{
- auto f =
- std::bind([](const std::unique_ptr<int>&) {}, std::make_unique<int>(1));
- EXPECT_EQ(0, performCallback(nullptr, f));
-}
-
-TEST(UtilsTest, PerformCallbackAcceptsMove)
-{
- auto f =
- std::bind([](const std::unique_ptr<int>&) {}, std::make_unique<int>(1));
- EXPECT_EQ(0, performCallback(nullptr, std::move(f)));
-}
-
-TEST(UtilsTest, SetPrepareSystemError)
-{
- EXPECT_EQ(0, performCallback("system_error", []() {
- throw std::system_error(EBUSY, std::generic_category());
- }));
-}
-
-TEST(UtilsTest, SetPrepareException)
-{
- EXPECT_EQ(0, performCallback("runtime_error", []() {
- throw std::runtime_error("Exception");
- }));
-}
-
-TEST(UtilsTest, SetPrepareUnknownException)
-{
- EXPECT_EQ(0,
- performCallback("unknown", []() { throw static_cast<int>(1); }));
-}
-
-} // namespace
-} // namespace internal
-} // namespace sdeventplus
diff --git a/test/meson.build b/test/meson.build
index f182367..6848112 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -25,7 +25,6 @@
'clock',
'event',
'exception',
- 'internal/utils',
'source/base',
'source/child',
'source/event',