diff options
Diffstat (limited to 'src/cpp')
-rw-r--r-- | src/cpp/client/channel_cc.cc | 30 | ||||
-rw-r--r-- | src/cpp/common/channel_arguments.cc | 5 |
2 files changed, 35 insertions, 0 deletions
diff --git a/src/cpp/client/channel_cc.cc b/src/cpp/client/channel_cc.cc index 5f1d00d2b4..357d8317ad 100644 --- a/src/cpp/client/channel_cc.cc +++ b/src/cpp/client/channel_cc.cc @@ -48,6 +48,7 @@ #include <grpc++/support/time.h> #include <grpc/grpc.h> #include <grpc/slice.h> +#include <grpc/support/alloc.h> #include <grpc/support/log.h> #include "src/core/lib/profiling/timers.h" @@ -61,6 +62,35 @@ Channel::Channel(const grpc::string& host, grpc_channel* channel) Channel::~Channel() { grpc_channel_destroy(c_channel_); } +namespace { + +grpc::string GetChannelInfoField(grpc_channel* channel, + grpc_channel_info* channel_info, + char*** channel_info_field) { + char* value = NULL; + memset(channel_info, 0, sizeof(*channel_info)); + *channel_info_field = &value; + grpc_channel_get_info(channel, channel_info); + if (value == NULL) return ""; + grpc::string result = value; + gpr_free(value); + return result; +} + +} // namespace + +grpc::string Channel::GetLoadBalancingPolicyName() const { + grpc_channel_info channel_info; + return GetChannelInfoField(c_channel_, &channel_info, + &channel_info.lb_policy_name); +} + +grpc::string Channel::GetServiceConfigJSON() const { + grpc_channel_info channel_info; + return GetChannelInfoField(c_channel_, &channel_info, + &channel_info.service_config_json); +} + Call Channel::CreateCall(const RpcMethod& method, ClientContext* context, CompletionQueue* cq) { const bool kRegistered = method.channel_tag() && context->authority().empty(); diff --git a/src/cpp/common/channel_arguments.cc b/src/cpp/common/channel_arguments.cc index bc0b68b3e0..1fdd106130 100644 --- a/src/cpp/common/channel_arguments.cc +++ b/src/cpp/common/channel_arguments.cc @@ -148,6 +148,11 @@ void ChannelArguments::SetLoadBalancingPolicyName( SetString(GRPC_ARG_LB_POLICY_NAME, lb_policy_name); } +void ChannelArguments::SetServiceConfigJSON( + const grpc::string& service_config_json) { + SetString(GRPC_ARG_SERVICE_CONFIG, service_config_json); +} + void ChannelArguments::SetInt(const grpc::string& key, int value) { grpc_arg arg; arg.type = GRPC_ARG_INTEGER; |