1 // Copyright 2019 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "base/fuchsia/scoped_service_binding.h" 6 7 #include <lib/sys/cpp/outgoing_directory.h> 8 #include <lib/vfs/cpp/pseudo_dir.h> 9 #include <lib/vfs/cpp/service.h> 10 11 namespace base { 12 namespace fuchsia { 13 namespace internal { 14 ScopedServiceBindingBase(sys::OutgoingDirectory * outgoing_directory)15ScopedServiceBindingBase::ScopedServiceBindingBase( 16 sys::OutgoingDirectory* outgoing_directory) 17 : ScopedServiceBindingBase( 18 outgoing_directory->GetOrCreateDirectory("svc")) {} 19 ScopedServiceBindingBase(vfs::PseudoDir * pseudo_dir)20ScopedServiceBindingBase::ScopedServiceBindingBase(vfs::PseudoDir* pseudo_dir) 21 : pseudo_dir_(pseudo_dir) {} 22 23 ScopedServiceBindingBase::~ScopedServiceBindingBase() = default; 24 RegisterService(const char * service_name,Connector connector)25void ScopedServiceBindingBase::RegisterService(const char* service_name, 26 Connector connector) { 27 pseudo_dir_->AddEntry(service_name, 28 std::make_unique<vfs::Service>(std::move(connector))); 29 } 30 UnregisterService(const char * service_name)31void ScopedServiceBindingBase::UnregisterService(const char* service_name) { 32 pseudo_dir_->RemoveEntry(service_name); 33 } 34 35 } // namespace internal 36 } // namespace fuchsia 37 } // namespace base 38