channel_create_impl.cc
Go to the documentation of this file.
1 // Copyright 2021 gRPC authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
16 
18 
19 #ifndef GRPC_NO_BINDER
20 
21 #include <memory>
22 #include <utility>
23 
31 
32 namespace {
33 
35 gpr_once g_factory_once = GPR_ONCE_INIT;
36 
37 void FactoryInit() { g_factory = new grpc_core::BinderClientChannelFactory(); }
38 } // namespace
39 
40 namespace grpc {
41 namespace internal {
42 
44  std::unique_ptr<grpc_binder::Binder> endpoint_binder,
45  const grpc_channel_args* args,
46  std::shared_ptr<grpc::experimental::binder::SecurityPolicy>
47  security_policy) {
49 
51  std::move(endpoint_binder), security_policy);
52  GPR_ASSERT(transport != nullptr);
53 
54  auto channel_args = grpc_core::CoreConfiguration::Get()
57  .Set(GRPC_ARG_DEFAULT_AUTHORITY, "binder.authority");
58  auto channel =
59  grpc_core::Channel::Create("binder_target_placeholder", channel_args,
61  // TODO(mingcl): Handle error properly
62  GPR_ASSERT(channel.ok());
64  return channel->release()->c_ptr();
65 }
66 
69 
70  gpr_once_init(&g_factory_once, FactoryInit);
71 
72  auto channel_args = grpc_core::CoreConfiguration::Get()
75  .SetObject(g_factory);
76 
77  auto channel =
78  grpc_core::Channel::Create("binder_channel_target_placeholder",
79  channel_args, GRPC_CLIENT_CHANNEL, nullptr);
80 
81  if (!channel.ok()) {
83  "binder_channel_target_placeholder",
84  static_cast<grpc_status_code>(channel.status().code()),
85  "Failed to create binder channel");
86  }
87 
88  return channel->release()->c_ptr();
89 }
90 
91 } // namespace internal
92 } // namespace grpc
93 #endif
core_configuration.h
grpc
Definition: grpcpp/alarm.h:33
gpr_once
pthread_once_t gpr_once
Definition: impl/codegen/sync_posix.h:50
binder.h
GRPC_CLIENT_DIRECT_CHANNEL
@ GRPC_CLIENT_DIRECT_CHANNEL
Definition: channel_stack_type.h:34
grpc_lame_client_channel_create
GRPCAPI grpc_channel * grpc_lame_client_channel_create(const char *target, grpc_status_code error_code, const char *error_message)
Definition: lame_client.cc:131
grpc_status_code
grpc_status_code
Definition: include/grpc/impl/codegen/status.h:28
GPR_ONCE_INIT
#define GPR_ONCE_INIT
Definition: impl/codegen/sync_posix.h:52
grpc::internal::CreateClientBinderChannelImpl
grpc_channel * CreateClientBinderChannelImpl(const grpc_channel_args *args)
Definition: channel_create_impl.cc:67
grpc_create_binder_transport_client
grpc_transport * grpc_create_binder_transport_client(std::unique_ptr< grpc_binder::Binder > endpoint_binder, std::shared_ptr< grpc::experimental::binder::SecurityPolicy > security_policy)
Definition: binder_transport.cc:737
grpc_channel_args
Definition: grpc_types.h:132
gpr_once_init
GPRAPI void gpr_once_init(gpr_once *once, void(*init_function)(void))
GRPC_ARG_DEFAULT_AUTHORITY
#define GRPC_ARG_DEFAULT_AUTHORITY
Definition: grpc_types.h:251
grpc_core::ChannelArgs::SetObject
GRPC_MUST_USE_RESULT ChannelArgs SetObject(T *p) const
Definition: channel_args.h:229
channel
wrapped_grpc_channel * channel
Definition: src/php/ext/grpc/call.h:33
asyncio_get_stats.args
args
Definition: asyncio_get_stats.py:40
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
GPR_ASSERT
#define GPR_ASSERT(x)
Definition: include/grpc/impl/codegen/log.h:94
grpc_core::CoreConfiguration::Get
static const CoreConfiguration & Get()
Definition: core_configuration.h:82
transport
grpc_transport transport
Definition: filter_fuzzer.cc:146
grpc_channel_args_destroy
void grpc_channel_args_destroy(grpc_channel_args *a)
Definition: channel_args.cc:360
grpc_core::CoreConfiguration::channel_args_preconditioning
const ChannelArgsPreconditioning & channel_args_preconditioning() const
Definition: core_configuration.h:139
grpc_core::ExecCtx
Definition: exec_ctx.h:97
grpc_core::ChannelArgs::Set
GRPC_MUST_USE_RESULT ChannelArgs Set(absl::string_view name, Value value) const
Definition: channel_args.cc:113
GRPC_CLIENT_CHANNEL
@ GRPC_CLIENT_CHANNEL
Definition: channel_stack_type.h:26
exec_ctx
grpc_core::ExecCtx exec_ctx
Definition: end2end_binder_transport_test.cc:75
channel_create_impl.h
grpc::internal::CreateDirectBinderChannelImplForTesting
grpc_channel * CreateDirectBinderChannelImplForTesting(std::unique_ptr< grpc_binder::Binder > endpoint_binder, const grpc_channel_args *args, std::shared_ptr< grpc::experimental::binder::SecurityPolicy > security_policy)
Definition: channel_create_impl.cc:43
grpc_channel
struct grpc_channel grpc_channel
Definition: grpc_types.h:62
grpc_transport
Definition: transport_impl.h:89
binder_connector.h
channel_args.h
api_trace.h
internal
Definition: benchmark/test/output_test_helper.cc:20
grpc_core::BinderClientChannelFactory
Definition: binder_connector.h:35
grpc_core::ChannelArgsPreconditioning::PreconditionChannelArgs
ChannelArgs PreconditionChannelArgs(const grpc_channel_args *args) const
Definition: channel_args_preconditioning.cc:34
grpc_core::Channel::Create
static absl::StatusOr< RefCountedPtr< Channel > > Create(const char *target, ChannelArgs args, grpc_channel_stack_type channel_stack_type, grpc_transport *optional_transport)
Definition: channel.cc:202
binder_transport.h
channel.h
port_platform.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:58:43