[c++ grpc] Add helper io_manager_tag::tag

This function encapsulates the `static_cast<io_manager*>(thing)` pattern
that was used throughout the codebase.
This commit is contained in:
Ara Ayvazyan 2018-05-08 21:18:11 -07:00 коммит произвёл Christopher Warrington
Родитель 73f1861e0a
Коммит 12e3b4c43d
4 изменённых файлов: 20 добавлений и 14 удалений

Просмотреть файл

@ -72,14 +72,14 @@ struct client_unary_call_data
_ioManager(std::move(ioManager)),
_threadPool(std::move(threadPool)),
_responseReader(),
_callbackArgs(context),
_cb(cb),
_callbackArgs(std::move(context)),
_cb(std::move(cb)),
_self()
{
BOOST_ASSERT(_channel);
BOOST_ASSERT(_ioManager);
BOOST_ASSERT(_threadPool);
BOOST_ASSERT(context);
BOOST_ASSERT(_callbackArgs.context);
}
/// @brief Initiates the client request and wires up completion
@ -88,7 +88,7 @@ struct client_unary_call_data
const grpc::internal::RpcMethod& method,
const bond::bonded<TRequest>& request)
{
_responseReader = std::unique_ptr<grpc::ClientAsyncResponseReader<bond::bonded<TResponse>>>(
_responseReader.reset(
::grpc::internal::ClientAsyncResponseReaderFactory<bond::bonded<TResponse>>::Create(
_channel.get(),
_ioManager->cq(),
@ -102,7 +102,7 @@ struct client_unary_call_data
_responseReader->Finish(
&_callbackArgs.response,
&_callbackArgs.status,
static_cast<void*>(static_cast<io_manager_tag*>(this)));
tag());
}
/// @brief Invoked after the response has been received.
@ -110,7 +110,7 @@ struct client_unary_call_data
{
if (ok && _cb)
{
_threadPool->schedule([this]()
_threadPool->schedule([this]
{
// pass a shared_ptr to unary_call_result, but that
// participates in shared ownership of the containing

Просмотреть файл

@ -15,13 +15,19 @@ namespace bond { namespace ext { namespace gRPC { namespace detail {
/// operation in its implementation of \ref invoke.
struct io_manager_tag
{
virtual ~io_manager_tag() { }
virtual ~io_manager_tag() = default;
/// @brief Called when this instance is dequeued from a completion
/// queue.
///
/// @param ok whether or not the initial operation succeeded
virtual void invoke(bool ok) = 0;
/// @return Returns a %tag value suitable for passing to completion queue routines.
io_manager_tag* tag()
{
return this;
}
};
} } } } // namespace bond::ext::gRPC::detail

Просмотреть файл

@ -94,7 +94,7 @@ namespace bond { namespace ext { namespace gRPC { namespace detail {
bool wasResponseSent = _responseSentFlag.test_and_set();
if (!wasResponseSent)
{
_responder.Finish(msg, status, static_cast<void*>(static_cast<io_manager_tag*>(this)));
_responder.Finish(msg, status, tag());
}
}
@ -103,7 +103,7 @@ namespace bond { namespace ext { namespace gRPC { namespace detail {
bool wasResponseSent = _responseSentFlag.test_and_set();
if (!wasResponseSent)
{
_responder.FinishWithError(status, static_cast<void*>(static_cast<io_manager_tag*>(this)));
_responder.FinishWithError(status, tag());
}
}
@ -179,8 +179,6 @@ namespace bond { namespace ext { namespace gRPC { namespace detail {
template <typename TRequest, typename TResponse>
class unary_call_base
{
using impl_type = unary_call_impl<TRequest, TResponse>;
public:
void swap(unary_call_base& rhs) noexcept
{
@ -240,6 +238,8 @@ namespace bond { namespace ext { namespace gRPC { namespace detail {
}
protected:
using impl_type = unary_call_impl<TRequest, TResponse>;
unary_call_base() = default;
explicit unary_call_base(boost::intrusive_ptr<impl_type> impl) noexcept

Просмотреть файл

@ -61,7 +61,7 @@ class io_managerTests
alarm_completion_tag<event> act;
gpr_timespec deadline = gpr_time_0(GPR_CLOCK_MONOTONIC);
grpc::Alarm alarm(ioManager.cq(), deadline, static_cast<io_manager_tag*>(&act));
grpc::Alarm alarm(ioManager.cq(), deadline, act.tag());
bool wasSet = act.completion_event.wait_for(std::chrono::seconds(30));
UT_AssertIsTrue(wasSet);
@ -81,7 +81,7 @@ class io_managerTests
alarms.reserve(numItems);
for (size_t i = 0; i < numItems; ++i)
{
alarms.emplace_back(ioManager.cq(), deadline, static_cast<io_manager_tag*>(&act));
alarms.emplace_back(ioManager.cq(), deadline, act.tag());
}
bool wasSet = act.completion_event.wait_for(std::chrono::seconds(30));
@ -146,7 +146,7 @@ class io_managerTests
alarm_completion_tag<event> act;
gpr_timespec deadline = gpr_time_0(GPR_CLOCK_MONOTONIC);
grpc::Alarm alarm(ioManager.cq(), deadline, static_cast<io_manager_tag*>(&act));
grpc::Alarm alarm(ioManager.cq(), deadline, act.tag());
bool wasSet = act.completion_event.wait_for(std::chrono::milliseconds(1250));
UT_AssertIsTrue(!wasSet);