mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Merge branch 'google3' to roll forward to cl/339936269.
This commit is contained in:
@@ -56,8 +56,6 @@ void ClientProxy::StartedAdvertising(
|
|||||||
const ConnectionListener& listener,
|
const ConnectionListener& listener,
|
||||||
absl::Span<proto::connections::Medium> mediums) {
|
absl::Span<proto::connections::Medium> mediums) {
|
||||||
MutexLock lock(&mutex_);
|
MutexLock lock(&mutex_);
|
||||||
|
|
||||||
if (connections_.empty()) local_endpoint_id_.clear();
|
|
||||||
advertising_info_ = {service_id, listener};
|
advertising_info_ = {service_id, listener};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,7 +65,7 @@ void ClientProxy::StoppedAdvertising() {
|
|||||||
if (IsAdvertising()) {
|
if (IsAdvertising()) {
|
||||||
advertising_info_.Clear();
|
advertising_info_.Clear();
|
||||||
}
|
}
|
||||||
if (connections_.empty()) local_endpoint_id_.clear();
|
ResetLocalEndpointIdIfNeeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ClientProxy::IsAdvertising() const {
|
bool ClientProxy::IsAdvertising() const {
|
||||||
@@ -83,10 +81,8 @@ std::string ClientProxy::GetAdvertisingServiceId() const {
|
|||||||
|
|
||||||
std::string ClientProxy::GetServiceId() const {
|
std::string ClientProxy::GetServiceId() const {
|
||||||
MutexLock lock(&mutex_);
|
MutexLock lock(&mutex_);
|
||||||
if (IsAdvertising())
|
if (IsAdvertising()) return advertising_info_.service_id;
|
||||||
return advertising_info_.service_id;
|
if (IsDiscovering()) return discovery_info_.service_id;
|
||||||
if (IsDiscovering())
|
|
||||||
return discovery_info_.service_id;
|
|
||||||
return "idle_service_id";
|
return "idle_service_id";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,8 +91,6 @@ void ClientProxy::StartedDiscovery(
|
|||||||
const DiscoveryListener& listener,
|
const DiscoveryListener& listener,
|
||||||
absl::Span<proto::connections::Medium> mediums) {
|
absl::Span<proto::connections::Medium> mediums) {
|
||||||
MutexLock lock(&mutex_);
|
MutexLock lock(&mutex_);
|
||||||
|
|
||||||
if (connections_.empty()) local_endpoint_id_.clear();
|
|
||||||
discovery_info_ = DiscoveryInfo{service_id, listener};
|
discovery_info_ = DiscoveryInfo{service_id, listener};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,7 +101,7 @@ void ClientProxy::StoppedDiscovery() {
|
|||||||
discovered_endpoint_ids_.clear();
|
discovered_endpoint_ids_.clear();
|
||||||
discovery_info_.Clear();
|
discovery_info_.Clear();
|
||||||
}
|
}
|
||||||
if (connections_.empty()) local_endpoint_id_.clear();
|
ResetLocalEndpointIdIfNeeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ClientProxy::IsDiscoveringServiceId(const std::string& service_id) const {
|
bool ClientProxy::IsDiscoveringServiceId(const std::string& service_id) const {
|
||||||
@@ -252,7 +246,7 @@ void ClientProxy::OnDisconnected(const std::string& endpoint_id, bool notify) {
|
|||||||
item->connection_listener.disconnected_cb({endpoint_id});
|
item->connection_listener.disconnected_cb({endpoint_id});
|
||||||
}
|
}
|
||||||
connections_.erase(endpoint_id);
|
connections_.erase(endpoint_id);
|
||||||
if (connections_.empty()) local_endpoint_id_.clear();
|
ResetLocalEndpointIdIfNeeded();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -502,6 +496,13 @@ void ClientProxy::RemoveAllEndpoints() {
|
|||||||
local_endpoint_id_.clear();
|
local_endpoint_id_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ClientProxy::ResetLocalEndpointIdIfNeeded() {
|
||||||
|
MutexLock lock(&mutex_);
|
||||||
|
if (connections_.empty() && !IsAdvertising() && !IsDiscovering()) {
|
||||||
|
local_endpoint_id_.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool ClientProxy::ConnectionStatusesContains(
|
bool ClientProxy::ConnectionStatusesContains(
|
||||||
const std::string& endpoint_id, Connection::Status status_to_match) const {
|
const std::string& endpoint_id, Connection::Status status_to_match) const {
|
||||||
const Connection* item = LookupConnection(endpoint_id);
|
const Connection* item = LookupConnection(endpoint_id);
|
||||||
|
|||||||
@@ -182,6 +182,7 @@ class ClientProxy final {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void RemoveAllEndpoints();
|
void RemoveAllEndpoints();
|
||||||
|
void ResetLocalEndpointIdIfNeeded();
|
||||||
bool ConnectionStatusesContains(const std::string& endpoint_id,
|
bool ConnectionStatusesContains(const std::string& endpoint_id,
|
||||||
Connection::Status status_to_match) const;
|
Connection::Status status_to_match) const;
|
||||||
void AppendConnectionStatus(const std::string& endpoint_id,
|
void AppendConnectionStatus(const std::string& endpoint_id,
|
||||||
|
|||||||
Reference in New Issue
Block a user