mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-15 07:06:11 -04:00
Use atexit to cleanup bus connections before exiting.
This commit is contained in:
@@ -28,12 +28,18 @@ static std::unique_ptr<sdbus::IConnection> global_default_bus_connection =
|
||||
nullptr;
|
||||
static absl::once_flag bus_connection_init_;
|
||||
|
||||
static void disconnectBus() {
|
||||
global_system_bus_connection = nullptr;
|
||||
global_default_bus_connection = nullptr;
|
||||
}
|
||||
|
||||
static void initBusConnections() {
|
||||
global_system_bus_connection = sdbus::createSystemBusConnection();
|
||||
global_system_bus_connection->enterEventLoopAsync();
|
||||
global_default_bus_connection =
|
||||
sdbus::createDefaultBusConnection("com.google.nearby");
|
||||
global_default_bus_connection->enterEventLoopAsync();
|
||||
atexit(disconnectBus);
|
||||
}
|
||||
|
||||
sdbus::IConnection &getSystemBusConnection() {
|
||||
|
||||
@@ -33,9 +33,14 @@ namespace nearby {
|
||||
static std::unique_ptr<linux::LogControl> global_log_control_;
|
||||
static absl::once_flag log_control_init_;
|
||||
|
||||
static void cleanup_log_control() {
|
||||
global_log_control_ = nullptr;
|
||||
}
|
||||
|
||||
static void init_log_control(std::nullptr_t) {
|
||||
global_log_control_ =
|
||||
std::make_unique<linux::LogControl>(linux::getDefaultBusConnection());
|
||||
atexit(cleanup_log_control);
|
||||
}
|
||||
|
||||
namespace api {
|
||||
|
||||
Reference in New Issue
Block a user