Rename NEARBY_LOG() to NEARBY_LOG_OBSOLETE()

PiperOrigin-RevId: 667785090
This commit is contained in:
Francis Tsui
2024-08-26 18:20:49 -07:00
committed by Copybara-Service
parent df166289bb
commit 4bca950bc7
13 changed files with 160 additions and 150 deletions
+12 -10
View File
@@ -62,8 +62,9 @@ bool BleMedium::StartScanning(
if (peripherals_.empty()) return;
auto context = peripherals_.find(&peripheral);
if (context == peripherals_.end()) return;
NEARBY_LOG(INFO, "Removing peripheral=%p, impl=%p",
&(context->second->peripheral), &peripheral);
NEARBY_LOG_OBSOLETE(INFO, "Removing peripheral=%p, impl=%p",
&(context->second->peripheral),
&peripheral);
discovered_peripheral_callback_.peripheral_lost_cb(
context->second->peripheral, service_id);
},
@@ -75,7 +76,7 @@ bool BleMedium::StopScanning(const std::string& service_id) {
MutexLock lock(&mutex_);
discovered_peripheral_callback_ = {};
peripherals_.clear();
NEARBY_LOG(INFO, "Ble Scanning disabled: impl=%p", &GetImpl());
NEARBY_LOG_OBSOLETE(INFO, "Ble Scanning disabled: impl=%p", &GetImpl());
}
return impl_->StopScanning(service_id);
}
@@ -94,12 +95,12 @@ bool BleMedium::StartAcceptingConnections(const std::string& service_id,
&socket, std::make_unique<AcceptedConnectionInfo>());
auto& context = *pair.first->second;
if (!pair.second) {
NEARBY_LOG(INFO, "Accepting (again) socket=%p, impl=%p",
&context.socket, &socket);
NEARBY_LOG_OBSOLETE(INFO, "Accepting (again) socket=%p, impl=%p",
&context.socket, &socket);
} else {
context.socket = BleSocket(&socket);
NEARBY_LOG(INFO, "Accepting socket=%p, impl=%p", &context.socket,
&socket);
NEARBY_LOG_OBSOLETE(INFO, "Accepting socket=%p, impl=%p",
&context.socket, &socket);
}
if (accepted_connection_callback_) {
accepted_connection_callback_(context.socket, service_id);
@@ -112,7 +113,8 @@ bool BleMedium::StopAcceptingConnections(const std::string& service_id) {
MutexLock lock(&mutex_);
accepted_connection_callback_ = nullptr;
sockets_.clear();
NEARBY_LOG(INFO, "Ble accepted connection disabled: impl=%p", &GetImpl());
NEARBY_LOG_OBSOLETE(INFO, "Ble accepted connection disabled: impl=%p",
&GetImpl());
}
return impl_->StopAcceptingConnections(service_id);
}
@@ -122,8 +124,8 @@ BleSocket BleMedium::Connect(BlePeripheral& peripheral,
CancellationFlag* cancellation_flag) {
{
MutexLock lock(&mutex_);
NEARBY_LOG(INFO, "BleMedium::Connect: peripheral=%p [impl=%p]", &peripheral,
&peripheral.GetImpl());
NEARBY_LOG_OBSOLETE(INFO, "BleMedium::Connect: peripheral=%p [impl=%p]",
&peripheral, &peripheral.GetImpl());
}
return BleSocket(
impl_->Connect(peripheral.GetImpl(), service_id, cancellation_flag));
+8 -6
View File
@@ -74,7 +74,7 @@ TEST_P(BleMediumTest, CanStartAcceptingConnectionsAndConnect) {
BlePeripheral& peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
NEARBY_LOG(
NEARBY_LOG_OBSOLETE(
INFO,
"Peripheral discovered: %s, %p, fast advertisement: %d",
peripheral.GetName().c_str(), &peripheral,
@@ -87,8 +87,9 @@ TEST_P(BleMediumTest, CanStartAcceptingConnectionsAndConnect) {
fast_advertisement_service_uuid);
ble_b.StartAcceptingConnections(
service_id, [&](BleSocket socket, const std::string& service_id) {
NEARBY_LOG(INFO, "Connection accepted: socket=%p, service_id=%s",
&socket, service_id.c_str());
NEARBY_LOG_OBSOLETE(INFO,
"Connection accepted: socket=%p, service_id=%s",
&socket, service_id.c_str());
accepted_latch.CountDown();
});
EXPECT_TRUE(found_latch.Await(kWaitDuration).result());
@@ -133,7 +134,7 @@ TEST_P(BleMediumTest, CanCancelConnect) {
BlePeripheral& peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
NEARBY_LOG(
NEARBY_LOG_OBSOLETE(
INFO,
"Peripheral discovered: %s, %p, fast advertisement: %d",
peripheral.GetName().c_str(), &peripheral,
@@ -146,8 +147,9 @@ TEST_P(BleMediumTest, CanCancelConnect) {
fast_advertisement_service_uuid);
ble_b.StartAcceptingConnections(
service_id, [&](BleSocket socket, const std::string& service_id) {
NEARBY_LOG(INFO, "Connection accepted: socket=%p, service_id=%s",
&socket, service_id.c_str());
NEARBY_LOG_OBSOLETE(INFO,
"Connection accepted: socket=%p, service_id=%s",
&socket, service_id.c_str());
accepted_latch.CountDown();
});
EXPECT_TRUE(found_latch.Await(kWaitDuration).result());
+3 -3
View File
@@ -91,7 +91,7 @@ bool BleV2Medium::StartScanning(const Uuid& service_uuid,
// prevent the stale data in cache.
peripherals_.clear();
scanning_enabled_ = true;
NEARBY_LOG(INFO, "Ble Scanning enabled; impl=%p", GetImpl());
NEARBY_LOG_OBSOLETE(INFO, "Ble Scanning enabled; impl=%p", GetImpl());
}
return success;
}
@@ -106,7 +106,7 @@ bool BleV2Medium::StopScanning() {
scanning_enabled_ = false;
peripherals_.clear();
scan_callback_ = {};
NEARBY_LOG(INFO, "Ble Scanning disabled: impl=%p", GetImpl());
NEARBY_LOG_OBSOLETE(INFO, "Ble Scanning disabled: impl=%p", GetImpl());
return impl_->StopScanning();
}
@@ -114,7 +114,7 @@ std::unique_ptr<api::ble_v2::BleMedium::ScanningSession>
BleV2Medium::StartScanning(const Uuid& service_uuid,
api::ble_v2::TxPowerLevel tx_power_level,
api::ble_v2::BleMedium::ScanningCallback callback) {
NEARBY_LOG(INFO, "platform mutex: %p", &mutex_);
NEARBY_LOG_OBSOLETE(INFO, "platform mutex: %p", &mutex_);
return impl_->StartScanning(
service_uuid, tx_power_level,
api::ble_v2::BleMedium::ScanningCallback{
+47 -44
View File
@@ -67,71 +67,73 @@ MediumSocket* BluetoothSocket::CreateVirtualSocket(
}
BluetoothClassicMedium::~BluetoothClassicMedium() {
NEARBY_LOG(INFO, "~BluetoothClassicMedium: observer_list_ size: %d",
observer_list_.size());
NEARBY_LOGS(INFO) << "~BluetoothClassicMedium: observer_list_ size: "
<< observer_list_.size();
if (!observer_list_.empty()) {
impl_->RemoveObserver(this);
}
StopDiscovery();
NEARBY_LOG(INFO, "eof ~BluetoothClassicMedium");
NEARBY_LOGS(INFO) << "eof ~BluetoothClassicMedium";
}
BluetoothSocket BluetoothClassicMedium::ConnectToService(
BluetoothDevice& remote_device, const std::string& service_uuid,
CancellationFlag* cancellation_flag) {
NEARBY_LOG(INFO,
"BluetoothClassicMedium::ConnectToService: service_uuid=%p, "
"device=%p, [impl=%p]",
service_uuid.c_str(), &remote_device, &remote_device.GetImpl());
NEARBY_LOG_OBSOLETE(
INFO,
"BluetoothClassicMedium::ConnectToService: service_uuid=%p, "
"device=%p, [impl=%p]",
service_uuid.c_str(), &remote_device, &remote_device.GetImpl());
return BluetoothSocket(impl_->ConnectToService(
remote_device.GetImpl(), service_uuid, cancellation_flag));
}
bool BluetoothClassicMedium::StartDiscovery(DiscoveryCallback callback) {
NEARBY_LOG(INFO, "BluetoothClassicMedium::StartDiscovery");
NEARBY_LOGS(INFO) << "BluetoothClassicMedium::StartDiscovery";
MutexLock lock(&mutex_);
if (discovery_enabled_) {
NEARBY_LOG(INFO, "BT Discovery already enabled; impl=%p", &GetImpl());
NEARBY_LOG_OBSOLETE(INFO, "BT Discovery already enabled; impl=%p",
&GetImpl());
return false;
}
bool success = impl_->StartDiscovery({
.device_discovered_cb =
[this](api::BluetoothDevice& device) {
NEARBY_LOG(VERBOSE, "BT .device_discovered_cb for %p",
device.GetName().c_str());
NEARBY_LOGS(VERBOSE)
<< "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(INFO, "Adding (again) device=%p, impl=%p",
&context.device, &device);
NEARBY_LOG_OBSOLETE(INFO, "Adding (again) device=%p, impl=%p",
&context.device, &device);
return;
}
context.device = BluetoothDevice(&device);
NEARBY_LOG(INFO, "Adding device=%p, impl=%p", &context.device,
&device);
NEARBY_LOG_OBSOLETE(INFO, "Adding device=%p, impl=%p",
&context.device, &device);
if (!discovery_enabled_) return;
discovery_callback_.device_discovered_cb(context.device);
},
.device_name_changed_cb =
[this](api::BluetoothDevice& device) {
NEARBY_LOG(VERBOSE, "BT .device_name_changed_cb for %p",
device.GetName().c_str());
NEARBY_LOGS(VERBOSE)
<< "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(INFO, "Renaming device=%p, impl=%p", &context.device,
&device);
NEARBY_LOG_OBSOLETE(INFO, "Renaming device=%p, impl=%p",
&context.device, &device);
if (!discovery_enabled_) return;
discovery_callback_.device_name_changed_cb(context.device);
},
.device_lost_cb =
[this](api::BluetoothDevice& device) {
NEARBY_LOG(VERBOSE, "BT .device_lost_cb for %p",
device.GetName().c_str());
NEARBY_LOGS(VERBOSE) << "BT .device_lost_cb for " <<
device.GetName();
MutexLock lock(&mutex_);
auto item = devices_.extract(&device);
if (!item) {
@@ -140,8 +142,8 @@ bool BluetoothClassicMedium::StartDiscovery(DiscoveryCallback callback) {
return;
}
auto& context = *item.mapped();
NEARBY_LOG(INFO, "Removing device=%p, impl=%p", &context.device,
&device);
NEARBY_LOG_OBSOLETE(INFO, "Removing device=%p, impl=%p",
&context.device, &device);
if (!discovery_enabled_) return;
discovery_callback_.device_lost_cb(context.device);
},
@@ -151,52 +153,53 @@ bool BluetoothClassicMedium::StartDiscovery(DiscoveryCallback callback) {
devices_.clear();
discovery_enabled_ = true;
}
NEARBY_LOG(INFO, "BT StartDiscovery result:%d; impl=%p", success, &GetImpl());
NEARBY_LOG_OBSOLETE(INFO, "BT StartDiscovery result:%d; impl=%p", success,
&GetImpl());
return success;
}
bool BluetoothClassicMedium::StopDiscovery() {
NEARBY_LOG(INFO, "BT StopDiscovery; impl=%p", &GetImpl());
NEARBY_LOG_OBSOLETE(INFO, "BT StopDiscovery; impl=%p", &GetImpl());
MutexLock lock(&mutex_);
if (!discovery_enabled_) return true;
discovery_enabled_ = false;
discovery_callback_ = {};
devices_.clear();
NEARBY_LOG(INFO, "BT Discovery disabled: impl=%p", &GetImpl());
NEARBY_LOG_OBSOLETE(INFO, "BT Discovery disabled: impl=%p", &GetImpl());
return impl_->StopDiscovery();
}
void BluetoothClassicMedium::AddObserver(Observer* observer) {
NEARBY_LOG(INFO, "BT AddObserver; impl=%p", &GetImpl());
NEARBY_LOG_OBSOLETE(INFO, "BT AddObserver; impl=%p", &GetImpl());
MutexLock lock(&mutex_);
if (observer_list_.empty()) {
impl_->AddObserver(this);
}
observer_list_.AddObserver(observer);
NEARBY_LOG(INFO, "BT AddObserver done");
NEARBY_LOGS(INFO) << "BT AddObserver done";
}
void BluetoothClassicMedium::RemoveObserver(Observer* observer) {
NEARBY_LOG(INFO, "BT RemoveObserver; impl=%p", &GetImpl());
NEARBY_LOG_OBSOLETE(INFO, "BT RemoveObserver; impl=%p", &GetImpl());
MutexLock lock(&mutex_);
observer_list_.RemoveObserver(observer);
if (observer_list_.empty()) {
impl_->RemoveObserver(this);
}
NEARBY_LOG(INFO, "BT RemoveObserver done");
NEARBY_LOGS(INFO) << "BT RemoveObserver done";
}
// api::BluetoothClassicMedium::Observer methods
void BluetoothClassicMedium::DeviceAdded(api::BluetoothDevice& device) {
NEARBY_LOG(VERBOSE, "BT DeviceAdded; name=%p, address=%p",
device.GetName().c_str(), device.GetMacAddress().c_str());
NEARBY_LOGS(VERBOSE) << "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_LOG(VERBOSE, "BT DeviceRemoved; name=%p, address=%p",
device.GetName().c_str(), device.GetMacAddress().c_str());
NEARBY_LOGS(VERBOSE) << "BT DeviceRemoved; name=" << device.GetName()
<< ", address=" << device.GetMacAddress();
BluetoothDevice bt_device(&device);
for (auto* observer : observer_list_.GetObservers()) {
observer->DeviceRemoved(bt_device);
@@ -204,9 +207,9 @@ void BluetoothClassicMedium::DeviceRemoved(api::BluetoothDevice& device) {
}
void BluetoothClassicMedium::DeviceAddressChanged(
api::BluetoothDevice& device, absl::string_view old_address) {
NEARBY_LOG(
VERBOSE, "BT DeviceAddressChanged; name=%p, address=%p, old_address=%p",
device.GetName().c_str(), device.GetMacAddress().c_str(), old_address);
NEARBY_LOGS(VERBOSE) << "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);
@@ -214,9 +217,9 @@ void BluetoothClassicMedium::DeviceAddressChanged(
}
void BluetoothClassicMedium::DevicePairedChanged(api::BluetoothDevice& device,
bool new_paired_status) {
NEARBY_LOG(VERBOSE, "BT DevicePairedChanged; name=%p, address=%p, status=%d",
device.GetName().c_str(), device.GetMacAddress().c_str(),
new_paired_status);
NEARBY_LOGS(VERBOSE) << "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);
@@ -224,10 +227,10 @@ void BluetoothClassicMedium::DevicePairedChanged(api::BluetoothDevice& device,
}
void BluetoothClassicMedium::DeviceConnectedStateChanged(
api::BluetoothDevice& device, bool connected) {
NEARBY_LOG(
VERBOSE,
"BT DeviceConnectedStateChanged: name=%p, address=%p, connected=%d",
device.GetName().c_str(), device.GetMacAddress().c_str(), connected);
NEARBY_LOGS(VERBOSE) << "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);
+12 -10
View File
@@ -261,11 +261,11 @@ bool BleMedium::StopAcceptingConnections(const std::string& service_id) {
std::unique_ptr<api::BleSocket> BleMedium::Connect(
api::BlePeripheral& remote_peripheral, const std::string& service_id,
CancellationFlag* cancellation_flag) {
NEARBY_LOG(INFO,
"G3 Ble Connect [self]: medium=%p, adapter=%p, peripheral=%p, "
"service_id=%s",
this, &GetAdapter(), &GetAdapter().GetPeripheral(),
service_id.c_str());
NEARBY_LOG_OBSOLETE(
INFO,
"G3 Ble Connect [self]: medium=%p, adapter=%p, peripheral=%p, "
"service_id=%s",
this, &GetAdapter(), &GetAdapter().GetPeripheral(), service_id.c_str());
// First, find an instance of remote medium, that exposed this peripheral.
auto& adapter = static_cast<BlePeripheral&>(remote_peripheral).GetAdapter();
auto* medium = static_cast<BleMedium*>(adapter.GetBleMedium());
@@ -273,10 +273,11 @@ std::unique_ptr<api::BleSocket> BleMedium::Connect(
if (!medium) return {}; // Can't find medium. Bail out.
BleServerSocket* remote_server_socket = nullptr;
NEARBY_LOG(INFO,
"G3 Ble Connect [peer]: medium=%p, adapter=%p, peripheral=%p, "
"service_id=%s",
medium, &adapter, &remote_peripheral, service_id.c_str());
NEARBY_LOG_OBSOLETE(
INFO,
"G3 Ble Connect [peer]: medium=%p, adapter=%p, peripheral=%p, "
"service_id=%s",
medium, &adapter, &remote_peripheral, service_id.c_str());
// Then, find our server socket context in this medium.
{
absl::MutexLock medium_lock(&medium->mutex_);
@@ -311,7 +312,8 @@ std::unique_ptr<api::BleSocket> BleMedium::Connect(
return {};
}
NEARBY_LOG(INFO, "G3 Ble Connect: connected: socket=%p", socket.get());
NEARBY_LOG_OBSOLETE(INFO, "G3 Ble Connect: connected: socket=%p",
socket.get());
return socket;
}
+2 -1
View File
@@ -93,7 +93,8 @@ class LogMessageVoidify {
? (void)0 \
: nearby::LogMessageVoidify() & NEARBY_LOG_MESSAGE(severity)->Stream()
#define NEARBY_LOG(severity, ...) \
// DO NOT USE. Switch to NEARBY_LOGS() instead.
#define NEARBY_LOG_OBSOLETE(severity, ...) \
NEARBY_LOG_IS_ON(severity) \
? NEARBY_LOG_MESSAGE(severity)->Print(__VA_ARGS__) : (void)0