mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Internal logging update
PiperOrigin-RevId: 669420403
This commit is contained in:
committed by
Copybara-Service
parent
e65a8a568c
commit
d5b5d92f87
@@ -19,6 +19,7 @@
|
||||
#include <utility>
|
||||
|
||||
#include "absl/container/flat_hash_map.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/platform/bluetooth_adapter.h"
|
||||
#include "internal/platform/cancellation_flag.h"
|
||||
#include "internal/platform/implementation/bluetooth_classic.h"
|
||||
@@ -79,11 +80,11 @@ BluetoothClassicMedium::~BluetoothClassicMedium() {
|
||||
BluetoothSocket BluetoothClassicMedium::ConnectToService(
|
||||
BluetoothDevice& remote_device, const std::string& service_uuid,
|
||||
CancellationFlag* cancellation_flag) {
|
||||
NEARBY_LOG_OBSOLETE(
|
||||
INFO,
|
||||
"BluetoothClassicMedium::ConnectToService: service_uuid=%p, "
|
||||
"device=%p, [impl=%p]",
|
||||
service_uuid.c_str(), &remote_device, &remote_device.GetImpl());
|
||||
NEARBY_LOGS(INFO) << "BluetoothClassicMedium::ConnectToService: "
|
||||
"service_uuid="
|
||||
<< service_uuid
|
||||
<< ", device=" << remote_device.GetMacAddress()
|
||||
<< ", [impl=" << &remote_device.GetImpl() << "]";
|
||||
return BluetoothSocket(impl_->ConnectToService(
|
||||
remote_device.GetImpl(), service_uuid, cancellation_flag));
|
||||
}
|
||||
@@ -92,48 +93,50 @@ bool BluetoothClassicMedium::StartDiscovery(DiscoveryCallback callback) {
|
||||
NEARBY_LOGS(INFO) << "BluetoothClassicMedium::StartDiscovery";
|
||||
MutexLock lock(&mutex_);
|
||||
if (discovery_enabled_) {
|
||||
NEARBY_LOG_OBSOLETE(INFO, "BT Discovery already enabled; impl=%p",
|
||||
&GetImpl());
|
||||
NEARBY_LOGS(INFO) << "BT Discovery already enabled; impl=" << &GetImpl();
|
||||
return false;
|
||||
}
|
||||
bool success = impl_->StartDiscovery({
|
||||
.device_discovered_cb =
|
||||
[this](api::BluetoothDevice& device) {
|
||||
NEARBY_LOGS(VERBOSE)
|
||||
<< "BT .device_discovered_cb for " << device.GetName();
|
||||
NEARBY_VLOG(1) << "BT .device_discovered_cb for "
|
||||
<< device.GetName();
|
||||
MutexLock lock(&mutex_);
|
||||
auto pair = devices_.emplace(
|
||||
&device, std::make_unique<DeviceDiscoveryInfo>());
|
||||
auto& context = *pair.first->second;
|
||||
if (!pair.second) {
|
||||
NEARBY_LOG_OBSOLETE(INFO, "Adding (again) device=%p, impl=%p",
|
||||
&context.device, &device);
|
||||
NEARBY_LOGS(INFO)
|
||||
<< "Adding (again) device=" << context.device.GetMacAddress()
|
||||
<< ",impl=" << &device;
|
||||
return;
|
||||
}
|
||||
context.device = BluetoothDevice(&device);
|
||||
NEARBY_LOG_OBSOLETE(INFO, "Adding device=%p, impl=%p",
|
||||
&context.device, &device);
|
||||
NEARBY_LOGS(INFO)
|
||||
<< "Adding device=" << context.device.GetMacAddress()
|
||||
<< ",impl=" << &device;
|
||||
if (!discovery_enabled_) return;
|
||||
discovery_callback_.device_discovered_cb(context.device);
|
||||
},
|
||||
.device_name_changed_cb =
|
||||
[this](api::BluetoothDevice& device) {
|
||||
NEARBY_LOGS(VERBOSE)
|
||||
<< "BT .device_name_changed_cb for " << device.GetName();
|
||||
NEARBY_VLOG(1) << "BT .device_name_changed_cb for "
|
||||
<< device.GetName();
|
||||
MutexLock lock(&mutex_);
|
||||
// If the device is not already in devices_, we should not be able
|
||||
// to change its name.
|
||||
if (devices_.find(&device) == devices_.end()) return;
|
||||
auto& context = *devices_[&device];
|
||||
NEARBY_LOG_OBSOLETE(INFO, "Renaming device=%p, impl=%p",
|
||||
&context.device, &device);
|
||||
NEARBY_LOGS(INFO)
|
||||
<< "Renaming device=" << context.device.GetMacAddress()
|
||||
<< ",impl=" << &device;
|
||||
if (!discovery_enabled_) return;
|
||||
discovery_callback_.device_name_changed_cb(context.device);
|
||||
},
|
||||
.device_lost_cb =
|
||||
[this](api::BluetoothDevice& device) {
|
||||
NEARBY_LOGS(VERBOSE) << "BT .device_lost_cb for " <<
|
||||
device.GetName();
|
||||
NEARBY_VLOG(1) << "BT .device_lost_cb for "
|
||||
<< device.GetMacAddress();
|
||||
MutexLock lock(&mutex_);
|
||||
auto item = devices_.extract(&device);
|
||||
if (!item) {
|
||||
@@ -142,8 +145,9 @@ bool BluetoothClassicMedium::StartDiscovery(DiscoveryCallback callback) {
|
||||
return;
|
||||
}
|
||||
auto& context = *item.mapped();
|
||||
NEARBY_LOG_OBSOLETE(INFO, "Removing device=%p, impl=%p",
|
||||
&context.device, &device);
|
||||
NEARBY_LOGS(INFO)
|
||||
<< "Removing device=" << context.device.GetMacAddress()
|
||||
<< ",impl=" << &device;
|
||||
if (!discovery_enabled_) return;
|
||||
discovery_callback_.device_lost_cb(context.device);
|
||||
},
|
||||
@@ -153,24 +157,24 @@ bool BluetoothClassicMedium::StartDiscovery(DiscoveryCallback callback) {
|
||||
devices_.clear();
|
||||
discovery_enabled_ = true;
|
||||
}
|
||||
NEARBY_LOG_OBSOLETE(INFO, "BT StartDiscovery result:%d; impl=%p", success,
|
||||
&GetImpl());
|
||||
NEARBY_LOGS(INFO) << "BT StartDiscovery result:" << success
|
||||
<< ", impl=" << &GetImpl();
|
||||
return success;
|
||||
}
|
||||
|
||||
bool BluetoothClassicMedium::StopDiscovery() {
|
||||
NEARBY_LOG_OBSOLETE(INFO, "BT StopDiscovery; impl=%p", &GetImpl());
|
||||
NEARBY_LOGS(INFO) << "BT StopDiscovery; impl=" << &GetImpl();
|
||||
MutexLock lock(&mutex_);
|
||||
if (!discovery_enabled_) return true;
|
||||
discovery_enabled_ = false;
|
||||
discovery_callback_ = {};
|
||||
devices_.clear();
|
||||
NEARBY_LOG_OBSOLETE(INFO, "BT Discovery disabled: impl=%p", &GetImpl());
|
||||
NEARBY_LOGS(INFO) << "BT Discovery disabled: impl=" << &GetImpl();
|
||||
return impl_->StopDiscovery();
|
||||
}
|
||||
|
||||
void BluetoothClassicMedium::AddObserver(Observer* observer) {
|
||||
NEARBY_LOG_OBSOLETE(INFO, "BT AddObserver; impl=%p", &GetImpl());
|
||||
NEARBY_LOGS(INFO) << "BT AddObserver; impl=" << &GetImpl();
|
||||
MutexLock lock(&mutex_);
|
||||
if (observer_list_.empty()) {
|
||||
impl_->AddObserver(this);
|
||||
@@ -179,7 +183,7 @@ void BluetoothClassicMedium::AddObserver(Observer* observer) {
|
||||
NEARBY_LOGS(INFO) << "BT AddObserver done";
|
||||
}
|
||||
void BluetoothClassicMedium::RemoveObserver(Observer* observer) {
|
||||
NEARBY_LOG_OBSOLETE(INFO, "BT RemoveObserver; impl=%p", &GetImpl());
|
||||
NEARBY_LOGS(INFO) << "BT RemoveObserver; impl=" << &GetImpl();
|
||||
MutexLock lock(&mutex_);
|
||||
observer_list_.RemoveObserver(observer);
|
||||
if (observer_list_.empty()) {
|
||||
@@ -190,16 +194,16 @@ void BluetoothClassicMedium::RemoveObserver(Observer* observer) {
|
||||
|
||||
// api::BluetoothClassicMedium::Observer methods
|
||||
void BluetoothClassicMedium::DeviceAdded(api::BluetoothDevice& device) {
|
||||
NEARBY_LOGS(VERBOSE) << "BT DeviceAdded; name=" << device.GetName()
|
||||
<< ", address=" << device.GetMacAddress();
|
||||
NEARBY_VLOG(1) << "BT DeviceAdded; name=" << device.GetName()
|
||||
<< ", address=" << device.GetMacAddress();
|
||||
BluetoothDevice bt_device(&device);
|
||||
for (auto* observer : observer_list_.GetObservers()) {
|
||||
observer->DeviceAdded(bt_device);
|
||||
}
|
||||
}
|
||||
void BluetoothClassicMedium::DeviceRemoved(api::BluetoothDevice& device) {
|
||||
NEARBY_LOGS(VERBOSE) << "BT DeviceRemoved; name=" << device.GetName()
|
||||
<< ", address=" << device.GetMacAddress();
|
||||
NEARBY_VLOG(1) << "BT DeviceRemoved; name=" << device.GetName()
|
||||
<< ", address=" << device.GetMacAddress();
|
||||
BluetoothDevice bt_device(&device);
|
||||
for (auto* observer : observer_list_.GetObservers()) {
|
||||
observer->DeviceRemoved(bt_device);
|
||||
@@ -207,9 +211,9 @@ void BluetoothClassicMedium::DeviceRemoved(api::BluetoothDevice& device) {
|
||||
}
|
||||
void BluetoothClassicMedium::DeviceAddressChanged(
|
||||
api::BluetoothDevice& device, absl::string_view old_address) {
|
||||
NEARBY_LOGS(VERBOSE) << "BT DeviceAddressChanged; name=" << device.GetName()
|
||||
<< ", address=" << device.GetMacAddress()
|
||||
<< ", old_address=" << old_address;
|
||||
NEARBY_VLOG(1) << "BT DeviceAddressChanged; name=" << device.GetName()
|
||||
<< ", address=" << device.GetMacAddress()
|
||||
<< ", old_address=" << old_address;
|
||||
BluetoothDevice bt_device(&device);
|
||||
for (auto* observer : observer_list_.GetObservers()) {
|
||||
observer->DeviceAddressChanged(bt_device, old_address);
|
||||
@@ -217,9 +221,9 @@ void BluetoothClassicMedium::DeviceAddressChanged(
|
||||
}
|
||||
void BluetoothClassicMedium::DevicePairedChanged(api::BluetoothDevice& device,
|
||||
bool new_paired_status) {
|
||||
NEARBY_LOGS(VERBOSE) << "BT DevicePairedChanged; name=" << device.GetName()
|
||||
<< ", address=" << device.GetMacAddress()
|
||||
<< ", status=" << new_paired_status;
|
||||
NEARBY_VLOG(1) << "BT DevicePairedChanged; name=" << device.GetName()
|
||||
<< ", address=" << device.GetMacAddress()
|
||||
<< ", status=" << new_paired_status;
|
||||
BluetoothDevice bt_device(&device);
|
||||
for (auto* observer : observer_list_.GetObservers()) {
|
||||
observer->DevicePairedChanged(bt_device, new_paired_status);
|
||||
@@ -227,10 +231,9 @@ void BluetoothClassicMedium::DevicePairedChanged(api::BluetoothDevice& device,
|
||||
}
|
||||
void BluetoothClassicMedium::DeviceConnectedStateChanged(
|
||||
api::BluetoothDevice& device, bool connected) {
|
||||
NEARBY_LOGS(VERBOSE) << "BT DeviceConnectedStateChanged: name="
|
||||
<< device.GetName()
|
||||
<< ", address=" << device.GetMacAddress()
|
||||
<< ", connected=" << connected;
|
||||
NEARBY_VLOG(1) << "BT DeviceConnectedStateChanged: name=" << device.GetName()
|
||||
<< ", address=" << device.GetMacAddress()
|
||||
<< ", connected=" << connected;
|
||||
BluetoothDevice bt_device(&device);
|
||||
for (auto* observer : observer_list_.GetObservers()) {
|
||||
observer->DeviceConnectedStateChanged(bt_device, connected);
|
||||
|
||||
Reference in New Issue
Block a user