blob: df0f5ff9c4d9390c213f0b293b1d629cb9f6785b [file] [log] [blame]
// Copyright 2023 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/devices/bin/driver_manager/bind_result_tracker.h"
namespace driver_manager {
BindResultTracker::BindResultTracker(size_t expected_result_count,
NodeBindingInfoResultCallback result_callback)
: expected_result_count_(expected_result_count),
currently_reported_(0),
result_callback_(std::move(result_callback)) {
ZX_ASSERT(expected_result_count > 0);
}
void BindResultTracker::ReportNoBind() {
size_t current;
{
std::scoped_lock guard(lock_);
currently_reported_++;
current = currently_reported_;
}
Complete(current);
}
void BindResultTracker::ReportSuccessfulBind(const std::string_view& node_name,
const std::string_view& driver) {
size_t current;
{
std::scoped_lock guard(lock_);
currently_reported_++;
auto node_binding_info = fuchsia_driver_development::wire::NodeBindingInfo::Builder(arena_)
.node_name(node_name)
.driver_url(driver)
.Build();
results_.emplace_back(node_binding_info);
current = currently_reported_;
}
Complete(current);
}
void BindResultTracker::ReportSuccessfulBind(
const std::string_view& node_name,
const std::vector<fuchsia_driver_legacy::CompositeParent>& legacy_composite_parents,
const std::vector<fuchsia_driver_framework::CompositeParent>& composite_parents) {
size_t current;
{
std::scoped_lock guard(lock_);
currently_reported_++;
auto node_binding_info =
fuchsia_driver_development::wire::NodeBindingInfo::Builder(arena_)
.node_name(node_name)
.legacy_composite_parents(fidl::ToWire(arena_, legacy_composite_parents))
.composite_parents(fidl::ToWire(arena_, composite_parents))
.Build();
results_.emplace_back(node_binding_info);
current = currently_reported_;
}
Complete(current);
}
void BindResultTracker::Complete(size_t current) {
if (current == expected_result_count_) {
result_callback_(
fidl::VectorView<fuchsia_driver_development::wire::NodeBindingInfo>(arena_, results_));
}
}
} // namespace driver_manager