diff options
Diffstat (limited to 'src/cpp/client/channel_cc.cc')
-rw-r--r-- | src/cpp/client/channel_cc.cc | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/src/cpp/client/channel_cc.cc b/src/cpp/client/channel_cc.cc index 43b3875cb3..357d8317ad 100644 --- a/src/cpp/client/channel_cc.cc +++ b/src/cpp/client/channel_cc.cc @@ -47,8 +47,9 @@ #include <grpc++/support/status.h> #include <grpc++/support/time.h> #include <grpc/grpc.h> +#include <grpc/slice.h> +#include <grpc/support/alloc.h> #include <grpc/support/log.h> -#include <grpc/support/slice.h> #include "src/core/lib/profiling/timers.h" namespace grpc { @@ -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(); @@ -106,11 +136,11 @@ grpc_connectivity_state Channel::GetState(bool try_to_connect) { } namespace { -class TagSaver GRPC_FINAL : public CompletionQueueTag { +class TagSaver final : public CompletionQueueTag { public: explicit TagSaver(void* tag) : tag_(tag) {} - ~TagSaver() GRPC_OVERRIDE {} - bool FinalizeResult(void** tag, bool* status) GRPC_OVERRIDE { + ~TagSaver() override {} + bool FinalizeResult(void** tag, bool* status) override { *tag = tag_; delete this; return true; |