Skip to content

Commit

Permalink
style: Remove start_server_rpc.hpp. Simplify default completion token
Browse files Browse the repository at this point in the history
  • Loading branch information
Tradias committed Sep 5, 2024
1 parent 61cdef6 commit 4045621
Show file tree
Hide file tree
Showing 17 changed files with 91 additions and 161 deletions.
4 changes: 2 additions & 2 deletions src/agrpc/alarm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class BasicAlarm
* completion signature is `void(bool)`. `true` if it expired, `false` if it was canceled.
*/
template <class Deadline, class CompletionToken = detail::DefaultCompletionTokenT<Executor>>
auto wait(const Deadline& deadline, CompletionToken&& token = detail::DefaultCompletionTokenT<Executor>{}) &
auto wait(const Deadline& deadline, CompletionToken&& token = CompletionToken{}) &
{
using Initiation = detail::GrpcSenderInitiation<detail::AlarmInitFunction<Deadline>>;
if constexpr (std::is_same_v<agrpc::UseSender, detail::RemoveCrefT<CompletionToken>>)
Expand Down Expand Up @@ -110,7 +110,7 @@ class BasicAlarm
* completion signature is `void(bool, BasicAlarm)`. `true` if it expired, `false` if it was canceled.
*/
template <class Deadline, class CompletionToken = detail::DefaultCompletionTokenT<Executor>>
auto wait(const Deadline& deadline, CompletionToken&& token = detail::DefaultCompletionTokenT<Executor>{}) &&
auto wait(const Deadline& deadline, CompletionToken&& token = CompletionToken{}) &&
{
using Initiation = detail::MoveAlarmSenderInitiation<Deadline>;
if constexpr (std::is_same_v<agrpc::UseSender, detail::RemoveCrefT<CompletionToken>>)
Expand Down
49 changes: 22 additions & 27 deletions src/agrpc/client_rpc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ class ClientRPCUnaryBase<PrepareAsyncUnary, Executor> : public detail::ClientRPC
*/
template <class CompletionToken = detail::DefaultCompletionTokenT<Executor>>
static auto request(agrpc::GrpcContext& grpc_context, StubT& stub, grpc::ClientContext& context,
const RequestT& request, ResponseT& response,
CompletionToken&& token = detail::DefaultCompletionTokenT<Executor>{})
const RequestT& request, ResponseT& response, CompletionToken&& token = CompletionToken{})
{
return detail::async_initiate_sender_implementation(
grpc_context, detail::ClientUnaryRequestSenderInitiation<ResponseT>{context, response},
Expand All @@ -143,7 +142,7 @@ class ClientRPCUnaryBase<PrepareAsyncUnary, Executor> : public detail::ClientRPC
*/
template <class CompletionToken = detail::DefaultCompletionTokenT<Executor>>
static auto request(const Executor& executor, StubT& stub, grpc::ClientContext& context, const RequestT& request,
ResponseT& response, CompletionToken&& token = detail::DefaultCompletionTokenT<Executor>{})
ResponseT& response, CompletionToken&& token = CompletionToken{})
{
return ClientRPCUnaryBase::request(detail::query_grpc_context(executor), stub, context, request, response,
static_cast<CompletionToken&&>(token));
Expand Down Expand Up @@ -184,7 +183,7 @@ class ClientRPCUnaryBase<PrepareAsyncUnary, Executor> : public detail::ClientRPC
* completion signature is `void(grpc::Status)`.
*/
template <class CompletionToken = detail::DefaultCompletionTokenT<Executor>>
auto finish(ResponseT& response, CompletionToken&& token = detail::DefaultCompletionTokenT<Executor>{})
auto finish(ResponseT& response, CompletionToken&& token = CompletionToken{})
{
return detail::async_initiate_sender_implementation(
this->grpc_context(), detail::ClientFinishUnarySenderInitation<Response>{response},
Expand Down Expand Up @@ -320,7 +319,7 @@ class ClientRPC<agrpc::ClientRPCType::GENERIC_UNARY, Executor>
template <class CompletionToken = detail::DefaultCompletionTokenT<Executor>>
static auto request(agrpc::GrpcContext& grpc_context, const std::string& method, grpc::GenericStub& stub,
grpc::ClientContext& context, const grpc::ByteBuffer& request, grpc::ByteBuffer& response,
CompletionToken&& token = detail::DefaultCompletionTokenT<Executor>{})
CompletionToken&& token = CompletionToken{})
{
return detail::async_initiate_sender_implementation(
grpc_context, detail::ClientUnaryRequestSenderInitiation<Response>{context, response},
Expand All @@ -334,7 +333,7 @@ class ClientRPC<agrpc::ClientRPCType::GENERIC_UNARY, Executor>
template <class CompletionToken = detail::DefaultCompletionTokenT<Executor>>
static auto request(const Executor& executor, const std::string& method, grpc::GenericStub& stub,
grpc::ClientContext& context, const grpc::ByteBuffer& request, grpc::ByteBuffer& response,
CompletionToken&& token = detail::DefaultCompletionTokenT<Executor>{})
CompletionToken&& token = CompletionToken{})
{
return ClientRPC::request(detail::query_grpc_context(executor), method, stub, context, request, response,
static_cast<CompletionToken&&>(token));
Expand Down Expand Up @@ -376,7 +375,7 @@ class ClientRPC<agrpc::ClientRPCType::GENERIC_UNARY, Executor>
* completion signature is `void(grpc::Status)`.
*/
template <class CompletionToken = detail::DefaultCompletionTokenT<Executor>>
auto finish(grpc::ByteBuffer& response, CompletionToken&& token = detail::DefaultCompletionTokenT<Executor>{})
auto finish(grpc::ByteBuffer& response, CompletionToken&& token = CompletionToken{})
{
return detail::async_initiate_sender_implementation(
this->grpc_context(), detail::ClientFinishUnarySenderInitation<Response>{response},
Expand Down Expand Up @@ -513,7 +512,7 @@ class ClientRPC<PrepareAsyncClientStreaming, Executor> : public detail::ClientRP
* error details.
*/
template <class CompletionToken = detail::DefaultCompletionTokenT<Executor>>
auto start(StubT& stub, ResponseT& response, CompletionToken&& token = detail::DefaultCompletionTokenT<Executor>{})
auto start(StubT& stub, ResponseT& response, CompletionToken&& token = CompletionToken{})
{
return detail::async_initiate_sender_implementation(
this->grpc_context(),
Expand Down Expand Up @@ -542,7 +541,7 @@ class ClientRPC<PrepareAsyncClientStreaming, Executor> : public detail::ClientRP
* `void(bool)`. `true` indicates that the metadata was read. If it is `false`, then the call is dead.
*/
template <class CompletionToken = detail::DefaultCompletionTokenT<Executor>>
auto read_initial_metadata(CompletionToken&& token = detail::DefaultCompletionTokenT<Executor>{})
auto read_initial_metadata(CompletionToken&& token = CompletionToken{})
{
return detail::async_initiate_sender_implementation(
this->grpc_context(), detail::ClientReadInitialMetadataWritableStreamSenderInitiation{},
Expand All @@ -557,8 +556,7 @@ class ClientRPC<PrepareAsyncClientStreaming, Executor> : public detail::ClientRP
* `write(request, token)`.
*/
template <class CompletionToken = detail::DefaultCompletionTokenT<Executor>>
auto write(const RequestT& request, grpc::WriteOptions options,
CompletionToken&& token = detail::DefaultCompletionTokenT<Executor>{})
auto write(const RequestT& request, grpc::WriteOptions options, CompletionToken&& token = CompletionToken{})
{
return detail::async_initiate_sender_implementation(
this->grpc_context(), detail::ClientWriteSenderInitiation<RequestT>{request, options},
Expand All @@ -578,7 +576,7 @@ class ClientRPC<PrepareAsyncClientStreaming, Executor> : public detail::ClientRP
* channel, etc).
*/
template <class CompletionToken = detail::DefaultCompletionTokenT<Executor>>
auto write(const RequestT& request, CompletionToken&& token = detail::DefaultCompletionTokenT<Executor>{})
auto write(const RequestT& request, CompletionToken&& token = CompletionToken{})
{
return write(request, grpc::WriteOptions{}, static_cast<CompletionToken&&>(token));
}
Expand Down Expand Up @@ -608,7 +606,7 @@ class ClientRPC<PrepareAsyncClientStreaming, Executor> : public detail::ClientRP
* completion signature is `void(grpc::Status)`.
*/
template <class CompletionToken = detail::DefaultCompletionTokenT<Executor>>
auto finish(CompletionToken&& token = detail::DefaultCompletionTokenT<Executor>{})
auto finish(CompletionToken&& token = CompletionToken{})
{
return detail::async_initiate_sender_implementation(
this->grpc_context(), detail::ClientFinishWritableStreamSenderInitiation{},
Expand Down Expand Up @@ -715,8 +713,7 @@ class ClientRPCServerStreamingBase<PrepareAsyncServerStreaming, Executor>
* error details.
*/
template <class CompletionToken = detail::DefaultCompletionTokenT<Executor>>
auto start(StubT& stub, const RequestT& request,
CompletionToken&& token = detail::DefaultCompletionTokenT<Executor>{})
auto start(StubT& stub, const RequestT& request, CompletionToken&& token = CompletionToken{})
{
return detail::async_initiate_sender_implementation(
this->grpc_context(),
Expand All @@ -736,7 +733,7 @@ class ClientRPCServerStreamingBase<PrepareAsyncServerStreaming, Executor>
* stream has failed (or been cancelled).
*/
template <class CompletionToken = detail::DefaultCompletionTokenT<Executor>>
auto read(ResponseT& response, CompletionToken&& token = detail::DefaultCompletionTokenT<Executor>{})
auto read(ResponseT& response, CompletionToken&& token = CompletionToken{})
{
return detail::async_initiate_sender_implementation(
this->grpc_context(), detail::ClientReadSenderInitiation<Responder>{*this, response},
Expand Down Expand Up @@ -772,7 +769,7 @@ class ClientRPCServerStreamingBase<PrepareAsyncServerStreaming, Executor>
* completion signature is `void(grpc::Status)`.
*/
template <class CompletionToken = detail::DefaultCompletionTokenT<Executor>>
auto finish(CompletionToken&& token = detail::DefaultCompletionTokenT<Executor>{})
auto finish(CompletionToken&& token = CompletionToken{})
{
return detail::async_initiate_sender_implementation(
this->grpc_context(), detail::ClientFinishServerStreamingSenderInitation{},
Expand Down Expand Up @@ -873,7 +870,7 @@ class ClientRPCBidiStreamingBase<ResponderT<RequestT, ResponseT>, Executor>
* `void(bool)`. `true` indicates that the metadata was read. If it is `false`, then the call is dead.
*/
template <class CompletionToken = detail::DefaultCompletionTokenT<Executor>>
auto read_initial_metadata(CompletionToken&& token = detail::DefaultCompletionTokenT<Executor>{})
auto read_initial_metadata(CompletionToken&& token = CompletionToken{})
{
return detail::async_initiate_sender_implementation(
this->grpc_context(), detail::ClientReadInitialMetadataWritableStreamSenderInitiation{},
Expand All @@ -894,7 +891,7 @@ class ClientRPCBidiStreamingBase<ResponderT<RequestT, ResponseT>, Executor>
* stream has failed (or been cancelled).
*/
template <class CompletionToken = detail::DefaultCompletionTokenT<Executor>>
auto read(ResponseT& response, CompletionToken&& token = detail::DefaultCompletionTokenT<Executor>{})
auto read(ResponseT& response, CompletionToken&& token = CompletionToken{})
{
return detail::async_initiate_sender_implementation(
this->grpc_context(), detail::ClientReadSenderInitiation<Responder>{*this, response},
Expand All @@ -915,8 +912,7 @@ class ClientRPCBidiStreamingBase<ResponderT<RequestT, ResponseT>, Executor>
* channel, etc).
*/
template <class CompletionToken = detail::DefaultCompletionTokenT<Executor>>
auto write(const RequestT& request, grpc::WriteOptions options,
CompletionToken&& token = detail::DefaultCompletionTokenT<Executor>{})
auto write(const RequestT& request, grpc::WriteOptions options, CompletionToken&& token = CompletionToken{})
{
return detail::async_initiate_sender_implementation(
this->grpc_context(), detail::ClientWriteSenderInitiation<RequestT>{request, options},
Expand All @@ -927,7 +923,7 @@ class ClientRPCBidiStreamingBase<ResponderT<RequestT, ResponseT>, Executor>
* @brief Send a message to the server (default WriteOptions)
*/
template <class CompletionToken = detail::DefaultCompletionTokenT<Executor>>
auto write(const RequestT& request, CompletionToken&& token = detail::DefaultCompletionTokenT<Executor>{})
auto write(const RequestT& request, CompletionToken&& token = CompletionToken{})
{
return write(request, grpc::WriteOptions{}, static_cast<CompletionToken&&>(token));
}
Expand All @@ -949,7 +945,7 @@ class ClientRPCBidiStreamingBase<ResponderT<RequestT, ResponseT>, Executor>
* wire because the call is already dead (i.e., canceled, deadline expired, other side dropped the channel, etc).
*/
template <class CompletionToken = detail::DefaultCompletionTokenT<Executor>>
auto writes_done(CompletionToken&& token = detail::DefaultCompletionTokenT<Executor>{})
auto writes_done(CompletionToken&& token = CompletionToken{})
{
return detail::async_initiate_sender_implementation(
this->grpc_context(), detail::ClientWritesDoneSenderInitiation{},
Expand Down Expand Up @@ -985,7 +981,7 @@ class ClientRPCBidiStreamingBase<ResponderT<RequestT, ResponseT>, Executor>
* completion signature is `void(grpc::Status)`.
*/
template <class CompletionToken = detail::DefaultCompletionTokenT<Executor>>
auto finish(CompletionToken&& token = detail::DefaultCompletionTokenT<Executor>{})
auto finish(CompletionToken&& token = CompletionToken{})
{
return detail::async_initiate_sender_implementation(
this->grpc_context(), detail::ClientFinishWritableStreamSenderInitiation{},
Expand Down Expand Up @@ -1096,7 +1092,7 @@ class ClientRPC<PrepareAsyncBidiStreaming, Executor>
* error details.
*/
template <class CompletionToken = detail::DefaultCompletionTokenT<Executor>>
auto start(StubT& stub, CompletionToken&& token = detail::DefaultCompletionTokenT<Executor>{})
auto start(StubT& stub, CompletionToken&& token = CompletionToken{})
{
return detail::async_initiate_sender_implementation(
this->grpc_context(),
Expand Down Expand Up @@ -1158,8 +1154,7 @@ class ClientRPC<agrpc::ClientRPCType::GENERIC_STREAMING, Executor>
* error details.
*/
template <class CompletionToken = detail::DefaultCompletionTokenT<Executor>>
auto start(const std::string& method, grpc::GenericStub& stub,
CompletionToken&& token = detail::DefaultCompletionTokenT<Executor>{})
auto start(const std::string& method, grpc::GenericStub& stub, CompletionToken&& token = CompletionToken{})
{
return detail::async_initiate_sender_implementation(
this->grpc_context(),
Expand Down
3 changes: 1 addition & 2 deletions src/agrpc/detail/grpc_context_implementation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ struct DoOneResult : CompletionQueueEventResult

static DoOneResult from(CompletionQueueEventResult handled_event, bool processed_local_work) noexcept
{
return {{static_cast<uint32_t>(handled_event.flags_ |
(processed_local_work ? DoOneResult::PROCESSED_LOCAL_WORK : uint32_t{}))}};
return {{handled_event.flags_ | (processed_local_work ? DoOneResult::PROCESSED_LOCAL_WORK : uint32_t{})}};
}

explicit operator bool() const noexcept { return processed_local_work() || handled_event(); }
Expand Down
4 changes: 2 additions & 2 deletions src/agrpc/detail/register_rpc_handler_asio_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <agrpc/detail/association.hpp>
#include <agrpc/detail/register_rpc_handler_base.hpp>
#include <agrpc/detail/rethrow_first_arg.hpp>
#include <agrpc/detail/rpc_request.hpp>
#include <agrpc/detail/server_rpc_starter.hpp>
#include <agrpc/detail/work_tracking_completion_handler.hpp>
#include <agrpc/grpc_context.hpp>

Expand Down Expand Up @@ -104,7 +104,7 @@ struct RegisterRPCHandlerInitiator
.release();
}

detail::GetServerRPCServiceT<ServerRPC>& service_;
detail::ServerRPCServiceT<ServerRPC>& service_;
};

template <class Operation>
Expand Down
2 changes: 1 addition & 1 deletion src/agrpc/detail/register_rpc_handler_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class RegisterRPCHandlerOperationComplete
template <class ServerRPC, class RPCHandler, class StopToken>
struct RegisterRPCHandlerOperationBase
{
using Service = detail::GetServerRPCServiceT<ServerRPC>;
using Service = detail::ServerRPCServiceT<ServerRPC>;
using ServerRPCExecutor = typename ServerRPC::executor_type;

RegisterRPCHandlerOperationBase(const ServerRPCExecutor& executor, Service& service, RPCHandler&& rpc_handler)
Expand Down
14 changes: 6 additions & 8 deletions src/agrpc/detail/register_sender_rpc_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#include <agrpc/detail/execution.hpp>
#include <agrpc/detail/forward.hpp>
#include <agrpc/detail/register_rpc_handler_base.hpp>
#include <agrpc/detail/rpc_request.hpp>
#include <agrpc/detail/sender_of.hpp>
#include <agrpc/detail/server_rpc_context_base.hpp>
#include <agrpc/detail/server_rpc_starter.hpp>
#include <agrpc/detail/utility.hpp>
#include <agrpc/grpc_context.hpp>

Expand Down Expand Up @@ -51,7 +51,7 @@ template <class ServerRPC, class RPCHandler>
class [[nodiscard]] RPCHandlerSender : public detail::SenderOf<void()>
{
private:
using Service = detail::GetServerRPCServiceT<ServerRPC>;
using Service = detail::ServerRPCServiceT<ServerRPC>;

public:
RPCHandlerSender(agrpc::GrpcContext& grpc_context, Service& service, RPCHandler&& rpc_handler)
Expand Down Expand Up @@ -155,7 +155,7 @@ void create_and_start_rpc_handler_operation(
template <class ServerRPC, class RPCHandler, class StopToken, class Allocator>
struct RPCHandlerOperation
{
using Service = detail::GetServerRPCServiceT<ServerRPC>;
using Service = detail::ServerRPCServiceT<ServerRPC>;
using Traits = typename ServerRPC::Traits;
using Starter = detail::ServerRPCStarterT<ServerRPC>;
using RPCHandlerInvokeResult = detail::RPCHandlerInvokeResultT<Starter&, RPCHandler&, ServerRPC&>;
Expand Down Expand Up @@ -263,9 +263,7 @@ struct RPCHandlerOperation
detail::InplaceWithFunction{},
[&]
{
return initial_request()
.start(rpc_, operation.service(), agrpc::use_sender)
.connect(StartReceiver{*this});
return starter().start(rpc_, operation.service(), agrpc::use_sender).connect(StartReceiver{*this});
})
{
base().increment_ref_count();
Expand Down Expand Up @@ -299,7 +297,7 @@ struct RPCHandlerOperation
detail::InplaceWithFunction{},
[&]
{
return exec::connect(initial_request().invoke(rpc_handler(), rpc_), FinishReceiver{*this});
return exec::connect(starter().invoke(rpc_handler(), rpc_), FinishReceiver{*this});
});
return {};
}
Expand All @@ -326,7 +324,7 @@ struct RPCHandlerOperation

auto& rpc_handler() noexcept { return base().rpc_handler(); }

auto& initial_request() noexcept { return impl1_.second(); }
auto& starter() noexcept { return impl1_.second(); }

auto& operation_state() noexcept { return impl2_.first(); }

Expand Down
2 changes: 1 addition & 1 deletion src/agrpc/detail/server_rpc_context_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ struct ServerRPCContextBaseAccess
};

template <class ServerRPC>
using GetServerRPCServiceT = decltype(detail::ServerRPCContextBaseAccess::service(std::declval<ServerRPC&>()));
using ServerRPCServiceT = decltype(detail::ServerRPCContextBaseAccess::service(std::declval<ServerRPC&>()));
}

AGRPC_NAMESPACE_END
Expand Down
Loading

0 comments on commit 4045621

Please sign in to comment.