mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-15 07:06:11 -04:00
Simplify ObjectManager listener code.
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
#include "internal/platform/implementation/linux/bluetooth_classic_socket.h"
|
||||
#include "internal/platform/implementation/linux/bluetooth_pairing.h"
|
||||
#include "internal/platform/implementation/linux/bluez.h"
|
||||
#include "internal/platform/implementation/linux/bluez_device_client_glue.h"
|
||||
#include "internal/platform/logging.h"
|
||||
|
||||
namespace nearby {
|
||||
@@ -37,9 +38,7 @@ BluetoothClassicMedium::~BluetoothClassicMedium() { unregisterProxy(); }
|
||||
void BluetoothClassicMedium::onInterfacesAdded(
|
||||
const sdbus::ObjectPath &object,
|
||||
const std::map<std::string, std::map<std::string, sdbus::Variant>>
|
||||
&interfacesAndProperties) {
|
||||
NEARBY_LOGS(VERBOSE) << __func__ << "New intefaces added at " << object;
|
||||
|
||||
&interfaces) {
|
||||
auto path_prefix = absl::Substitute(
|
||||
"$0/dev_", adapter_->GetBluezAdapterObject().getObjectPath());
|
||||
if (object.find(path_prefix) != 0) {
|
||||
@@ -51,23 +50,18 @@ void BluetoothClassicMedium::onInterfacesAdded(
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto it = interfacesAndProperties.begin();
|
||||
it != interfacesAndProperties.end(); it++) {
|
||||
auto interface = it->first;
|
||||
if (interfaces.count(org::bluez::Device1_proxy::INTERFACE_NAME) == 1) {
|
||||
NEARBY_LOGS(INFO) << __func__ << ": Encountered new device at " << object;
|
||||
|
||||
if (interface == "org.bluez.Device1") {
|
||||
NEARBY_LOGS(INFO) << __func__ << ": Encountered new device at " << object;
|
||||
auto &device = devices_->add_new_device(object);
|
||||
|
||||
auto &device = devices_->add_new_device(object);
|
||||
if (discovery_cb_.has_value() &&
|
||||
discovery_cb_->device_discovered_cb != nullptr) {
|
||||
discovery_cb_->device_discovered_cb(device);
|
||||
}
|
||||
|
||||
if (discovery_cb_.has_value() &&
|
||||
discovery_cb_->device_discovered_cb != nullptr) {
|
||||
discovery_cb_->device_discovered_cb(device);
|
||||
}
|
||||
|
||||
for (auto &observer : observers_.GetObservers()) {
|
||||
observer->DeviceAdded(device);
|
||||
}
|
||||
for (auto &observer : observers_.GetObservers()) {
|
||||
observer->DeviceAdded(device);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -75,16 +69,13 @@ void BluetoothClassicMedium::onInterfacesAdded(
|
||||
void BluetoothClassicMedium::onInterfacesRemoved(
|
||||
const sdbus::ObjectPath &object,
|
||||
const std::vector<std::string> &interfaces) {
|
||||
NEARBY_LOGS(VERBOSE) << __func__ << ": Intefaces removed at " << object;
|
||||
|
||||
auto path_prefix = absl::Substitute("$0/dev_", adapter_->GetObjectPath());
|
||||
if (object.find(path_prefix) != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto &interface : interfaces) {
|
||||
if (interface == bluez::DEVICE_INTERFACE) {
|
||||
|
||||
if (interface == org::bluez::Device1_proxy::INTERFACE_NAME) {
|
||||
{
|
||||
auto device = devices_->get_device_by_path(object);
|
||||
if (!device.has_value()) {
|
||||
@@ -95,15 +86,16 @@ void BluetoothClassicMedium::onInterfacesRemoved(
|
||||
return;
|
||||
}
|
||||
|
||||
NEARBY_LOGS(INFO) << __func__ << ": " << object << " has been removed";
|
||||
for (auto &observer : observers_.GetObservers()) {
|
||||
observer->DeviceRemoved(*device);
|
||||
}
|
||||
|
||||
NEARBY_LOGS(INFO) << __func__ << ": Device " << object
|
||||
<< " has been removed";
|
||||
if (discovery_cb_.has_value() &&
|
||||
discovery_cb_->device_lost_cb != nullptr) {
|
||||
discovery_cb_->device_lost_cb(*device);
|
||||
}
|
||||
|
||||
for (auto &observer : observers_.GetObservers()) {
|
||||
observer->DeviceRemoved(*device);
|
||||
}
|
||||
}
|
||||
devices_->remove_device_by_path(object);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user