Files
rk35xx-android14/external/libbrillo/brillo/dbus/dbus_service_watcher.cc
T
hmz007 36ed224bac Rockchip Anroid14_SDK 20240628-rkr5 (2556df1a)
Signed-off-by: hmz007 <hmz007@gmail.com>
Change-Id: Ib87fdbe7a0be7dc961af3500fe9ea4589a127f9f
2024-10-29 18:12:02 +08:00

40 lines
1.2 KiB
C++

// Copyright 2015 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <brillo/dbus/dbus_service_watcher.h>
#include <base/bind.h>
namespace brillo {
namespace dbus_utils {
DBusServiceWatcher::DBusServiceWatcher(
scoped_refptr<dbus::Bus> bus,
const std::string& connection_name,
const base::Closure& on_connection_vanish)
: bus_{bus},
connection_name_{connection_name},
on_connection_vanish_{on_connection_vanish} {
monitoring_callback_ = base::Bind(
&DBusServiceWatcher::OnServiceOwnerChange, weak_factory_.GetWeakPtr());
// Register to listen, and then request the current owner;
bus_->ListenForServiceOwnerChange(connection_name_, monitoring_callback_);
bus_->GetServiceOwner(connection_name_, monitoring_callback_);
}
DBusServiceWatcher::~DBusServiceWatcher() {
bus_->UnlistenForServiceOwnerChange(
connection_name_, monitoring_callback_);
}
void DBusServiceWatcher::OnServiceOwnerChange(
const std::string& service_owner) {
if (service_owner.empty()) {
on_connection_vanish_.Run();
}
}
} // namespace dbus_utils
} // namespace brillo