blob: 3ee8b2e31bc326bc45330af490d9254bc8dd4058 [file]
// Copyright 2020 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.
#ifndef SRC_DEVELOPER_FORENSICS_UTILS_INSTRUMENTED_BINDING_SET_H_
#define SRC_DEVELOPER_FORENSICS_UTILS_INSTRUMENTED_BINDING_SET_H_
#include <lib/async/dispatcher.h>
#include <lib/fidl/cpp/channel.h>
#include <lib/fidl/cpp/wire/channel.h>
#include <lib/inspect/cpp/vmo/types.h>
#include <string>
#include "src/developer/forensics/utils/inspect_node_manager.h"
namespace forensics {
template <typename Protocol>
requires(fidl::IsProtocolV<Protocol>)
class InstrumentedBindingSet {
public:
InstrumentedBindingSet(async_dispatcher_t* dispatcher, fidl::Server<Protocol>* impl,
InspectNodeManager* node, const std::string& path)
: dispatcher_(dispatcher),
impl_(impl),
current_num_connections_(node->Get(path).CreateUint("current_num_connections", 0)),
total_num_connections_(node->Get(path).CreateUint("total_num_connections", 0)) {}
void AddBinding(fidl::ServerEnd<Protocol> server_end) {
current_num_connections_.Add(1u);
total_num_connections_.Add(1u);
connections_.AddBinding(
dispatcher_, std::move(server_end), impl_,
[this](const fidl::UnbindInfo) { current_num_connections_.Subtract(1u); });
}
private:
async_dispatcher_t* dispatcher_;
fidl::Server<Protocol>* impl_;
inspect::UintProperty current_num_connections_;
inspect::UintProperty total_num_connections_;
fidl::ServerBindingGroup<Protocol> connections_;
};
} // namespace forensics
#endif // SRC_DEVELOPER_FORENSICS_UTILS_INSTRUMENTED_BINDING_SET_H_