diff --git a/internal/platform/implementation/linux/dbus.cc b/internal/platform/implementation/linux/dbus.cc index 5a3d48f3..1bbaa7b3 100644 --- a/internal/platform/implementation/linux/dbus.cc +++ b/internal/platform/implementation/linux/dbus.cc @@ -13,8 +13,8 @@ // limitations under the License. #include -#include #include +#include #include @@ -27,9 +27,13 @@ static std::unique_ptr global_system_bus_connection = nullptr; static std::unique_ptr global_default_bus_connection = nullptr; +static std::unique_ptr system_root_object_manager = nullptr; +static std::unique_ptr default_root_object_manager = nullptr; static absl::once_flag bus_connection_init_; static void disconnectBus() { + system_root_object_manager = nullptr; + default_root_object_manager = nullptr; global_system_bus_connection = nullptr; global_default_bus_connection = nullptr; } @@ -39,6 +43,11 @@ static void initBusConnections() { global_system_bus_connection->enterEventLoopAsync(); global_default_bus_connection = sdbus::createDefaultBusConnection(); global_default_bus_connection->enterEventLoopAsync(); + system_root_object_manager = + std::make_unique(*global_system_bus_connection); + default_root_object_manager = + std::make_unique(*global_default_bus_connection); + atexit(disconnectBus); } diff --git a/internal/platform/implementation/linux/dbus.h b/internal/platform/implementation/linux/dbus.h index 7df2770c..a16b1fb6 100644 --- a/internal/platform/implementation/linux/dbus.h +++ b/internal/platform/implementation/linux/dbus.h @@ -15,7 +15,9 @@ #ifndef PLATFORM_IMPL_LINUX_DBUS_H_ #define PLATFORM_IMPL_LINUX_DBUS_H_ +#include #include +#include #include "internal/platform/logging.h" #define DBUS_LOG_METHOD_CALL_ERROR(p, m, e) \ @@ -46,6 +48,17 @@ namespace nearby { namespace linux { extern sdbus::IConnection &getSystemBusConnection(); extern sdbus::IConnection &getDefaultBusConnection(); +class RootObjectManager final + : public sdbus::AdaptorInterfaces { + public: + explicit RootObjectManager(sdbus::IConnection &system_bus) + : AdaptorInterfaces(system_bus, "/") { + registerAdaptor(); + } + ~RootObjectManager() { unregisterAdaptor(); } +}; + } // namespace linux } // namespace nearby #endif