Move ClientContext from ::grpc_impl to ::grpc

Reverts: https://github.com/grpc/grpc/pull/19261
pull/23795/head
Karthik Ravi Shankar 4 years ago
parent 0649026e8a
commit 751b9c105f
  1. 1
      BUILD
  2. 1
      BUILD.gn
  3. 2
      CMakeLists.txt
  4. 2
      Makefile
  5. 2
      build_autogenerated.yaml
  6. 1
      gRPC-C++.podspec
  7. 7
      include/grpcpp/channel.h
  8. 27
      include/grpcpp/impl/codegen/async_stream_impl.h
  9. 12
      include/grpcpp/impl/codegen/async_unary_call_impl.h
  10. 8
      include/grpcpp/impl/codegen/call_op_set.h
  11. 9
      include/grpcpp/impl/codegen/channel_interface.h
  12. 36
      include/grpcpp/impl/codegen/client_callback_impl.h
  13. 505
      include/grpcpp/impl/codegen/client_context.h
  14. 517
      include/grpcpp/impl/codegen/client_context_impl.h
  15. 17
      include/grpcpp/impl/codegen/client_interceptor.h
  16. 9
      include/grpcpp/impl/codegen/client_unary_call.h
  17. 2
      include/grpcpp/impl/codegen/intercepted_channel.h
  18. 4
      include/grpcpp/impl/codegen/server_context_impl.h
  19. 21
      include/grpcpp/impl/codegen/sync_stream_impl.h
  20. 16
      src/cpp/client/client_context.cc
  21. 6
      test/cpp/util/cli_call.h
  22. 1
      tools/doxygen/Doxyfile.c++
  23. 1
      tools/doxygen/Doxyfile.c++.internal

@ -2254,7 +2254,6 @@ grpc_cc_library(
"include/grpcpp/impl/codegen/client_callback.h",
"include/grpcpp/impl/codegen/client_callback_impl.h",
"include/grpcpp/impl/codegen/client_context.h",
"include/grpcpp/impl/codegen/client_context_impl.h",
"include/grpcpp/impl/codegen/client_interceptor.h",
"include/grpcpp/impl/codegen/client_unary_call.h",
"include/grpcpp/impl/codegen/completion_queue.h",

@ -1127,7 +1127,6 @@ config("grpc_config") {
"include/grpcpp/impl/codegen/client_callback.h",
"include/grpcpp/impl/codegen/client_callback_impl.h",
"include/grpcpp/impl/codegen/client_context.h",
"include/grpcpp/impl/codegen/client_context_impl.h",
"include/grpcpp/impl/codegen/client_interceptor.h",
"include/grpcpp/impl/codegen/client_unary_call.h",
"include/grpcpp/impl/codegen/completion_queue.h",

@ -2771,7 +2771,6 @@ foreach(_hdr
include/grpcpp/impl/codegen/client_callback.h
include/grpcpp/impl/codegen/client_callback_impl.h
include/grpcpp/impl/codegen/client_context.h
include/grpcpp/impl/codegen/client_context_impl.h
include/grpcpp/impl/codegen/client_interceptor.h
include/grpcpp/impl/codegen/client_unary_call.h
include/grpcpp/impl/codegen/completion_queue.h
@ -3457,7 +3456,6 @@ foreach(_hdr
include/grpcpp/impl/codegen/client_callback.h
include/grpcpp/impl/codegen/client_callback_impl.h
include/grpcpp/impl/codegen/client_context.h
include/grpcpp/impl/codegen/client_context_impl.h
include/grpcpp/impl/codegen/client_interceptor.h
include/grpcpp/impl/codegen/client_unary_call.h
include/grpcpp/impl/codegen/completion_queue.h

@ -4897,7 +4897,6 @@ PUBLIC_HEADERS_CXX += \
include/grpcpp/impl/codegen/client_callback.h \
include/grpcpp/impl/codegen/client_callback_impl.h \
include/grpcpp/impl/codegen/client_context.h \
include/grpcpp/impl/codegen/client_context_impl.h \
include/grpcpp/impl/codegen/client_interceptor.h \
include/grpcpp/impl/codegen/client_unary_call.h \
include/grpcpp/impl/codegen/completion_queue.h \
@ -5581,7 +5580,6 @@ PUBLIC_HEADERS_CXX += \
include/grpcpp/impl/codegen/client_callback.h \
include/grpcpp/impl/codegen/client_callback_impl.h \
include/grpcpp/impl/codegen/client_context.h \
include/grpcpp/impl/codegen/client_context_impl.h \
include/grpcpp/impl/codegen/client_interceptor.h \
include/grpcpp/impl/codegen/client_unary_call.h \
include/grpcpp/impl/codegen/completion_queue.h \

@ -2114,7 +2114,6 @@ libs:
- include/grpcpp/impl/codegen/client_callback.h
- include/grpcpp/impl/codegen/client_callback_impl.h
- include/grpcpp/impl/codegen/client_context.h
- include/grpcpp/impl/codegen/client_context_impl.h
- include/grpcpp/impl/codegen/client_interceptor.h
- include/grpcpp/impl/codegen/client_unary_call.h
- include/grpcpp/impl/codegen/completion_queue.h
@ -2492,7 +2491,6 @@ libs:
- include/grpcpp/impl/codegen/client_callback.h
- include/grpcpp/impl/codegen/client_callback_impl.h
- include/grpcpp/impl/codegen/client_context.h
- include/grpcpp/impl/codegen/client_context_impl.h
- include/grpcpp/impl/codegen/client_interceptor.h
- include/grpcpp/impl/codegen/client_unary_call.h
- include/grpcpp/impl/codegen/completion_queue.h

@ -106,7 +106,6 @@ Pod::Spec.new do |s|
'include/grpcpp/impl/codegen/client_callback.h',
'include/grpcpp/impl/codegen/client_callback_impl.h',
'include/grpcpp/impl/codegen/client_context.h',
'include/grpcpp/impl/codegen/client_context_impl.h',
'include/grpcpp/impl/codegen/client_interceptor.h',
'include/grpcpp/impl/codegen/client_unary_call.h',
'include/grpcpp/impl/codegen/completion_queue.h',

@ -86,7 +86,7 @@ class Channel final : public ::grpc::ChannelInterface,
interceptor_creators);
::grpc::internal::Call CreateCall(const ::grpc::internal::RpcMethod& method,
::grpc_impl::ClientContext* context,
::grpc::ClientContext* context,
::grpc::CompletionQueue* cq) override;
void PerformOpsOnCall(::grpc::internal::CallOpSetInterface* ops,
::grpc::internal::Call* call) override;
@ -101,9 +101,8 @@ class Channel final : public ::grpc::ChannelInterface,
::grpc::CompletionQueue* CallbackCQ() override;
::grpc::internal::Call CreateCallInternal(
const ::grpc::internal::RpcMethod& method,
::grpc_impl::ClientContext* context, ::grpc::CompletionQueue* cq,
size_t interceptor_pos) override;
const ::grpc::internal::RpcMethod& method, ::grpc::ClientContext* context,
::grpc::CompletionQueue* cq, size_t interceptor_pos) override;
const std::string host_;
grpc_channel* const c_channel_; // owned

@ -180,7 +180,7 @@ class ClientAsyncReaderFactory {
static ClientAsyncReader<R>* Create(::grpc::ChannelInterface* channel,
::grpc::CompletionQueue* cq,
const ::grpc::internal::RpcMethod& method,
::grpc_impl::ClientContext* context,
::grpc::ClientContext* context,
const W& request, bool start, void* tag) {
::grpc::internal::Call call = channel->CreateCall(method, context, cq);
return new (::grpc::g_core_codegen_interface->grpc_call_arena_alloc(
@ -259,9 +259,8 @@ class ClientAsyncReader final : public ClientAsyncReaderInterface<R> {
private:
friend class internal::ClientAsyncReaderFactory<R>;
template <class W>
ClientAsyncReader(::grpc::internal::Call call,
::grpc_impl::ClientContext* context, const W& request,
bool start, void* tag)
ClientAsyncReader(::grpc::internal::Call call, ::grpc::ClientContext* context,
const W& request, bool start, void* tag)
: context_(context), call_(call), started_(start) {
// TODO(ctiller): don't assert
GPR_CODEGEN_ASSERT(init_ops_.SendMessage(request).ok());
@ -280,7 +279,7 @@ class ClientAsyncReader final : public ClientAsyncReaderInterface<R> {
call_.PerformOps(&init_ops_);
}
::grpc_impl::ClientContext* context_;
::grpc::ClientContext* context_;
::grpc::internal::Call call_;
bool started_;
::grpc::internal::CallOpSet<::grpc::internal::CallOpSendInitialMetadata,
@ -329,7 +328,7 @@ class ClientAsyncWriterFactory {
static ClientAsyncWriter<W>* Create(::grpc::ChannelInterface* channel,
::grpc::CompletionQueue* cq,
const ::grpc::internal::RpcMethod& method,
::grpc_impl::ClientContext* context,
::grpc::ClientContext* context,
R* response, bool start, void* tag) {
::grpc::internal::Call call = channel->CreateCall(method, context, cq);
return new (::grpc::g_core_codegen_interface->grpc_call_arena_alloc(
@ -426,9 +425,8 @@ class ClientAsyncWriter final : public ClientAsyncWriterInterface<W> {
private:
friend class internal::ClientAsyncWriterFactory<W>;
template <class R>
ClientAsyncWriter(::grpc::internal::Call call,
::grpc_impl::ClientContext* context, R* response,
bool start, void* tag)
ClientAsyncWriter(::grpc::internal::Call call, ::grpc::ClientContext* context,
R* response, bool start, void* tag)
: context_(context), call_(call), started_(start) {
finish_ops_.RecvMessage(response);
finish_ops_.AllowNoMessage();
@ -450,7 +448,7 @@ class ClientAsyncWriter final : public ClientAsyncWriterInterface<W> {
}
}
::grpc_impl::ClientContext* context_;
::grpc::ClientContext* context_;
::grpc::internal::Call call_;
bool started_;
::grpc::internal::CallOpSet<::grpc::internal::CallOpRecvInitialMetadata>
@ -494,8 +492,8 @@ class ClientAsyncReaderWriterFactory {
/// used to send to the server when starting the call.
static ClientAsyncReaderWriter<W, R>* Create(
::grpc::ChannelInterface* channel, ::grpc::CompletionQueue* cq,
const ::grpc::internal::RpcMethod& method,
::grpc_impl::ClientContext* context, bool start, void* tag) {
const ::grpc::internal::RpcMethod& method, ::grpc::ClientContext* context,
bool start, void* tag) {
::grpc::internal::Call call = channel->CreateCall(method, context, cq);
return new (::grpc::g_core_codegen_interface->grpc_call_arena_alloc(
@ -601,8 +599,7 @@ class ClientAsyncReaderWriter final
private:
friend class internal::ClientAsyncReaderWriterFactory<W, R>;
ClientAsyncReaderWriter(::grpc::internal::Call call,
::grpc_impl::ClientContext* context, bool start,
void* tag)
::grpc::ClientContext* context, bool start, void* tag)
: context_(context), call_(call), started_(start) {
if (start) {
StartCallInternal(tag);
@ -622,7 +619,7 @@ class ClientAsyncReaderWriter final
}
}
::grpc_impl::ClientContext* context_;
::grpc::ClientContext* context_;
::grpc::internal::Call call_;
bool started_;
::grpc::internal::CallOpSet<::grpc::internal::CallOpRecvInitialMetadata>

@ -21,7 +21,7 @@
#include <grpcpp/impl/codegen/call.h>
#include <grpcpp/impl/codegen/channel_interface.h>
#include <grpcpp/impl/codegen/client_context_impl.h>
#include <grpcpp/impl/codegen/client_context.h>
#include <grpcpp/impl/codegen/server_context_impl.h>
#include <grpcpp/impl/codegen/service_type.h>
#include <grpcpp/impl/codegen/status.h>
@ -78,8 +78,8 @@ class ClientAsyncResponseReaderFactory {
template <class W>
static ClientAsyncResponseReader<R>* Create(
::grpc::ChannelInterface* channel, ::grpc::CompletionQueue* cq,
const ::grpc::internal::RpcMethod& method,
::grpc_impl::ClientContext* context, const W& request, bool start) {
const ::grpc::internal::RpcMethod& method, ::grpc::ClientContext* context,
const W& request, bool start) {
::grpc::internal::Call call = channel->CreateCall(method, context, cq);
return new (::grpc::g_core_codegen_interface->grpc_call_arena_alloc(
call.call(), sizeof(ClientAsyncResponseReader<R>)))
@ -153,15 +153,15 @@ class ClientAsyncResponseReader final
private:
friend class internal::ClientAsyncResponseReaderFactory<R>;
::grpc_impl::ClientContext* const context_;
::grpc::ClientContext* const context_;
::grpc::internal::Call call_;
bool started_;
bool initial_metadata_read_ = false;
template <class W>
ClientAsyncResponseReader(::grpc::internal::Call call,
::grpc_impl::ClientContext* context,
const W& request, bool start)
::grpc::ClientContext* context, const W& request,
bool start)
: context_(context), call_(call), started_(start) {
// Bind the metadata at time of StartCallInternal but set up the rest here
// TODO(ctiller): don't assert

@ -29,7 +29,7 @@
#include <grpcpp/impl/codegen/call.h>
#include <grpcpp/impl/codegen/call_hook.h>
#include <grpcpp/impl/codegen/call_op_set_interface.h>
#include <grpcpp/impl/codegen/client_context_impl.h>
#include <grpcpp/impl/codegen/client_context.h>
#include <grpcpp/impl/codegen/completion_queue.h>
#include <grpcpp/impl/codegen/completion_queue_tag.h>
#include <grpcpp/impl/codegen/config.h>
@ -721,7 +721,7 @@ class CallOpRecvInitialMetadata {
public:
CallOpRecvInitialMetadata() : metadata_map_(nullptr) {}
void RecvInitialMetadata(::grpc_impl::ClientContext* context) {
void RecvInitialMetadata(::grpc::ClientContext* context) {
context->initial_metadata_received_ = true;
metadata_map_ = &context->recv_initial_metadata_;
}
@ -770,7 +770,7 @@ class CallOpClientRecvStatus {
CallOpClientRecvStatus()
: recv_status_(nullptr), debug_error_string_(nullptr) {}
void ClientRecvStatus(::grpc_impl::ClientContext* context, Status* status) {
void ClientRecvStatus(::grpc::ClientContext* context, Status* status) {
client_context_ = context;
metadata_map_ = &client_context_->trailing_metadata_;
recv_status_ = status;
@ -836,7 +836,7 @@ class CallOpClientRecvStatus {
private:
bool hijacked_ = false;
::grpc_impl::ClientContext* client_context_;
::grpc::ClientContext* client_context_;
MetadataMap* metadata_map_;
Status* recv_status_;
const char* debug_error_string_;

@ -25,7 +25,6 @@
#include <grpcpp/impl/codegen/time.h>
namespace grpc_impl {
class ClientContext;
template <class R>
class ClientReader;
template <class W>
@ -55,6 +54,7 @@ class ClientCallbackUnaryFactory;
namespace grpc {
class ChannelInterface;
class ClientContext;
class CompletionQueue;
namespace experimental {
@ -135,7 +135,7 @@ class ChannelInterface {
friend class ::grpc::experimental::DelegatingChannel;
friend class ::grpc::internal::InterceptedChannel;
virtual internal::Call CreateCall(const internal::RpcMethod& method,
::grpc_impl::ClientContext* context,
::grpc::ClientContext* context,
::grpc::CompletionQueue* cq) = 0;
virtual void PerformOpsOnCall(internal::CallOpSetInterface* ops,
internal::Call* call) = 0;
@ -155,9 +155,8 @@ class ChannelInterface {
// method and adding a new pure method to an interface would be a breaking
// change (even though this is private and non-API)
virtual internal::Call CreateCallInternal(
const internal::RpcMethod& /*method*/,
::grpc_impl::ClientContext* /*context*/, ::grpc::CompletionQueue* /*cq*/,
size_t /*interceptor_pos*/) {
const internal::RpcMethod& /*method*/, ::grpc::ClientContext* /*context*/,
::grpc::CompletionQueue* /*cq*/, size_t /*interceptor_pos*/) {
return internal::Call();
}

@ -30,13 +30,13 @@
namespace grpc {
class Channel;
class ClientContext;
namespace internal {
class RpcMethod;
} // namespace internal
} // namespace grpc
namespace grpc_impl {
class ClientContext;
namespace internal {
@ -45,7 +45,7 @@ namespace internal {
template <class InputMessage, class OutputMessage>
void CallbackUnaryCall(::grpc::ChannelInterface* channel,
const ::grpc::internal::RpcMethod& method,
::grpc_impl::ClientContext* context,
::grpc::ClientContext* context,
const InputMessage* request, OutputMessage* result,
std::function<void(::grpc::Status)> on_completion) {
CallbackUnaryCallImpl<InputMessage, OutputMessage> x(
@ -57,7 +57,7 @@ class CallbackUnaryCallImpl {
public:
CallbackUnaryCallImpl(::grpc::ChannelInterface* channel,
const ::grpc::internal::RpcMethod& method,
::grpc_impl::ClientContext* context,
::grpc::ClientContext* context,
const InputMessage* request, OutputMessage* result,
std::function<void(::grpc::Status)> on_completion) {
::grpc::CompletionQueue* cq = channel->CallbackCQ();
@ -574,7 +574,7 @@ class ClientCallbackReaderWriterImpl
friend class ClientCallbackReaderWriterFactory<Request, Response>;
ClientCallbackReaderWriterImpl(grpc::internal::Call call,
::grpc_impl::ClientContext* context,
::grpc::ClientContext* context,
ClientBidiReactor<Request, Response>* reactor)
: context_(context),
call_(call),
@ -641,7 +641,7 @@ class ClientCallbackReaderWriterImpl
}
}
::grpc_impl::ClientContext* const context_;
::grpc::ClientContext* const context_;
grpc::internal::Call call_;
ClientBidiReactor<Request, Response>* const reactor_;
@ -690,7 +690,7 @@ class ClientCallbackReaderWriterFactory {
public:
static void Create(::grpc::ChannelInterface* channel,
const ::grpc::internal::RpcMethod& method,
::grpc_impl::ClientContext* context,
::grpc::ClientContext* context,
ClientBidiReactor<Request, Response>* reactor) {
grpc::internal::Call call =
channel->CreateCall(method, context, channel->CallbackCQ());
@ -785,8 +785,7 @@ class ClientCallbackReaderImpl : public ClientCallbackReader<Response> {
template <class Request>
ClientCallbackReaderImpl(::grpc::internal::Call call,
::grpc_impl::ClientContext* context,
Request* request,
::grpc::ClientContext* context, Request* request,
ClientReadReactor<Response>* reactor)
: context_(context), call_(call), reactor_(reactor) {
this->BindReactor(reactor);
@ -812,7 +811,7 @@ class ClientCallbackReaderImpl : public ClientCallbackReader<Response> {
}
}
::grpc_impl::ClientContext* const context_;
::grpc::ClientContext* const context_;
grpc::internal::Call call_;
ClientReadReactor<Response>* const reactor_;
@ -848,8 +847,7 @@ class ClientCallbackReaderFactory {
template <class Request>
static void Create(::grpc::ChannelInterface* channel,
const ::grpc::internal::RpcMethod& method,
::grpc_impl::ClientContext* context,
const Request* request,
::grpc::ClientContext* context, const Request* request,
ClientReadReactor<Response>* reactor) {
grpc::internal::Call call =
channel->CreateCall(method, context, channel->CallbackCQ());
@ -970,8 +968,7 @@ class ClientCallbackWriterImpl : public ClientCallbackWriter<Request> {
template <class Response>
ClientCallbackWriterImpl(::grpc::internal::Call call,
::grpc_impl::ClientContext* context,
Response* response,
::grpc::ClientContext* context, Response* response,
ClientWriteReactor<Request>* reactor)
: context_(context),
call_(call),
@ -1027,7 +1024,7 @@ class ClientCallbackWriterImpl : public ClientCallbackWriter<Request> {
}
}
::grpc_impl::ClientContext* const context_;
::grpc::ClientContext* const context_;
grpc::internal::Call call_;
ClientWriteReactor<Request>* const reactor_;
@ -1074,7 +1071,7 @@ class ClientCallbackWriterFactory {
template <class Response>
static void Create(::grpc::ChannelInterface* channel,
const ::grpc::internal::RpcMethod& method,
::grpc_impl::ClientContext* context, Response* response,
::grpc::ClientContext* context, Response* response,
ClientWriteReactor<Request>* reactor) {
grpc::internal::Call call =
channel->CreateCall(method, context, channel->CallbackCQ());
@ -1130,7 +1127,7 @@ class ClientCallbackUnaryImpl final : public ClientCallbackUnary {
template <class Request, class Response>
ClientCallbackUnaryImpl(::grpc::internal::Call call,
::grpc_impl::ClientContext* context, Request* request,
::grpc::ClientContext* context, Request* request,
Response* response, ClientUnaryReactor* reactor)
: context_(context), call_(call), reactor_(reactor) {
this->BindReactor(reactor);
@ -1156,7 +1153,7 @@ class ClientCallbackUnaryImpl final : public ClientCallbackUnary {
}
}
::grpc_impl::ClientContext* const context_;
::grpc::ClientContext* const context_;
grpc::internal::Call call_;
ClientUnaryReactor* const reactor_;
@ -1182,9 +1179,8 @@ class ClientCallbackUnaryFactory {
template <class Request, class Response>
static void Create(::grpc::ChannelInterface* channel,
const ::grpc::internal::RpcMethod& method,
::grpc_impl::ClientContext* context,
const Request* request, Response* response,
ClientUnaryReactor* reactor) {
::grpc::ClientContext* context, const Request* request,
Response* response, ClientUnaryReactor* reactor) {
grpc::internal::Call call =
channel->CreateCall(method, context, channel->CallbackCQ());

@ -1,6 +1,6 @@
/*
*
* Copyright 2019 gRPC authors.
* Copyright 2015 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,15 +16,512 @@
*
*/
/// A ClientContext allows the person implementing a service client to:
///
/// - Add custom metadata key-value pairs that will propagated to the server
/// side.
/// - Control call settings such as compression and authentication.
/// - Initial and trailing metadata coming from the server.
/// - Get performance metrics (ie, census).
///
/// Context settings are only relevant to the call they are invoked with, that
/// is to say, they aren't sticky. Some of these settings, such as the
/// compression options, can be made persistent at channel construction time
/// (see \a grpc::CreateCustomChannel).
///
/// \warning ClientContext instances should \em not be reused across rpcs.
#ifndef GRPCPP_IMPL_CODEGEN_CLIENT_CONTEXT_H
#define GRPCPP_IMPL_CODEGEN_CLIENT_CONTEXT_H
#include <grpcpp/impl/codegen/client_context_impl.h>
#include <map>
#include <memory>
#include <string>
#include <grpc/impl/codegen/compression_types.h>
#include <grpc/impl/codegen/propagation_bits.h>
#include <grpcpp/impl/codegen/client_interceptor.h>
#include <grpcpp/impl/codegen/config.h>
#include <grpcpp/impl/codegen/core_codegen_interface.h>
#include <grpcpp/impl/codegen/create_auth_context.h>
#include <grpcpp/impl/codegen/metadata_map.h>
#include <grpcpp/impl/codegen/rpc_method.h>
#include <grpcpp/impl/codegen/security/auth_context.h>
#include <grpcpp/impl/codegen/slice.h>
#include <grpcpp/impl/codegen/status.h>
#include <grpcpp/impl/codegen/string_ref.h>
#include <grpcpp/impl/codegen/sync.h>
#include <grpcpp/impl/codegen/time.h>
struct census_context;
struct grpc_call;
namespace grpc_impl {
namespace internal {
template <class InputMessage, class OutputMessage>
class CallbackUnaryCallImpl;
template <class Request, class Response>
class ClientCallbackReaderWriterImpl;
template <class Response>
class ClientCallbackReaderImpl;
template <class Request>
class ClientCallbackWriterImpl;
class ClientCallbackUnaryImpl;
class ClientContextAccessor;
} // namespace internal
class ServerContext;
template <class R>
class ClientReader;
template <class W>
class ClientWriter;
template <class W, class R>
class ClientReaderWriter;
template <class R>
class ClientAsyncReader;
template <class W>
class ClientAsyncWriter;
template <class W, class R>
class ClientAsyncReaderWriter;
template <class R>
class ClientAsyncResponseReader;
class ServerContextBase;
class CallbackServerContext;
} // namespace grpc_impl
namespace grpc {
typedef ::grpc_impl::ClientContext ClientContext;
typedef ::grpc_impl::PropagationOptions PropagationOptions;
namespace testing {
class InteropClientContextInspector;
} // namespace testing
namespace internal {
class RpcMethod;
template <class InputMessage, class OutputMessage>
class BlockingUnaryCallImpl;
class CallOpClientRecvStatus;
class CallOpRecvInitialMetadata;
class ServerContextImpl;
template <class InputMessage, class OutputMessage>
class CallbackUnaryCallImpl;
template <class Request, class Response>
class ClientCallbackReaderWriterImpl;
template <class Response>
class ClientCallbackReaderImpl;
template <class Request>
class ClientCallbackWriterImpl;
class ClientCallbackUnaryImpl;
class ClientContextAccessor;
} // namespace internal
class CallCredentials;
class Channel;
class ChannelInterface;
class CompletionQueue;
/// Options for \a ClientContext::FromServerContext specifying which traits from
/// the \a ServerContext to propagate (copy) from it into a new \a
/// ClientContext.
///
/// \see ClientContext::FromServerContext
class PropagationOptions {
public:
PropagationOptions() : propagate_(GRPC_PROPAGATE_DEFAULTS) {}
PropagationOptions& enable_deadline_propagation() {
propagate_ |= GRPC_PROPAGATE_DEADLINE;
return *this;
}
PropagationOptions& disable_deadline_propagation() {
propagate_ &= ~GRPC_PROPAGATE_DEADLINE;
return *this;
}
PropagationOptions& enable_census_stats_propagation() {
propagate_ |= GRPC_PROPAGATE_CENSUS_STATS_CONTEXT;
return *this;
}
PropagationOptions& disable_census_stats_propagation() {
propagate_ &= ~GRPC_PROPAGATE_CENSUS_STATS_CONTEXT;
return *this;
}
PropagationOptions& enable_census_tracing_propagation() {
propagate_ |= GRPC_PROPAGATE_CENSUS_TRACING_CONTEXT;
return *this;
}
PropagationOptions& disable_census_tracing_propagation() {
propagate_ &= ~GRPC_PROPAGATE_CENSUS_TRACING_CONTEXT;
return *this;
}
PropagationOptions& enable_cancellation_propagation() {
propagate_ |= GRPC_PROPAGATE_CANCELLATION;
return *this;
}
PropagationOptions& disable_cancellation_propagation() {
propagate_ &= ~GRPC_PROPAGATE_CANCELLATION;
return *this;
}
uint32_t c_bitmask() const { return propagate_; }
private:
uint32_t propagate_;
};
/// A ClientContext allows the person implementing a service client to:
///
/// - Add custom metadata key-value pairs that will propagated to the server
/// side.
/// - Control call settings such as compression and authentication.
/// - Initial and trailing metadata coming from the server.
/// - Get performance metrics (ie, census).
///
/// Context settings are only relevant to the call they are invoked with, that
/// is to say, they aren't sticky. Some of these settings, such as the
/// compression options, can be made persistent at channel construction time
/// (see \a grpc::CreateCustomChannel).
///
/// \warning ClientContext instances should \em not be reused across rpcs.
/// \warning The ClientContext instance used for creating an rpc must remain
/// alive and valid for the lifetime of the rpc.
class ClientContext {
public:
ClientContext();
~ClientContext();
/// Create a new \a ClientContext as a child of an incoming server call,
/// according to \a options (\see PropagationOptions).
///
/// \param server_context The source server context to use as the basis for
/// constructing the client context.
/// \param options The options controlling what to copy from the \a
/// server_context.
///
/// \return A newly constructed \a ClientContext instance based on \a
/// server_context, with traits propagated (copied) according to \a options.
static std::unique_ptr<ClientContext> FromServerContext(
const grpc_impl::ServerContext& server_context,
PropagationOptions options = PropagationOptions());
static std::unique_ptr<ClientContext> FromCallbackServerContext(
const grpc_impl::CallbackServerContext& server_context,
PropagationOptions options = PropagationOptions());
/// Add the (\a meta_key, \a meta_value) pair to the metadata associated with
/// a client call. These are made available at the server side by the \a
/// grpc::ServerContext::client_metadata() method.
///
/// \warning This method should only be called before invoking the rpc.
///
/// \param meta_key The metadata key. If \a meta_value is binary data, it must
/// end in "-bin".
/// \param meta_value The metadata value. If its value is binary, the key name
/// must end in "-bin".
///
/// Metadata must conform to the following format:
/// Custom-Metadata -> Binary-Header / ASCII-Header
/// Binary-Header -> {Header-Name "-bin" } {binary value}
/// ASCII-Header -> Header-Name ASCII-Value
/// Header-Name -> 1*( %x30-39 / %x61-7A / "_" / "-" / ".") ; 0-9 a-z _ - .
/// ASCII-Value -> 1*( %x20-%x7E ) ; space and printable ASCII
void AddMetadata(const std::string& meta_key, const std::string& meta_value);
/// Return a collection of initial metadata key-value pairs. Note that keys
/// may happen more than once (ie, a \a std::multimap is returned).
///
/// \warning This method should only be called after initial metadata has been
/// received. For streaming calls, see \a
/// ClientReaderInterface::WaitForInitialMetadata().
///
/// \return A multimap of initial metadata key-value pairs from the server.
const std::multimap<grpc::string_ref, grpc::string_ref>&
GetServerInitialMetadata() const {
GPR_CODEGEN_ASSERT(initial_metadata_received_);
return *recv_initial_metadata_.map();
}
/// Return a collection of trailing metadata key-value pairs. Note that keys
/// may happen more than once (ie, a \a std::multimap is returned).
///
/// \warning This method is only callable once the stream has finished.
///
/// \return A multimap of metadata trailing key-value pairs from the server.
const std::multimap<grpc::string_ref, grpc::string_ref>&
GetServerTrailingMetadata() const {
// TODO(yangg) check finished
return *trailing_metadata_.map();
}
/// Set the deadline for the client call.
///
/// \warning This method should only be called before invoking the rpc.
///
/// \param deadline the deadline for the client call. Units are determined by
/// the type used. The deadline is an absolute (not relative) time.
template <typename T>
void set_deadline(const T& deadline) {
grpc::TimePoint<T> deadline_tp(deadline);
deadline_ = deadline_tp.raw_time();
}
/// EXPERIMENTAL: Indicate that this request is idempotent.
/// By default, RPCs are assumed to <i>not</i> be idempotent.
///
/// If true, the gRPC library assumes that it's safe to initiate
/// this RPC multiple times.
void set_idempotent(bool idempotent) { idempotent_ = idempotent; }
/// EXPERIMENTAL: Set this request to be cacheable.
/// If set, grpc is free to use the HTTP GET verb for sending the request,
/// with the possibility of receiving a cached response.
void set_cacheable(bool cacheable) { cacheable_ = cacheable; }
/// EXPERIMENTAL: Trigger wait-for-ready or not on this request.
/// See https://github.com/grpc/grpc/blob/master/doc/wait-for-ready.md.
/// If set, if an RPC is made when a channel's connectivity state is
/// TRANSIENT_FAILURE or CONNECTING, the call will not "fail fast",
/// and the channel will wait until the channel is READY before making the
/// call.
void set_wait_for_ready(bool wait_for_ready) {
wait_for_ready_ = wait_for_ready;
wait_for_ready_explicitly_set_ = true;
}
/// DEPRECATED: Use set_wait_for_ready() instead.
void set_fail_fast(bool fail_fast) { set_wait_for_ready(!fail_fast); }
/// Return the deadline for the client call.
std::chrono::system_clock::time_point deadline() const {
return grpc::Timespec2Timepoint(deadline_);
}
/// Return a \a gpr_timespec representation of the client call's deadline.
gpr_timespec raw_deadline() const { return deadline_; }
/// Set the per call authority header (see
/// https://tools.ietf.org/html/rfc7540#section-8.1.2.3).
void set_authority(const std::string& authority) { authority_ = authority; }
/// Return the authentication context for the associated client call.
/// It is only valid to call this during the lifetime of the client call.
///
/// \see grpc::AuthContext.
std::shared_ptr<const grpc::AuthContext> auth_context() const {
if (auth_context_.get() == nullptr) {
auth_context_ = grpc::CreateAuthContext(call_);
}
return auth_context_;
}
/// Set credentials for the client call.
///
/// A credentials object encapsulates all the state needed by a client to
/// authenticate with a server and make various assertions, e.g., about the
/// client’s identity, role, or whether it is authorized to make a particular
/// call.
///
/// It is legal to call this only before initial metadata is sent.
///
/// \see https://grpc.io/docs/guides/auth.html
void set_credentials(const std::shared_ptr<grpc::CallCredentials>& creds);
/// EXPERIMENTAL debugging API
///
/// Returns the credentials for the client call. This should be used only in
/// tests and for diagnostic purposes, and should not be used by application
/// logic.
std::shared_ptr<grpc::CallCredentials> credentials() { return creds_; }
/// Return the compression algorithm the client call will request be used.
/// Note that the gRPC runtime may decide to ignore this request, for example,
/// due to resource constraints.
grpc_compression_algorithm compression_algorithm() const {
return compression_algorithm_;
}
/// Set \a algorithm to be the compression algorithm used for the client call.
///
/// \param algorithm The compression algorithm used for the client call.
void set_compression_algorithm(grpc_compression_algorithm algorithm);
/// Flag whether the initial metadata should be \a corked
///
/// If \a corked is true, then the initial metadata will be coalesced with the
/// write of first message in the stream. As a result, any tag set for the
/// initial metadata operation (starting a client-streaming or bidi-streaming
/// RPC) will not actually be sent to the completion queue or delivered
/// via Next.
///
/// \param corked The flag indicating whether the initial metadata is to be
/// corked or not.
void set_initial_metadata_corked(bool corked) {
initial_metadata_corked_ = corked;
}
/// Return the peer uri in a string.
/// It is only valid to call this during the lifetime of the client call.
///
/// \warning This value is never authenticated or subject to any security
/// related code. It must not be used for any authentication related
/// functionality. Instead, use auth_context.
///
/// \return The call's peer URI.
std::string peer() const;
/// Sets the census context.
/// It is only valid to call this before the client call is created. A common
/// place of setting census context is from within the DefaultConstructor
/// method of GlobalCallbacks.
void set_census_context(struct census_context* ccp) { census_context_ = ccp; }
/// Returns the census context that has been set, or nullptr if not set.
struct census_context* census_context() const {
return census_context_;
}
/// Send a best-effort out-of-band cancel on the call associated with
/// this client context. The call could be in any stage; e.g., if it is
/// already finished, it may still return success.
///
/// There is no guarantee the call will be cancelled.
///
/// Note that TryCancel() does not change any of the tags that are pending
/// on the completion queue. All pending tags will still be delivered
/// (though their ok result may reflect the effect of cancellation).
void TryCancel();
/// Global Callbacks
///
/// Can be set exactly once per application to install hooks whenever
/// a client context is constructed and destructed.
class GlobalCallbacks {
public:
virtual ~GlobalCallbacks() {}
virtual void DefaultConstructor(ClientContext* context) = 0;
virtual void Destructor(ClientContext* context) = 0;
};
static void SetGlobalCallbacks(GlobalCallbacks* callbacks);
/// Should be used for framework-level extensions only.
/// Applications never need to call this method.
grpc_call* c_call() { return call_; }
/// EXPERIMENTAL debugging API
///
/// if status is not ok() for an RPC, this will return a detailed string
/// of the gRPC Core error that led to the failure. It should not be relied
/// upon for anything other than gaining more debug data in failure cases.
std::string debug_error_string() const { return debug_error_string_; }
private:
// Disallow copy and assign.
ClientContext(const ClientContext&);
ClientContext& operator=(const ClientContext&);
friend class ::grpc::testing::InteropClientContextInspector;
friend class ::grpc::internal::CallOpClientRecvStatus;
friend class ::grpc::internal::CallOpRecvInitialMetadata;
friend class ::grpc::Channel;
template <class R>
friend class ::grpc_impl::ClientReader;
template <class W>
friend class ::grpc_impl::ClientWriter;
template <class W, class R>
friend class ::grpc_impl::ClientReaderWriter;
template <class R>
friend class ::grpc_impl::ClientAsyncReader;
template <class W>
friend class ::grpc_impl::ClientAsyncWriter;
template <class W, class R>
friend class ::grpc_impl::ClientAsyncReaderWriter;
template <class R>
friend class ::grpc_impl::ClientAsyncResponseReader;
template <class InputMessage, class OutputMessage>
friend class ::grpc::internal::BlockingUnaryCallImpl;
template <class InputMessage, class OutputMessage>
friend class ::grpc_impl::internal::CallbackUnaryCallImpl;
template <class Request, class Response>
friend class ::grpc_impl::internal::ClientCallbackReaderWriterImpl;
template <class Response>
friend class ::grpc_impl::internal::ClientCallbackReaderImpl;
template <class Request>
friend class ::grpc_impl::internal::ClientCallbackWriterImpl;
friend class ::grpc_impl::internal::ClientCallbackUnaryImpl;
friend class ::grpc_impl::internal::ClientContextAccessor;
// Used by friend class CallOpClientRecvStatus
void set_debug_error_string(const std::string& debug_error_string) {
debug_error_string_ = debug_error_string;
}
grpc_call* call() const { return call_; }
void set_call(grpc_call* call,
const std::shared_ptr<::grpc::Channel>& channel);
grpc::experimental::ClientRpcInfo* set_client_rpc_info(
const char* method, grpc::internal::RpcMethod::RpcType type,
grpc::ChannelInterface* channel,
const std::vector<std::unique_ptr<
grpc::experimental::ClientInterceptorFactoryInterface>>& creators,
size_t interceptor_pos) {
rpc_info_ = grpc::experimental::ClientRpcInfo(this, type, method, channel);
rpc_info_.RegisterInterceptors(creators, interceptor_pos);
return &rpc_info_;
}
uint32_t initial_metadata_flags() const {
return (idempotent_ ? GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST : 0) |
(wait_for_ready_ ? GRPC_INITIAL_METADATA_WAIT_FOR_READY : 0) |
(cacheable_ ? GRPC_INITIAL_METADATA_CACHEABLE_REQUEST : 0) |
(wait_for_ready_explicitly_set_
? GRPC_INITIAL_METADATA_WAIT_FOR_READY_EXPLICITLY_SET
: 0) |
(initial_metadata_corked_ ? GRPC_INITIAL_METADATA_CORKED : 0);
}
std::string authority() { return authority_; }
void SendCancelToInterceptors();
static std::unique_ptr<ClientContext> FromInternalServerContext(
const grpc_impl::ServerContextBase& server_context,
PropagationOptions options);
bool initial_metadata_received_;
bool wait_for_ready_;
bool wait_for_ready_explicitly_set_;
bool idempotent_;
bool cacheable_;
std::shared_ptr<::grpc::Channel> channel_;
grpc::internal::Mutex mu_;
grpc_call* call_;
bool call_canceled_;
gpr_timespec deadline_;
grpc::string authority_;
std::shared_ptr<grpc::CallCredentials> creds_;
mutable std::shared_ptr<const grpc::AuthContext> auth_context_;
struct census_context* census_context_;
std::multimap<std::string, std::string> send_initial_metadata_;
mutable grpc::internal::MetadataMap recv_initial_metadata_;
mutable grpc::internal::MetadataMap trailing_metadata_;
grpc_call* propagate_from_call_;
PropagationOptions propagation_options_;
grpc_compression_algorithm compression_algorithm_;
bool initial_metadata_corked_;
std::string debug_error_string_;
grpc::experimental::ClientRpcInfo rpc_info_;
};
} // namespace grpc

@ -1,517 +0,0 @@
/*
*
* Copyright 2015 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/// A ClientContext allows the person implementing a service client to:
///
/// - Add custom metadata key-value pairs that will propagated to the server
/// side.
/// - Control call settings such as compression and authentication.
/// - Initial and trailing metadata coming from the server.
/// - Get performance metrics (ie, census).
///
/// Context settings are only relevant to the call they are invoked with, that
/// is to say, they aren't sticky. Some of these settings, such as the
/// compression options, can be made persistent at channel construction time
/// (see \a grpc::CreateCustomChannel).
///
/// \warning ClientContext instances should \em not be reused across rpcs.
#ifndef GRPCPP_IMPL_CODEGEN_CLIENT_CONTEXT_IMPL_H
#define GRPCPP_IMPL_CODEGEN_CLIENT_CONTEXT_IMPL_H
#include <map>
#include <memory>
#include <string>
#include <grpc/impl/codegen/compression_types.h>
#include <grpc/impl/codegen/propagation_bits.h>
#include <grpcpp/impl/codegen/client_interceptor.h>
#include <grpcpp/impl/codegen/config.h>
#include <grpcpp/impl/codegen/core_codegen_interface.h>
#include <grpcpp/impl/codegen/create_auth_context.h>
#include <grpcpp/impl/codegen/metadata_map.h>
#include <grpcpp/impl/codegen/rpc_method.h>
#include <grpcpp/impl/codegen/security/auth_context.h>
#include <grpcpp/impl/codegen/slice.h>
#include <grpcpp/impl/codegen/status.h>
#include <grpcpp/impl/codegen/string_ref.h>
#include <grpcpp/impl/codegen/sync.h>
#include <grpcpp/impl/codegen/time.h>
struct census_context;
struct grpc_call;
namespace grpc {
class CallCredentials;
class Channel;
class ChannelInterface;
class CompletionQueue;
namespace internal {
class RpcMethod;
template <class InputMessage, class OutputMessage>
class BlockingUnaryCallImpl;
class CallOpClientRecvStatus;
class CallOpRecvInitialMetadata;
class ServerContextImpl;
} // namespace internal
namespace testing {
class InteropClientContextInspector;
} // namespace testing
} // namespace grpc
namespace grpc_impl {
namespace internal {
template <class InputMessage, class OutputMessage>
class CallbackUnaryCallImpl;
template <class Request, class Response>
class ClientCallbackReaderWriterImpl;
template <class Response>
class ClientCallbackReaderImpl;
template <class Request>
class ClientCallbackWriterImpl;
class ClientCallbackUnaryImpl;
class ClientContextAccessor;
} // namespace internal
class ServerContext;
template <class R>
class ClientReader;
template <class W>
class ClientWriter;
template <class W, class R>
class ClientReaderWriter;
template <class R>
class ClientAsyncReader;
template <class W>
class ClientAsyncWriter;
template <class W, class R>
class ClientAsyncReaderWriter;
template <class R>
class ClientAsyncResponseReader;
class ServerContextBase;
class CallbackServerContext;
/// Options for \a ClientContext::FromServerContext specifying which traits from
/// the \a ServerContext to propagate (copy) from it into a new \a
/// ClientContext.
///
/// \see ClientContext::FromServerContext
class PropagationOptions {
public:
PropagationOptions() : propagate_(GRPC_PROPAGATE_DEFAULTS) {}
PropagationOptions& enable_deadline_propagation() {
propagate_ |= GRPC_PROPAGATE_DEADLINE;
return *this;
}
PropagationOptions& disable_deadline_propagation() {
propagate_ &= ~GRPC_PROPAGATE_DEADLINE;
return *this;
}
PropagationOptions& enable_census_stats_propagation() {
propagate_ |= GRPC_PROPAGATE_CENSUS_STATS_CONTEXT;
return *this;
}
PropagationOptions& disable_census_stats_propagation() {
propagate_ &= ~GRPC_PROPAGATE_CENSUS_STATS_CONTEXT;
return *this;
}
PropagationOptions& enable_census_tracing_propagation() {
propagate_ |= GRPC_PROPAGATE_CENSUS_TRACING_CONTEXT;
return *this;
}
PropagationOptions& disable_census_tracing_propagation() {
propagate_ &= ~GRPC_PROPAGATE_CENSUS_TRACING_CONTEXT;
return *this;
}
PropagationOptions& enable_cancellation_propagation() {
propagate_ |= GRPC_PROPAGATE_CANCELLATION;
return *this;
}
PropagationOptions& disable_cancellation_propagation() {
propagate_ &= ~GRPC_PROPAGATE_CANCELLATION;
return *this;
}
uint32_t c_bitmask() const { return propagate_; }
private:
uint32_t propagate_;
};
/// A ClientContext allows the person implementing a service client to:
///
/// - Add custom metadata key-value pairs that will propagated to the server
/// side.
/// - Control call settings such as compression and authentication.
/// - Initial and trailing metadata coming from the server.
/// - Get performance metrics (ie, census).
///
/// Context settings are only relevant to the call they are invoked with, that
/// is to say, they aren't sticky. Some of these settings, such as the
/// compression options, can be made persistent at channel construction time
/// (see \a grpc::CreateCustomChannel).
///
/// \warning ClientContext instances should \em not be reused across rpcs.
/// \warning The ClientContext instance used for creating an rpc must remain
/// alive and valid for the lifetime of the rpc.
class ClientContext {
public:
ClientContext();
~ClientContext();
/// Create a new \a ClientContext as a child of an incoming server call,
/// according to \a options (\see PropagationOptions).
///
/// \param server_context The source server context to use as the basis for
/// constructing the client context.
/// \param options The options controlling what to copy from the \a
/// server_context.
///
/// \return A newly constructed \a ClientContext instance based on \a
/// server_context, with traits propagated (copied) according to \a options.
static std::unique_ptr<ClientContext> FromServerContext(
const grpc_impl::ServerContext& server_context,
PropagationOptions options = PropagationOptions());
static std::unique_ptr<ClientContext> FromCallbackServerContext(
const grpc_impl::CallbackServerContext& server_context,
PropagationOptions options = PropagationOptions());
/// Add the (\a meta_key, \a meta_value) pair to the metadata associated with
/// a client call. These are made available at the server side by the \a
/// grpc::ServerContext::client_metadata() method.
///
/// \warning This method should only be called before invoking the rpc.
///
/// \param meta_key The metadata key. If \a meta_value is binary data, it must
/// end in "-bin".
/// \param meta_value The metadata value. If its value is binary, the key name
/// must end in "-bin".
///
/// Metadata must conform to the following format:
/// Custom-Metadata -> Binary-Header / ASCII-Header
/// Binary-Header -> {Header-Name "-bin" } {binary value}
/// ASCII-Header -> Header-Name ASCII-Value
/// Header-Name -> 1*( %x30-39 / %x61-7A / "_" / "-" / ".") ; 0-9 a-z _ - .
/// ASCII-Value -> 1*( %x20-%x7E ) ; space and printable ASCII
void AddMetadata(const std::string& meta_key, const std::string& meta_value);
/// Return a collection of initial metadata key-value pairs. Note that keys
/// may happen more than once (ie, a \a std::multimap is returned).
///
/// \warning This method should only be called after initial metadata has been
/// received. For streaming calls, see \a
/// ClientReaderInterface::WaitForInitialMetadata().
///
/// \return A multimap of initial metadata key-value pairs from the server.
const std::multimap<grpc::string_ref, grpc::string_ref>&
GetServerInitialMetadata() const {
GPR_CODEGEN_ASSERT(initial_metadata_received_);
return *recv_initial_metadata_.map();
}
/// Return a collection of trailing metadata key-value pairs. Note that keys
/// may happen more than once (ie, a \a std::multimap is returned).
///
/// \warning This method is only callable once the stream has finished.
///
/// \return A multimap of metadata trailing key-value pairs from the server.
const std::multimap<grpc::string_ref, grpc::string_ref>&
GetServerTrailingMetadata() const {
// TODO(yangg) check finished
return *trailing_metadata_.map();
}
/// Set the deadline for the client call.
///
/// \warning This method should only be called before invoking the rpc.
///
/// \param deadline the deadline for the client call. Units are determined by
/// the type used. The deadline is an absolute (not relative) time.
template <typename T>
void set_deadline(const T& deadline) {
grpc::TimePoint<T> deadline_tp(deadline);
deadline_ = deadline_tp.raw_time();
}
/// EXPERIMENTAL: Indicate that this request is idempotent.
/// By default, RPCs are assumed to <i>not</i> be idempotent.
///
/// If true, the gRPC library assumes that it's safe to initiate
/// this RPC multiple times.
void set_idempotent(bool idempotent) { idempotent_ = idempotent; }
/// EXPERIMENTAL: Set this request to be cacheable.
/// If set, grpc is free to use the HTTP GET verb for sending the request,
/// with the possibility of receiving a cached response.
void set_cacheable(bool cacheable) { cacheable_ = cacheable; }
/// EXPERIMENTAL: Trigger wait-for-ready or not on this request.
/// See https://github.com/grpc/grpc/blob/master/doc/wait-for-ready.md.
/// If set, if an RPC is made when a channel's connectivity state is
/// TRANSIENT_FAILURE or CONNECTING, the call will not "fail fast",
/// and the channel will wait until the channel is READY before making the
/// call.
void set_wait_for_ready(bool wait_for_ready) {
wait_for_ready_ = wait_for_ready;
wait_for_ready_explicitly_set_ = true;
}
/// DEPRECATED: Use set_wait_for_ready() instead.
void set_fail_fast(bool fail_fast) { set_wait_for_ready(!fail_fast); }
/// Return the deadline for the client call.
std::chrono::system_clock::time_point deadline() const {
return grpc::Timespec2Timepoint(deadline_);
}
/// Return a \a gpr_timespec representation of the client call's deadline.
gpr_timespec raw_deadline() const { return deadline_; }
/// Set the per call authority header (see
/// https://tools.ietf.org/html/rfc7540#section-8.1.2.3).
void set_authority(const std::string& authority) { authority_ = authority; }
/// Return the authentication context for the associated client call.
/// It is only valid to call this during the lifetime of the client call.
///
/// \see grpc::AuthContext.
std::shared_ptr<const grpc::AuthContext> auth_context() const {
if (auth_context_.get() == nullptr) {
auth_context_ = grpc::CreateAuthContext(call_);
}
return auth_context_;
}
/// Set credentials for the client call.
///
/// A credentials object encapsulates all the state needed by a client to
/// authenticate with a server and make various assertions, e.g., about the
/// client’s identity, role, or whether it is authorized to make a particular
/// call.
///
/// It is legal to call this only before initial metadata is sent.
///
/// \see https://grpc.io/docs/guides/auth.html
void set_credentials(const std::shared_ptr<grpc::CallCredentials>& creds);
/// EXPERIMENTAL debugging API
///
/// Returns the credentials for the client call. This should be used only in
/// tests and for diagnostic purposes, and should not be used by application
/// logic.
std::shared_ptr<grpc::CallCredentials> credentials() { return creds_; }
/// Return the compression algorithm the client call will request be used.
/// Note that the gRPC runtime may decide to ignore this request, for example,
/// due to resource constraints.
grpc_compression_algorithm compression_algorithm() const {
return compression_algorithm_;
}
/// Set \a algorithm to be the compression algorithm used for the client call.
///
/// \param algorithm The compression algorithm used for the client call.
void set_compression_algorithm(grpc_compression_algorithm algorithm);
/// Flag whether the initial metadata should be \a corked
///
/// If \a corked is true, then the initial metadata will be coalesced with the
/// write of first message in the stream. As a result, any tag set for the
/// initial metadata operation (starting a client-streaming or bidi-streaming
/// RPC) will not actually be sent to the completion queue or delivered
/// via Next.
///
/// \param corked The flag indicating whether the initial metadata is to be
/// corked or not.
void set_initial_metadata_corked(bool corked) {
initial_metadata_corked_ = corked;
}
/// Return the peer uri in a string.
/// It is only valid to call this during the lifetime of the client call.
///
/// \warning This value is never authenticated or subject to any security
/// related code. It must not be used for any authentication related
/// functionality. Instead, use auth_context.
///
/// \return The call's peer URI.
std::string peer() const;
/// Sets the census context.
/// It is only valid to call this before the client call is created. A common
/// place of setting census context is from within the DefaultConstructor
/// method of GlobalCallbacks.
void set_census_context(struct census_context* ccp) { census_context_ = ccp; }
/// Returns the census context that has been set, or nullptr if not set.
struct census_context* census_context() const {
return census_context_;
}
/// Send a best-effort out-of-band cancel on the call associated with
/// this client context. The call could be in any stage; e.g., if it is
/// already finished, it may still return success.
///
/// There is no guarantee the call will be cancelled.
///
/// Note that TryCancel() does not change any of the tags that are pending
/// on the completion queue. All pending tags will still be delivered
/// (though their ok result may reflect the effect of cancellation).
void TryCancel();
/// Global Callbacks
///
/// Can be set exactly once per application to install hooks whenever
/// a client context is constructed and destructed.
class GlobalCallbacks {
public:
virtual ~GlobalCallbacks() {}
virtual void DefaultConstructor(ClientContext* context) = 0;
virtual void Destructor(ClientContext* context) = 0;
};
static void SetGlobalCallbacks(GlobalCallbacks* callbacks);
/// Should be used for framework-level extensions only.
/// Applications never need to call this method.
grpc_call* c_call() { return call_; }
/// EXPERIMENTAL debugging API
///
/// if status is not ok() for an RPC, this will return a detailed string
/// of the gRPC Core error that led to the failure. It should not be relied
/// upon for anything other than gaining more debug data in failure cases.
std::string debug_error_string() const { return debug_error_string_; }
private:
// Disallow copy and assign.
ClientContext(const ClientContext&);
ClientContext& operator=(const ClientContext&);
friend class ::grpc::testing::InteropClientContextInspector;
friend class ::grpc::internal::CallOpClientRecvStatus;
friend class ::grpc::internal::CallOpRecvInitialMetadata;
friend class ::grpc::Channel;
template <class R>
friend class ::grpc_impl::ClientReader;
template <class W>
friend class ::grpc_impl::ClientWriter;
template <class W, class R>
friend class ::grpc_impl::ClientReaderWriter;
template <class R>
friend class ::grpc_impl::ClientAsyncReader;
template <class W>
friend class ::grpc_impl::ClientAsyncWriter;
template <class W, class R>
friend class ::grpc_impl::ClientAsyncReaderWriter;
template <class R>
friend class ::grpc_impl::ClientAsyncResponseReader;
template <class InputMessage, class OutputMessage>
friend class ::grpc::internal::BlockingUnaryCallImpl;
template <class InputMessage, class OutputMessage>
friend class ::grpc_impl::internal::CallbackUnaryCallImpl;
template <class Request, class Response>
friend class ::grpc_impl::internal::ClientCallbackReaderWriterImpl;
template <class Response>
friend class ::grpc_impl::internal::ClientCallbackReaderImpl;
template <class Request>
friend class ::grpc_impl::internal::ClientCallbackWriterImpl;
friend class ::grpc_impl::internal::ClientCallbackUnaryImpl;
friend class ::grpc_impl::internal::ClientContextAccessor;
// Used by friend class CallOpClientRecvStatus
void set_debug_error_string(const std::string& debug_error_string) {
debug_error_string_ = debug_error_string;
}
grpc_call* call() const { return call_; }
void set_call(grpc_call* call,
const std::shared_ptr<::grpc::Channel>& channel);
grpc::experimental::ClientRpcInfo* set_client_rpc_info(
const char* method, grpc::internal::RpcMethod::RpcType type,
grpc::ChannelInterface* channel,
const std::vector<std::unique_ptr<
grpc::experimental::ClientInterceptorFactoryInterface>>& creators,
size_t interceptor_pos) {
rpc_info_ = grpc::experimental::ClientRpcInfo(this, type, method, channel);
rpc_info_.RegisterInterceptors(creators, interceptor_pos);
return &rpc_info_;
}
uint32_t initial_metadata_flags() const {
return (idempotent_ ? GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST : 0) |
(wait_for_ready_ ? GRPC_INITIAL_METADATA_WAIT_FOR_READY : 0) |
(cacheable_ ? GRPC_INITIAL_METADATA_CACHEABLE_REQUEST : 0) |
(wait_for_ready_explicitly_set_
? GRPC_INITIAL_METADATA_WAIT_FOR_READY_EXPLICITLY_SET
: 0) |
(initial_metadata_corked_ ? GRPC_INITIAL_METADATA_CORKED : 0);
}
std::string authority() { return authority_; }
void SendCancelToInterceptors();
static std::unique_ptr<ClientContext> FromInternalServerContext(
const grpc_impl::ServerContextBase& server_context,
PropagationOptions options);
bool initial_metadata_received_;
bool wait_for_ready_;
bool wait_for_ready_explicitly_set_;
bool idempotent_;
bool cacheable_;
std::shared_ptr<::grpc::Channel> channel_;
grpc::internal::Mutex mu_;
grpc_call* call_;
bool call_canceled_;
gpr_timespec deadline_;
grpc::string authority_;
std::shared_ptr<grpc::CallCredentials> creds_;
mutable std::shared_ptr<const grpc::AuthContext> auth_context_;
struct census_context* census_context_;
std::multimap<std::string, std::string> send_initial_metadata_;
mutable grpc::internal::MetadataMap recv_initial_metadata_;
mutable grpc::internal::MetadataMap trailing_metadata_;
grpc_call* propagate_from_call_;
PropagationOptions propagation_options_;
grpc_compression_algorithm compression_algorithm_;
bool initial_metadata_corked_;
std::string debug_error_string_;
grpc::experimental::ClientRpcInfo rpc_info_;
};
} // namespace grpc_impl
#endif // GRPCPP_IMPL_CODEGEN_CLIENT_CONTEXT_IMPL_H

@ -26,14 +26,10 @@
#include <grpcpp/impl/codegen/rpc_method.h>
#include <grpcpp/impl/codegen/string_ref.h>
namespace grpc_impl {
class ClientContext;
} // namespace grpc_impl
namespace grpc {
class Channel;
class ClientContext;
namespace internal {
class InterceptorBatchMethodsImpl;
@ -96,7 +92,7 @@ class ClientRpcInfo {
/// Return a pointer to the underlying ClientContext structure associated
/// with the RPC to support features that apply to it
grpc_impl::ClientContext* client_context() { return ctx_; }
grpc::ClientContext* client_context() { return ctx_; }
/// Return the type of the RPC (unary or a streaming flavor)
Type type() const { return type_; }
@ -119,9 +115,8 @@ class ClientRpcInfo {
ClientRpcInfo() = default;
// Constructor will only be called from ClientContext
ClientRpcInfo(grpc_impl::ClientContext* ctx,
internal::RpcMethod::RpcType type, const char* method,
grpc::ChannelInterface* channel)
ClientRpcInfo(grpc::ClientContext* ctx, internal::RpcMethod::RpcType type,
const char* method, grpc::ChannelInterface* channel)
: ctx_(ctx),
type_(static_cast<Type>(type)),
method_(method),
@ -163,7 +158,7 @@ class ClientRpcInfo {
}
}
grpc_impl::ClientContext* ctx_ = nullptr;
grpc::ClientContext* ctx_ = nullptr;
// TODO(yashykt): make type_ const once move-assignment is deleted
Type type_{Type::UNKNOWN};
const char* method_ = nullptr;
@ -173,7 +168,7 @@ class ClientRpcInfo {
size_t hijacked_interceptor_ = 0;
friend class internal::InterceptorBatchMethodsImpl;
friend class grpc_impl::ClientContext;
friend class grpc::ClientContext;
};
// PLEASE DO NOT USE THIS. ALWAYS PREFER PER CHANNEL INTERCEPTORS OVER A GLOBAL

@ -25,18 +25,15 @@
#include <grpcpp/impl/codegen/core_codegen_interface.h>
#include <grpcpp/impl/codegen/status.h>
namespace grpc_impl {
class ClientContext;
} // namespace grpc_impl
namespace grpc {
class ClientContext;
namespace internal {
class RpcMethod;
/// Wrapper that performs a blocking unary call
template <class InputMessage, class OutputMessage>
Status BlockingUnaryCall(ChannelInterface* channel, const RpcMethod& method,
grpc_impl::ClientContext* context,
grpc::ClientContext* context,
const InputMessage& request, OutputMessage* result) {
return BlockingUnaryCallImpl<InputMessage, OutputMessage>(
channel, method, context, request, result)
@ -47,7 +44,7 @@ template <class InputMessage, class OutputMessage>
class BlockingUnaryCallImpl {
public:
BlockingUnaryCallImpl(ChannelInterface* channel, const RpcMethod& method,
grpc_impl::ClientContext* context,
grpc::ClientContext* context,
const InputMessage& request, OutputMessage* result) {
::grpc::CompletionQueue cq(grpc_completion_queue_attributes{
GRPC_CQ_CURRENT_VERSION, GRPC_CQ_PLUCK, GRPC_CQ_DEFAULT_POLLING,

@ -46,7 +46,7 @@ class InterceptedChannel : public ChannelInterface {
InterceptedChannel(ChannelInterface* channel, size_t pos)
: channel_(channel), interceptor_pos_(pos) {}
Call CreateCall(const RpcMethod& method, ::grpc_impl::ClientContext* context,
Call CreateCall(const RpcMethod& method, ::grpc::ClientContext* context,
::grpc::CompletionQueue* cq) override {
return channel_->CreateCallInternal(method, context, cq, interceptor_pos_);
}

@ -49,7 +49,6 @@ struct grpc_call;
struct census_context;
namespace grpc_impl {
class ClientContext;
class Server;
template <class W, class R>
class ServerAsyncReader;
@ -94,6 +93,7 @@ class ErrorMethodHandler;
} // namespace grpc_impl
namespace grpc {
class ClientContext;
class CompletionQueue;
class GenericServerContext;
class ServerInterface;
@ -373,7 +373,7 @@ class ServerContextBase {
friend class ::grpc_impl::internal::ErrorMethodHandler;
template <class Base>
friend class ::grpc_impl::internal::FinishOnlyReactor;
friend class ::grpc_impl::ClientContext;
friend class ::grpc::ClientContext;
friend class ::grpc::GenericServerContext;
#ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL
friend class ::grpc::GenericCallbackServerContext;

@ -20,7 +20,7 @@
#include <grpcpp/impl/codegen/call.h>
#include <grpcpp/impl/codegen/channel_interface.h>
#include <grpcpp/impl/codegen/client_context_impl.h>
#include <grpcpp/impl/codegen/client_context.h>
#include <grpcpp/impl/codegen/completion_queue.h>
#include <grpcpp/impl/codegen/core_codegen_interface.h>
#include <grpcpp/impl/codegen/server_context_impl.h>
@ -162,7 +162,7 @@ class ClientReaderFactory {
template <class W>
static ClientReader<R>* Create(::grpc::ChannelInterface* channel,
const ::grpc::internal::RpcMethod& method,
::grpc_impl::ClientContext* context,
::grpc::ClientContext* context,
const W& request) {
return new ClientReader<R>(channel, method, context, request);
}
@ -231,7 +231,7 @@ class ClientReader final : public ClientReaderInterface<R> {
private:
friend class internal::ClientReaderFactory<R>;
::grpc_impl::ClientContext* context_;
::grpc::ClientContext* context_;
::grpc::CompletionQueue cq_;
::grpc::internal::Call call_;
@ -241,7 +241,7 @@ class ClientReader final : public ClientReaderInterface<R> {
template <class W>
ClientReader(::grpc::ChannelInterface* channel,
const ::grpc::internal::RpcMethod& method,
::grpc_impl::ClientContext* context, const W& request)
::grpc::ClientContext* context, const W& request)
: context_(context),
cq_(grpc_completion_queue_attributes{
GRPC_CQ_CURRENT_VERSION, GRPC_CQ_PLUCK, GRPC_CQ_DEFAULT_POLLING,
@ -282,8 +282,7 @@ class ClientWriterFactory {
template <class R>
static ClientWriter<W>* Create(::grpc::ChannelInterface* channel,
const ::grpc::internal::RpcMethod& method,
::grpc_impl::ClientContext* context,
R* response) {
::grpc::ClientContext* context, R* response) {
return new ClientWriter<W>(channel, method, context, response);
}
};
@ -376,7 +375,7 @@ class ClientWriter : public ClientWriterInterface<W> {
template <class R>
ClientWriter(::grpc::ChannelInterface* channel,
const ::grpc::internal::RpcMethod& method,
::grpc_impl::ClientContext* context, R* response)
::grpc::ClientContext* context, R* response)
: context_(context),
cq_(grpc_completion_queue_attributes{
GRPC_CQ_CURRENT_VERSION, GRPC_CQ_PLUCK, GRPC_CQ_DEFAULT_POLLING,
@ -395,7 +394,7 @@ class ClientWriter : public ClientWriterInterface<W> {
}
}
::grpc_impl::ClientContext* context_;
::grpc::ClientContext* context_;
::grpc::internal::CallOpSet<::grpc::internal::CallOpRecvInitialMetadata,
::grpc::internal::CallOpGenericRecvMessage,
::grpc::internal::CallOpClientRecvStatus>
@ -434,7 +433,7 @@ class ClientReaderWriterFactory {
static ClientReaderWriter<W, R>* Create(
::grpc::ChannelInterface* channel,
const ::grpc::internal::RpcMethod& method,
::grpc_impl::ClientContext* context) {
::grpc::ClientContext* context) {
return new ClientReaderWriter<W, R>(channel, method, context);
}
};
@ -543,7 +542,7 @@ class ClientReaderWriter final : public ClientReaderWriterInterface<W, R> {
private:
friend class internal::ClientReaderWriterFactory<W, R>;
::grpc_impl::ClientContext* context_;
::grpc::ClientContext* context_;
::grpc::CompletionQueue cq_;
::grpc::internal::Call call_;
@ -552,7 +551,7 @@ class ClientReaderWriter final : public ClientReaderWriterInterface<W, R> {
/// used to send to the server when starting the call.
ClientReaderWriter(::grpc::ChannelInterface* channel,
const ::grpc::internal::RpcMethod& method,
::grpc_impl::ClientContext* context)
::grpc::ClientContext* context)
: context_(context),
cq_(grpc_completion_queue_attributes{
GRPC_CQ_CURRENT_VERSION, GRPC_CQ_PLUCK, GRPC_CQ_DEFAULT_POLLING,

@ -34,8 +34,6 @@
namespace grpc {
class Channel;
} // namespace grpc
namespace grpc_impl {
class DefaultGlobalClientCallbacks final
: public ClientContext::GlobalCallbacks {
@ -45,7 +43,7 @@ class DefaultGlobalClientCallbacks final
void Destructor(ClientContext* /*context*/) override {}
};
static grpc::internal::GrpcLibraryInitializer g_gli_initializer;
static internal::GrpcLibraryInitializer g_gli_initializer;
static DefaultGlobalClientCallbacks* g_default_client_callbacks =
new DefaultGlobalClientCallbacks();
static ClientContext::GlobalCallbacks* g_client_callbacks =
@ -75,7 +73,7 @@ ClientContext::~ClientContext() {
}
void ClientContext::set_credentials(
const std::shared_ptr<grpc::CallCredentials>& creds) {
const std::shared_ptr<CallCredentials>& creds) {
creds_ = creds;
// If call_ is set, we have already created the call, and set the call
// credentials. This should only be done before we have started the batch
@ -116,8 +114,8 @@ void ClientContext::AddMetadata(const std::string& meta_key,
}
void ClientContext::set_call(grpc_call* call,
const std::shared_ptr<::grpc::Channel>& channel) {
grpc::internal::MutexLock lock(&mu_);
const std::shared_ptr<Channel>& channel) {
internal::MutexLock lock(&mu_);
GPR_ASSERT(call_ == nullptr);
call_ = call;
channel_ = channel;
@ -147,7 +145,7 @@ void ClientContext::set_compression_algorithm(
}
void ClientContext::TryCancel() {
grpc::internal::MutexLock lock(&mu_);
internal::MutexLock lock(&mu_);
if (call_) {
SendCancelToInterceptors();
grpc_call_cancel(call_, nullptr);
@ -157,7 +155,7 @@ void ClientContext::TryCancel() {
}
void ClientContext::SendCancelToInterceptors() {
grpc::internal::CancelInterceptorBatchMethods cancel_methods;
internal::CancelInterceptorBatchMethods cancel_methods;
for (size_t i = 0; i < rpc_info_.interceptors_.size(); i++) {
rpc_info_.RunInterceptor(&cancel_methods, i);
}
@ -180,4 +178,4 @@ void ClientContext::SetGlobalCallbacks(GlobalCallbacks* client_callbacks) {
g_client_callbacks = client_callbacks;
}
} // namespace grpc_impl
} // namespace grpc

@ -27,11 +27,9 @@
#include <grpcpp/support/status.h>
#include <grpcpp/support/string_ref.h>
namespace grpc_impl {
namespace grpc {
class ClientContext;
} // namespace grpc_impl
namespace grpc {
namespace testing {
@ -88,7 +86,7 @@ class CliCall final {
private:
std::unique_ptr<grpc::GenericStub> stub_;
grpc_impl::ClientContext ctx_;
grpc::ClientContext ctx_;
std::unique_ptr<grpc::GenericClientAsyncReaderWriter> call_;
grpc::CompletionQueue cq_;
gpr_mu write_mu_;

@ -962,7 +962,6 @@ include/grpcpp/impl/codegen/channel_interface.h \
include/grpcpp/impl/codegen/client_callback.h \
include/grpcpp/impl/codegen/client_callback_impl.h \
include/grpcpp/impl/codegen/client_context.h \
include/grpcpp/impl/codegen/client_context_impl.h \
include/grpcpp/impl/codegen/client_interceptor.h \
include/grpcpp/impl/codegen/client_unary_call.h \
include/grpcpp/impl/codegen/completion_queue.h \

@ -962,7 +962,6 @@ include/grpcpp/impl/codegen/channel_interface.h \
include/grpcpp/impl/codegen/client_callback.h \
include/grpcpp/impl/codegen/client_callback_impl.h \
include/grpcpp/impl/codegen/client_context.h \
include/grpcpp/impl/codegen/client_context_impl.h \
include/grpcpp/impl/codegen/client_interceptor.h \
include/grpcpp/impl/codegen/client_unary_call.h \
include/grpcpp/impl/codegen/completion_queue.h \

Loading…
Cancel
Save