blob: 7d2b92b4ef895db34273409f4633d3cdea729872 [file] [log] [blame]
// Copyright 2019 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 <lib/fidl/cpp/interface_handle.h>
#include <lib/fidl/cpp/service_connector.h>
namespace fidl {
// A connector for a member of a service instance.
template <typename Protocol>
class MemberConnector final {
// Constructs a connector for a member of a service instance.
// As |dir| is not owned by the connector, it must outlive it.
MemberConnector(const ServiceConnector* service, std::string name)
: service_(service), name_(std::move(name)) {}
// Connects to the member using |request|.
zx_status_t Connect(InterfaceRequest<Protocol> request) const {
return service_->Connect(name_, request.TakeChannel());
// Connects to the member and returns a new handle.
InterfaceHandle<Protocol> Connect() const {
InterfaceHandle<Protocol> handle;
zx_status_t status = service_->Connect(name_, handle.NewRequest().TakeChannel());
if (status != ZX_OK) {
return nullptr;
return handle;
// Returns the name of this member.
const std::string& name() const { return name_; }
const ServiceConnector* const service_;
const std::string name_;
} // namespace fidl