mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
Consolidate BWU service ID bookkeeping into the BaseBwuHandler class. This eliminates duplicated code in per-medium BWU handlers and allows us to easily augment the bookkeeping with endpoint IDs in a subsequent CL. Also, localize all service ID wrapping to the BaseBwuHandler class. A postfix is appended to the service ID during bandwidth upgrade, e.g., "NearbyShare_INITIATOR_BWU"; this is done to distinguish a medium's use for advertising/discovery vs. its use for device-to-device connections. This CL should theoretically be a no-op, but per-medium BWU handlers were inconsistent in their implementations. PiperOrigin-RevId: 442019603
56 lines
1.8 KiB
C++
56 lines
1.8 KiB
C++
// Copyright 2022 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 "connections/implementation/base_bwu_handler.h"
|
|
|
|
#include <string>
|
|
#include <utility>
|
|
|
|
#include "connections/implementation/service_id_constants.h"
|
|
#include "internal/platform/logging.h"
|
|
|
|
namespace location {
|
|
namespace nearby {
|
|
namespace connections {
|
|
|
|
BaseBwuHandler::BaseBwuHandler(BwuNotifications bwu_notifications)
|
|
: bwu_notifications_(std::move(bwu_notifications)) {}
|
|
|
|
ByteArray BaseBwuHandler::InitializeUpgradedMediumForEndpoint(
|
|
ClientProxy* client, const std::string& service_id,
|
|
const std::string& endpoint_id) {
|
|
std::string upgrade_service_id = WrapInitiatorUpgradeServiceId(service_id);
|
|
|
|
// Perform any medium-specific handling in the child class.
|
|
ByteArray upgrade_path_available_frame =
|
|
HandleInitializeUpgradedMediumForEndpoint(client, upgrade_service_id,
|
|
endpoint_id);
|
|
if (!upgrade_path_available_frame.Empty()) {
|
|
active_service_ids_.insert(upgrade_service_id);
|
|
}
|
|
|
|
return upgrade_path_available_frame;
|
|
}
|
|
|
|
void BaseBwuHandler::RevertInitiatorState() {
|
|
for (const auto& service_id : active_service_ids_) {
|
|
HandleRevertInitiatorStateForService(service_id);
|
|
}
|
|
active_service_ids_.clear();
|
|
}
|
|
|
|
} // namespace connections
|
|
} // namespace nearby
|
|
} // namespace location
|