Modify D-Bus to using asio server
DBus updates are now using the asio server way.
Tested:
Tested with unit tests and locally on a machine.
Signed-off-by: Kasun Athukorala <kasunath@google.com>
Change-Id: I77553bcc3baae70e5d684a62f2c19592ff844665
Signed-off-by: Brandon Kim <brandonkim@google.com>
diff --git a/include/dbus/file_notifier.hpp b/include/dbus/file_notifier.hpp
index da37158..1e72a6b 100644
--- a/include/dbus/file_notifier.hpp
+++ b/include/dbus/file_notifier.hpp
@@ -1,6 +1,6 @@
#pragma once
-#include <sdbusplus/server.hpp>
+#include <sdbusplus/asio/object_server.hpp>
#include <xyz/openbmc_project/Common/FilePath/server.hpp>
#include <format>
@@ -9,36 +9,46 @@
namespace bios_bmc_smm_error_logger
{
-using FileNotifierInterface = sdbusplus::server::object_t<
- sdbusplus::xyz::openbmc_project::Common::server::FilePath>;
-
/**
* @brief A class for notifying file paths of CPER logs.
*/
-class CperFileNotifier : public FileNotifierInterface
+class CperFileNotifier
{
public:
/**
* @brief Constructor for the CperFileNotifier class.
*
- * @param bus - bus to attach to.
+ * @param server - sdbusplus asio object server.
* @param filePath - full path of the CPER log JSON file.
* @param entry - index of the DBus file path object.
*/
- CperFileNotifier(sdbusplus::bus_t& bus, const std::string& filePath,
- uint64_t entry) :
- FileNotifierInterface(bus, generatePath(entry).c_str(),
- action::emit_no_signals)
+ CperFileNotifier(sdbusplus::asio::object_server& server,
+ const std::string& filePath, uint64_t entry) :
+ server(server)
{
- // We only need the interface added signal for the fault monitor. So
- // stop emitting properties changed signal.
- path(filePath, /*skipSignal=*/true);
+ pathIface = server.add_interface(generatePath(entry).c_str(),
+ "xyz.openbmc_project.Common.FilePath");
+ pathIface->register_property("Path", filePath);
+ pathIface->initialize();
}
+ ~CperFileNotifier()
+ {
+ server.remove_interface(pathIface);
+ }
+
+ CperFileNotifier& operator=(const CperFileNotifier&) = delete;
+ CperFileNotifier& operator=(CperFileNotifier&&) = delete;
+ CperFileNotifier(const CperFileNotifier&) = delete;
+ CperFileNotifier(CperFileNotifier&&) = default;
+
static constexpr const char* cperBasePath =
"/xyz/openbmc_project/external_storer/bios_bmc_smm_error_logger/CPER";
private:
+ sdbusplus::asio::object_server& server;
+ std::shared_ptr<sdbusplus::asio::dbus_interface> pathIface;
+
/**
* @brief Generate a path for the CperFileNotifier DBus object.
*
diff --git a/include/rde/external_storer_file.hpp b/include/rde/external_storer_file.hpp
index 8eda3c6..6d813af 100644
--- a/include/rde/external_storer_file.hpp
+++ b/include/rde/external_storer_file.hpp
@@ -76,14 +76,15 @@
/**
* @brief Constructor for the ExternalStorerFileInterface.
*
- * @param[in] bus - bus to attach to.
+ * @param[in] conn - sdbusplus asio connection.
* @param[in] rootPath - root path for creating redfish folders.
* Eg: "/run/bmcweb"
* @param[in] fileHandler - an ExternalStorerFileWriter object. This class
* will take the ownership of this object.
*/
ExternalStorerFileInterface(
- sdbusplus::bus_t& bus, std::string_view rootPath,
+ const std::shared_ptr<sdbusplus::asio::connection>& conn,
+ std::string_view rootPath,
std::unique_ptr<FileHandlerInterface> fileHandler);
bool publishJson(std::string_view jsonStr) override;
diff --git a/include/rde/notifier_dbus_handler.hpp b/include/rde/notifier_dbus_handler.hpp
index e90fa71..708a45a 100644
--- a/include/rde/notifier_dbus_handler.hpp
+++ b/include/rde/notifier_dbus_handler.hpp
@@ -2,6 +2,8 @@
#include "dbus/file_notifier.hpp"
+#include <sdbusplus/asio/object_server.hpp>
+
#include <memory>
#include <vector>
@@ -19,9 +21,10 @@
/**
* @brief Constructor for the CperFileNotifierHandler class.
*
- * @param bus - bus to attache to.
+ * @param conn - sdbusplus asio connection.
*/
- explicit CperFileNotifierHandler(sdbusplus::bus_t& bus);
+ explicit CperFileNotifierHandler(
+ const std::shared_ptr<sdbusplus::asio::connection>& conn);
/**
* @brief Create a DBus object with the provided filePath value.
@@ -31,8 +34,8 @@
void createEntry(const std::string& filePath);
private:
- sdbusplus::bus_t& bus;
sdbusplus::server::manager_t objManager;
+ sdbusplus::asio::object_server objServer;
/**
* @brief A vector to keep track of DBus FilePath objects.
diff --git a/src/main.cpp b/src/main.cpp
index 31d6b03..6bb546c 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -91,13 +91,12 @@
std::shared_ptr<sdbusplus::asio::connection> conn =
std::make_shared<sdbusplus::asio::connection>(io);
conn->request_name("xyz.openbmc_project.bios_bmc_smm_error_logger");
- sdbusplus::bus_t& bus = static_cast<sdbusplus::bus_t&>(*conn);
std::unique_ptr<rde::FileHandlerInterface> fileIface =
std::make_unique<rde::ExternalStorerFileWriter>();
std::unique_ptr<rde::ExternalStorerInterface> exFileIface =
std::make_unique<rde::ExternalStorerFileInterface>(
- bus, "/run/bmcweb", std::move(fileIface));
+ conn, "/run/bmcweb", std::move(fileIface));
std::shared_ptr<rde::RdeCommandHandler> rdeCommandHandler =
std::make_unique<rde::RdeCommandHandler>(std::move(exFileIface));
diff --git a/src/rde/external_storer_file.cpp b/src/rde/external_storer_file.cpp
index 5cc14cf..1ffea44 100644
--- a/src/rde/external_storer_file.cpp
+++ b/src/rde/external_storer_file.cpp
@@ -46,10 +46,11 @@
}
ExternalStorerFileInterface::ExternalStorerFileInterface(
- sdbusplus::bus_t& bus, std::string_view rootPath,
+ const std::shared_ptr<sdbusplus::asio::connection>& conn,
+ std::string_view rootPath,
std::unique_ptr<FileHandlerInterface> fileHandler) :
rootPath(rootPath), fileHandler(std::move(fileHandler)), logServiceId(""),
- cperNotifier(std::make_unique<CperFileNotifierHandler>(bus))
+ cperNotifier(std::make_unique<CperFileNotifierHandler>(conn))
{}
bool ExternalStorerFileInterface::publishJson(std::string_view jsonStr)
diff --git a/src/rde/notifier_dbus_handler.cpp b/src/rde/notifier_dbus_handler.cpp
index 2151925..e6d5e4e 100644
--- a/src/rde/notifier_dbus_handler.cpp
+++ b/src/rde/notifier_dbus_handler.cpp
@@ -5,15 +5,17 @@
namespace rde
{
-CperFileNotifierHandler::CperFileNotifierHandler(sdbusplus::bus_t& bus) :
- bus(bus), objManager(bus, CperFileNotifier::cperBasePath)
+CperFileNotifierHandler::CperFileNotifierHandler(
+ const std::shared_ptr<sdbusplus::asio::connection>& conn) :
+ objManager(static_cast<sdbusplus::bus_t&>(*conn),
+ CperFileNotifier::cperBasePath),
+ objServer(conn)
{}
void CperFileNotifierHandler::createEntry(const std::string& filePath)
{
- auto obj = std::make_unique<CperFileNotifier>(bus, filePath, nextEntry);
- // Notify fault log monitor through InterfacesAdded signal.
- obj->emit_added();
+ auto obj =
+ std::make_unique<CperFileNotifier>(objServer, filePath, nextEntry);
notifierObjs.push_back(std::move(obj));
++nextEntry;
}
diff --git a/test/external_storer_file_test.cpp b/test/external_storer_file_test.cpp
index 04f6b2b..3cba35d 100644
--- a/test/external_storer_file_test.cpp
+++ b/test/external_storer_file_test.cpp
@@ -1,7 +1,6 @@
#include "rde/external_storer_file.hpp"
-#include <sdbusplus/bus.hpp>
-#include <sdbusplus/test/sdbus_mock.hpp>
+#include <boost/asio/io_context.hpp>
#include <string_view>
@@ -18,7 +17,6 @@
using ::testing::DoAll;
using ::testing::Return;
using ::testing::SaveArg;
-using ::testing::StrEq;
class MockFileWriter : public FileHandlerInterface
{
@@ -34,26 +32,18 @@
{
public:
ExternalStorerFileTest() :
- bus(sdbusplus::get_mocked_new(&sdbusMock)),
+ conn(std::make_shared<sdbusplus::asio::connection>(io)),
mockFileWriter(std::make_unique<MockFileWriter>())
{
mockFileWriterPtr = dynamic_cast<MockFileWriter*>(mockFileWriter.get());
-
- EXPECT_CALL(
- sdbusMock,
- sd_bus_add_object_manager(
- nullptr, _,
- StrEq(
- "/xyz/openbmc_project/external_storer/bios_bmc_smm_error_logger/CPER")))
- .WillOnce(Return(0));
-
exStorer = std::make_unique<ExternalStorerFileInterface>(
- bus, rootPath, std::move(mockFileWriter));
+ conn, rootPath, std::move(mockFileWriter));
}
protected:
- sdbusplus::SdBusMock sdbusMock;
- sdbusplus::bus_t bus;
+ boost::asio::io_context io;
+ std::shared_ptr<sdbusplus::asio::connection> conn;
+
std::unique_ptr<FileHandlerInterface> mockFileWriter;
std::unique_ptr<ExternalStorerFileInterface> exStorer;
MockFileWriter* mockFileWriterPtr;
@@ -168,24 +158,9 @@
EXPECT_CALL(*mockFileWriterPtr, createFile(_, _))
.WillOnce(DoAll(SaveArg<1>(&logEntryOut), Return(true)));
- constexpr const char* dbusPath =
- "/xyz/openbmc_project/external_storer/bios_bmc_smm_error_logger/CPER/entry0";
- constexpr const char* dbusInterface = "xyz.openbmc_project.Common.FilePath";
-
- EXPECT_CALL(sdbusMock, sd_bus_add_object_vtable(nullptr, _, StrEq(dbusPath),
- StrEq(dbusInterface), _, _))
- .WillOnce(Return(0));
- EXPECT_CALL(sdbusMock,
- sd_bus_emit_interfaces_added_strv(nullptr, StrEq(dbusPath), _))
- .WillOnce(Return(0));
-
EXPECT_THAT(exStorer->publishJson(jsonLogEntry), true);
EXPECT_NE(logEntryOut["Id"], nullptr);
EXPECT_EQ(logEntryOut["@odata.id"], nullptr);
-
- EXPECT_CALL(sdbusMock, sd_bus_emit_interfaces_removed_strv(
- nullptr, StrEq(dbusPath), _))
- .WillOnce(Return(0));
}
TEST_F(ExternalStorerFileTest, OtherSchemaNoOdataIdTest)