mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Replace some C like syntax and add missing include files.
PiperOrigin-RevId: 401541156
This commit is contained in:
committed by
Copybara-Service
parent
8259c92b37
commit
686351c4c3
@@ -59,11 +59,11 @@ std::function<void()> MakeDataPump(
|
||||
std::string label, InputStream* input, OutputStream* output,
|
||||
std::function<void(const ByteArray&)> monitor = nullptr) {
|
||||
return [label, input, output, monitor]() {
|
||||
NEARBY_LOG(INFO, "streaming data thorough '%s'", label.c_str());
|
||||
NEARBY_LOGS(INFO) << "streaming data through '" << label << "'";
|
||||
while (true) {
|
||||
auto read_response = input->Read(Pipe::kChunkSize);
|
||||
if (!read_response.ok()) {
|
||||
NEARBY_LOG(INFO, "Peer reader closed on '%s'", label.c_str());
|
||||
NEARBY_LOGS(INFO) << "Peer reader closed on '" << label << "'";
|
||||
output->Close();
|
||||
break;
|
||||
}
|
||||
@@ -72,12 +72,12 @@ std::function<void()> MakeDataPump(
|
||||
}
|
||||
auto write_response = output->Write(read_response.result());
|
||||
if (write_response.Raised()) {
|
||||
NEARBY_LOG(INFO, "Peer writer closed on '%s'", label.c_str());
|
||||
NEARBY_LOGS(INFO) << "Peer writer closed on '" << label << "'";
|
||||
input->Close();
|
||||
break;
|
||||
}
|
||||
}
|
||||
NEARBY_LOG(INFO, "streaming terminated on '%s'", label.c_str());
|
||||
NEARBY_LOGS(INFO) << "streaming terminated on '" << label << "'";
|
||||
};
|
||||
}
|
||||
|
||||
@@ -90,7 +90,8 @@ std::function<void(const ByteArray&)> MakeDataMonitor(const std::string& label,
|
||||
absl::MutexLock lock(mutex);
|
||||
*capture += s;
|
||||
}
|
||||
NEARBY_LOG(INFO, "source='%s'; message='%s'", label.c_str(), s.c_str());
|
||||
NEARBY_LOGS(INFO) << "source='" << label << "'"
|
||||
<< "; message='" << s << "'";
|
||||
};
|
||||
}
|
||||
|
||||
@@ -114,7 +115,7 @@ DoDhKeyExchange(BaseEndpointChannel* channel_a,
|
||||
std::unique_ptr<securegcm::UKey2Handshake> ukey2,
|
||||
const std::string& auth_token,
|
||||
const ByteArray& raw_auth_token) {
|
||||
NEARBY_LOG(INFO, "client-A side key negotiation done");
|
||||
NEARBY_LOGS(INFO) << "client-A side key negotiation done";
|
||||
EXPECT_TRUE(ukey2->VerifyHandshake());
|
||||
auto context = ukey2->ToConnectionContext();
|
||||
EXPECT_NE(context, nullptr);
|
||||
@@ -124,7 +125,7 @@ DoDhKeyExchange(BaseEndpointChannel* channel_a,
|
||||
.on_failure_cb =
|
||||
[&latch](const std::string& endpoint_id,
|
||||
EndpointChannel* channel) {
|
||||
NEARBY_LOG(INFO, "client-A side key negotiation failed");
|
||||
NEARBY_LOGS(INFO) << "client-A side key negotiation failed";
|
||||
latch.CountDown();
|
||||
},
|
||||
});
|
||||
@@ -137,7 +138,7 @@ DoDhKeyExchange(BaseEndpointChannel* channel_a,
|
||||
std::unique_ptr<securegcm::UKey2Handshake> ukey2,
|
||||
const std::string& auth_token,
|
||||
const ByteArray& raw_auth_token) {
|
||||
NEARBY_LOG(INFO, "client-B side key negotiation done");
|
||||
NEARBY_LOGS(INFO) << "client-B side key negotiation done";
|
||||
EXPECT_TRUE(ukey2->VerifyHandshake());
|
||||
auto context = ukey2->ToConnectionContext();
|
||||
EXPECT_NE(context, nullptr);
|
||||
@@ -147,7 +148,7 @@ DoDhKeyExchange(BaseEndpointChannel* channel_a,
|
||||
.on_failure_cb =
|
||||
[&latch](const std::string& endpoint_id,
|
||||
EndpointChannel* channel) {
|
||||
NEARBY_LOG(INFO, "client-B side key negotiation failed");
|
||||
NEARBY_LOGS(INFO) << "client-B side key negotiation failed";
|
||||
latch.CountDown();
|
||||
},
|
||||
});
|
||||
|
||||
@@ -82,7 +82,7 @@ BwuManager::BwuManager(
|
||||
}
|
||||
|
||||
BwuManager::~BwuManager() {
|
||||
NEARBY_LOG(INFO, "BwuManager going down");
|
||||
NEARBY_LOGS(INFO) << "BwuManager going down";
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ void BwuManager::InitBwuHandlers() {
|
||||
}
|
||||
|
||||
void BwuManager::Shutdown() {
|
||||
NEARBY_LOG(INFO, "Initiating shutdown of BwuManager.");
|
||||
NEARBY_LOGS(INFO) << "Initiating shutdown of BwuManager.";
|
||||
|
||||
endpoint_manager_->UnregisterFrameProcessor(
|
||||
V1Frame::BANDWIDTH_UPGRADE_NEGOTIATION, this);
|
||||
@@ -135,7 +135,7 @@ void BwuManager::Shutdown() {
|
||||
}
|
||||
handlers_.clear();
|
||||
|
||||
NEARBY_LOG(INFO, "BwuHandler has shut down.");
|
||||
NEARBY_LOGS(INFO) << "BwuHandler has shut down.";
|
||||
}
|
||||
|
||||
// This is the point on the Initiator side where the
|
||||
@@ -143,8 +143,8 @@ void BwuManager::Shutdown() {
|
||||
void BwuManager::InitiateBwuForEndpoint(ClientProxy* client,
|
||||
const std::string& endpoint_id,
|
||||
Medium new_medium) {
|
||||
NEARBY_LOG(INFO, "InitiateBwuForEndpoint for endpoint %s with medium %d",
|
||||
endpoint_id.c_str(), new_medium);
|
||||
NEARBY_LOGS(INFO) << "InitiateBwuForEndpoint for endpoint " << endpoint_id
|
||||
<< " with medium " << new_medium;
|
||||
RunOnBwuManagerThread("bwu-init", [this, client, endpoint_id, new_medium]() {
|
||||
Medium proposed_medium = ChooseBestUpgradeMedium(
|
||||
client->GetUpgradeMediums(endpoint_id).GetMediums(true));
|
||||
@@ -380,10 +380,9 @@ void BwuManager::OnIncomingConnection(
|
||||
SystemClock::ElapsedRealtime();
|
||||
EndpointChannel* channel = connection->channel.get();
|
||||
if (channel == nullptr) {
|
||||
NEARBY_LOG(
|
||||
ERROR,
|
||||
"BwuManager failed to create new EndpointChannel for incoming "
|
||||
"socket.");
|
||||
NEARBY_LOGS(ERROR)
|
||||
<< "BwuManager failed to create new EndpointChannel for incoming "
|
||||
"socket.";
|
||||
connection->socket->Close();
|
||||
AttemptToRecordBandwidthUpgradeErrorForUnknownEndpoint(
|
||||
proto::connections::MEDIUM_ERROR,
|
||||
@@ -458,9 +457,9 @@ void BwuManager::RunOnBwuManagerThread(const std::string& name,
|
||||
void BwuManager::RunUpgradeProtocol(
|
||||
ClientProxy* client, const std::string& endpoint_id,
|
||||
std::unique_ptr<EndpointChannel> new_channel) {
|
||||
NEARBY_LOG(INFO, "RunUpgradeProtocol new channel @%d name: %s, medium: %d",
|
||||
new_channel.get(), new_channel->GetName().c_str(),
|
||||
new_channel->GetMedium());
|
||||
NEARBY_LOGS(INFO) << "RunUpgradeProtocol new channel @" << new_channel.get()
|
||||
<< " name: " << new_channel->GetName()
|
||||
<< ", medium: " << new_channel->GetMedium();
|
||||
// First, register this new EndpointChannel as *the* EndpointChannel to use
|
||||
// for this endpoint here onwards. NOTE: We pause this new EndpointChannel
|
||||
// until we've completely drained the old EndpointChannel to avoid out of
|
||||
@@ -559,7 +558,7 @@ void BwuManager::ProcessBwuPathAvailableEvent(
|
||||
}
|
||||
// Check for the correct medium so we don't process an incorrect OfflineFrame.
|
||||
if (medium != medium_) {
|
||||
NEARBY_LOG(INFO, "Medium not matching");
|
||||
NEARBY_LOGS(INFO) << "Medium not matching";
|
||||
RunUpgradeFailedProtocol(client, endpoint_id, upgrade_path_info);
|
||||
return;
|
||||
}
|
||||
@@ -590,7 +589,7 @@ void BwuManager::ProcessBwuPathAvailableEvent(
|
||||
client->GetConnectionToken(endpoint_id));
|
||||
|
||||
if (channel == nullptr) {
|
||||
NEARBY_LOG(INFO, "Failed to get new channel.");
|
||||
NEARBY_LOGS(INFO) << "Failed to get new channel.";
|
||||
RunUpgradeFailedProtocol(client, endpoint_id, upgrade_path_info);
|
||||
return;
|
||||
}
|
||||
@@ -603,10 +602,10 @@ std::unique_ptr<EndpointChannel>
|
||||
BwuManager::ProcessBwuPathAvailableEventInternal(
|
||||
ClientProxy* client, const string& endpoint_id,
|
||||
const UpgradePathInfo& upgrade_path_info) {
|
||||
NEARBY_LOG(INFO,
|
||||
"ProcessBwuPathAvailableEventInternal for endpoint %s medium %d",
|
||||
endpoint_id.c_str(),
|
||||
parser::UpgradePathInfoMediumToMedium(upgrade_path_info.medium()));
|
||||
NEARBY_LOGS(INFO) << "ProcessBwuPathAvailableEventInternal for endpoint "
|
||||
<< endpoint_id << " medium "
|
||||
<< parser::UpgradePathInfoMediumToMedium(
|
||||
upgrade_path_info.medium());
|
||||
std::unique_ptr<EndpointChannel> channel =
|
||||
handler_->CreateUpgradedEndpointChannel(client, client->GetServiceId(),
|
||||
endpoint_id, upgrade_path_info);
|
||||
@@ -667,9 +666,10 @@ BwuManager::ProcessBwuPathAvailableEventInternal(
|
||||
void BwuManager::RunUpgradeFailedProtocol(
|
||||
ClientProxy* client, const std::string& endpoint_id,
|
||||
const UpgradePathInfo& upgrade_path_info) {
|
||||
NEARBY_LOG(INFO, "RunUpgradeFailedProtocol for endpoint %s medium %d",
|
||||
endpoint_id.c_str(),
|
||||
parser::UpgradePathInfoMediumToMedium(upgrade_path_info.medium()));
|
||||
NEARBY_LOGS(INFO) << "RunUpgradeFailedProtocol for endpoint " << endpoint_id
|
||||
<< " medium "
|
||||
<< parser::UpgradePathInfoMediumToMedium(
|
||||
upgrade_path_info.medium());
|
||||
// We attempted to connect to the new medium that the remote device has set up
|
||||
// for us but we failed. We need to let the remote device know so that they
|
||||
// can pick another medium for us to try.
|
||||
@@ -713,9 +713,9 @@ void BwuManager::RunUpgradeFailedProtocol(
|
||||
|
||||
bool BwuManager::ReadClientIntroductionFrame(EndpointChannel* channel,
|
||||
ClientIntroduction& introduction) {
|
||||
NEARBY_LOG(INFO,
|
||||
"ReadClientIntroductionFrame with channel name: %s, medium: %d",
|
||||
channel->GetName().c_str(), channel->GetMedium());
|
||||
NEARBY_LOGS(INFO) << "ReadClientIntroductionFrame with channel name: "
|
||||
<< channel->GetName()
|
||||
<< ", medium: " << channel->GetMedium();
|
||||
CancelableAlarm timeout_alarm(
|
||||
"BwuManager::ReadClientIntroductionFrame",
|
||||
[channel]() {
|
||||
@@ -794,16 +794,16 @@ bool BwuManager::ReadClientIntroductionAckFrame(EndpointChannel* channel) {
|
||||
}
|
||||
|
||||
bool BwuManager::WriteClientIntroductionAckFrame(EndpointChannel* channel) {
|
||||
NEARBY_LOG(INFO,
|
||||
"WriteClientIntroductionAckFrame channel name: %s, medium: %d",
|
||||
channel->GetName().c_str(), channel->GetMedium());
|
||||
NEARBY_LOGS(INFO) << "WriteClientIntroductionAckFrame channel name: "
|
||||
<< channel->GetName()
|
||||
<< ", medium: " << channel->GetMedium();
|
||||
return channel->Write(parser::ForBwuIntroductionAck()).Ok();
|
||||
}
|
||||
|
||||
void BwuManager::ProcessLastWriteToPriorChannelEvent(
|
||||
ClientProxy* client, const std::string& endpoint_id) {
|
||||
NEARBY_LOG(INFO, "ProcessLastWriteToPriorChannelEvent for endpoint %s",
|
||||
endpoint_id.c_str());
|
||||
NEARBY_LOGS(INFO) << "ProcessLastWriteToPriorChannelEvent for endpoint "
|
||||
<< endpoint_id;
|
||||
// By this point in the upgrade protocol, there is the guarantee that both
|
||||
// involved endpoints have registered a new EndpointChannel with the
|
||||
// EndpointChannelManager as the official channel for communication; given
|
||||
@@ -853,8 +853,8 @@ void BwuManager::ProcessLastWriteToPriorChannelEvent(
|
||||
|
||||
void BwuManager::ProcessSafeToClosePriorChannelEvent(
|
||||
ClientProxy* client, const std::string& endpoint_id) {
|
||||
NEARBY_LOG(INFO, "ProcessSafeToClosePriorChannelEvent for endpoint %s",
|
||||
endpoint_id.c_str());
|
||||
NEARBY_LOGS(INFO) << "ProcessSafeToClosePriorChannelEvent for endpoint "
|
||||
<< endpoint_id;
|
||||
// By this point in the upgrade protocol, there's no more writes happening
|
||||
// over the prior EndpointChannel, and the remote device has given us the
|
||||
// go-ahead to close this EndpointChannel [1], so we can safely close it
|
||||
@@ -877,12 +877,10 @@ void BwuManager::ProcessSafeToClosePriorChannelEvent(
|
||||
<< endpoint_id << ", can't complete the upgrade protocol.";
|
||||
return;
|
||||
}
|
||||
|
||||
NEARBY_LOG(INFO,
|
||||
"BwuManager successfully received a "
|
||||
"BWU_NEGOTIATION.SAFE_TO_CLOSE_PRIOR_CHANNEL OfflineFrame while "
|
||||
"trying to upgrade endpoint %s.",
|
||||
endpoint_id.c_str());
|
||||
NEARBY_LOGS(INFO)
|
||||
<< "BwuManager successfully received a "
|
||||
<< "BWU_NEGOTIATION.SAFE_TO_CLOSE_PRIOR_CHANNEL OfflineFrame while "
|
||||
<< "trying to upgrade endpoint " << endpoint_id;
|
||||
|
||||
// Each encrypted message includes the key to decrypt the next message. The
|
||||
// disconnect message is optional and may not be received under normal
|
||||
@@ -988,10 +986,8 @@ void BwuManager::RetryUpgradeMediums(ClientProxy* client,
|
||||
const std::string& endpoint_id,
|
||||
std::vector<Medium> upgrade_mediums) {
|
||||
Medium next_medium = ChooseBestUpgradeMedium(upgrade_mediums);
|
||||
NEARBY_LOG(
|
||||
INFO,
|
||||
"RetryUpgradeMediums for endpoint %s after ChooseBestUpgradeMedium: %d",
|
||||
endpoint_id.c_str(), next_medium);
|
||||
NEARBY_LOGS(INFO) << "RetryUpgradeMediums for endpoint " << endpoint_id
|
||||
<< " after ChooseBestUpgradeMedium: " << next_medium;
|
||||
|
||||
// If current medium is not WiFi and we have not succeeded with upgrading
|
||||
// yet, retry upgrade.
|
||||
@@ -1005,20 +1001,18 @@ void BwuManager::RetryUpgradeMediums(ClientProxy* client,
|
||||
|
||||
// Attempt to set the new upgrade medium.
|
||||
if (!SetCurrentBwuHandler(next_medium)) {
|
||||
NEARBY_LOG(
|
||||
INFO,
|
||||
"BwuManager failed to attempt a new bandwidth upgrade for endpoint %s "
|
||||
"because we couldn't set a new bandwidth upgrade medium.",
|
||||
endpoint_id.c_str());
|
||||
NEARBY_LOGS(INFO)
|
||||
<< "BwuManager failed to attempt a new bandwidth upgrade for endpoint "
|
||||
<< endpoint_id
|
||||
<< " because we couldn't set a new bandwidth upgrade medium.";
|
||||
return;
|
||||
}
|
||||
|
||||
// Now that we've successfully picked a new upgrade medium to try,
|
||||
// re-initiate the bandwidth upgrade.
|
||||
NEARBY_LOG(INFO,
|
||||
"BwuManager is attempting to upgrade endpoint %s again with a new "
|
||||
" bandwidth upgrade medium.",
|
||||
endpoint_id.c_str());
|
||||
NEARBY_LOGS(INFO) << "BwuManager is attempting to upgrade endpoint "
|
||||
<< endpoint_id
|
||||
<< " again with a new bandwidth upgrade medium.";
|
||||
InitiateBwuForEndpoint(client, endpoint_id, next_medium);
|
||||
}
|
||||
|
||||
@@ -1069,10 +1063,9 @@ Medium BwuManager::ChooseBestUpgradeMedium(const std::vector<Medium>& mediums) {
|
||||
// Case 2: This is our first time upgrading, but there are no available
|
||||
// upgrade mediums. Fall through to returning UNKNOWN_MEDIUM at the
|
||||
// bottom.
|
||||
NEARBY_LOG(
|
||||
INFO,
|
||||
"Current upgrade medium is unset, but there are no common supported "
|
||||
"upgrade mediums.");
|
||||
NEARBY_LOGS(INFO)
|
||||
<< "Current upgrade medium is unset, but there are no common supported "
|
||||
"upgrade mediums.";
|
||||
} else {
|
||||
// Case 3: We have already upgraded, and there is a list of supported
|
||||
// mediums to check against. Return the current upgrade medium if it's in
|
||||
@@ -1185,7 +1178,7 @@ void BwuManager::CancelRetryUpgradeAlarm(const std::string& endpoint_id) {
|
||||
}
|
||||
|
||||
void BwuManager::CancelAllRetryUpgradeAlarms() {
|
||||
NEARBY_LOG(INFO, "CancelAllRetryUpgradeAlarms invoked");
|
||||
NEARBY_LOGS(INFO) << "CancelAllRetryUpgradeAlarms invoked";
|
||||
for (auto& item : retry_upgrade_alarms_) {
|
||||
const std::string& endpoint_id = item.first;
|
||||
CancelableAlarm& cancellable_alarm = item.second.first;
|
||||
|
||||
@@ -27,9 +27,11 @@ namespace nearby {
|
||||
namespace connections {
|
||||
namespace {
|
||||
|
||||
constexpr std::array<char, 6> kTestRemoteBluetoothMacAddress{0x01, 0x23, 0x45,
|
||||
0x67, 0x89, 0xab};
|
||||
constexpr std::array<char, 2> kTestEndpointInfo{0xcd, 0xef};
|
||||
// Need to wrap with static_cast<char> to silence -Wc++11-narrowing issue.
|
||||
constexpr std::array<char, 6> kTestRemoteBluetoothMacAddress{
|
||||
0x01, 0x23, 0x45, 0x67, static_cast<char>(0x89), static_cast<char>(0xab)};
|
||||
constexpr std::array<char, 2> kTestEndpointInfo{static_cast<char>(0xcd),
|
||||
static_cast<char>(0xef)};
|
||||
constexpr std::array<char, 3> kTestServiceIdHash{0x01, 0x23, 0x45};
|
||||
|
||||
const char kTestEndpointId[] = "abcd";
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "platform/base/byte_array.h"
|
||||
@@ -55,9 +56,10 @@ TEST(OfflineFramesTest, CanParseMessageFromBytes) {
|
||||
auto* sub_frame = v1_frame->mutable_connection_request();
|
||||
|
||||
v1_frame->set_type(V1Frame::CONNECTION_REQUEST);
|
||||
sub_frame->set_endpoint_id(kEndpointId);
|
||||
sub_frame->set_endpoint_name(kEndpointName);
|
||||
sub_frame->set_endpoint_info(kEndpointName);
|
||||
// OSS matchers don't like implicitly comparing string_views to strings.
|
||||
sub_frame->set_endpoint_id(std::string(kEndpointId));
|
||||
sub_frame->set_endpoint_name(std::string(kEndpointName));
|
||||
sub_frame->set_endpoint_info(std::string(kEndpointName));
|
||||
sub_frame->set_nonce(kNonce);
|
||||
sub_frame->set_keep_alive_interval_millis(kKeepAliveIntervalMillis);
|
||||
sub_frame->set_keep_alive_timeout_millis(kKeepAliveTimeoutMillis);
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "core/internal/offline_frames.h"
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
@@ -43,7 +43,7 @@ MediumEnvironment& MediumEnvironment::Instance() {
|
||||
|
||||
void MediumEnvironment::Start(EnvironmentConfig config) {
|
||||
if (!enabled_.exchange(true)) {
|
||||
NEARBY_LOG(INFO, "MediumEnvironment::Start()");
|
||||
NEARBY_LOGS(INFO) << "MediumEnvironment::Start()";
|
||||
config_ = std::move(config);
|
||||
Reset();
|
||||
}
|
||||
@@ -51,14 +51,14 @@ void MediumEnvironment::Start(EnvironmentConfig config) {
|
||||
|
||||
void MediumEnvironment::Stop() {
|
||||
if (enabled_.exchange(false)) {
|
||||
NEARBY_LOG(INFO, "MediumEnvironment::Stop()");
|
||||
NEARBY_LOGS(INFO) << "MediumEnvironment::Stop()";
|
||||
Sync(false);
|
||||
}
|
||||
}
|
||||
|
||||
void MediumEnvironment::Reset() {
|
||||
RunOnMediumEnvironmentThread([this]() {
|
||||
NEARBY_LOG(INFO, "MediumEnvironment::Reset()");
|
||||
NEARBY_LOGS(INFO) << "MediumEnvironment::Reset()";
|
||||
bluetooth_adapters_.clear();
|
||||
bluetooth_mediums_.clear();
|
||||
ble_mediums_.clear();
|
||||
@@ -73,7 +73,7 @@ void MediumEnvironment::Reset() {
|
||||
|
||||
void MediumEnvironment::Sync(bool enable_notifications) {
|
||||
enable_notifications_ = enable_notifications;
|
||||
NEARBY_LOG(INFO, "MediumEnvironment::sync(%d)", enable_notifications);
|
||||
NEARBY_LOGS(INFO) << "MediumEnvironment::sync=" << enable_notifications;
|
||||
int count = 0;
|
||||
do {
|
||||
CountDownLatch latch(1);
|
||||
@@ -87,7 +87,8 @@ void MediumEnvironment::Sync(bool enable_notifications) {
|
||||
RunOnMediumEnvironmentThread([&latch]() { latch.CountDown(); });
|
||||
latch.Await();
|
||||
} while (count < job_count_);
|
||||
NEARBY_LOG(INFO, "MediumEnvironment::Sync(): done [count=%d]", count);
|
||||
NEARBY_LOGS(INFO) << "MediumEnvironment::Sync(): done [count=" << count
|
||||
<< "]";
|
||||
}
|
||||
|
||||
const EnvironmentConfig& MediumEnvironment::GetEnvironmentConfig() {
|
||||
@@ -102,15 +103,16 @@ void MediumEnvironment::OnBluetoothAdapterChangedState(
|
||||
RunOnMediumEnvironmentThread([this, &adapter, &adapter_device,
|
||||
name = std::move(name), enabled, mode,
|
||||
&latch]() {
|
||||
NEARBY_LOG(INFO,
|
||||
"[adapter=%p, device=%p] update: name=%s, enabled=%d, mode=%d",
|
||||
&adapter, &adapter_device, name.c_str(), enabled, mode);
|
||||
NEARBY_LOGS(INFO) << "[adapter=" << &adapter
|
||||
<< ", device=" << &adapter_device << "] update: name="
|
||||
<< ", enabled=" << enabled << ", mode=" << int32_t(mode);
|
||||
for (auto& medium_info : bluetooth_mediums_) {
|
||||
auto& info = medium_info.second;
|
||||
// Do not send notification to medium that owns this adapter.
|
||||
if (info.adapter == &adapter) continue;
|
||||
NEARBY_LOG(INFO, "[adapter=%p, device=%p] notify: adapter=%p", &adapter,
|
||||
&adapter_device, info.adapter);
|
||||
NEARBY_LOGS(INFO) << "[adapter=" << &adapter
|
||||
<< ", device=" << &adapter_device
|
||||
<< "] notify: adapter=" << info.adapter;
|
||||
OnBluetoothDeviceStateChanged(info, adapter_device, name, mode, enabled);
|
||||
}
|
||||
// We don't care if there is an adapter already since all we store is a
|
||||
@@ -134,10 +136,9 @@ void MediumEnvironment::OnBluetoothDeviceStateChanged(
|
||||
if (!enabled_) return;
|
||||
auto item = info.devices.find(&device);
|
||||
if (item == info.devices.end()) {
|
||||
NEARBY_LOG(INFO,
|
||||
"G3 OnBluetoothDeviceStateChanged [device impl=%p]: new device; "
|
||||
"notify=%d",
|
||||
&device, enable_notifications_.load());
|
||||
NEARBY_LOGS(INFO) << "G3 OnBluetoothDeviceStateChanged [device impl="
|
||||
<< &device << "]: new device; notify="
|
||||
<< enable_notifications_.load();
|
||||
if (mode == api::BluetoothAdapter::ScanMode::kConnectableDiscoverable &&
|
||||
enabled) {
|
||||
// New device is turned on, and is in discoverable state.
|
||||
@@ -149,10 +150,9 @@ void MediumEnvironment::OnBluetoothDeviceStateChanged(
|
||||
}
|
||||
}
|
||||
} else {
|
||||
NEARBY_LOG(INFO,
|
||||
"G3 OnBluetoothDeviceStateChanged [device impl=%p]: exisitng "
|
||||
"device; notify=%d",
|
||||
&device, enable_notifications_.load());
|
||||
NEARBY_LOGS(INFO) << "G3 OnBluetoothDeviceStateChanged [device impl="
|
||||
<< &device << "]: existing device; notify="
|
||||
<< enable_notifications_.load();
|
||||
auto& discovered_name = item->second;
|
||||
if (mode == api::BluetoothAdapter::ScanMode::kConnectableDiscoverable &&
|
||||
enabled) {
|
||||
@@ -209,45 +209,41 @@ void MediumEnvironment::OnBlePeripheralStateChanged(
|
||||
BleMediumContext& info, api::BlePeripheral& peripheral,
|
||||
const std::string& service_id, bool fast_advertisement, bool enabled) {
|
||||
if (!enabled_) return;
|
||||
NEARBY_LOG(INFO,
|
||||
"G3 OnBleServiceStateChanged [peripheral impl=%p]; context=%p; "
|
||||
"service_id=%s; notify=%d",
|
||||
&peripheral, &info, service_id.c_str(),
|
||||
enable_notifications_.load());
|
||||
NEARBY_LOGS(INFO) << "G3 OnBleServiceStateChanged [peripheral impl="
|
||||
<< &peripheral << "]; context=" << &info
|
||||
<< "; service_id=" << service_id
|
||||
<< "; notify=" << enable_notifications_.load();
|
||||
if (!enable_notifications_) return;
|
||||
RunOnMediumEnvironmentThread(
|
||||
[&info, enabled, &peripheral, service_id, fast_advertisement]() {
|
||||
NEARBY_LOG(INFO,
|
||||
"G3 [Run] OnBlePeripheralStateChanged [peripheral impl=%p]; "
|
||||
"context=%p; service_id=%s; enabled=%d",
|
||||
&peripheral, &info, service_id.c_str(), enabled);
|
||||
if (enabled) {
|
||||
info.discovery_callback.peripheral_discovered_cb(
|
||||
peripheral, service_id, fast_advertisement);
|
||||
} else {
|
||||
info.discovery_callback.peripheral_lost_cb(peripheral, service_id);
|
||||
}
|
||||
});
|
||||
RunOnMediumEnvironmentThread([&info, enabled, &peripheral, service_id,
|
||||
fast_advertisement]() {
|
||||
NEARBY_LOGS(INFO) << "G3 [Run] OnBleServiceStateChanged [peripheral impl="
|
||||
<< &peripheral << "]; context=" << &info
|
||||
<< "; service_id=" << service_id
|
||||
<< "; notify=" << enabled;
|
||||
if (enabled) {
|
||||
info.discovery_callback.peripheral_discovered_cb(peripheral, service_id,
|
||||
fast_advertisement);
|
||||
} else {
|
||||
info.discovery_callback.peripheral_lost_cb(peripheral, service_id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void MediumEnvironment::OnWifiLanServiceStateChanged(
|
||||
WifiLanMediumContext& info, api::WifiLanService& wifi_lan_service,
|
||||
const std::string& service_id, bool enabled) {
|
||||
if (!enabled_) return;
|
||||
NEARBY_LOG(
|
||||
INFO,
|
||||
"G3 OnWifiLanServiceStateChanged [wifi_lan_service impl=%p]; context=%p; "
|
||||
"service_id=%s; notify=%d",
|
||||
&wifi_lan_service, &info, service_id.c_str(),
|
||||
enable_notifications_.load());
|
||||
NEARBY_LOGS(INFO) << "G3 OnWifiLanServiceStateChanged [wifi_lan_service impl="
|
||||
<< &wifi_lan_service << "]; context=" << &info
|
||||
<< "; service_id=" << service_id
|
||||
<< "; notify=" << enable_notifications_.load();
|
||||
if (!enable_notifications_) return;
|
||||
RunOnMediumEnvironmentThread(
|
||||
[&info, enabled, &wifi_lan_service, service_id]() {
|
||||
NEARBY_LOG(
|
||||
INFO,
|
||||
"G3 [Run] OnWifiLanServiceStateChanged [wifi_lan_service impl=%p]; "
|
||||
"context=%p; service_id=%s; enabled=%d",
|
||||
&wifi_lan_service, &info, service_id.c_str(), enabled);
|
||||
NEARBY_LOGS(INFO)
|
||||
<< "G3 [Run] OnWifiLanServiceStateChanged [wifi_lan_service impl="
|
||||
<< &wifi_lan_service << "]; context=" << &info
|
||||
<< "; service_id=" << service_id << "; enabled=" << enabled;
|
||||
auto service_id_context = info.services.find(service_id);
|
||||
if (service_id_context == info.services.end()) return;
|
||||
|
||||
@@ -279,8 +275,8 @@ void MediumEnvironment::RegisterBluetoothMedium(
|
||||
}})
|
||||
.first->second;
|
||||
auto* owned_adapter = context.adapter;
|
||||
NEARBY_LOG(INFO, "Registered: medium=%p; adapter=%p", &medium,
|
||||
owned_adapter);
|
||||
NEARBY_LOGS(INFO) << "Registered: medium=" << &medium
|
||||
<< "; adapter=" << owned_adapter;
|
||||
for (auto& adapter_device : bluetooth_adapters_) {
|
||||
auto& adapter = adapter_device.first;
|
||||
auto& device = adapter_device.second;
|
||||
@@ -302,11 +298,11 @@ void MediumEnvironment::UpdateBluetoothMedium(
|
||||
auto& context = item->second;
|
||||
context.callback = std::move(callback);
|
||||
auto* owned_adapter = context.adapter;
|
||||
NEARBY_LOG(
|
||||
INFO,
|
||||
"Updated: this=%p; medium=%p; adapter=%p; name=%s; enabled=%d; mode=%d",
|
||||
this, &medium, owned_adapter, owned_adapter->GetName().c_str(),
|
||||
owned_adapter->IsEnabled(), owned_adapter->GetScanMode());
|
||||
NEARBY_LOGS(INFO) << "Updated: this=" << this << "; medium=" << &medium
|
||||
<< "; adapter=" << owned_adapter
|
||||
<< "; name=" << owned_adapter->GetName()
|
||||
<< "; enabled=" << owned_adapter->IsEnabled()
|
||||
<< "; mode=" << int32_t(owned_adapter->GetScanMode());
|
||||
for (auto& adapter_device : bluetooth_adapters_) {
|
||||
auto& adapter = adapter_device.first;
|
||||
auto& device = adapter_device.second;
|
||||
@@ -332,7 +328,7 @@ void MediumEnvironment::RegisterBleMedium(api::BleMedium& medium) {
|
||||
if (!enabled_) return;
|
||||
RunOnMediumEnvironmentThread([this, &medium]() {
|
||||
ble_mediums_.insert({&medium, BleMediumContext{}});
|
||||
NEARBY_LOG(INFO, "Registered: medium=%p", &medium);
|
||||
NEARBY_LOGS(INFO) << "Registered: medium:" << &medium;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -344,20 +340,19 @@ void MediumEnvironment::UpdateBleMediumForAdvertising(
|
||||
fast_advertisement, enabled]() {
|
||||
auto item = ble_mediums_.find(&medium);
|
||||
if (item == ble_mediums_.end()) {
|
||||
NEARBY_LOG(INFO,
|
||||
"UpdateBleMediumForAdvertising failed. There is no medium "
|
||||
"registered.");
|
||||
NEARBY_LOGS(INFO) << "UpdateBleMediumForAdvertising failed. There is no "
|
||||
"medium registered.";
|
||||
return;
|
||||
}
|
||||
auto& context = item->second;
|
||||
context.ble_peripheral = &peripheral;
|
||||
context.advertising = enabled;
|
||||
context.fast_advertisement = fast_advertisement;
|
||||
NEARBY_LOG(INFO,
|
||||
"Update Ble medium for advertising: this=%p; medium=%p; "
|
||||
"service_id=%s; name=%s; fast_advertisement=%d; enabled=%d; ",
|
||||
this, &medium, service_id.c_str(), peripheral.GetName().c_str(),
|
||||
fast_advertisement, enabled);
|
||||
NEARBY_LOGS(INFO) << "Update Ble medium for advertising: this=" << this
|
||||
<< "; medium=" << &medium << "; service_id=" << service_id
|
||||
<< "; name=" << peripheral.GetName()
|
||||
<< "; fast_advertisement=" << fast_advertisement
|
||||
<< "; enabled=" << enabled;
|
||||
for (auto& medium_info : ble_mediums_) {
|
||||
auto& local_medium = medium_info.first;
|
||||
auto& info = medium_info.second;
|
||||
@@ -379,19 +374,18 @@ void MediumEnvironment::UpdateBleMediumForScanning(
|
||||
callback = std::move(callback), enabled]() {
|
||||
auto item = ble_mediums_.find(&medium);
|
||||
if (item == ble_mediums_.end()) {
|
||||
NEARBY_LOG(INFO,
|
||||
"UpdateBleMediumFoScanning failed. There is no medium "
|
||||
"registered.");
|
||||
NEARBY_LOGS(INFO)
|
||||
<< "UpdateBleMediumFoScanning failed. There is no medium "
|
||||
"registered.";
|
||||
return;
|
||||
}
|
||||
auto& context = item->second;
|
||||
context.discovery_callback = std::move(callback);
|
||||
NEARBY_LOG(
|
||||
INFO,
|
||||
"Update Ble medium for scanning: this=%p; medium=%p; "
|
||||
"service_id=%s; fast_advertisement_service_uuid=%s; enabled=%d ;",
|
||||
this, &medium, service_id.c_str(),
|
||||
fast_advertisement_service_uuid.c_str(), enabled);
|
||||
NEARBY_LOGS(INFO) << "Update Ble medium for scanning: this=" << this
|
||||
<< "; medium=" << &medium << "; service_id=" << service_id
|
||||
<< "; fast_advertisement_service_uuid="
|
||||
<< fast_advertisement_service_uuid
|
||||
<< "; enabled=" << enabled;
|
||||
for (auto& medium_info : ble_mediums_) {
|
||||
auto& local_medium = medium_info.first;
|
||||
auto& info = medium_info.second;
|
||||
@@ -414,16 +408,15 @@ void MediumEnvironment::UpdateBleMediumForAcceptedConnection(
|
||||
[this, &medium, service_id, callback = std::move(callback)]() {
|
||||
auto item = ble_mediums_.find(&medium);
|
||||
if (item == ble_mediums_.end()) {
|
||||
NEARBY_LOG(
|
||||
INFO, "Update Ble medium failed. There is no medium registered.");
|
||||
NEARBY_LOGS(INFO)
|
||||
<< "Update Ble medium failed. There is no medium registered.";
|
||||
return;
|
||||
}
|
||||
auto& context = item->second;
|
||||
context.accepted_connection_callback = std::move(callback);
|
||||
NEARBY_LOG(INFO,
|
||||
"Update Ble medium for accepted callback: this=%p; "
|
||||
"medium=%p; service_id=%s; ",
|
||||
this, &medium, service_id.c_str());
|
||||
NEARBY_LOGS(INFO) << "Update Ble medium for accepted callback: this="
|
||||
<< this << "; medium=" << &medium
|
||||
<< "; service_id=" << service_id;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -432,7 +425,7 @@ void MediumEnvironment::UnregisterBleMedium(api::BleMedium& medium) {
|
||||
RunOnMediumEnvironmentThread([this, &medium]() {
|
||||
auto item = ble_mediums_.extract(&medium);
|
||||
if (item.empty()) return;
|
||||
NEARBY_LOG(INFO, "Unregistered Ble medium");
|
||||
NEARBY_LOGS(INFO) << "Unregistered Ble medium";
|
||||
});
|
||||
}
|
||||
|
||||
@@ -443,9 +436,9 @@ void MediumEnvironment::CallBleAcceptedConnectionCallback(
|
||||
RunOnMediumEnvironmentThread([this, &medium, &socket, service_id]() {
|
||||
auto item = ble_mediums_.find(&medium);
|
||||
if (item == ble_mediums_.end()) {
|
||||
NEARBY_LOG(INFO,
|
||||
"Call AcceptedConnectionCallback failed.. There is no medium "
|
||||
"registered.");
|
||||
NEARBY_LOGS(INFO)
|
||||
<< "Call AcceptedConnectionCallback failed. There is no medium "
|
||||
"registered.";
|
||||
return;
|
||||
}
|
||||
auto& info = item->second;
|
||||
@@ -463,8 +456,8 @@ void MediumEnvironment::RegisterWebRtcSignalingMessenger(
|
||||
std::move(complete_callback)}]() {
|
||||
webrtc_signaling_message_callback_[self_id] = std::move(message_callback);
|
||||
webrtc_signaling_complete_callback_[self_id] = std::move(complete_callback);
|
||||
NEARBY_LOG(INFO, "Registered signaling message callback for id = %s",
|
||||
self_id.c_str());
|
||||
NEARBY_LOGS(INFO) << "Registered signaling message callback for id = "
|
||||
<< self_id;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -476,8 +469,8 @@ void MediumEnvironment::UnregisterWebRtcSignalingMessenger(
|
||||
webrtc_signaling_message_callback_.extract(self_id);
|
||||
auto complete_callback_item =
|
||||
webrtc_signaling_complete_callback_.extract(self_id);
|
||||
NEARBY_LOG(INFO, "Unregistered signaling callbacks for id = %s",
|
||||
self_id.c_str());
|
||||
NEARBY_LOGS(INFO) << "Unregistered signaling message callback for id = "
|
||||
<< self_id;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -488,8 +481,8 @@ void MediumEnvironment::SendWebRtcSignalingMessage(absl::string_view peer_id,
|
||||
[this, peer_id{std::string(peer_id)}, message]() {
|
||||
auto item = webrtc_signaling_message_callback_.find(peer_id);
|
||||
if (item == webrtc_signaling_message_callback_.end()) {
|
||||
NEARBY_LOG(WARNING, "No callback registered for peer id = %s",
|
||||
peer_id.c_str());
|
||||
NEARBY_LOGS(WARNING)
|
||||
<< "No callback registered for peer id = " << peer_id;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -504,8 +497,8 @@ void MediumEnvironment::SendWebRtcSignalingComplete(absl::string_view peer_id,
|
||||
[this, peer_id{std::string(peer_id)}, success]() {
|
||||
auto item = webrtc_signaling_complete_callback_.find(peer_id);
|
||||
if (item == webrtc_signaling_complete_callback_.end()) {
|
||||
NEARBY_LOG(WARNING, "No callback registered for peer id = %s",
|
||||
peer_id.c_str());
|
||||
NEARBY_LOGS(WARNING)
|
||||
<< "No callback registered for peer id = " << peer_id;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -535,7 +528,7 @@ void MediumEnvironment::RegisterWifiLanMedium(api::WifiLanMedium& medium) {
|
||||
if (!enabled_) return;
|
||||
RunOnMediumEnvironmentThread([this, &medium]() {
|
||||
wifi_lan_mediums_.insert({&medium, WifiLanMediumContext{}});
|
||||
NEARBY_LOG(INFO, "Registered: medium=%p", &medium);
|
||||
NEARBY_LOGS(INFO) << "Registered: medium=" << &medium;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -547,9 +540,9 @@ void MediumEnvironment::UpdateWifiLanMediumForAdvertising(
|
||||
enabled]() {
|
||||
auto item = wifi_lan_mediums_.find(&medium);
|
||||
if (item == wifi_lan_mediums_.end()) {
|
||||
NEARBY_LOG(INFO,
|
||||
"UpdateWifiLanMediumForAdvertising failed. There is no medium "
|
||||
"registered.");
|
||||
NEARBY_LOGS(INFO)
|
||||
<< "UpdateWifiLanMediumForAdvertising failed. There is no medium "
|
||||
"registered.";
|
||||
return;
|
||||
}
|
||||
auto& context = item->second;
|
||||
@@ -563,13 +556,12 @@ void MediumEnvironment::UpdateWifiLanMediumForAdvertising(
|
||||
} else {
|
||||
service_id_context->second.advertising = enabled;
|
||||
}
|
||||
NEARBY_LOG(
|
||||
INFO,
|
||||
"Update WifiLan medium for advertising: this=%p; medium=%p; "
|
||||
"service_id=%s; wifi_lan_service=%p, service_info_name=%s; enabled=%d",
|
||||
this, &medium, service_id.c_str(), &wifi_lan_service,
|
||||
wifi_lan_service.GetServiceInfo().GetServiceInfoName().c_str(),
|
||||
enabled);
|
||||
NEARBY_LOGS(INFO) << "Update WifiLan medium for advertising: this=" << this
|
||||
<< "; medium=" << &medium << "; service_id=" << service_id
|
||||
<< "; wifi_lan_service=" << &wifi_lan_service
|
||||
<< ", service_info_name="
|
||||
<< wifi_lan_service.GetServiceInfo().GetServiceInfoName()
|
||||
<< "; enabled=" << enabled;
|
||||
for (auto& medium_info : wifi_lan_mediums_) {
|
||||
auto& local_medium = medium_info.first;
|
||||
auto& info = medium_info.second;
|
||||
@@ -588,9 +580,9 @@ void MediumEnvironment::UpdateWifiLanMediumForDiscovery(
|
||||
callback = std::move(callback), enabled]() {
|
||||
auto item = wifi_lan_mediums_.find(&medium);
|
||||
if (item == wifi_lan_mediums_.end()) {
|
||||
NEARBY_LOG(INFO,
|
||||
"UpdateWifiLanMediumForDiscovery failed. There is no medium "
|
||||
"registered.");
|
||||
NEARBY_LOGS(INFO)
|
||||
<< "UpdateWifiLanMediumForDiscovery failed. There is no medium "
|
||||
"registered.";
|
||||
return;
|
||||
}
|
||||
auto& context = item->second;
|
||||
@@ -603,10 +595,9 @@ void MediumEnvironment::UpdateWifiLanMediumForDiscovery(
|
||||
} else {
|
||||
service_id_context->second.discovery_callback = std::move(callback);
|
||||
}
|
||||
NEARBY_LOG(INFO,
|
||||
"Update WifiLan medium for discovery: this=%p; medium=%p; "
|
||||
"service_id=%s; enabled=%d; ",
|
||||
this, &medium, service_id.c_str(), enabled);
|
||||
NEARBY_LOGS(INFO) << "Update WifiLan medium for discovery: this=" << this
|
||||
<< "; medium=" << &medium << "; service_id=" << service_id
|
||||
<< "; enabled=" << enabled;
|
||||
for (auto& medium_info : wifi_lan_mediums_) {
|
||||
auto& local_medium = medium_info.first;
|
||||
auto& info = medium_info.second;
|
||||
@@ -633,8 +624,8 @@ void MediumEnvironment::UpdateWifiLanMediumForAcceptedConnection(
|
||||
callback = std::move(callback)]() {
|
||||
auto item = wifi_lan_mediums_.find(&medium);
|
||||
if (item == wifi_lan_mediums_.end()) {
|
||||
NEARBY_LOG(
|
||||
INFO, "Update WifiLan medium failed. There is no medium registered.");
|
||||
NEARBY_LOGS(INFO)
|
||||
<< "Update WifiLan medium failed. There is no medium registered.";
|
||||
return;
|
||||
}
|
||||
auto& context = item->second;
|
||||
@@ -648,10 +639,9 @@ void MediumEnvironment::UpdateWifiLanMediumForAcceptedConnection(
|
||||
service_id_context->second.accepted_connection_callback =
|
||||
std::move(callback);
|
||||
}
|
||||
NEARBY_LOG(INFO,
|
||||
"Update WifiLan medium for accepted callback: this=%p; "
|
||||
"medium=%p; service_id=%s; ",
|
||||
this, &medium, service_id.c_str());
|
||||
NEARBY_LOGS(INFO) << "Update WifiLan medium for accepted callback: this="
|
||||
<< this << "; medium=" << &medium
|
||||
<< "; service_id=" << service_id;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -660,7 +650,7 @@ void MediumEnvironment::UnregisterWifiLanMedium(api::WifiLanMedium& medium) {
|
||||
RunOnMediumEnvironmentThread([this, &medium]() {
|
||||
auto item = wifi_lan_mediums_.extract(&medium);
|
||||
if (item.empty()) return;
|
||||
NEARBY_LOG(INFO, "Unregistered WifiLan medium");
|
||||
NEARBY_LOGS(INFO) << "Unregistered WifiLan medium";
|
||||
});
|
||||
}
|
||||
|
||||
@@ -671,9 +661,9 @@ void MediumEnvironment::CallWifiLanAcceptedConnectionCallback(
|
||||
RunOnMediumEnvironmentThread([this, &medium, &socket, service_id]() {
|
||||
auto item = wifi_lan_mediums_.find(&medium);
|
||||
if (item == wifi_lan_mediums_.end()) {
|
||||
NEARBY_LOG(INFO,
|
||||
"Call AcceptedConnectionCallback failed.. There is no medium "
|
||||
"registered.");
|
||||
NEARBY_LOGS(INFO)
|
||||
<< "Call AcceptedConnectionCallback failed.. There is no medium "
|
||||
"registered.";
|
||||
return;
|
||||
}
|
||||
auto& info = item->second;
|
||||
|
||||
@@ -126,8 +126,8 @@ bool BluetoothServerSocket::Connect(BluetoothSocket& socket) {
|
||||
absl::MutexLock lock(&mutex_);
|
||||
if (closed_) return false;
|
||||
if (socket.IsConnected()) {
|
||||
NEARBY_LOG(ERROR,
|
||||
"Failed to connect to BT server socket: already connected");
|
||||
NEARBY_LOGS(ERROR)
|
||||
<< "Failed to connect to BT server socket: already connected";
|
||||
return true; // already connected.
|
||||
}
|
||||
// add client socket to the pending list
|
||||
@@ -201,9 +201,9 @@ bool BluetoothClassicMedium::StopDiscovery() {
|
||||
std::unique_ptr<api::BluetoothSocket> BluetoothClassicMedium::ConnectToService(
|
||||
api::BluetoothDevice& remote_device, const std::string& service_uuid,
|
||||
CancellationFlag* cancellation_flag) {
|
||||
NEARBY_LOG(INFO,
|
||||
"G3 ConnectToService [self]: medium=%p, adapter=%p, device=%p",
|
||||
this, &GetAdapter(), &GetAdapter().GetDevice());
|
||||
NEARBY_LOGS(INFO) << "G3 ConnectToService [self]: medium=" << this
|
||||
<< ", adapter=" << &GetAdapter()
|
||||
<< ", device=" << &GetAdapter().GetDevice();
|
||||
// First, find an instance of remote medium, that exposed this device.
|
||||
auto& adapter = static_cast<BluetoothDevice&>(remote_device).GetAdapter();
|
||||
auto* medium =
|
||||
@@ -212,18 +212,17 @@ std::unique_ptr<api::BluetoothSocket> BluetoothClassicMedium::ConnectToService(
|
||||
if (!medium) return {}; // Adapter is not bound to medium. Bail out.
|
||||
|
||||
BluetoothServerSocket* server_socket = nullptr;
|
||||
NEARBY_LOG(
|
||||
INFO,
|
||||
"G3 ConnectToService [peer]: medium=%p, adapter=%p, device=%p, uuid=%s",
|
||||
medium, &adapter, &remote_device, service_uuid.c_str());
|
||||
NEARBY_LOGS(INFO) << "G3 ConnectToService [peer]: medium=" << medium
|
||||
<< ", adapter=" << &adapter << ", device=" << &remote_device
|
||||
<< ", uuid=" << service_uuid.c_str();
|
||||
// Then, find our server socket context in this medium.
|
||||
{
|
||||
absl::MutexLock medium_lock(&medium->mutex_);
|
||||
auto item = medium->sockets_.find(service_uuid);
|
||||
server_socket = item != sockets_.end() ? item->second : nullptr;
|
||||
if (server_socket == nullptr) {
|
||||
NEARBY_LOG(ERROR, "Failed to find BT Server socket: uuid=%s",
|
||||
service_uuid.c_str());
|
||||
NEARBY_LOGS(ERROR) << "Failed to find BT Server socket: uuid="
|
||||
<< service_uuid;
|
||||
return {};
|
||||
}
|
||||
}
|
||||
@@ -243,12 +242,13 @@ std::unique_ptr<api::BluetoothSocket> BluetoothClassicMedium::ConnectToService(
|
||||
auto socket = std::make_unique<BluetoothSocket>(&GetAdapter());
|
||||
// Finally, Request to connect to this socket.
|
||||
if (!server_socket->Connect(*socket)) {
|
||||
NEARBY_LOG(ERROR, "Failed to connect to existing BT Server socket: uuid=%s",
|
||||
service_uuid.c_str());
|
||||
NEARBY_LOGS(ERROR)
|
||||
<< "Failed to connect to existing BT Server socket: uuid="
|
||||
<< service_uuid;
|
||||
return {};
|
||||
}
|
||||
|
||||
NEARBY_LOG(INFO, "G3 ConnectToService: connected: socket=%p", socket.get());
|
||||
NEARBY_LOGS(INFO) << "G3 ConnectToService: connected: socket="
|
||||
<< socket.get();
|
||||
return socket;
|
||||
}
|
||||
|
||||
@@ -260,8 +260,8 @@ BluetoothClassicMedium::ListenForService(const std::string& service_name,
|
||||
absl::MutexLock lock(&mutex_);
|
||||
sockets_.erase(uuid);
|
||||
});
|
||||
NEARBY_LOG(INFO, "Adding service: medium=%p, uuid=%s", this,
|
||||
service_uuid.c_str());
|
||||
NEARBY_LOGS(INFO) << "Adding service: medium=" << this
|
||||
<< ", uuid=" << service_uuid;
|
||||
absl::MutexLock lock(&mutex_);
|
||||
sockets_.emplace(service_uuid, socket.get());
|
||||
return socket;
|
||||
|
||||
Reference in New Issue
Block a user