Merge branch 'google3' to master, roll forward up to cl/355302206.

This commit is contained in:
hai007
2021-02-04 13:34:05 -08:00
41 changed files with 1194 additions and 472 deletions
+1
View File
@@ -69,6 +69,7 @@ cc_library(
":types",
"//platform/api:comm",
"//platform/base",
"//platform/base:cancellation_flag",
"//platform/base:logging",
"//platform/base:test_util",
"//absl/base:core_headers",
+9 -1
View File
@@ -317,7 +317,8 @@ bool BleMedium::StopAcceptingConnections(const std::string& service_id) {
}
std::unique_ptr<api::BleSocket> BleMedium::Connect(
api::BlePeripheral& remote_peripheral, const std::string& service_id) {
api::BlePeripheral& remote_peripheral, const std::string& service_id,
CancellationFlag* cancellation_flag) {
NEARBY_LOG(INFO,
"G3 Ble Connect [self]: medium=%p, adapter=%p, peripheral=%p, "
"service_id=%s",
@@ -346,6 +347,13 @@ std::unique_ptr<api::BleSocket> BleMedium::Connect(
}
}
if (cancellation_flag->Cancelled()) {
NEARBY_LOGS(ERROR) << "G3 BLE Connect: Has been cancelled: "
"service_id="
<< service_id;
return {};
}
BlePeripheral peripheral = static_cast<BlePeripheral&>(remote_peripheral);
auto socket = std::make_unique<BleSocket>(&peripheral);
// Finally, Request to connect to this socket.
+3 -2
View File
@@ -183,8 +183,9 @@ class BleMedium : public api::BleMedium {
// On success, returns a new BleSocket.
// On error, returns nullptr.
std::unique_ptr<api::BleSocket> Connect(
api::BlePeripheral& remote_peripheral,
const std::string& service_id) override ABSL_LOCKS_EXCLUDED(mutex_);
api::BlePeripheral& remote_peripheral, const std::string& service_id,
CancellationFlag* cancellation_flag) override
ABSL_LOCKS_EXCLUDED(mutex_);
BluetoothAdapter& GetAdapter() { return *adapter_; }
+9 -1
View File
@@ -199,7 +199,8 @@ bool BluetoothClassicMedium::StopDiscovery() {
}
std::unique_ptr<api::BluetoothSocket> BluetoothClassicMedium::ConnectToService(
api::BluetoothDevice& remote_device, const std::string& service_uuid) {
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());
@@ -227,6 +228,13 @@ std::unique_ptr<api::BluetoothSocket> BluetoothClassicMedium::ConnectToService(
}
}
if (cancellation_flag->Cancelled()) {
NEARBY_LOGS(ERROR) << "G3 Bluetooth Connect: Has been cancelled: "
"service_uuid="
<< service_uuid;
return {};
}
auto socket = std::make_unique<BluetoothSocket>(&GetAdapter());
// Finally, Request to connect to this socket.
if (!server_socket->Connect(*socket)) {
+3 -2
View File
@@ -201,8 +201,9 @@ class BluetoothClassicMedium : public api::BluetoothClassicMedium {
// On success, returns a new BluetoothSocket.
// On error, returns nullptr.
std::unique_ptr<api::BluetoothSocket> ConnectToService(
api::BluetoothDevice& remote_device,
const std::string& service_uuid) override ABSL_LOCKS_EXCLUDED(mutex_);
api::BluetoothDevice& remote_device, const std::string& service_uuid,
CancellationFlag* cancellation_flag) override
ABSL_LOCKS_EXCLUDED(mutex_);
BluetoothAdapter& GetAdapter() { return *adapter_; }
+9 -2
View File
@@ -317,8 +317,8 @@ bool WifiLanMedium::StopAcceptingConnections(const std::string& service_id) {
}
std::unique_ptr<api::WifiLanSocket> WifiLanMedium::Connect(
api::WifiLanService& remote_wifi_lan_service,
const std::string& service_id) {
api::WifiLanService& remote_wifi_lan_service, const std::string& service_id,
CancellationFlag* cancellation_flag) {
NEARBY_LOG(
INFO,
"G3 WifiLan Connect: medium=%p, wifi_lan_service=%p, "
@@ -354,6 +354,13 @@ std::unique_ptr<api::WifiLanSocket> WifiLanMedium::Connect(
}
}
if (cancellation_flag->Cancelled()) {
NEARBY_LOGS(INFO) << "G3 WifiLan Connect: Has been cancelled: "
"service_id="
<< service_id;
return {};
}
WifiLanService wifi_lan_service =
static_cast<WifiLanService&>(remote_wifi_lan_service);
auto socket = std::make_unique<WifiLanSocket>(&wifi_lan_service);
+3 -1
View File
@@ -204,7 +204,9 @@ class WifiLanMedium : public api::WifiLanMedium {
// On error, returns nullptr.
std::unique_ptr<api::WifiLanSocket> Connect(
api::WifiLanService& remote_wifi_lan_service,
const std::string& service_id) override ABSL_LOCKS_EXCLUDED(mutex_);
const std::string& service_id,
CancellationFlag* cancellation_flag) override
ABSL_LOCKS_EXCLUDED(mutex_);
api::WifiLanService* GetRemoteService(const std::string& ip_address,
int port) override;