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
@@ -66,11 +66,10 @@ BluetoothDeviceName::BluetoothDeviceName(
}
if (bluetooth_device_name_bytes.size() < kMinBluetoothDeviceNameLength) {
NEARBY_LOG(INFO,
"Cannot deserialize BluetoothDeviceName: expecting min %d raw "
"bytes, got %" PRIu64,
kMinBluetoothDeviceNameLength,
bluetooth_device_name_bytes.size());
NEARBY_LOGS(INFO)
<< "Cannot deserialize BluetoothDeviceName: expecting min "
<< kMinBluetoothDeviceNameLength << " raw bytes, got "
<< bluetooth_device_name_bytes.size();
return;
}
@@ -81,9 +80,9 @@ BluetoothDeviceName::BluetoothDeviceName(
version_ =
static_cast<Version>((version_and_pcp_byte & kVersionBitmask) >> 5);
if (version_ != Version::kV1) {
NEARBY_LOG(INFO,
"Cannot deserialize BluetoothDeviceName: unsupported version=%d",
version_);
NEARBY_LOGS(INFO)
<< "Cannot deserialize BluetoothDeviceName: unsupported version="
<< static_cast<int>(version_);
return;
}
// The lower 5 bits are supposed to be the Pcp.
@@ -94,9 +93,9 @@ BluetoothDeviceName::BluetoothDeviceName(
case Pcp::kP2pPointToPoint:
break;
default:
NEARBY_LOG(
INFO, "Cannot deserialize BluetoothDeviceName: unsupported V1 PCP %d",
pcp_);
NEARBY_LOGS(INFO)
<< "Cannot deserialize BluetoothDeviceName: unsupported V1 PCP "
<< static_cast<int>(pcp_);
return;
}
@@ -123,10 +122,10 @@ BluetoothDeviceName::BluetoothDeviceName(
endpoint_info_ = base_input_stream.ReadBytes(expected_endpoint_info_length);
if (endpoint_info_.Empty() ||
endpoint_info_.size() != expected_endpoint_info_length) {
NEARBY_LOG(INFO,
"Cannot deserialize BluetoothDeviceName: expected "
"endpoint info to be %d bytes, got %" PRIu64,
expected_endpoint_info_length, endpoint_info_.size());
NEARBY_LOGS(INFO) << "Cannot deserialize BluetoothDeviceName: expected "
"endpoint info to be "
<< expected_endpoint_info_length << " bytes, got "
<< endpoint_info_.size();
// Clear endpoint_id for validity.
endpoint_id_.clear();
@@ -144,10 +143,10 @@ BluetoothDeviceName::BluetoothDeviceName(
uwb_address_ = base_input_stream.ReadBytes(expected_uwb_address_length);
if (uwb_address_.Empty() ||
uwb_address_.size() != expected_uwb_address_length) {
NEARBY_LOG(INFO,
"Cannot deserialize BluetoothDeviceName: "
"expected uwbAddress size to be %d bytes, got %" PRIu64,
expected_uwb_address_length, uwb_address_.size());
NEARBY_LOGS(INFO) << "Cannot deserialize BluetoothDeviceName: expected "
"uwbAddress size to be "
<< expected_uwb_address_length << " bytes, got "
<< uwb_address_.size();
// Clear endpoint_id for validity.
endpoint_id_.clear();
@@ -179,11 +178,11 @@ BluetoothDeviceName::operator std::string() const {
ByteArray usable_endpoint_info(endpoint_info_);
if (endpoint_info_.size() > kMaxEndpointInfoLength) {
NEARBY_LOG(INFO,
"While serializing Advertisement, truncating Endpoint Name %s "
"(%lu bytes) down to %d bytes",
absl::BytesToHexString(endpoint_info_.data()).c_str(),
endpoint_info_.size(), kMaxEndpointInfoLength);
NEARBY_LOGS(INFO)
<< "While serializing Advertisement, truncating Endpoint Name "
<< absl::BytesToHexString(endpoint_info_.data()) << " ("
<< endpoint_info_.size() << " bytes) down to " << kMaxEndpointInfoLength
<< " bytes";
usable_endpoint_info.SetData(endpoint_info_.data(), kMaxEndpointInfoLength);
}
@@ -351,9 +351,9 @@ TEST_F(EndpointManagerTest, SendControlMessageAndPayloadAckWorks) {
auto failed_ids_2 = em_.SendPayloadAck(header.id(),
std::vector<std::string>{endpoint_id_});
EXPECT_EQ(failed_ids_2, std::vector<std::string>{});
NEARBY_LOG(INFO, "Will unregister endpoint now");
NEARBY_LOGS(INFO) << "Will unregister endpoint now";
em_.UnregisterEndpoint(client_.get(), endpoint_id_);
NEARBY_LOG(INFO, "Will call destructors now");
NEARBY_LOGS(INFO) << "Will call destructors now";
}
TEST_F(EndpointManagerTest, SingleReadOnReadError) {
+10 -10
View File
@@ -87,11 +87,11 @@ TEST_P(BleTest, CanStartAcceptingConnectionsAndConnect) {
BlePeripheral& peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
NEARBY_LOG(INFO,
"Discovered peripheral=%p [impl=%p], fast "
"advertisement=%d.",
&peripheral, &peripheral.GetImpl(),
fast_advertisement);
NEARBY_LOG_OBSOLETE(INFO,
"Discovered peripheral=%p [impl=%p], fast "
"advertisement=%d.",
&peripheral, &peripheral.GetImpl(),
fast_advertisement);
atomic_discovered_peripheral.store(peripheral);
found_latch.CountDown();
},
@@ -139,11 +139,11 @@ TEST_P(BleTest, CanCancelConnect) {
BlePeripheral& peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
NEARBY_LOG(INFO,
"Discovered peripheral=%p [impl=%p], fast "
"advertisement = %d.",
&peripheral, &peripheral.GetImpl(),
fast_advertisement);
NEARBY_LOG_OBSOLETE(INFO,
"Discovered peripheral=%p [impl=%p], fast "
"advertisement = %d.",
&peripheral, &peripheral.GetImpl(),
fast_advertisement);
atomic_discovered_peripheral.store(peripheral);
found_latch.CountDown();
},
@@ -109,9 +109,9 @@ TEST_P(BleV2Test, CanConnect) {
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
discovered_peripheral = peripheral;
NEARBY_LOG(INFO,
"Discovered peripheral=%p, fast advertisement=%d",
&peripheral, fast_advertisement);
NEARBY_LOG_OBSOLETE(
INFO, "Discovered peripheral=%p, fast advertisement=%d",
&peripheral, fast_advertisement);
discovered_latch.CountDown();
},
});
@@ -167,9 +167,9 @@ TEST_P(BleV2Test, CanCancelConnect) {
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
discovered_peripheral = peripheral;
NEARBY_LOG(INFO,
"Discovered peripheral=%p, fast advertisement=%d",
&peripheral, fast_advertisement);
NEARBY_LOG_OBSOLETE(
INFO, "Discovered peripheral=%p, fast advertisement=%d",
&peripheral, fast_advertisement);
discovered_latch.CountDown();
},
});
@@ -268,8 +268,8 @@ TEST_P(BluetoothClassicTest, CanConnect) {
.device_discovered_cb =
[&latch, &discovered_device](BluetoothDevice& device) {
discovered_device = device;
NEARBY_LOG(INFO, "Discovered device=%p [impl=%p]", &device,
&device.GetImpl());
NEARBY_LOG_OBSOLETE(INFO, "Discovered device=%p [impl=%p]",
&device, &device.GetImpl());
latch.CountDown();
},
}));
@@ -317,8 +317,8 @@ TEST_P(BluetoothClassicTest, CanCancelBeforeConnect) {
{
.device_discovered_cb =
[&latch, &discovered_device](BluetoothDevice& device) {
NEARBY_LOG(INFO, "Discovered device=%p [impl=%p]", &device,
&device.GetImpl());
NEARBY_LOG_OBSOLETE(INFO, "Discovered device=%p [impl=%p]",
&device, &device.GetImpl());
discovered_device = device;
latch.CountDown();
},
@@ -384,8 +384,8 @@ TEST_P(BluetoothClassicTest, CanCancelDuringConnect) {
.device_discovered_cb =
[&latch, &discovered_device](BluetoothDevice& device) {
discovered_device = device;
NEARBY_LOG(INFO, "Discovered device=%p [impl=%p]", &device,
&device.GetImpl());
NEARBY_LOG_OBSOLETE(INFO, "Discovered device=%p [impl=%p]",
&device, &device.GetImpl());
latch.CountDown();
},
}));
@@ -449,8 +449,8 @@ TEST_P(BluetoothClassicTest, CanCancelDuringConnect_MultipleEndpoints) {
.device_discovered_cb =
[&latch, &discovered_device](BluetoothDevice& device) {
discovered_device = device;
NEARBY_LOG(INFO, "Discovered device=%p [impl=%p]", &device,
&device.GetImpl());
NEARBY_LOG_OBSOLETE(INFO, "Discovered device=%p [impl=%p]",
&device, &device.GetImpl());
latch.CountDown();
},
}));
@@ -592,22 +592,22 @@ TEST_F(BluetoothClassicTest, CanDiscoverDeviceChanges) {
.device_discovered_cb =
[&discovered_latch, &discovered_device](BluetoothDevice& device) {
discovered_device = device;
NEARBY_LOG(INFO, "Discovered device=%p [impl=%p]", &device,
&device.GetImpl());
NEARBY_LOG_OBSOLETE(INFO, "Discovered device=%p [impl=%p]",
&device, &device.GetImpl());
discovered_latch.CountDown();
},
.device_name_changed_cb =
[&rename_latch, &discovered_device](BluetoothDevice& device) {
discovered_device = device;
NEARBY_LOG(INFO, "Rename device=%p [impl=%p]", &device,
&device.GetImpl());
NEARBY_LOG_OBSOLETE(INFO, "Rename device=%p [impl=%p]", &device,
&device.GetImpl());
rename_latch.CountDown();
},
.device_lost_cb =
[&lost_latch, &discovered_device](BluetoothDevice& device) {
discovered_device = device;
NEARBY_LOG(INFO, "Lost device=%p [impl=%p]", &device,
&device.GetImpl());
NEARBY_LOG_OBSOLETE(INFO, "Lost device=%p [impl=%p]", &device,
&device.GetImpl());
lost_latch.CountDown();
},
}));
@@ -638,8 +638,8 @@ TEST_F(BluetoothClassicTest, CanStartAcceptingConnections) {
.device_discovered_cb =
[&latch, &discovered_device](BluetoothDevice& device) {
discovered_device = device;
NEARBY_LOG(INFO, "Discovered device=%p [impl=%p]", &device,
&device.GetImpl());
NEARBY_LOG_OBSOLETE(INFO, "Discovered device=%p [impl=%p]",
&device, &device.GetImpl());
latch.CountDown();
},
}));
+17 -16
View File
@@ -314,7 +314,8 @@ PayloadManager::PayloadManager(EndpointManager& endpoint_manager)
}
void PayloadManager::CancelAllPayloads() {
NEARBY_LOG(INFO, "PayloadManager: canceling payloads; self=%p", this);
NEARBY_LOG_OBSOLETE(INFO, "PayloadManager: canceling payloads; self=%p",
this);
{
MutexLock lock(&mutex_);
int pending_outgoing_payloads = 0;
@@ -330,9 +331,9 @@ void PayloadManager::CancelAllPayloads() {
}
}
if (shutdown_barrier_) {
NEARBY_LOG(INFO,
"PayloadManager: waiting for pending outgoing payloads; self=%p",
this);
NEARBY_LOG_OBSOLETE(
INFO, "PayloadManager: waiting for pending outgoing payloads; self=%p",
this);
shutdown_barrier_->Await();
}
}
@@ -344,12 +345,12 @@ void PayloadManager::DisconnectFromEndpointManager() {
}
PayloadManager::~PayloadManager() {
NEARBY_LOG(INFO, "PayloadManager: going down; self=%p", this);
NEARBY_LOG_OBSOLETE(INFO, "PayloadManager: going down; self=%p", this);
ThroughputRecorderContainer::GetInstance().Shutdown();
DisconnectFromEndpointManager();
CancelAllPayloads();
NEARBY_LOG(INFO, "PayloadManager: turn down payload executors; self=%p",
this);
NEARBY_LOG_OBSOLETE(
INFO, "PayloadManager: turn down payload executors; self=%p", this);
bytes_payload_executor_.Shutdown();
stream_payload_executor_.Shutdown();
file_payload_executor_.Shutdown();
@@ -360,27 +361,27 @@ PayloadManager::~PayloadManager() {
RunOnStatusUpdateThread(
"~payload-manager",
[this, &stop_latch]() RUN_ON_PAYLOAD_STATUS_UPDATE_THREAD() {
NEARBY_LOG(INFO, "PayloadManager: stop tracking payloads; self=%p",
this);
NEARBY_LOG_OBSOLETE(
INFO, "PayloadManager: stop tracking payloads; self=%p", this);
MutexLock lock(&mutex_);
pending_payloads_.StopTrackingAllPayloads();
stop_latch.CountDown();
});
stop_latch.Await();
NEARBY_LOG(INFO, "PayloadManager: turn down notification executor; self=%p",
this);
NEARBY_LOG_OBSOLETE(
INFO, "PayloadManager: turn down notification executor; self=%p", this);
// Stop all the ongoing Runnables (as gracefully as possible).
payload_status_update_executor_.Shutdown();
NEARBY_LOG(INFO, "PayloadManager: down; self=%p", this);
NEARBY_LOG_OBSOLETE(INFO, "PayloadManager: down; self=%p", this);
}
bool PayloadManager::NotifyShutdown() {
MutexLock lock(&mutex_);
if (!shutdown_.Get()) return false;
if (!shutdown_barrier_) return false;
NEARBY_LOG(INFO, "PayloadManager [shutdown mode]");
NEARBY_LOGS(INFO) << "PayloadManager [shutdown mode]";
shutdown_barrier_->CountDown();
return true;
}
@@ -389,8 +390,8 @@ void PayloadManager::SendPayload(ClientProxy* client,
const EndpointIds& endpoint_ids,
Payload payload) {
if (shutdown_.Get()) return;
NEARBY_LOG(INFO, "SendPayload: endpoint_ids={%s}",
ToString(endpoint_ids).c_str());
NEARBY_LOGS(INFO) << "SendPayload: endpoint_ids={" << ToString(endpoint_ids)
<< "}";
// Before transfer to internal payload, retrieves the Payload size for
// analytics.
std::int64_t payload_total_size;
@@ -662,7 +663,7 @@ PayloadManager::ControlMessageEventToPayloadStatus(
return location::nearby::proto::connections::PayloadStatus::
REMOTE_CANCELLATION;
default:
NEARBY_LOG(INFO, "PayloadManager: unknown event=%d", event);
NEARBY_LOGS(INFO) << "PayloadManager: unknown event=" << event;
return location::nearby::proto::connections::PayloadStatus::
UNKNOWN_PAYLOAD_STATUS;
}
+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
+2 -2
View File
@@ -64,8 +64,8 @@ int GetMask(const DataElement& element) {
return GetActionMask(ActionBit(element.GetValue()[0]));
}
}
NEARBY_LOG(WARNING, "Data Element 0x%x not supported in base advertisement",
type);
NEARBY_LOG_OBSOLETE(
WARNING, "Data Element 0x%x not supported in base advertisement", type);
return kEmptyMask;
}