Internal logging update

PiperOrigin-RevId: 669420403
This commit is contained in:
Guogang Li
2024-08-30 13:08:35 -07:00
committed by Copybara-Service
parent e65a8a568c
commit d5b5d92f87
69 changed files with 617 additions and 724 deletions
+2 -2
View File
@@ -155,7 +155,7 @@ absl::StatusOr<HttpResponse> NearbyHttpClient::InternalGetResponse(
request_stream << std::endl;
request_stream << "body size: " << request.GetBody().GetRawData().size()
<< std::endl;
NEARBY_LOGS(VERBOSE) << request_stream.str();
NEARBY_VLOG(1) << request_stream.str();
}
absl::StatusOr<api::WebResponse> web_response =
@@ -176,7 +176,7 @@ absl::StatusOr<HttpResponse> NearbyHttpClient::InternalGetResponse(
}
response_stream << std::endl;
response_stream << "body size: " << web_response->body.size() << std::endl;
NEARBY_LOGS(VERBOSE) << response_stream.str();
NEARBY_VLOG(1) << response_stream.str();
}
HttpResponse response;
-1
View File
@@ -499,7 +499,6 @@ cc_test(
"crypto_test.cc",
"direct_executor_test.cc",
"future_test.cc",
"logging_test.cc",
"multi_thread_executor_test.cc",
"mutex_test.cc",
"scheduled_executor_test.cc",
+20 -12
View File
@@ -14,6 +14,13 @@
#include "internal/platform/ble.h"
#include <memory>
#include <string>
#include <utility>
#include "internal/platform/bluetooth_adapter.h"
#include "internal/platform/cancellation_flag.h"
#include "internal/platform/implementation/ble.h"
#include "internal/platform/logging.h"
#include "internal/platform/mutex_lock.h"
@@ -62,9 +69,9 @@ bool BleMedium::StartScanning(
if (peripherals_.empty()) return;
auto context = peripherals_.find(&peripheral);
if (context == peripherals_.end()) return;
NEARBY_LOG_OBSOLETE(INFO, "Removing peripheral=%p, impl=%p",
&(context->second->peripheral),
&peripheral);
NEARBY_LOGS(INFO) << "Removing peripheral="
<< context->second->peripheral.GetName()
<< ", impl=" << &peripheral;
discovered_peripheral_callback_.peripheral_lost_cb(
context->second->peripheral, service_id);
},
@@ -76,7 +83,7 @@ bool BleMedium::StopScanning(const std::string& service_id) {
MutexLock lock(&mutex_);
discovered_peripheral_callback_ = {};
peripherals_.clear();
NEARBY_LOG_OBSOLETE(INFO, "Ble Scanning disabled: impl=%p", &GetImpl());
NEARBY_LOGS(INFO) << "Ble Scanning disabled: impl=" << &GetImpl();
}
return impl_->StopScanning(service_id);
}
@@ -95,12 +102,12 @@ bool BleMedium::StartAcceptingConnections(const std::string& service_id,
&socket, std::make_unique<AcceptedConnectionInfo>());
auto& context = *pair.first->second;
if (!pair.second) {
NEARBY_LOG_OBSOLETE(INFO, "Accepting (again) socket=%p, impl=%p",
&context.socket, &socket);
NEARBY_LOGS(INFO) << "Accepting (again) socket=" << &context.socket
<< ", impl=" << &socket;
} else {
context.socket = BleSocket(&socket);
NEARBY_LOG_OBSOLETE(INFO, "Accepting socket=%p, impl=%p",
&context.socket, &socket);
NEARBY_LOGS(INFO)
<< "Accepting socket=" << &context.socket << ", impl=" << &socket;
}
if (accepted_connection_callback_) {
accepted_connection_callback_(context.socket, service_id);
@@ -113,8 +120,8 @@ bool BleMedium::StopAcceptingConnections(const std::string& service_id) {
MutexLock lock(&mutex_);
accepted_connection_callback_ = nullptr;
sockets_.clear();
NEARBY_LOG_OBSOLETE(INFO, "Ble accepted connection disabled: impl=%p",
&GetImpl());
NEARBY_LOGS(INFO) << "Ble accepted connection disabled: impl="
<< &GetImpl();
}
return impl_->StopAcceptingConnections(service_id);
}
@@ -124,8 +131,9 @@ BleSocket BleMedium::Connect(BlePeripheral& peripheral,
CancellationFlag* cancellation_flag) {
{
MutexLock lock(&mutex_);
NEARBY_LOG_OBSOLETE(INFO, "BleMedium::Connect: peripheral=%p [impl=%p]",
&peripheral, &peripheral.GetImpl());
NEARBY_LOGS(INFO) << "BleMedium::Connect: peripheral="
<< peripheral.GetName()
<< ",impl=" << &peripheral.GetImpl();
}
return BleSocket(
impl_->Connect(peripheral.GetImpl(), service_id, cancellation_flag));
+16 -16
View File
@@ -15,10 +15,14 @@
#include "internal/platform/ble.h"
#include <memory>
#include <string>
#include "gmock/gmock.h"
#include "protobuf-matchers/protocol-buffer-matchers.h"
#include "gtest/gtest.h"
#include "internal/platform/bluetooth_adapter.h"
#include "internal/platform/byte_array.h"
#include "internal/platform/cancellation_flag.h"
#include "internal/platform/count_down_latch.h"
#include "internal/platform/logging.h"
#include "internal/platform/medium_environment.h"
@@ -74,11 +78,10 @@ TEST_P(BleMediumTest, CanStartAcceptingConnectionsAndConnect) {
BlePeripheral& peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
NEARBY_LOG_OBSOLETE(
INFO,
"Peripheral discovered: %s, %p, fast advertisement: %d",
peripheral.GetName().c_str(), &peripheral,
fast_advertisement);
NEARBY_LOGS(INFO)
<< "Discovered peripheral=" << peripheral.GetName()
<< ", impl=" << &peripheral.GetImpl()
<< ", fast advertisement=" << fast_advertisement;
discovered_peripheral = &peripheral;
found_latch.CountDown();
},
@@ -87,9 +90,8 @@ TEST_P(BleMediumTest, CanStartAcceptingConnectionsAndConnect) {
fast_advertisement_service_uuid);
ble_b.StartAcceptingConnections(
service_id, [&](BleSocket socket, const std::string& service_id) {
NEARBY_LOG_OBSOLETE(INFO,
"Connection accepted: socket=%p, service_id=%s",
&socket, service_id.c_str());
NEARBY_LOGS(INFO) << "Connection accepted: socket=" << &socket
<< ", service_id=" << service_id;
accepted_latch.CountDown();
});
EXPECT_TRUE(found_latch.Await(kWaitDuration).result());
@@ -134,11 +136,10 @@ TEST_P(BleMediumTest, CanCancelConnect) {
BlePeripheral& peripheral, const std::string& service_id,
const ByteArray& advertisement_bytes,
bool fast_advertisement) {
NEARBY_LOG_OBSOLETE(
INFO,
"Peripheral discovered: %s, %p, fast advertisement: %d",
peripheral.GetName().c_str(), &peripheral,
fast_advertisement);
NEARBY_LOGS(INFO)
<< "Discovered peripheral=" << peripheral.GetName()
<< ", impl=" << &peripheral.GetImpl()
<< ", fast advertisement=" << fast_advertisement;
discovered_peripheral = &peripheral;
found_latch.CountDown();
},
@@ -147,9 +148,8 @@ TEST_P(BleMediumTest, CanCancelConnect) {
fast_advertisement_service_uuid);
ble_b.StartAcceptingConnections(
service_id, [&](BleSocket socket, const std::string& service_id) {
NEARBY_LOG_OBSOLETE(INFO,
"Connection accepted: socket=%p, service_id=%s",
&socket, service_id.c_str());
NEARBY_LOGS(INFO) << "Connection accepted: socket=" << &socket
<< ", service_id=" << service_id;
accepted_latch.CountDown();
});
EXPECT_TRUE(found_latch.Await(kWaitDuration).result());
+4 -3
View File
@@ -22,6 +22,7 @@
#include "internal/platform/implementation/ble_v2.h"
#include "internal/platform/logging.h"
#include "internal/platform/mutex_lock.h"
#include "internal/platform/uuid.h"
namespace nearby {
@@ -91,7 +92,7 @@ bool BleV2Medium::StartScanning(const Uuid& service_uuid,
// prevent the stale data in cache.
peripherals_.clear();
scanning_enabled_ = true;
NEARBY_LOG_OBSOLETE(INFO, "Ble Scanning enabled; impl=%p", GetImpl());
NEARBY_LOGS(INFO) << "Ble Scanning enabled; impl=" << GetImpl();
}
return success;
}
@@ -106,7 +107,7 @@ bool BleV2Medium::StopScanning() {
scanning_enabled_ = false;
peripherals_.clear();
scan_callback_ = {};
NEARBY_LOG_OBSOLETE(INFO, "Ble Scanning disabled: impl=%p", GetImpl());
NEARBY_LOGS(INFO) << "Ble Scanning disabled: impl=" << GetImpl();
return impl_->StopScanning();
}
@@ -114,7 +115,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_OBSOLETE(INFO, "platform mutex: %p", &mutex_);
NEARBY_LOGS(INFO) << "platform mutex: " << &mutex_;
return impl_->StartScanning(
service_uuid, tx_power_level,
api::ble_v2::BleMedium::ScanningCallback{
+1 -2
View File
@@ -50,8 +50,7 @@ void BlockingQueueStream::Write(const ByteArray& bytes) {
is_writing_ = true;
blocking_queue_.Put(bytes);
is_writing_ = false;
NEARBY_LOGS(VERBOSE) << "BlockingQueueStream wrote " << bytes.size()
<< " bytes";
NEARBY_VLOG(1) << "BlockingQueueStream wrote " << bytes.size() << " bytes";
}
Exception BlockingQueueStream::Close() {
+44 -41
View File
@@ -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);
+14 -15
View File
@@ -21,6 +21,7 @@
#include "absl/functional/any_invocable.h"
#include "absl/log/check.h"
#include "absl/strings/escaping.h"
#include "absl/synchronization/mutex.h"
#include "internal/platform/byte_array.h"
#include "internal/platform/cancellation_flag.h"
@@ -142,10 +143,11 @@ bool BleMedium::StartAdvertising(
const std::string& service_id, const ByteArray& advertisement_bytes,
const std::string& fast_advertisement_service_uuid) {
NEARBY_LOGS(INFO) << "G3 Ble StartAdvertising: service_id=" << service_id
<< ", advertisement bytes=" << advertisement_bytes.data()
<< ", advertisement bytes="
<< absl::BytesToHexString(std::string(advertisement_bytes))
<< "(" << advertisement_bytes.size() << "),"
<< " fast advertisement service uuid="
<< fast_advertisement_service_uuid;
<< ", fast advertisement service uuid="
<< absl::BytesToHexString(fast_advertisement_service_uuid);
auto& env = MediumEnvironment::Instance();
auto& peripheral = adapter_->GetPeripheral();
peripheral.SetAdvertisementBytes(service_id, advertisement_bytes);
@@ -261,11 +263,10 @@ 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_OBSOLETE(
INFO,
"G3 Ble Connect [self]: medium=%p, adapter=%p, peripheral=%p, "
"service_id=%s",
this, &GetAdapter(), &GetAdapter().GetPeripheral(), service_id.c_str());
NEARBY_LOGS(INFO) << "G3 Ble Connect [self]: medium=" << this
<< ", adapter=" << &GetAdapter()
<< ", peripheral=" << &GetAdapter().GetPeripheral()
<< ", service_id=" << service_id;
// 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,11 +274,10 @@ std::unique_ptr<api::BleSocket> BleMedium::Connect(
if (!medium) return {}; // Can't find medium. Bail out.
BleServerSocket* remote_server_socket = nullptr;
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());
NEARBY_LOGS(INFO) << "G3 Ble Connect [peer]: medium=" << medium
<< ", adapter=" << &adapter
<< ", peripheral=" << &remote_peripheral
<< ", service_id=" << service_id;
// Then, find our server socket context in this medium.
{
absl::MutexLock medium_lock(&medium->mutex_);
@@ -312,8 +312,7 @@ std::unique_ptr<api::BleSocket> BleMedium::Connect(
return {};
}
NEARBY_LOG_OBSOLETE(INFO, "G3 Ble Connect: connected: socket=%p",
socket.get());
NEARBY_LOGS(INFO) << "G3 Ble Connect: connected: socket=" << socket.get();
return socket;
}
@@ -148,9 +148,9 @@ bool BleGattClient::DiscoverServiceAndCharacteristics(
absl::StrAppend(out, std::string(uuid));
});
NEARBY_LOGS(VERBOSE) << __func__ << ": Discover service_uuid="
<< std::string(service_uuid)
<< " with characteristic_uuids=" << flat_characteristics;
NEARBY_VLOG(1) << __func__
<< ": Discover service_uuid=" << std::string(service_uuid)
<< " with characteristic_uuids=" << flat_characteristics;
try {
if (ble_device_ == nullptr) {
@@ -208,8 +208,7 @@ bool BleGattClient::DiscoverServiceAndCharacteristics(
winrt::guid uuid = service.Uuid();
std::string uuid_string = winrt::to_string(winrt::to_hstring(uuid));
NEARBY_LOGS(VERBOSE) << __func__
<< ": Found service UUID=" << uuid_string;
NEARBY_VLOG(1) << __func__ << ": Found service UUID=" << uuid_string;
if (!is_nearby_uuid_equal_to_winrt_guid(service_uuid, uuid)) {
NEARBY_LOGS(WARNING)
<< __func__
@@ -239,8 +238,8 @@ bool BleGattClient::DiscoverServiceAndCharacteristics(
gatt_characteristic.Uuid())));
});
NEARBY_LOGS(VERBOSE) << __func__ << ": Found GATT characteristics="
<< flat_characteristics;
NEARBY_VLOG(1) << __func__
<< ": Found GATT characteristics=" << flat_characteristics;
bool found_all = true;
@@ -270,7 +269,7 @@ bool BleGattClient::DiscoverServiceAndCharacteristics(
}
// found all characteristics.
NEARBY_LOGS(VERBOSE) << __func__ << ": Found all characteristics.";
NEARBY_VLOG(1) << __func__ << ": Found all characteristics.";
return true;
}
@@ -294,9 +293,9 @@ absl::optional<api::ble_v2::GattCharacteristic>
BleGattClient::GetCharacteristic(const Uuid& service_uuid,
const Uuid& characteristic_uuid) {
absl::MutexLock lock(&mutex_);
NEARBY_LOGS(VERBOSE) << __func__ << ": Stared to get characteristic UUID="
<< std::string(characteristic_uuid)
<< " in service UUID=" << std::string(service_uuid);
NEARBY_VLOG(1) << __func__ << ": Stared to get characteristic UUID="
<< std::string(characteristic_uuid)
<< " in service UUID=" << std::string(service_uuid);
try {
std::optional<GattCharacteristic> gatt_characteristic =
GetNativeCharacteristic(service_uuid, characteristic_uuid);
@@ -341,8 +340,8 @@ BleGattClient::GetCharacteristic(const Uuid& service_uuid,
native_characteristic_map_[result].native_characteristic =
gatt_characteristic;
NEARBY_LOGS(VERBOSE) << __func__ << ": Return Characteristic. uuid="
<< std::string(characteristic_uuid);
NEARBY_VLOG(1) << __func__ << ": Return Characteristic. uuid="
<< std::string(characteristic_uuid);
return result;
} catch (std::exception exception) {
@@ -361,8 +360,8 @@ BleGattClient::GetCharacteristic(const Uuid& service_uuid,
absl::optional<std::string> BleGattClient::ReadCharacteristic(
const api::ble_v2::GattCharacteristic& characteristic) {
absl::MutexLock lock(&mutex_);
NEARBY_LOGS(VERBOSE) << __func__ << ": Read characteristic="
<< std::string(characteristic.uuid);
NEARBY_VLOG(1) << __func__ << ": Read characteristic="
<< std::string(characteristic.uuid);
try {
std::optional<GattCharacteristic> gatt_characteristic =
GetNativeCharacteristic(characteristic.service_uuid,
@@ -397,8 +396,8 @@ absl::optional<std::string> BleGattClient::ReadCharacteristic(
data.push_back(static_cast<char>(data_reader.ReadByte()));
}
NEARBY_LOGS(VERBOSE) << __func__
<< ": Got characteristic value length=" << data.size();
NEARBY_VLOG(1) << __func__
<< ": Got characteristic value length=" << data.size();
return data;
} catch (std::exception exception) {
@@ -418,8 +417,8 @@ bool BleGattClient::WriteCharacteristic(
const api::ble_v2::GattCharacteristic& characteristic,
absl::string_view value, api::ble_v2::GattClient::WriteType write_type) {
absl::MutexLock lock(&mutex_);
NEARBY_LOGS(VERBOSE) << __func__ << ": write characteristic: "
<< std::string(characteristic.uuid);
NEARBY_VLOG(1) << __func__ << ": write characteristic: "
<< std::string(characteristic.uuid);
try {
std::optional<GattCharacteristic> gatt_characteristic =
native_characteristic_map_[characteristic].native_characteristic;
@@ -449,10 +448,9 @@ bool BleGattClient::WriteCharacteristic(
<< GattCommunicationStatusToString(status);
return false;
} else {
NEARBY_LOGS(VERBOSE) << __func__
<< ": Write data to GATT characteristic: "
<< std::string(characteristic.uuid)
<< ", bytes count: " << value.size();
NEARBY_VLOG(1) << __func__ << ": Write data to GATT characteristic: "
<< std::string(characteristic.uuid)
<< ", bytes count: " << value.size();
return true;
}
} catch (std::exception exception) {
@@ -473,8 +471,7 @@ bool BleGattClient::SetCharacteristicSubscription(
absl::AnyInvocable<void(absl::string_view value)>
on_characteristic_changed_cb) {
absl::MutexLock lock(&mutex_);
NEARBY_LOGS(VERBOSE) << __func__
<< ": Started to set Characteristic Subscription.";
NEARBY_VLOG(1) << __func__ << ": Started to set Characteristic Subscription.";
GattClientCharacteristicConfigurationDescriptorValue gcccd_value =
GattClientCharacteristicConfigurationDescriptorValue::None;
if ((characteristic.property & Property::kNotify) != Property::kNone) {
@@ -552,7 +549,7 @@ bool BleGattClient::SetCharacteristicSubscription(
void BleGattClient::Disconnect() {
absl::MutexLock lock(&mutex_);
try {
NEARBY_LOGS(VERBOSE) << __func__ << ": Disconnect is called.";
NEARBY_VLOG(1) << __func__ << ": Disconnect is called.";
if (ble_device_ != nullptr) {
ble_device_.Close();
ble_device_ = nullptr;
@@ -571,10 +568,9 @@ void BleGattClient::Disconnect() {
std::optional<GattCharacteristic> BleGattClient::GetNativeCharacteristic(
const Uuid& service_uuid, const Uuid& characteristic_uuid) {
NEARBY_LOGS(VERBOSE) << __func__
<< ": Stared to get native characteristic UUID="
<< std::string(characteristic_uuid)
<< " in service UUID=" << std::string(service_uuid);
NEARBY_VLOG(1) << __func__ << ": Stared to get native characteristic UUID="
<< std::string(characteristic_uuid)
<< " in service UUID=" << std::string(service_uuid);
try {
if (ble_device_ == nullptr) {
@@ -604,9 +600,9 @@ std::optional<GattCharacteristic> BleGattClient::GetNativeCharacteristic(
gatt_characteristics_result.Characteristics()) {
if (is_nearby_uuid_equal_to_winrt_guid(characteristic_uuid,
characteristic.Uuid())) {
NEARBY_LOGS(VERBOSE)
<< __func__ << ": Return native Characteristic. uuid="
<< std::string(characteristic_uuid);
NEARBY_VLOG(1) << __func__
<< ": Return native Characteristic. uuid="
<< std::string(characteristic_uuid);
return characteristic;
}
@@ -632,9 +628,8 @@ std::optional<GattCharacteristic> BleGattClient::GetNativeCharacteristic(
bool BleGattClient::WriteCharacteristicConfigurationDescriptor(
GattCharacteristic& characteristic,
GattClientCharacteristicConfigurationDescriptorValue value) {
NEARBY_LOGS(VERBOSE)
<< __func__
<< ": Stared to write characteristic configuration descriptor";
NEARBY_VLOG(1) << __func__
<< ": Stared to write characteristic configuration descriptor";
try {
GattCommunicationStatus status =
@@ -642,9 +637,9 @@ bool BleGattClient::WriteCharacteristicConfigurationDescriptor(
.WriteClientCharacteristicConfigurationDescriptorAsync(value)
.get();
if (status == GattCommunicationStatus::Success) {
NEARBY_LOGS(VERBOSE) << __func__
<< ": Successfully write client characteristic "
"configuration descriptor";
NEARBY_VLOG(1) << __func__
<< ": Successfully write client characteristic "
"configuration descriptor";
return true;
}
NEARBY_LOGS(ERROR) << __func__
@@ -670,7 +665,7 @@ bool BleGattClient::WriteCharacteristicConfigurationDescriptor(
void BleGattClient::OnCharacteristicValueChanged(
const api::ble_v2::GattCharacteristic& characteristic,
GattValueChangedEventArgs args) {
NEARBY_LOGS(VERBOSE) << __func__ << ": Gatt Characteristic value changed.";
NEARBY_VLOG(1) << __func__ << ": Gatt Characteristic value changed.";
IBuffer buffer = args.CharacteristicValue();
int size = buffer.Length();
DataReader data_reader = DataReader::FromBuffer(buffer);
@@ -679,8 +674,8 @@ void BleGattClient::OnCharacteristicValueChanged(
for (int i = 0; i < size; ++i) {
data.push_back(static_cast<char>(data_reader.ReadByte()));
}
NEARBY_LOGS(VERBOSE) << __func__
<< ": Got characteristic value length= " << data.size();
NEARBY_VLOG(1) << __func__
<< ": Got characteristic value length= " << data.size();
absl::AnyInvocable<void(absl::string_view value)>
on_characteristic_changed_cb;
@@ -167,8 +167,7 @@ bool BleGattServer::UpdateCharacteristic(
for (auto& it : gatt_characteristic_datas_) {
if (it.gatt_characteristic.uuid == characteristic.uuid) {
NEARBY_LOGS(VERBOSE) << __func__
<< ": Found the characteristic to update.";
NEARBY_VLOG(1) << __func__ << ": Found the characteristic to update.";
it.data = value;
// If it is in running, notify the value changed.
@@ -201,8 +200,8 @@ absl::Status BleGattServer::NotifyCharacteristicChanged(
const ByteArray& new_value) {
absl::MutexLock lock(&mutex_);
// Currently, the method is not hooked up at platform layer.
NEARBY_LOGS(VERBOSE) << __func__ << ": Notify characteristic="
<< std::string(characteristic.uuid) << " changed.";
NEARBY_VLOG(1) << __func__ << ": Notify characteristic="
<< std::string(characteristic.uuid) << " changed.";
return absl::OkStatus();
}
@@ -210,7 +209,7 @@ void BleGattServer::Stop() {
absl::AnyInvocable<void()> close_notifier = nullptr;
{
absl::MutexLock lock(&mutex_);
NEARBY_LOGS(VERBOSE) << __func__ << ": Start to stop GATT server.";
NEARBY_VLOG(1) << __func__ << ": Start to stop GATT server.";
if (gatt_service_provider_ != nullptr) {
try {
if (is_advertising_) {
@@ -242,8 +241,8 @@ void BleGattServer::Stop() {
bool BleGattServer::InitializeGattServer() {
try {
// Create and advertise GATT service.
NEARBY_LOGS(VERBOSE) << __func__ << ": Create GATT service service_uuid="
<< std::string(service_uuid_);
NEARBY_VLOG(1) << __func__ << ": Create GATT service service_uuid="
<< std::string(service_uuid_);
if (adapter_ == nullptr) {
NEARBY_LOGS(ERROR) << __func__ << ": Bluetooth adapter is absent.";
@@ -320,12 +319,10 @@ bool BleGattServer::InitializeGattServer() {
is_notify_supported = true;
}
NEARBY_LOGS(VERBOSE) << __func__
<< ": GATT characteristic properties: read="
<< is_read_supported
<< ",write=" << is_write_supported
<< ",indicate=" << is_indicate_supported
<< ",notify=" << is_notify_supported;
NEARBY_VLOG(1) << __func__ << ": GATT characteristic properties: read="
<< is_read_supported << ",write=" << is_write_supported
<< ",indicate=" << is_indicate_supported
<< ",notify=" << is_notify_supported;
gatt_characteristic_parameters.CharacteristicProperties(properties);
gatt_characteristic_parameters.WriteProtectionLevel(
@@ -334,10 +331,10 @@ bool BleGattServer::InitializeGattServer() {
winrt::guid characteristic_uuid = nearby_uuid_to_winrt_guid(
characteristic_data.gatt_characteristic.uuid);
NEARBY_LOGS(VERBOSE) << __func__
<< ": Create characteristic characteristic_uuid="
<< winrt::to_string(
winrt::to_hstring(characteristic_uuid));
NEARBY_VLOG(1) << __func__
<< ": Create characteristic characteristic_uuid="
<< winrt::to_string(
winrt::to_hstring(characteristic_uuid));
GattLocalCharacteristicResult result =
gatt_service_provider_.Service()
@@ -356,9 +353,9 @@ bool BleGattServer::InitializeGattServer() {
::winrt::guid local_characteristic_guid =
characteristic_data.local_characteristic.Uuid();
NEARBY_LOGS(VERBOSE) << __func__ << ": Local GATT characteristic. uuid: "
<< winrt::to_string(
winrt::to_hstring(local_characteristic_guid));
NEARBY_VLOG(1) << __func__ << ": Local GATT characteristic. uuid: "
<< winrt::to_string(
winrt::to_hstring(local_characteristic_guid));
// Setup gatt local characteristic events.
if (is_read_supported) {
@@ -408,9 +405,9 @@ bool BleGattServer::StartAdvertisement(const ByteArray& service_data,
absl::MutexLock lock(&mutex_);
try {
NEARBY_LOGS(VERBOSE) << __func__ << ": service_data="
<< absl::BytesToHexString(service_data.AsStringView())
<< ", is_connectable=" << is_connectable;
NEARBY_VLOG(1) << __func__ << ": service_data="
<< absl::BytesToHexString(service_data.AsStringView())
<< ", is_connectable=" << is_connectable;
if (is_advertising_) {
NEARBY_LOGS(ERROR) << ": GATT server is already in advertising.";
@@ -567,7 +564,7 @@ void BleGattServer::SetCloseNotifier(absl::AnyInvocable<void()> notifier) {
request.RespondWithValue(buffer);
deferral.Complete();
NEARBY_LOGS(VERBOSE) << __func__ << ": Sent data to remote device.";
NEARBY_VLOG(1) << __func__ << ": Sent data to remote device.";
return {};
} catch (std::exception exception) {
NEARBY_LOGS(ERROR) << __func__ << ": Exception: " << exception.what();
@@ -600,11 +600,11 @@ void BleMedium::AdvertisementReceivedHandler(
ByteArray advertisement_data(data);
NEARBY_LOGS(VERBOSE) << "Nearby BLE Medium Advertisement discovered. "
"0x16 Service data: advertisement bytes= 0x"
<< absl::BytesToHexString(
advertisement_data.AsStringView())
<< "(" << advertisement_data.size() << ")";
NEARBY_VLOG(1) << "Nearby BLE Medium Advertisement discovered. "
"0x16 Service data: advertisement bytes= 0x"
<< absl::BytesToHexString(
advertisement_data.AsStringView())
<< "(" << advertisement_data.size() << ")";
std::string peripheral_name =
uint64_to_mac_address_string(args.BluetoothAddress());
@@ -1085,13 +1085,12 @@ void BleV2Medium::AdvertisementReceivedHandler(
ByteArray advertisement_data(data);
NEARBY_LOGS(VERBOSE) << "Nearby BLE Medium "
<< service_uuid_.Get16BitAsString()
<< " Advertisement discovered. "
"0x16 Service data: advertisement bytes= 0x"
<< absl::BytesToHexString(
advertisement_data.AsStringView())
<< "(" << advertisement_data.size() << ")";
NEARBY_VLOG(1) << "Nearby BLE Medium " << service_uuid_.Get16BitAsString()
<< " Advertisement discovered. "
"0x16 Service data: advertisement bytes= 0x"
<< absl::BytesToHexString(
advertisement_data.AsStringView())
<< "(" << advertisement_data.size() << ")";
std::string bluetooth_address =
uint64_to_mac_address_string(args.BluetoothAddress());
@@ -40,26 +40,26 @@ api::ble_v2::BlePeripheral* BleV2Socket::GetRemotePeripheral() {
bool BleV2Socket::Connect(api::ble_v2::BlePeripheral* ble_peripheral) {
// TODO(b/271031645): implement BLE socket using weave
NEARBY_LOGS(VERBOSE) << __func__ << ": Connect to BLE peripheral="
<< ble_peripheral->GetAddress();
NEARBY_VLOG(1) << __func__ << ": Connect to BLE peripheral="
<< ble_peripheral->GetAddress();
return false;
}
ExceptionOr<ByteArray> BleV2Socket::BleInputStream::Read(std::int64_t size) {
// TODO(b/271031645): implement BLE socket using weave
NEARBY_LOGS(VERBOSE) << __func__ << ": Read data size=" << size;
NEARBY_VLOG(1) << __func__ << ": Read data size=" << size;
return ExceptionOr<ByteArray>(Exception::kIo);
}
Exception BleV2Socket::BleInputStream::Close() {
// TODO(b/271031645): implement BLE socket using weave
NEARBY_LOGS(VERBOSE) << __func__ << ": Close BLE input stream.";
NEARBY_VLOG(1) << __func__ << ": Close BLE input stream.";
return {Exception::kSuccess};
}
Exception BleV2Socket::BleOutputStream::Write(const ByteArray& data) {
// TODO(b/271031645): implement BLE socket using weave
NEARBY_LOGS(VERBOSE) << __func__ << ": Write data size=" << data.size();
NEARBY_VLOG(1) << __func__ << ": Write data size=" << data.size();
return {Exception::kIo};
}
@@ -40,6 +40,7 @@
#include "absl/strings/str_format.h"
#include "third_party/json/src/json.hpp"
#include "internal/platform/feature_flags.h"
#include "internal/platform/implementation/platform.h"
#include "internal/platform/implementation/windows/generated/winrt/Windows.Foundation.h"
#include "internal/platform/implementation/windows/utils.h"
#include "internal/platform/logging.h"
@@ -347,8 +348,8 @@ void BluetoothAdapter::RestoreRadioNameIfNecessary() {
return;
}
NEARBY_LOGS(VERBOSE) << __func__
<< ": loaded settings: " << local_settings.dump();
NEARBY_VLOG(1) << __func__
<< ": loaded settings: " << local_settings.dump();
LocalSettings settings = local_settings.get<LocalSettings>();
@@ -391,8 +392,8 @@ void BluetoothAdapter::StoreRadioNames(absl::string_view original_radio_name,
json encoded_local_settings;
to_json(encoded_local_settings, local_settings);
NEARBY_LOGS(VERBOSE) << __func__ << ": saved settings: "
<< encoded_local_settings.dump();
NEARBY_VLOG(1) << __func__
<< ": saved settings: " << encoded_local_settings.dump();
ByteArray data(encoded_local_settings.dump());
@@ -345,8 +345,8 @@ std::unique_ptr<api::BluetoothSocket> BluetoothClassicMedium::ConnectToService(
std::unique_ptr<api::BluetoothPairing> BluetoothClassicMedium::CreatePairing(
api::BluetoothDevice& remote_device) {
NEARBY_LOGS(VERBOSE) << __func__ << ": Start to createPairing with device: "
<< remote_device.GetMacAddress();
NEARBY_VLOG(1) << __func__ << ": Start to createPairing with device: "
<< remote_device.GetMacAddress();
try {
winrt::Windows::Devices::Bluetooth::BluetoothDevice bluetooth_device =
winrt::Windows::Devices::Bluetooth::BluetoothDevice::
@@ -360,8 +360,8 @@ std::unique_ptr<api::BluetoothPairing> BluetoothClassicMedium::CreatePairing(
return std::make_unique<BluetoothPairing>(bluetooth_device,
custom_pairing);
}
NEARBY_LOGS(VERBOSE) << __func__
<< ": Failed to get DeviceInformationCustomPairing.";
NEARBY_VLOG(1) << __func__
<< ": Failed to get DeviceInformationCustomPairing.";
} catch (std::exception exception) {
NEARBY_LOGS(ERROR) << __func__ << " : Failed to create pairing. exception: "
<< exception.what();
@@ -54,8 +54,7 @@ BluetoothPairing::BluetoothPairing(
BluetoothDevice bluetooth_device,
DeviceInformationCustomPairing custom_pairing)
: bluetooth_device_(bluetooth_device), custom_pairing_(custom_pairing) {
NEARBY_LOGS(VERBOSE) << __func__
<< ": BluetoothPairing is created for device.";
NEARBY_VLOG(1) << __func__ << ": BluetoothPairing is created for device.";
}
BluetoothPairing::~BluetoothPairing() {
@@ -64,19 +63,17 @@ BluetoothPairing::~BluetoothPairing() {
std::exchange(pairing_requested_token_, {}));
}
CancelPairing();
NEARBY_LOGS(VERBOSE) << __func__
<< ": BluetoothPairing is destroyed for device.";
NEARBY_VLOG(1) << __func__ << ": BluetoothPairing is destroyed for device.";
}
bool BluetoothPairing::InitiatePairing(
api::BluetoothPairingCallback pairing_cb) {
NEARBY_LOGS(VERBOSE) << __func__ << ": Start to initiate pairing process.";
NEARBY_VLOG(1) << __func__ << ": Start to initiate pairing process.";
try {
pairing_requested_token_ = custom_pairing_.PairingRequested(
{this, &BluetoothPairing::OnPairingRequested});
if (!pairing_requested_token_) {
NEARBY_LOGS(VERBOSE) << __func__
<< " Failed to registered pairing callback.";
NEARBY_VLOG(1) << __func__ << " Failed to registered pairing callback.";
return false;
}
pairing_callback_ = std::move(pairing_cb);
@@ -107,14 +104,14 @@ bool BluetoothPairing::InitiatePairing(
bool BluetoothPairing::FinishPairing(
std::optional<absl::string_view> pin_code) {
NEARBY_LOGS(VERBOSE) << __func__ << "Start to finish pairing.";
NEARBY_VLOG(1) << __func__ << "Start to finish pairing.";
try {
if (!pairing_requested_) {
NEARBY_LOGS(VERBOSE) << __func__ << "No pairing requested.";
NEARBY_VLOG(1) << __func__ << "No pairing requested.";
return false;
}
if (!pairing_deferral_) {
NEARBY_LOGS(VERBOSE) << __func__ << "No ongoing pairing process.";
NEARBY_VLOG(1) << __func__ << "No ongoing pairing process.";
return false;
}
if (expecting_pin_code_) {
@@ -129,7 +126,7 @@ bool BluetoothPairing::FinishPairing(
pairing_requested_.Accept();
}
pairing_deferral_.Complete();
NEARBY_LOGS(VERBOSE) << "Successfully finished pairing.";
NEARBY_VLOG(1) << "Successfully finished pairing.";
return true;
} catch (std::exception exception) {
NEARBY_LOGS(ERROR) << __func__ << ": Failed to finish pairing. exception: "
@@ -146,11 +143,10 @@ bool BluetoothPairing::FinishPairing(
}
bool BluetoothPairing::CancelPairing() {
NEARBY_LOGS(VERBOSE) << __func__
<< " Start to cancel ongoing pairing process.";
NEARBY_VLOG(1) << __func__ << " Start to cancel ongoing pairing process.";
try {
if (!pairing_deferral_) {
NEARBY_LOGS(VERBOSE) << __func__ << "No ongoing pairing process.";
NEARBY_VLOG(1) << __func__ << "No ongoing pairing process.";
return true;
}
// There is no way to explicitly cancel an in-progress pairing on Windows as
@@ -161,7 +157,7 @@ bool BluetoothPairing::CancelPairing() {
// deferral is completed, will know that cancellation was the actual result.
was_cancelled_ = true;
pairing_deferral_.Close();
NEARBY_LOGS(VERBOSE) << __func__ << "Canceled ongoing pairing process.";
NEARBY_VLOG(1) << __func__ << "Canceled ongoing pairing process.";
return true;
} catch (std::exception exception) {
NEARBY_LOGS(ERROR) << __func__ << ": Failed to cancel ongoing pairing "
@@ -178,20 +174,19 @@ bool BluetoothPairing::CancelPairing() {
}
bool BluetoothPairing::Unpair() {
NEARBY_LOGS(VERBOSE) << __func__ << ": Start to unpair with remote device.";
NEARBY_VLOG(1) << __func__ << ": Start to unpair with remote device.";
try {
if (!IsPaired()) {
NEARBY_LOGS(VERBOSE) << __func__ << " : Remote device Was not paired.";
NEARBY_VLOG(1) << __func__ << " : Remote device Was not paired.";
return true;
}
DeviceUnpairingResult unpairing_result =
bluetooth_device_.DeviceInformation().Pairing().UnpairAsync().get();
if (unpairing_result.Status() == DeviceUnpairingResultStatus::Unpaired) {
NEARBY_LOGS(VERBOSE) << __func__ << ": Unpaired with remote device.";
NEARBY_VLOG(1) << __func__ << ": Unpaired with remote device.";
return true;
}
NEARBY_LOGS(VERBOSE) << __func__
<< ": Failed to unpaired with remote device.";
NEARBY_VLOG(1) << __func__ << ": Failed to unpaired with remote device.";
} catch (std::exception exception) {
NEARBY_LOGS(ERROR) << __func__
<< ": Failed to unpaired with device. exception: "
@@ -229,7 +224,7 @@ bool BluetoothPairing::IsPaired() {
void BluetoothPairing::OnPairingRequested(
DeviceInformationCustomPairing custom_pairing,
DevicePairingRequestedEventArgs pairing_requested) {
NEARBY_LOGS(VERBOSE) << __func__ << "Requested to pair.";
NEARBY_VLOG(1) << __func__ << "Requested to pair.";
try {
DevicePairingKinds pairing_kind = pairing_requested.PairingKind();
pairing_requested_ = pairing_requested;
@@ -32,8 +32,8 @@ Executor::Executor(int32_t max_concurrency)
void Executor::Execute(Runnable&& runnable) {
if (shut_down_) {
NEARBY_LOGS(VERBOSE) << "Warning: " << __func__
<< ": Attempt to execute on a shut down pool.";
NEARBY_VLOG(1) << "Warning: " << __func__
<< ": Attempt to execute on a shut down pool.";
return;
}
@@ -25,7 +25,7 @@
namespace nearby {
namespace windows {
api::LogMessage::Severity min_log_severity_ = api::LogMessage::Severity::kInfo;
api::LogMessage::Severity g_min_log_severity = api::LogMessage::Severity::kInfo;
inline absl::LogSeverity ConvertSeverity(api::LogMessage::Severity severity) {
switch (severity) {
@@ -65,11 +65,11 @@ std::ostream& LogMessage::Stream() { return log_streamer_.stream(); }
namespace api {
void LogMessage::SetMinLogSeverity(Severity severity) {
windows::min_log_severity_ = severity;
windows::g_min_log_severity = severity;
}
bool LogMessage::ShouldCreateLogMessage(Severity severity) {
return severity >= windows::min_log_severity_;
return severity >= windows::g_min_log_severity;
}
} // namespace api
} // namespace nearby
@@ -36,7 +36,6 @@ class LogMessage : public api::LogMessage {
private:
google::LogMessage log_streamer_;
static api::LogMessage::Severity min_log_severity_;
};
} // namespace windows
@@ -25,6 +25,7 @@
#include "nlohmann/json.hpp"
#include "nlohmann/json_fwd.hpp"
#include "internal/base/files.h"
#include "internal/platform/implementation/platform.h"
#include "internal/platform/implementation/windows/preferences_repository.h"
#include "internal/platform/logging.h"
@@ -83,13 +83,12 @@ ThreadPool::ThreadPool(PTP_POOL thread_pool,
: thread_pool_(thread_pool),
thread_pool_environ_(thread_pool_environ),
max_pool_size_(max_pool_size) {
NEARBY_LOGS(VERBOSE) << __func__ << ": Thread pool(" << this
<< ") is created with size:" << max_pool_size_;
NEARBY_VLOG(1) << __func__ << ": Thread pool(" << this
<< ") is created with size:" << max_pool_size_;
}
ThreadPool::~ThreadPool() {
NEARBY_LOGS(VERBOSE) << __func__ << ": Thread pool(" << this
<< ") is released.";
NEARBY_VLOG(1) << __func__ << ": Thread pool(" << this << ") is released.";
if (thread_pool_ == nullptr) {
return;
@@ -112,8 +111,8 @@ bool ThreadPool::Run(Runnable task) {
PTP_WORK work;
tasks_.push(std::move(task));
NEARBY_LOGS(VERBOSE) << __func__ << ": Scheduled to run task("
<< &tasks_.back() << ").";
NEARBY_VLOG(1) << __func__ << ": Scheduled to run task(" << &tasks_.back()
<< ").";
work = CreateThreadpoolWork(WorkCallback, this, &thread_pool_environ_);
if (work == nullptr) {
@@ -146,19 +145,19 @@ void ThreadPool::ShutDown() {
if (running_tasks_count_ == 0) {
CloseThreadpool(thread_pool_);
thread_pool_ = nullptr;
NEARBY_LOGS(VERBOSE) << __func__ << ": Thread pool(" << this
<< ") is shut down.";
NEARBY_VLOG(1) << __func__ << ": Thread pool(" << this
<< ") is shut down.";
return;
}
if (shutdown_latch_ != nullptr) {
NEARBY_LOGS(VERBOSE) << __func__ << ": Thread pool(" << this
<< ") is already in shutting down.";
NEARBY_VLOG(1) << __func__ << ": Thread pool(" << this
<< ") is already in shutting down.";
return;
}
NEARBY_LOGS(VERBOSE) << __func__ << ": Thread pool(" << this
<< ") is shutting down.";
NEARBY_VLOG(1) << __func__ << ": Thread pool(" << this
<< ") is shutting down.";
shutdown_latch_ = std::make_unique<CountDownLatch>(1);
}
@@ -170,8 +169,7 @@ void ThreadPool::ShutDown() {
absl::MutexLock lock(&mutex_);
CloseThreadpool(thread_pool_);
thread_pool_ = nullptr;
NEARBY_LOGS(VERBOSE) << __func__ << ": Thread pool(" << this
<< ") is shut down.";
NEARBY_VLOG(1) << __func__ << ": Thread pool(" << this << ") is shut down.";
}
}
@@ -185,8 +183,7 @@ void ThreadPool::RunNextTask() {
return;
}
if (!tasks_.empty()) {
NEARBY_LOGS(VERBOSE) << __func__ << ": Run task(" << &tasks_.front()
<< ").";
NEARBY_VLOG(1) << __func__ << ": Run task(" << &tasks_.front() << ").";
task = std::move(tasks_.front());
tasks_.pop();
@@ -15,18 +15,20 @@
#include "internal/platform/implementation/windows/utils.h"
#include <windows.h>
#include <winsock2.h>
// Standard C/C++ headers
#include <codecvt>
#include <cstddef>
#include <cstdint>
#include <exception>
#include <locale>
#include <stdexcept>
#include <string>
#include <vector>
// Third party headers
#include "absl/strings/ascii.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
// Nearby connections headers
@@ -182,8 +184,8 @@ Uuid winrt_guid_to_nearby_uuid(const ::winrt::guid& guid) {
int64_t data3 = guid.Data3;
int64_t msb = ((data1 >> 24) & 0xff) << 56 | ((data1 >> 16) & 0xff) << 48 |
((data1 >> 8) & 0xff) << 40 | ((data1)&0xff) << 32 |
((data2 >> 8) & 0xff) << 24 | ((data2)&0xff) << 16 |
((data1 >> 8) & 0xff) << 40 | ((data1) & 0xff) << 32 |
((data2 >> 8) & 0xff) << 24 | ((data2) & 0xff) << 16 |
((data3 >> 8) & 0xff) << 8 | (data3 & 0xff);
int64_t lsb =
@@ -215,7 +217,7 @@ winrt::guid nearby_uuid_to_winrt_guid(Uuid uuid) {
}
bool is_nearby_uuid_equal_to_winrt_guid(const Uuid& uuid,
const ::winrt::guid& guid) {
const ::winrt::guid& guid) {
return uuid == winrt_guid_to_nearby_uuid(guid);
}
@@ -242,7 +244,7 @@ bool InspectableReader::ReadBoolean(IInspectable inspectable) {
return property_value.GetBoolean();
}
uint16 InspectableReader::ReadUint16(IInspectable inspectable) {
uint16_t InspectableReader::ReadUint16(IInspectable inspectable) {
if (inspectable == nullptr) {
return 0;
}
@@ -260,7 +262,7 @@ uint16 InspectableReader::ReadUint16(IInspectable inspectable) {
return property_value.GetUInt16();
}
uint32 InspectableReader::ReadUint32(IInspectable inspectable) {
uint32_t InspectableReader::ReadUint32(IInspectable inspectable) {
if (inspectable == nullptr) {
return 0;
}
@@ -316,7 +318,7 @@ std::vector<std::string> InspectableReader::ReadStringArray(
winrt::com_array<winrt::hstring> strings;
property_value.GetStringArray(strings);
for (winrt::hstring str : strings) {
for (const winrt::hstring& str : strings) {
result.push_back(winrt::to_string(str));
}
return result;
@@ -60,8 +60,7 @@ const std::string WebRtcMedium::GetDefaultCountryCode() {
}
std::wstring wideGeo(systemGeoName);
std::string systemGeoNameString(wideGeo.begin(), wideGeo.end());
NEARBY_LOGS(VERBOSE) << "GetUserDefaultGeoName() returns: "
<< systemGeoNameString;
NEARBY_VLOG(1) << "GetUserDefaultGeoName() returns: " << systemGeoNameString;
return systemGeoNameString;
}
@@ -281,7 +281,6 @@ void WifiHotspotServerSocket::SocketErrorNotice(absl::string_view reason) {
bool WifiHotspotServerSocket::SetupServerSocketWinSock() {
WSADATA wsa_data;
WSAEVENT socket_event;
int flag = 1;
int result = WSAStartup(MAKEWORD(2, 2), &wsa_data);
@@ -347,7 +346,7 @@ bool WifiHotspotServerSocket::SetupServerSocketWinSock() {
return false;
}
NEARBY_LOGS(INFO) << "Hotspot Server Socket " << listen_socket_
<< " started to listen with socket event: " << socket_event;
<< " started to listen.";
submittable_executor_.Execute([this]() {
DWORD index;
@@ -116,11 +116,11 @@ DEVINST SearchForDeviceInstance(wchar_t* pEntireDeviceList);
void CloseRegKeyHandle(HKEY softwareKey); // NOLINT
void OpenRegKeyHandle(DEVINST devInst, HKEY& softwareKey);
DWORD GetRegKeyWCHARValue(DEVINST deviceInstance, LPCWSTR keyName, // NOLINT
wchar_t* valOut, PDWORD pValLen, // NOLINT
PDWORD pDataType); // NOLINT
wchar_t* valOut, PDWORD pValLen, // NOLINT
PDWORD pDataType); // NOLINT
DWORD GetFullDllLoadPathFromPieRegistry(DEVINST pieDeviceInstance,
PWCHAR* ppDllPathValue); // NOLINT
HADAPTER WifiGetAdapterList(HINSTANCE murocApiDllHandle, // NOLINT
HADAPTER WifiGetAdapterList(HINSTANCE murocApiDllHandle, // NOLINT
PINTEL_ADAPTER_LIST_V120* ppAllAdapters);
void RegisterIntelCallback(HINSTANCE murocApiDllHandle,
MurocDefs::PINTEL_CALLBACK pIntelEventCbHandle);
@@ -185,7 +185,7 @@ int WifiIntel::GetGOChannel() {
nullptr;
int channel = -1;
DWORD dwError = ERROR_SUCCESS; // NOLINT
DWORD dwError = ERROR_SUCCESS; // NOLINT
MUROC_RET murocApiRetVal = IWLAN_E_FAILURE; // NOLINT
INTEL_WIFI_HEADER intelWifiHeader;
MurocDefs::INTEL_GO_OPERATION_CHANNEL_SETTING intelGOChan;
@@ -194,8 +194,7 @@ int WifiIntel::GetGOChannel() {
WifiPanQueryPreferredChannelSettingFunc =
(WIFIPANQUERYPREFERREDCHANNELSETTING)GetProcAddress( // NOLINT
muroc_api_dll_handle_,
"WifiPanQueryPreferredChannelSetting");
muroc_api_dll_handle_, "WifiPanQueryPreferredChannelSetting");
if (WifiPanQueryPreferredChannelSettingFunc == nullptr) {
dwError = GetLastError(); // NOLINT
@@ -204,7 +203,7 @@ int WifiIntel::GetGOChannel() {
<< dwError;
return channel;
}
NEARBY_LOGS(VERBOSE)
NEARBY_VLOG(1)
<< "Load WifiPanQueryPreferredChannelSetting API completed successfully";
intelWifiHeader.dwSize =
@@ -236,9 +235,8 @@ int WifiIntel::GetGOChannel() {
bool WifiIntel::SetScanFilter(int channel) {
#ifndef NO_INTEL_PIE
WIFILEGACYGOSETSCANFILTER WifiLegacyGoSetScanFilterFunc =
nullptr;
DWORD dwError = ERROR_SUCCESS; // NOLINT
WIFILEGACYGOSETSCANFILTER WifiLegacyGoSetScanFilterFunc = nullptr;
DWORD dwError = ERROR_SUCCESS; // NOLINT
MUROC_RET murocApiRetVal = IWLAN_E_FAILURE; // NOLINT
INTEL_WIFI_HEADER intelWifiHeader;
MurocDefs::WIFI_LEGACY_GO_SCAN_FILTER scanFilter;
@@ -249,21 +247,18 @@ bool WifiIntel::SetScanFilter(int channel) {
NEARBY_LOGS(INFO) << "Set scan channel:" << channel;
WifiLegacyGoSetScanFilterFunc =
(WIFILEGACYGOSETSCANFILTER)GetProcAddress( // NOLINT
muroc_api_dll_handle_,
"WifiLegacyGoSetScanFilter");
muroc_api_dll_handle_, "WifiLegacyGoSetScanFilter");
if (WifiLegacyGoSetScanFilterFunc == nullptr) {
dwError = GetLastError(); // NOLINT
NEARBY_LOGS(INFO)
<< "GetProcAddress WifiLegacyGoSetScanFilterFunc error: "
<< dwError;
NEARBY_LOGS(INFO) << "GetProcAddress WifiLegacyGoSetScanFilterFunc error: "
<< dwError;
return false;
}
NEARBY_LOGS(VERBOSE)
NEARBY_VLOG(1)
<< "Load WifiLegacyGoSetScanFilterFunc API completed successfully";
intelWifiHeader.dwSize =
sizeof(MurocDefs::WIFI_LEGACY_GO_SCAN_FILTER);
intelWifiHeader.dwSize = sizeof(MurocDefs::WIFI_LEGACY_GO_SCAN_FILTER);
memset(&scanFilter, 0, sizeof(scanFilter));
scanFilter.channel = (UINT8)channel;
murocApiRetVal = WifiLegacyGoSetScanFilterFunc(
@@ -288,9 +283,8 @@ bool WifiIntel::SetScanFilter(int channel) {
bool WifiIntel::ResetScanFilter() {
#ifndef NO_INTEL_PIE
WIFIPANRESETLEGACYGOSCANFILTER WifiPanReSetLegacyGoScanFilterFunc =
nullptr;
DWORD dwError = ERROR_SUCCESS; // NOLINT
WIFIPANRESETLEGACYGOSCANFILTER WifiPanReSetLegacyGoScanFilterFunc = nullptr;
DWORD dwError = ERROR_SUCCESS; // NOLINT
MUROC_RET murocApiRetVal = IWLAN_E_FAILURE; // NOLINT
INTEL_WIFI_HEADER intelWifiHeader;
@@ -298,8 +292,7 @@ bool WifiIntel::ResetScanFilter() {
WifiPanReSetLegacyGoScanFilterFunc =
(WIFIPANRESETLEGACYGOSCANFILTER)GetProcAddress( // NOLINT
muroc_api_dll_handle_,
"WifiPanReSetLegacyGoScanFilter");
muroc_api_dll_handle_, "WifiPanReSetLegacyGoScanFilter");
if (WifiPanReSetLegacyGoScanFilterFunc == nullptr) {
dwError = GetLastError(); // NOLINT
@@ -308,11 +301,11 @@ bool WifiIntel::ResetScanFilter() {
<< dwError;
return false;
}
NEARBY_LOGS(VERBOSE)
NEARBY_VLOG(1)
<< "Load WifiPanReSetLegacyGoScanFilterFunc API completed successfully";
intelWifiHeader.dwSize = 0;
murocApiRetVal = WifiPanReSetLegacyGoScanFilterFunc(
wifi_adapter_handle_, &intelWifiHeader);
murocApiRetVal = WifiPanReSetLegacyGoScanFilterFunc(wifi_adapter_handle_,
&intelWifiHeader);
if (murocApiRetVal == IWLAN_E_SUCCESS) { // NOLINT
NEARBY_LOGS(INFO) << "Calling WifiPanReSetLegacyGoScanFilter API succeeded";
@@ -385,8 +378,7 @@ bool IsHwIdMatching(DEVINST devInst, const wchar_t* expecedHwId) {
// Compare to given HW ID
wchar_t* pdest = wcsstr(currentDeviceHwId, expecedHwId); // NOLINT
if (nullptr != pdest) {
std::wcout << "wifi_intel.cc"
<< ":" << __LINE__
std::wcout << "wifi_intel.cc" << ":" << __LINE__
<< "] Intel WIFI hwId is found: " << expecedHwId << std::endl;
isHwIdFound = true;
}
@@ -442,10 +434,10 @@ void OpenRegKeyHandle(DEVINST devInst, HKEY& softwareKey) {
if (devInst != NULL) {
// opens a registry key for device-specific configuration information.
configRet = CM_Open_DevNode_Key(devInst, KEY_READ, 0, // NOLINT
RegDisposition_OpenExisting,
&softwareKey, CM_REGISTRY_SOFTWARE);
RegDisposition_OpenExisting, &softwareKey,
CM_REGISTRY_SOFTWARE);
NEARBY_LOGS(VERBOSE) << absl::StrFormat("softwareKey %p ", softwareKey);
NEARBY_VLOG(1) << absl::StrFormat("softwareKey %p ", softwareKey);
if (configRet != CR_SUCCESS) {
NEARBY_LOGS(INFO)
@@ -493,11 +485,11 @@ DWORD GetFullDllLoadPathFromPieRegistry(DEVINST pieDeviceInstance,
<< "Unexpected error! GetRegKeyWCHARValue return Value of " << status;
return status;
} else {
NEARBY_LOGS(VERBOSE) << "Queried key length successfully!";
NEARBY_VLOG(1) << "Queried key length successfully!";
}
dllFullPathLen = (dllPathBufferLen + sizeof(PIE_API_DLL));
NEARBY_LOGS(VERBOSE) << "dll Full Path Length = " << dllFullPathLen;
NEARBY_VLOG(1) << "dll Full Path Length = " << dllFullPathLen;
pLoadPathString = new wchar_t[dllFullPathLen];
SecureZeroMemory(pLoadPathString, dllFullPathLen); // NOLINT
@@ -513,15 +505,14 @@ DWORD GetFullDllLoadPathFromPieRegistry(DEVINST pieDeviceInstance,
return status;
} else {
pathString = pLoadPathString;
NEARBY_LOGS(VERBOSE) << "Queried key successfully!";
NEARBY_VLOG(1) << "Queried key successfully!";
}
std::wstring fullString = pathString + PIE_API_DLL;
wcscpy_s(pLoadPathString, dllFullPathLen, fullString.c_str()); // NOLINT
std::wcout << "wifi_intel.cc"
<< ":" << __LINE__
std::wcout << "wifi_intel.cc" << ":" << __LINE__
<< "] PIE Dll Path and Name = " << pLoadPathString << std::endl;
if (ppDllPathValue != nullptr) {
@@ -551,8 +542,8 @@ HINSTANCE WifiIntel::PIEDllLoader() {
// load the library and get the handle
murocApiDllHandle = LoadLibraryW(pDllPathValue); // NOLINT
NEARBY_LOGS(VERBOSE) << absl::StrFormat("Muroc Api Dll Handle is 0x%p ",
murocApiDllHandle);
NEARBY_VLOG(1) << absl::StrFormat("Muroc Api Dll Handle is 0x%p ",
murocApiDllHandle);
} else {
NEARBY_LOGS(INFO) << "GetFullDllLoadPathFromPieRegistry fails eith error: "
<< ret;
@@ -581,8 +572,8 @@ HADAPTER WifiGetAdapterList(HINSTANCE murocApiDllHandle,
return INVALID_HADAPTER;
}
NEARBY_LOGS(VERBOSE) << "GetProcAddress for WifiGetAdapterListFunction API "
"completed successfully";
NEARBY_VLOG(1) << "GetProcAddress for WifiGetAdapterListFunction API "
"completed successfully";
INTEL_WIFI_HEADER intelHeader = {INTEL_STRUCT_VERSION_V156, // NOLINT
sizeof(MurocDefs::INTEL_ADAPTER_LIST_V120)};
MUROC_RET murocApiRetVal = IWLAN_E_FAILURE;
@@ -619,7 +610,7 @@ void RegisterIntelCallback(
return;
}
NEARBY_LOGS(VERBOSE) << "Load RegisterIntelCallback API successfully";
NEARBY_VLOG(1) << "Load RegisterIntelCallback API successfully";
MUROC_RET murocApiRetVal = IWLAN_E_FAILURE;
murocApiRetVal = registerIntelCBFunc(pIntelEventCbHandle);
@@ -649,13 +640,13 @@ void DeregisterIntelCallback(HINSTANCE murocApiDllHandle,
}
{
NEARBY_LOGS(VERBOSE) << "Load DeregisterIntelCallback API successfully";
NEARBY_VLOG(1) << "Load DeregisterIntelCallback API successfully";
MUROC_RET murocApiRetVal = IWLAN_E_FAILURE;
murocApiRetVal = deregisterIntelCBFunc(fnCallback);
if (murocApiRetVal == IWLAN_E_SUCCESS) {
NEARBY_LOGS(VERBOSE) << "Calling DeregisterIntelCallback API succeeded.";
NEARBY_VLOG(1) << "Calling DeregisterIntelCallback API succeeded.";
} else {
NEARBY_LOGS(INFO)
<< "Calling DeregisterIntelCallback API fails with error:"
@@ -683,13 +674,13 @@ void FreeMemoryList(HINSTANCE murocApiDllHandle, void* ptr) {
}
if ((freeMemoryListFunction != nullptr)) {
NEARBY_LOGS(VERBOSE) << "Load FreeListMemory API successfully";
NEARBY_VLOG(1) << "Load FreeListMemory API successfully";
MUROC_RET murocApiRetVal = IWLAN_E_FAILURE;
murocApiRetVal = freeMemoryListFunction(ptr);
if (murocApiRetVal == IWLAN_E_SUCCESS) {
NEARBY_LOGS(VERBOSE) << "Calling FreeListMemory API succeeded.";
NEARBY_VLOG(1) << "Calling FreeListMemory API succeeded.";
} else {
NEARBY_LOGS(INFO) << "Calling FreeListMemory API failed with error: "
<< murocApiRetVal;
+13 -80
View File
@@ -1,4 +1,4 @@
// Copyright 2020 Google LLC
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -15,91 +15,24 @@
#ifndef PLATFORM_BASE_LOGGING_H_
#define PLATFORM_BASE_LOGGING_H_
// base/logging.h is only included to allow logging clients to include CHECK's.
// In Chrome this is base/check.h. See crbug/1212611.
#ifdef NEARBY_CHROMIUM
#if defined(NEARBY_CHROMIUM)
// Chromium does not use absl log. Forward to Chromium native log macros.
#include "base/check.h"
// base/logging.h is available externally as "glog". However, this repo contains
// template files that can't be built by Swift Package Manager. To build with
// SPM we only need CHECK and DCHECK defined.
#elif defined(NEARBY_SWIFTPM)
#include <sstream>
#define CHECK(condition) static_cast<void>(0), condition ? (void) 0 : abort()
#define DCHECK(condition) static_cast<void>(0), (void) 0
#define CHECK_GT(a, b) static_cast<void>(0), a > b ? (void) 0 : abort()
#define DCHECK_GT(a, b) static_cast<void>(0), a > b ? (void) 0 : abort()
#define CHECK_LE(a, b) static_cast<void>(0), a <= b ? (void) 0 : abort()
#define DCHECK_LE(a, b) static_cast<void>(0), a <= b ? (void) 0 : abort()
#define CHECK_NE(a, b) static_cast<void>(0), a != b ? (void) 0 : abort()
#define DCHECK_NE(a, b) static_cast<void>(0), a != b ? (void) 0 : abort()
#define CHECK_EQ(a, b) static_cast<void>(0), a == b ? (void) 0 : abort()
#define DCHECK_EQ(a, b) static_cast<void>(0), a == b ? (void) 0 : abort()
#define CHECK_GE(a, b) static_cast<void>(0), a >= b ? (void) 0 : abort()
#define DCHECK_GE(a, b) static_cast<void>(0), a >= b ? (void) 0 : abort()
#else
#include "base/check_op.h"
#include "glog/logging.h"
#else // defined(NEARBY_CHROMIUM)
// IWYU pragma: begin_exports
#include "absl/log/check.h" // nogncheck
#include "absl/log/log.h" // nogncheck
#include "absl/log/log.h" // nogncheck
// IWYU pragma: end_exports
#endif
#include "internal/platform/implementation/log_message.h"
#include "internal/platform/implementation/platform.h"
namespace nearby {
// This class is used to explicitly ignore values in the conditional
// logging macros. This avoids compiler warnings like "value computed
// is not used" and "statement has no effect".
class LogMessageVoidify {
public:
LogMessageVoidify() = default;
// This has to be an operator with a precedence lower than << but
// higher than ?:
void operator&(std::ostream&) {}
};
} // namespace nearby
// Severity enum conversion
#define NEARBY_SEVERITY_VERBOSE nearby::api::LogMessage::Severity::kVerbose
#define NEARBY_SEVERITY_INFO nearby::api::LogMessage::Severity::kInfo
#define NEARBY_SEVERITY_WARNING nearby::api::LogMessage::Severity::kWarning
#define NEARBY_SEVERITY_ERROR nearby::api::LogMessage::Severity::kError
#define NEARBY_SEVERITY_FATAL nearby::api::LogMessage::Severity::kFatal
#if defined(_WIN32)
// wingdi.h defines ERROR to be 0. When we call LOG(ERROR), it gets substituted
// with 0, and it expands to NEARBY_SEVERITY_0. To allow us to keep using this
// syntax, we define this macro to do the same thing as NEARBY_SEVERITY_ERROR.
#define NEARBY_SEVERITY_0 nearby::api::LogMessage::Severity::kError
#endif // defined(_WIN32)
#define NEARBY_SEVERITY(severity) NEARBY_SEVERITY_##severity
// Log enabling
#define NEARBY_LOG_IS_ON(severity) \
nearby::api::LogMessage::ShouldCreateLogMessage(NEARBY_SEVERITY(severity))
#define NEARBY_LOG_SET_SEVERITY(severity) \
nearby::api::LogMessage::SetMinLogSeverity(NEARBY_SEVERITY(severity))
// Log message creation
#define NEARBY_LOG_MESSAGE(severity) \
nearby::api::ImplementationPlatform::CreateLogMessage( \
__FILE__, __LINE__, NEARBY_SEVERITY(severity))
#endif // defined(NEARBY_CHROMIUM)
// Public APIs
// The stream statement must come last or otherwise it won't compile.
#define NEARBY_LOGS(severity) \
!(NEARBY_LOG_IS_ON(severity)) \
? (void)0 \
: nearby::LogMessageVoidify() & NEARBY_LOG_MESSAGE(severity)->Stream()
// The stream statement must come last, or it won't compile.
#define NEARBY_VLOG(level) VLOG(level)
#define NEARBY_LOGS(severity) 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
#ifdef NEARBY_SWIFTPM
#define LOG(severity) NEARBY_LOGS(severity)
#endif
#define NEARBY_DLOG(severity) DLOG(severity)
#define NEARBY_DVLOG(severity) DVLOG(severity)
#endif // PLATFORM_BASE_LOGGING_H_
-53
View File
@@ -1,53 +0,0 @@
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "internal/platform/logging.h"
#include "gmock/gmock.h"
#include "protobuf-matchers/protocol-buffer-matchers.h"
#include "gtest/gtest.h"
namespace {
TEST(LoggingTest, CanLog) {
NEARBY_LOG_SET_SEVERITY(INFO);
int num = 42;
NEARBY_LOGS(INFO) << "The answer to everything: " << num++;
EXPECT_EQ(num, 43);
}
TEST(LoggingTest, CanLog_LoggingDisabled) {
NEARBY_LOG_SET_SEVERITY(ERROR);
int num = 42;
NEARBY_LOGS(INFO) << "The answer to everything: " << num++;
// num++ should not be evaluated
EXPECT_EQ(num, 42);
}
TEST(LoggingTest, CanStream) {
NEARBY_LOG_SET_SEVERITY(INFO);
int num = 42;
NEARBY_LOGS(INFO) << "The answer to everything: " << num++;
EXPECT_EQ(num, 43);
}
TEST(LoggingTest, CanStream_LoggingDisabled) {
NEARBY_LOG_SET_SEVERITY(ERROR);
int num = 42;
NEARBY_LOGS(INFO) << "The answer to everything: " << num++;
// num++ should not be evaluated
EXPECT_EQ(num, 42);
}
} // namespace
+6 -4
View File
@@ -24,6 +24,7 @@
#include "absl/container/flat_hash_set.h"
#include "absl/status/status.h"
#include "absl/strings/escaping.h"
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
#include "absl/time/time.h"
@@ -180,7 +181,7 @@ void MediumEnvironment::OnBluetoothDeviceStateChanged(
// Store device name, and report it as discovered.
info.devices.emplace(&device, name);
if (enable_notifications_) {
NEARBY_LOGS(VERBOSE) << "Notify about new discovered device";
NEARBY_VLOG(1) << "Notify about new discovered device";
info.callback.device_discovered_cb(device);
for (auto& observer : observers_.GetObservers()) {
observer->DeviceAdded(device);
@@ -204,7 +205,7 @@ void MediumEnvironment::OnBluetoothDeviceStateChanged(
} else {
// Device is in discovery mode, so we are reporting it anyway.
if (enable_notifications_) {
NEARBY_LOGS(VERBOSE) << "Notify about existing discovered device";
NEARBY_VLOG(1) << "Notify about existing discovered device";
info.callback.device_discovered_cb(device);
for (auto& observer : observers_.GetObservers()) {
observer->DeviceAdded(device);
@@ -216,7 +217,7 @@ void MediumEnvironment::OnBluetoothDeviceStateChanged(
// Known device is turned off.
// Erase it from the map, and report as lost.
if (enable_notifications_) {
NEARBY_LOGS(VERBOSE) << "Notify about removed device";
NEARBY_VLOG(1) << "Notify about removed device";
info.callback.device_lost_cb(device);
for (auto& observer : observers_.GetObservers()) {
observer->DeviceRemoved(device);
@@ -530,7 +531,8 @@ void MediumEnvironment::UpdateBleMediumForScanning(
<< "; medium=" << &medium
<< "; service_id=" << service_id
<< "; fast_advertisement_service_uuid="
<< fast_advertisement_service_uuid
<< absl::BytesToHexString(
fast_advertisement_service_uuid)
<< "; enabled=" << enabled;
for (auto& medium_info : ble_mediums_) {
auto& local_medium = medium_info.first;
+1 -1
View File
@@ -139,7 +139,7 @@ void BaseSocket::WritePacket(absl::StatusOr<Packet> packet) {
NEARBY_LOGS(WARNING) << "Packet status:" << packet.status();
return;
}
CHECK(packet->SetPacketCounter(packet_counter_generator_.Next()).ok());
CHECK_OK(packet->SetPacketCounter(packet_counter_generator_.Next()));
NEARBY_LOGS(INFO) << "transmitting packet";
connection_.Transmit(packet->GetBytes());
}
+4
View File
@@ -20,7 +20,11 @@
#include <utility>
#include "absl/base/thread_annotations.h"
#include "internal/platform/byte_array.h"
#include "internal/platform/future.h"
#include "internal/platform/logging.h"
#include "internal/platform/mutex.h"
#include "internal/platform/runnable.h"
#include "internal/platform/single_thread_executor.h"
#include "internal/weave/connection.h"
#include "internal/weave/control_packet_write_request.h"
@@ -18,6 +18,7 @@
#include <utility>
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "internal/weave/packet.h"
namespace nearby {
+1
View File
@@ -22,6 +22,7 @@
#include <vector>
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
#include "internal/platform/byte_array.h"
+2
View File
@@ -15,11 +15,13 @@
#ifndef THIRD_PARTY_NEARBY_INTERNAL_WEAVE_PACKET_H_
#define THIRD_PARTY_NEARBY_INTERNAL_WEAVE_PACKET_H_
#include <cstdint>
#include <string>
#include <utility>
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/string_view.h"
#include "internal/platform/byte_array.h"
namespace nearby {
+1
View File
@@ -31,6 +31,7 @@ cc_library(
"//internal/weave",
"@com_google_absl//absl/random",
"@com_google_absl//absl/status",
"@com_google_absl//absl/strings",
],
)
+5
View File
@@ -14,12 +14,17 @@
#include "internal/weave/sockets/client_socket.h"
#include <cstdint>
#include <memory>
#include <string>
#include <utility>
#include "absl/status/status.h"
#include "absl/strings/str_cat.h"
#include "internal/platform/logging.h"
#include "internal/weave/base_socket.h"
#include "internal/weave/connection.h"
#include "internal/weave/packet.h"
#include "internal/weave/socket_callback.h"
#include "internal/weave/sockets/initial_data_provider.h"
+2
View File
@@ -17,8 +17,10 @@
#include <memory>
#include "internal/platform/single_thread_executor.h"
#include "internal/weave/base_socket.h"
#include "internal/weave/connection.h"
#include "internal/weave/packet.h"
#include "internal/weave/socket_callback.h"
#include "internal/weave/sockets/initial_data_provider.h"
@@ -15,9 +15,12 @@
#ifndef THIRD_PARTY_NEARBY_INTERNAL_WEAVE_SOCKETS_INITIAL_DATA_PROVIDER_H_
#define THIRD_PARTY_NEARBY_INTERNAL_WEAVE_SOCKETS_INITIAL_DATA_PROVIDER_H_
#include <cmath>
#include <cstdint>
#include <string>
#include "absl/random/random.h"
#include "absl/strings/str_cat.h"
namespace nearby {
namespace weave {
+4
View File
@@ -20,8 +20,12 @@
#include <utility>
#include "absl/status/status.h"
#include "absl/strings/string_view.h"
#include "internal/platform/logging.h"
#include "internal/weave/base_socket.h"
#include "internal/weave/connection.h"
#include "internal/weave/packet.h"
#include "internal/weave/socket_callback.h"
namespace nearby {
namespace weave {
+1 -2
View File
@@ -15,10 +15,9 @@
#ifndef THIRD_PARTY_NEARBY_INTERNAL_WEAVE_SOCKETS_SERVER_SOCKET_H_
#define THIRD_PARTY_NEARBY_INTERNAL_WEAVE_SOCKETS_SERVER_SOCKET_H_
#include <memory>
#include "internal/weave/base_socket.h"
#include "internal/weave/connection.h"
#include "internal/weave/packet.h"
#include "internal/weave/socket_callback.h"
namespace nearby {