xref: /aosp_15_r20/external/cronet/base/fuchsia/test_interface_natural_impl.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2023 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef BASE_FUCHSIA_TEST_INTERFACE_NATURAL_IMPL_H_
6 #define BASE_FUCHSIA_TEST_INTERFACE_NATURAL_IMPL_H_
7 
8 #include <fidl/base.testfidl/cpp/fidl.h>
9 #include <fidl/fuchsia.io/cpp/markers.h>
10 #include <lib/fidl/cpp/traits.h>
11 #include <lib/fidl/cpp/wire/connect_service.h>
12 #include <lib/sys/cpp/service_directory.h>
13 
14 namespace base {
15 
16 class TestInterfaceNaturalImpl
17     : public fidl::Server<base_testfidl::TestInterface> {
18  public:
19   TestInterfaceNaturalImpl();
20   ~TestInterfaceNaturalImpl() override;
21 
22   // TestInterface implementation:
23   void Add(AddRequest& request, AddCompleter::Sync& completer) override;
24 
bindings()25   fidl::ServerBindingGroup<base_testfidl::TestInterface>& bindings() {
26     return bindings_;
27   }
28 
29  private:
30   fidl::ServerBindingGroup<base_testfidl::TestInterface> bindings_;
31 };
32 
33 // Connects and returns a client for `TestInterface` at the specified `name`.
34 fidl::Client<base_testfidl::TestInterface> CreateTestInterfaceClient(
35     fidl::UnownedClientEnd<fuchsia_io::Directory> service_directory,
36     const std::string& name =
37         fidl::DiscoverableProtocolName<base_testfidl::TestInterface>);
38 
39 // Exercises the `TestInterface` channel identified by `client`, returning
40 // `ZX_OK` on success. Any error-handler for `client` will be removed before
41 // this function returns.
42 zx_status_t VerifyTestInterface(
43     fidl::Client<base_testfidl::TestInterface>& client);
44 
45 }  // namespace base
46 
47 #endif  // BASE_FUCHSIA_TEST_INTERFACE_NATURAL_IMPL_H_
48