// Copyright 2018 The Chromium 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 BASE_FUCHSIA_COMPONENT_CONTEXT_H_ #define BASE_FUCHSIA_COMPONENT_CONTEXT_H_ #include "base/base_export.h" #include "base/fuchsia/fidl_interface_request.h" #include "base/fuchsia/scoped_zx_handle.h" #include "base/macros.h" #include "base/strings/string_piece.h" namespace fidl { template class InterfacePtr; template class SynchronousInterfacePtr; } // namespace fidl namespace base { namespace fuchsia { // Provides access to the component's environment. class BASE_EXPORT ComponentContext { public: explicit ComponentContext(ScopedZxHandle service_root); ~ComponentContext(); // Returns default ComponentContext instance for the current process. It uses // /srv namespace to connect to environment services. static ComponentContext* GetDefault(); // Satisfies the interface |request| by binding the channel to a service. void ConnectToService(FidlInterfaceRequest request); // Same as above, but returns interface pointer instead of taking a request. template fidl::InterfacePtr ConnectToService() { fidl::InterfacePtr result; ConnectToService(FidlInterfaceRequest(&result)); return result; } // Connects to an environment service and returns synchronous interface // implementation. template fidl::SynchronousInterfacePtr ConnectToServiceSync() { fidl::SynchronousInterfacePtr result; ConnectToService(FidlInterfaceRequest(&result)); return result; } private: ScopedZxHandle service_root_; DISALLOW_COPY_AND_ASSIGN(ComponentContext); }; } // namespace fuchsia } // namespace base #endif // BASE_FUCHSIA_COMPONENT_CONTEXT_H_