/*
*
- * Copyright 2015 gRPC authors.
+ * Copyright 2019 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* 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.
- *
*/
#ifndef GRPCPP_IMPL_CODEGEN_ASYNC_STREAM_H
#define GRPCPP_IMPL_CODEGEN_ASYNC_STREAM_H
+// IWYU pragma: private, include <grpcpp/support/async_stream.h>
+
#include <grpcpp/impl/codegen/call.h>
#include <grpcpp/impl/codegen/channel_interface.h>
#include <grpcpp/impl/codegen/core_codegen_interface.h>
/// when the call has been ended.
/// Should not be used concurrently with other operations.
///
- /// It is appropriate to call this method when both:
+ /// It is appropriate to call this method exactly once when both:
/// * the client side has no more message to send
/// (this can be declared implicitly by calling this method, or
/// explicitly through an earlier call to the <i>WritesDone</i> method
///
/// \param[in] tag Tag identifying this request.
/// \param[out] status To be updated with the operation status.
- virtual void Finish(Status* status, void* tag) = 0;
+ virtual void Finish(::grpc::Status* status, void* tag) = 0;
};
/// An interface that yields a sequence of messages of type \a R.
/// \param[in] msg The message to be written.
/// \param[in] options The WriteOptions to be used to write this message.
/// \param[in] tag The tag identifying the operation.
- virtual void Write(const W& msg, WriteOptions options, void* tag) = 0;
+ virtual void Write(const W& msg, ::grpc::WriteOptions options, void* tag) = 0;
/// Request the writing of \a msg and coalesce it with the writing
/// of trailing metadata, using WriteOptions \a options with
/// \param[in] msg The message to be written.
/// \param[in] options The WriteOptions to be used to write this message.
/// \param[in] tag The tag identifying the operation.
- void WriteLast(const W& msg, WriteOptions options, void* tag) {
+ void WriteLast(const W& msg, ::grpc::WriteOptions options, void* tag) {
Write(msg, options.set_last_message(), tag);
}
};
/// Note that \a context will be used to fill in custom initial metadata
/// used to send to the server when starting the call.
template <class W>
- static ClientAsyncReader<R>* Create(ChannelInterface* channel,
- CompletionQueue* cq,
+ static ClientAsyncReader<R>* Create(::grpc::ChannelInterface* channel,
+ ::grpc::CompletionQueue* cq,
const ::grpc::internal::RpcMethod& method,
- ClientContext* context, const W& request,
- bool start, void* tag) {
+ ::grpc::ClientContext* context,
+ const W& request, bool start, void* tag) {
::grpc::internal::Call call = channel->CreateCall(method, context, cq);
- return new (g_core_codegen_interface->grpc_call_arena_alloc(
+ return new (::grpc::g_core_codegen_interface->grpc_call_arena_alloc(
call.call(), sizeof(ClientAsyncReader<R>)))
ClientAsyncReader<R>(call, context, request, start, tag);
}
class ClientAsyncReader final : public ClientAsyncReaderInterface<R> {
public:
// always allocated against a call arena, no memory free required
- static void operator delete(void* ptr, std::size_t size) {
- assert(size == sizeof(ClientAsyncReader));
+ static void operator delete(void* /*ptr*/, std::size_t size) {
+ GPR_CODEGEN_ASSERT(size == sizeof(ClientAsyncReader));
}
// This operator should never be called as the memory should be freed as part
// delete to the operator new so that some compilers will not complain (see
// https://github.com/grpc/grpc/issues/11301) Note at the time of adding this
// there are no tests catching the compiler warning.
- static void operator delete(void*, void*) { assert(0); }
+ static void operator delete(void*, void*) { GPR_CODEGEN_ASSERT(false); }
void StartCall(void* tag) override {
- assert(!started_);
+ GPR_CODEGEN_ASSERT(!started_);
started_ = true;
StartCallInternal(tag);
}
/// calling code can access the received metadata through the
/// \a ClientContext.
void ReadInitialMetadata(void* tag) override {
- assert(started_);
+ GPR_CODEGEN_ASSERT(started_);
GPR_CODEGEN_ASSERT(!context_->initial_metadata_received_);
meta_ops_.set_output_tag(tag);
}
void Read(R* msg, void* tag) override {
- assert(started_);
+ GPR_CODEGEN_ASSERT(started_);
read_ops_.set_output_tag(tag);
if (!context_->initial_metadata_received_) {
read_ops_.RecvInitialMetadata(context_);
/// Side effect:
/// - the \a ClientContext associated with this call is updated with
/// possible initial and trailing metadata received from the server.
- void Finish(Status* status, void* tag) override {
- assert(started_);
+ void Finish(::grpc::Status* status, void* tag) override {
+ GPR_CODEGEN_ASSERT(started_);
finish_ops_.set_output_tag(tag);
if (!context_->initial_metadata_received_) {
finish_ops_.RecvInitialMetadata(context_);
private:
friend class internal::ClientAsyncReaderFactory<R>;
template <class W>
- ClientAsyncReader(::grpc::internal::Call call, ClientContext* context,
+ 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
if (start) {
StartCallInternal(tag);
} else {
- assert(tag == nullptr);
+ GPR_CODEGEN_ASSERT(tag == nullptr);
}
}
call_.PerformOps(&init_ops_);
}
- ClientContext* context_;
+ ::grpc::ClientContext* context_;
::grpc::internal::Call call_;
bool started_;
::grpc::internal::CallOpSet<::grpc::internal::CallOpSendInitialMetadata,
/// message from the server upon a successful call to the \a Finish
/// method of this instance.
template <class R>
- static ClientAsyncWriter<W>* Create(ChannelInterface* channel,
- CompletionQueue* cq,
+ static ClientAsyncWriter<W>* Create(::grpc::ChannelInterface* channel,
+ ::grpc::CompletionQueue* cq,
const ::grpc::internal::RpcMethod& method,
- ClientContext* context, R* response,
- bool start, void* tag) {
+ ::grpc::ClientContext* context,
+ R* response, bool start, void* tag) {
::grpc::internal::Call call = channel->CreateCall(method, context, cq);
- return new (g_core_codegen_interface->grpc_call_arena_alloc(
+ return new (::grpc::g_core_codegen_interface->grpc_call_arena_alloc(
call.call(), sizeof(ClientAsyncWriter<W>)))
ClientAsyncWriter<W>(call, context, response, start, tag);
}
class ClientAsyncWriter final : public ClientAsyncWriterInterface<W> {
public:
// always allocated against a call arena, no memory free required
- static void operator delete(void* ptr, std::size_t size) {
- assert(size == sizeof(ClientAsyncWriter));
+ static void operator delete(void* /*ptr*/, std::size_t size) {
+ GPR_CODEGEN_ASSERT(size == sizeof(ClientAsyncWriter));
}
// This operator should never be called as the memory should be freed as part
// delete to the operator new so that some compilers will not complain (see
// https://github.com/grpc/grpc/issues/11301) Note at the time of adding this
// there are no tests catching the compiler warning.
- static void operator delete(void*, void*) { assert(0); }
+ static void operator delete(void*, void*) { GPR_CODEGEN_ASSERT(false); }
void StartCall(void* tag) override {
- assert(!started_);
+ GPR_CODEGEN_ASSERT(!started_);
started_ = true;
StartCallInternal(tag);
}
/// associated with this call is updated, and the calling code can access
/// the received metadata through the \a ClientContext.
void ReadInitialMetadata(void* tag) override {
- assert(started_);
+ GPR_CODEGEN_ASSERT(started_);
GPR_CODEGEN_ASSERT(!context_->initial_metadata_received_);
meta_ops_.set_output_tag(tag);
}
void Write(const W& msg, void* tag) override {
- assert(started_);
+ GPR_CODEGEN_ASSERT(started_);
write_ops_.set_output_tag(tag);
// TODO(ctiller): don't assert
GPR_CODEGEN_ASSERT(write_ops_.SendMessage(msg).ok());
call_.PerformOps(&write_ops_);
}
- void Write(const W& msg, WriteOptions options, void* tag) override {
- assert(started_);
+ void Write(const W& msg, ::grpc::WriteOptions options, void* tag) override {
+ GPR_CODEGEN_ASSERT(started_);
write_ops_.set_output_tag(tag);
if (options.is_last_message()) {
options.set_buffer_hint();
}
void WritesDone(void* tag) override {
- assert(started_);
+ GPR_CODEGEN_ASSERT(started_);
write_ops_.set_output_tag(tag);
write_ops_.ClientSendClose();
call_.PerformOps(&write_ops_);
/// possible initial and trailing metadata received from the server.
/// - attempts to fill in the \a response parameter passed to this class's
/// constructor with the server's response message.
- void Finish(Status* status, void* tag) override {
- assert(started_);
+ void Finish(::grpc::Status* status, void* tag) override {
+ GPR_CODEGEN_ASSERT(started_);
finish_ops_.set_output_tag(tag);
if (!context_->initial_metadata_received_) {
finish_ops_.RecvInitialMetadata(context_);
private:
friend class internal::ClientAsyncWriterFactory<W>;
template <class R>
- ClientAsyncWriter(::grpc::internal::Call call, ClientContext* context,
+ ClientAsyncWriter(::grpc::internal::Call call, ::grpc::ClientContext* context,
R* response, bool start, void* tag)
: context_(context), call_(call), started_(start) {
finish_ops_.RecvMessage(response);
if (start) {
StartCallInternal(tag);
} else {
- assert(tag == nullptr);
+ GPR_CODEGEN_ASSERT(tag == nullptr);
}
}
}
}
- ClientContext* context_;
+ ::grpc::ClientContext* context_;
::grpc::internal::Call call_;
bool started_;
::grpc::internal::CallOpSet<::grpc::internal::CallOpRecvInitialMetadata>
/// Note that \a context will be used to fill in custom initial metadata
/// used to send to the server when starting the call.
static ClientAsyncReaderWriter<W, R>* Create(
- ChannelInterface* channel, CompletionQueue* cq,
- const ::grpc::internal::RpcMethod& method, ClientContext* context,
+ ::grpc::ChannelInterface* channel, ::grpc::CompletionQueue* cq,
+ const ::grpc::internal::RpcMethod& method, ::grpc::ClientContext* context,
bool start, void* tag) {
::grpc::internal::Call call = channel->CreateCall(method, context, cq);
- return new (g_core_codegen_interface->grpc_call_arena_alloc(
+ return new (::grpc::g_core_codegen_interface->grpc_call_arena_alloc(
call.call(), sizeof(ClientAsyncReaderWriter<W, R>)))
ClientAsyncReaderWriter<W, R>(call, context, start, tag);
}
: public ClientAsyncReaderWriterInterface<W, R> {
public:
// always allocated against a call arena, no memory free required
- static void operator delete(void* ptr, std::size_t size) {
- assert(size == sizeof(ClientAsyncReaderWriter));
+ static void operator delete(void* /*ptr*/, std::size_t size) {
+ GPR_CODEGEN_ASSERT(size == sizeof(ClientAsyncReaderWriter));
}
// This operator should never be called as the memory should be freed as part
// delete to the operator new so that some compilers will not complain (see
// https://github.com/grpc/grpc/issues/11301) Note at the time of adding this
// there are no tests catching the compiler warning.
- static void operator delete(void*, void*) { assert(0); }
+ static void operator delete(void*, void*) { GPR_CODEGEN_ASSERT(false); }
void StartCall(void* tag) override {
- assert(!started_);
+ GPR_CODEGEN_ASSERT(!started_);
started_ = true;
StartCallInternal(tag);
}
/// is updated with it, and then the receiving initial metadata can
/// be accessed through this \a ClientContext.
void ReadInitialMetadata(void* tag) override {
- assert(started_);
+ GPR_CODEGEN_ASSERT(started_);
GPR_CODEGEN_ASSERT(!context_->initial_metadata_received_);
meta_ops_.set_output_tag(tag);
}
void Read(R* msg, void* tag) override {
- assert(started_);
+ GPR_CODEGEN_ASSERT(started_);
read_ops_.set_output_tag(tag);
if (!context_->initial_metadata_received_) {
read_ops_.RecvInitialMetadata(context_);
}
void Write(const W& msg, void* tag) override {
- assert(started_);
+ GPR_CODEGEN_ASSERT(started_);
write_ops_.set_output_tag(tag);
// TODO(ctiller): don't assert
GPR_CODEGEN_ASSERT(write_ops_.SendMessage(msg).ok());
call_.PerformOps(&write_ops_);
}
- void Write(const W& msg, WriteOptions options, void* tag) override {
- assert(started_);
+ void Write(const W& msg, ::grpc::WriteOptions options, void* tag) override {
+ GPR_CODEGEN_ASSERT(started_);
write_ops_.set_output_tag(tag);
if (options.is_last_message()) {
options.set_buffer_hint();
}
void WritesDone(void* tag) override {
- assert(started_);
+ GPR_CODEGEN_ASSERT(started_);
write_ops_.set_output_tag(tag);
write_ops_.ClientSendClose();
call_.PerformOps(&write_ops_);
/// Side effect
/// - the \a ClientContext associated with this call is updated with
/// possible initial and trailing metadata sent from the server.
- void Finish(Status* status, void* tag) override {
- assert(started_);
+ void Finish(::grpc::Status* status, void* tag) override {
+ GPR_CODEGEN_ASSERT(started_);
finish_ops_.set_output_tag(tag);
if (!context_->initial_metadata_received_) {
finish_ops_.RecvInitialMetadata(context_);
private:
friend class internal::ClientAsyncReaderWriterFactory<W, R>;
- ClientAsyncReaderWriter(::grpc::internal::Call call, ClientContext* context,
- bool start, void* tag)
+ ClientAsyncReaderWriter(::grpc::internal::Call call,
+ ::grpc::ClientContext* context, bool start, void* tag)
: context_(context), call_(call), started_(start) {
if (start) {
StartCallInternal(tag);
} else {
- assert(tag == nullptr);
+ GPR_CODEGEN_ASSERT(tag == nullptr);
}
}
}
}
- ClientContext* context_;
+ ::grpc::ClientContext* context_;
::grpc::internal::Call call_;
bool started_;
::grpc::internal::CallOpSet<::grpc::internal::CallOpRecvInitialMetadata>
template <class W, class R>
class ServerAsyncReaderInterface
- : public internal::ServerAsyncStreamingInterface,
+ : public ::grpc::internal::ServerAsyncStreamingInterface,
public internal::AsyncReaderInterface<R> {
public:
/// Indicate that the stream is to be finished with a certain status code
/// \param[in] tag Tag identifying this request.
/// \param[in] status To be sent to the client as the result of this call.
/// \param[in] msg To be sent to the client as the response for this call.
- virtual void Finish(const W& msg, const Status& status, void* tag) = 0;
+ virtual void Finish(const W& msg, const ::grpc::Status& status,
+ void* tag) = 0;
/// Indicate that the stream is to be finished with a certain
/// non-OK status code.
/// \param[in] tag Tag identifying this request.
/// \param[in] status To be sent to the client as the result of this call.
/// - Note: \a status must have a non-OK code.
- virtual void FinishWithError(const Status& status, void* tag) = 0;
+ virtual void FinishWithError(const ::grpc::Status& status, void* tag) = 0;
};
/// Async server-side API for doing client-streaming RPCs,
template <class W, class R>
class ServerAsyncReader final : public ServerAsyncReaderInterface<W, R> {
public:
- explicit ServerAsyncReader(ServerContext* ctx)
+ explicit ServerAsyncReader(::grpc::ServerContext* ctx)
: call_(nullptr, nullptr, nullptr), ctx_(ctx) {}
/// See \a ServerAsyncStreamingInterface::SendInitialMetadata for semantics.
///
/// gRPC doesn't take ownership or a reference to \a msg and \a status, so it
/// is safe to deallocate once Finish returns.
- void Finish(const W& msg, const Status& status, void* tag) override {
+ void Finish(const W& msg, const ::grpc::Status& status, void* tag) override {
finish_ops_.set_output_tag(tag);
if (!ctx_->sent_initial_metadata_) {
finish_ops_.SendInitialMetadata(&ctx_->initial_metadata_,
///
/// gRPC doesn't take ownership or a reference to \a status, so it is safe to
/// to deallocate once FinishWithError returns.
- void FinishWithError(const Status& status, void* tag) override {
+ void FinishWithError(const ::grpc::Status& status, void* tag) override {
GPR_CODEGEN_ASSERT(!status.ok());
finish_ops_.set_output_tag(tag);
if (!ctx_->sent_initial_metadata_) {
void BindCall(::grpc::internal::Call* call) override { call_ = *call; }
::grpc::internal::Call call_;
- ServerContext* ctx_;
+ ::grpc::ServerContext* ctx_;
::grpc::internal::CallOpSet<::grpc::internal::CallOpSendInitialMetadata>
meta_ops_;
::grpc::internal::CallOpSet<::grpc::internal::CallOpRecvMessage<R>> read_ops_;
template <class W>
class ServerAsyncWriterInterface
- : public internal::ServerAsyncStreamingInterface,
+ : public ::grpc::internal::ServerAsyncStreamingInterface,
public internal::AsyncWriterInterface<W> {
public:
/// Indicate that the stream is to be finished with a certain status code.
///
/// \param[in] tag Tag identifying this request.
/// \param[in] status To be sent to the client as the result of this call.
- virtual void Finish(const Status& status, void* tag) = 0;
+ virtual void Finish(const ::grpc::Status& status, void* tag) = 0;
/// Request the writing of \a msg and coalesce it with trailing metadata which
/// contains \a status, using WriteOptions options with
/// \param[in] options The WriteOptions to be used to write this message.
/// \param[in] status The Status that server returns to client.
/// \param[in] tag The tag identifying the operation.
- virtual void WriteAndFinish(const W& msg, WriteOptions options,
- const Status& status, void* tag) = 0;
+ virtual void WriteAndFinish(const W& msg, ::grpc::WriteOptions options,
+ const ::grpc::Status& status, void* tag) = 0;
};
/// Async server-side API for doing server streaming RPCs,
template <class W>
class ServerAsyncWriter final : public ServerAsyncWriterInterface<W> {
public:
- explicit ServerAsyncWriter(ServerContext* ctx)
+ explicit ServerAsyncWriter(::grpc::ServerContext* ctx)
: call_(nullptr, nullptr, nullptr), ctx_(ctx) {}
/// See \a ServerAsyncStreamingInterface::SendInitialMetadata for semantics.
call_.PerformOps(&write_ops_);
}
- void Write(const W& msg, WriteOptions options, void* tag) override {
+ void Write(const W& msg, ::grpc::WriteOptions options, void* tag) override {
write_ops_.set_output_tag(tag);
if (options.is_last_message()) {
options.set_buffer_hint();
///
/// gRPC doesn't take ownership or a reference to \a msg and \a status, so it
/// is safe to deallocate once WriteAndFinish returns.
- void WriteAndFinish(const W& msg, WriteOptions options, const Status& status,
- void* tag) override {
+ void WriteAndFinish(const W& msg, ::grpc::WriteOptions options,
+ const ::grpc::Status& status, void* tag) override {
write_ops_.set_output_tag(tag);
EnsureInitialMetadataSent(&write_ops_);
options.set_buffer_hint();
///
/// gRPC doesn't take ownership or a reference to \a status, so it is safe to
/// to deallocate once Finish returns.
- void Finish(const Status& status, void* tag) override {
+ void Finish(const ::grpc::Status& status, void* tag) override {
finish_ops_.set_output_tag(tag);
EnsureInitialMetadataSent(&finish_ops_);
finish_ops_.ServerSendStatus(&ctx_->trailing_metadata_, status);
}
::grpc::internal::Call call_;
- ServerContext* ctx_;
+ ::grpc::ServerContext* ctx_;
::grpc::internal::CallOpSet<::grpc::internal::CallOpSendInitialMetadata>
meta_ops_;
::grpc::internal::CallOpSet<::grpc::internal::CallOpSendInitialMetadata,
/// Server-side interface for asynchronous bi-directional streaming.
template <class W, class R>
class ServerAsyncReaderWriterInterface
- : public internal::ServerAsyncStreamingInterface,
+ : public ::grpc::internal::ServerAsyncStreamingInterface,
public internal::AsyncWriterInterface<W>,
public internal::AsyncReaderInterface<R> {
public:
///
/// \param[in] tag Tag identifying this request.
/// \param[in] status To be sent to the client as the result of this call.
- virtual void Finish(const Status& status, void* tag) = 0;
+ virtual void Finish(const ::grpc::Status& status, void* tag) = 0;
/// Request the writing of \a msg and coalesce it with trailing metadata which
/// contains \a status, using WriteOptions options with
/// \param[in] options The WriteOptions to be used to write this message.
/// \param[in] status The Status that server returns to client.
/// \param[in] tag The tag identifying the operation.
- virtual void WriteAndFinish(const W& msg, WriteOptions options,
- const Status& status, void* tag) = 0;
+ virtual void WriteAndFinish(const W& msg, ::grpc::WriteOptions options,
+ const ::grpc::Status& status, void* tag) = 0;
};
/// Async server-side API for doing bidirectional streaming RPCs,
class ServerAsyncReaderWriter final
: public ServerAsyncReaderWriterInterface<W, R> {
public:
- explicit ServerAsyncReaderWriter(ServerContext* ctx)
+ explicit ServerAsyncReaderWriter(::grpc::ServerContext* ctx)
: call_(nullptr, nullptr, nullptr), ctx_(ctx) {}
/// See \a ServerAsyncStreamingInterface::SendInitialMetadata for semantics.
call_.PerformOps(&write_ops_);
}
- void Write(const W& msg, WriteOptions options, void* tag) override {
+ void Write(const W& msg, ::grpc::WriteOptions options, void* tag) override {
write_ops_.set_output_tag(tag);
if (options.is_last_message()) {
options.set_buffer_hint();
//
/// gRPC doesn't take ownership or a reference to \a msg and \a status, so it
/// is safe to deallocate once WriteAndFinish returns.
- void WriteAndFinish(const W& msg, WriteOptions options, const Status& status,
- void* tag) override {
+ void WriteAndFinish(const W& msg, ::grpc::WriteOptions options,
+ const ::grpc::Status& status, void* tag) override {
write_ops_.set_output_tag(tag);
EnsureInitialMetadataSent(&write_ops_);
options.set_buffer_hint();
//
/// gRPC doesn't take ownership or a reference to \a status, so it is safe to
/// to deallocate once Finish returns.
- void Finish(const Status& status, void* tag) override {
+ void Finish(const ::grpc::Status& status, void* tag) override {
finish_ops_.set_output_tag(tag);
EnsureInitialMetadataSent(&finish_ops_);
}
private:
- friend class ::grpc_impl::Server;
+ friend class ::grpc::Server;
void BindCall(::grpc::internal::Call* call) override { call_ = *call; }
}
::grpc::internal::Call call_;
- ServerContext* ctx_;
+ ::grpc::ServerContext* ctx_;
::grpc::internal::CallOpSet<::grpc::internal::CallOpSendInitialMetadata>
meta_ops_;
::grpc::internal::CallOpSet<::grpc::internal::CallOpRecvMessage<R>> read_ops_;
};
} // namespace grpc
-
#endif // GRPCPP_IMPL_CODEGEN_ASYNC_STREAM_H