Skip to content

Commit

Permalink
style: Remove unnecessary RegisterRPCHandlerSenderOperationBase
Browse files Browse the repository at this point in the history
  • Loading branch information
Tradias committed Dec 14, 2024
1 parent c9433ee commit 33a46d1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 31 deletions.
6 changes: 2 additions & 4 deletions src/agrpc/detail/register_rpc_handler_asio_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ template <class ServerRPC, class RPCHandler, class CompletionHandlerT>
class RegisterRPCHandlerOperationAsioBase
: public detail::RegisterRPCHandlerOperationBase<ServerRPC, RPCHandler,
detail::CancellationSlotT<CompletionHandlerT&>>,
public detail::RegisterRPCHandlerOperationComplete,
private detail::WorkTracker<detail::AssociatedExecutorT<CompletionHandlerT>>
{
public:
Expand All @@ -58,7 +57,7 @@ class RegisterRPCHandlerOperationAsioBase
}
}

RegisterRPCHandlerOperationAsioBase& self_;
Base& self_;
};

public:
Expand All @@ -71,8 +70,7 @@ class RegisterRPCHandlerOperationAsioBase
template <class Ch>
RegisterRPCHandlerOperationAsioBase(const ServerRPCExecutor& executor, Service& service, RPCHandler&& rpc_handler,
Ch&& completion_handler, CompletionBase::Complete on_complete)
: Base(executor, service, static_cast<RPCHandler&&>(rpc_handler)),
CompletionBase(on_complete),
: Base(executor, service, static_cast<RPCHandler&&>(rpc_handler), on_complete),
WorkTracker(asio::get_associated_executor(completion_handler)),
completion_handler_(static_cast<Ch&&>(completion_handler))
{
Expand Down
10 changes: 7 additions & 3 deletions src/agrpc/detail/register_rpc_handler_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,17 @@ class RegisterRPCHandlerOperationComplete
};

template <class ServerRPC, class RPCHandler, class StopToken>
struct RegisterRPCHandlerOperationBase
struct RegisterRPCHandlerOperationBase : RegisterRPCHandlerOperationComplete
{
using Service = detail::ServerRPCServiceT<ServerRPC>;
using ServerRPCExecutor = typename ServerRPC::executor_type;

RegisterRPCHandlerOperationBase(const ServerRPCExecutor& executor, Service& service, RPCHandler&& rpc_handler)
: executor_(executor), service_(service), rpc_handler_(static_cast<RPCHandler&&>(rpc_handler))
RegisterRPCHandlerOperationBase(const ServerRPCExecutor& executor, Service& service, RPCHandler&& rpc_handler,
RegisterRPCHandlerOperationComplete::Complete complete)
: RegisterRPCHandlerOperationComplete{complete},
executor_(executor),
service_(service),
rpc_handler_(static_cast<RPCHandler&&>(rpc_handler))
{
}

Expand Down
32 changes: 8 additions & 24 deletions src/agrpc/detail/register_sender_rpc_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,28 +74,13 @@ class [[nodiscard]] RPCHandlerSender : public detail::SenderOf<void()>

private:
template <class, class, class>
friend struct detail::RegisterRPCHandlerSenderOperationBase;
friend struct detail::RegisterRPCHandlerOperationBase;

agrpc::GrpcContext& grpc_context_;
Service& service_;
RPCHandler rpc_handler_;
};

template <class ServerRPC, class RPCHandler, class StopToken>
struct RegisterRPCHandlerSenderOperationBase : RegisterRPCHandlerOperationBase<ServerRPC, RPCHandler, StopToken>,
RegisterRPCHandlerOperationComplete
{
RegisterRPCHandlerSenderOperationBase(RPCHandlerSender<ServerRPC, RPCHandler>&& sender,
RegisterRPCHandlerOperationComplete::Complete complete)
: RegisterRPCHandlerOperationBase<ServerRPC, RPCHandler, StopToken>{sender.grpc_context_.get_executor(),
sender.service_,
static_cast<RPCHandler&&>(
sender.rpc_handler_)},
RegisterRPCHandlerOperationComplete{complete}
{
}
};

template <class Receiver, class Signature, bool IsNotifyWhenDone>
struct GetWaitForDoneOperationState
{
Expand Down Expand Up @@ -150,7 +135,7 @@ struct RPCHandlerOperationWaitForDone

template <class ServerRPC, class RPCHandler, class StopToken, class Allocator>
std::optional<std::exception_ptr> create_and_start_rpc_handler_operation(
RegisterRPCHandlerSenderOperationBase<ServerRPC, RPCHandler, StopToken>& operation, const Allocator& allocator);
RegisterRPCHandlerOperationBase<ServerRPC, RPCHandler, StopToken>& operation, const Allocator& allocator);

template <class ServerRPC, class RPCHandler, class StopToken, class Allocator>
struct RPCHandlerOperation
Expand All @@ -160,8 +145,7 @@ struct RPCHandlerOperation
using Starter = detail::ServerRPCStarter<>;
using RequestMessageFactory = detail::ServerRPCRequestMessageFactoryT<ServerRPC, RPCHandler>;
using RPCHandlerInvokeResult = detail::RPCHandlerInvokeResultT<ServerRPC&, RPCHandler&, RequestMessageFactory&>;
using RegisterRPCHandlerSenderOperationBase =
detail::RegisterRPCHandlerSenderOperationBase<ServerRPC, RPCHandler, StopToken>;
using RegisterRPCHandlerOperationBase = detail::RegisterRPCHandlerOperationBase<ServerRPC, RPCHandler, StopToken>;

struct StartReceiver
{
Expand Down Expand Up @@ -264,7 +248,7 @@ struct RPCHandlerOperation

using OperationState = std::variant<StartOperationState, FinishOperationState, WaitForDoneOperationState>;

explicit RPCHandlerOperation(RegisterRPCHandlerSenderOperationBase& operation, const Allocator& allocator)
explicit RPCHandlerOperation(RegisterRPCHandlerOperationBase& operation, const Allocator& allocator)
: impl1_(operation, operation.rpc_handler()),
rpc_(detail::ServerRPCContextBaseAccess::construct<ServerRPC>(operation.get_executor())),
impl2_(detail::SecondThenVariadic{}, allocator, std::in_place_type<StartOperationState>,
Expand Down Expand Up @@ -340,14 +324,14 @@ struct RPCHandlerOperation

auto& get_allocator() noexcept { return impl2_.second(); }

detail::CompressedPair<RegisterRPCHandlerSenderOperationBase&, RequestMessageFactory> impl1_;
detail::CompressedPair<RegisterRPCHandlerOperationBase&, RequestMessageFactory> impl1_;
ServerRPC rpc_;
detail::CompressedPair<OperationState, Allocator> impl2_;
};

template <class ServerRPC, class RPCHandler, class StopToken, class Allocator>
std::optional<std::exception_ptr> create_and_start_rpc_handler_operation(
RegisterRPCHandlerSenderOperationBase<ServerRPC, RPCHandler, StopToken>& operation, const Allocator& allocator)
RegisterRPCHandlerOperationBase<ServerRPC, RPCHandler, StopToken>& operation, const Allocator& allocator)
{
if AGRPC_UNLIKELY (operation.is_stopped())
{
Expand All @@ -366,11 +350,11 @@ std::optional<std::exception_ptr> create_and_start_rpc_handler_operation(

template <class ServerRPC, class RPCHandler, class Receiver>
class RPCHandlerSenderOperation
: public detail::RegisterRPCHandlerSenderOperationBase<ServerRPC, RPCHandler, exec::stop_token_type_t<Receiver&>>
: public detail::RegisterRPCHandlerOperationBase<ServerRPC, RPCHandler, exec::stop_token_type_t<Receiver&>>
{
private:
using StopToken = exec::stop_token_type_t<Receiver&>;
using Base = detail::RegisterRPCHandlerSenderOperationBase<ServerRPC, RPCHandler, StopToken>;
using Base = detail::RegisterRPCHandlerOperationBase<ServerRPC, RPCHandler, StopToken>;
using Allocator = detail::RemoveCrefT<decltype(exec::get_allocator(std::declval<Receiver&>()))>;
using RPCHandlerOperation = detail::RPCHandlerOperation<ServerRPC, RPCHandler, StopToken, Allocator>;
using RPCHandlerSender = detail::RPCHandlerSender<ServerRPC, RPCHandler>;
Expand Down

0 comments on commit 33a46d1

Please sign in to comment.