Skip to content

Commit

Permalink
Make _batchRequestQueue const (#1769)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier authored Feb 8, 2024
1 parent d939b57 commit 2d3a545
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 29 deletions.
48 changes: 33 additions & 15 deletions cpp/include/Ice/Proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace IceInternal
{

//
// Class for handling the proxy's begin_ice_flushBatchRequest request.
// Class for handling the proxy's flushBatchRequest request.
//
class ICE_API ProxyFlushBatchAsync : public ProxyOutgoingAsyncBase
{
Expand Down Expand Up @@ -522,9 +522,7 @@ class ICE_API ObjectPrx : public Proxy<ObjectPrx>, public ::std::enable_shared_f
virtual ~ObjectPrx() = default;

/// \cond INTERNAL
ObjectPrx(const IceInternal::ReferencePtr& ref) noexcept : _reference(ref)
{
}
ObjectPrx(const IceInternal::ReferencePtr& ref) noexcept;
/// \endcond

/**
Expand Down Expand Up @@ -1132,10 +1130,21 @@ class ICE_API ObjectPrx : public Proxy<ObjectPrx>, public ::std::enable_shared_f
ice_flushBatchRequestsAsync(::std::function<void(::std::exception_ptr)> ex,
::std::function<void(bool)> sent = nullptr)
{
using LambdaOutgoing = ::IceInternal::ProxyFlushBatchLambda;
auto outAsync = ::std::make_shared<LambdaOutgoing>(shared_from_this(), std::move(ex), std::move(sent));
_iceI_flushBatchRequests(outAsync);
return [outAsync]() { outAsync->cancel(); };
if (_batchRequestQueue)
{
using LambdaOutgoing = ::IceInternal::ProxyFlushBatchLambda;
auto outAsync = ::std::make_shared<LambdaOutgoing>(shared_from_this(), std::move(ex), std::move(sent));
_iceI_flushBatchRequests(outAsync);
return [outAsync]() { outAsync->cancel(); };
}
else
{
if (sent)
{
sent(true);
}
return []() {}; // return a callable function target that does nothing.
}
}

/**
Expand All @@ -1145,10 +1154,19 @@ class ICE_API ObjectPrx : public Proxy<ObjectPrx>, public ::std::enable_shared_f
template<template<typename> class P = std::promise> auto
ice_flushBatchRequestsAsync() -> decltype(std::declval<P<void>>().get_future())
{
using PromiseOutgoing = ::IceInternal::ProxyFlushBatchPromise<P<void>>;
auto outAsync = ::std::make_shared<PromiseOutgoing>(shared_from_this());
_iceI_flushBatchRequests(outAsync);
return outAsync->getFuture();
if (_batchRequestQueue)
{
using PromiseOutgoing = ::IceInternal::ProxyFlushBatchPromise<P<void>>;
auto outAsync = ::std::make_shared<PromiseOutgoing>(shared_from_this());
_iceI_flushBatchRequests(outAsync);
return outAsync->getFuture();
}
else
{
P<void> p;
p.set_value();
return p.get_future();
}
}

/// \cond INTERNAL
Expand All @@ -1162,7 +1180,7 @@ class ICE_API ObjectPrx : public Proxy<ObjectPrx>, public ::std::enable_shared_f
void _checkTwowayOnly(const ::std::string&) const;

::IceInternal::RequestHandlerPtr _getRequestHandler();
::IceInternal::BatchRequestQueuePtr _getBatchRequestQueue();
::IceInternal::BatchRequestQueuePtr _getBatchRequestQueue() const { return _batchRequestQueue; }
::IceInternal::RequestHandlerPtr _setRequestHandler(const ::IceInternal::RequestHandlerPtr&);
void _updateRequestHandler(const ::IceInternal::RequestHandlerPtr&, const ::IceInternal::RequestHandlerPtr&);

Expand Down Expand Up @@ -1225,9 +1243,9 @@ class ICE_API ObjectPrx : public Proxy<ObjectPrx>, public ::std::enable_shared_f
IceInternal::ReferencePtr _timeout(int) const;
IceInternal::ReferencePtr _twoway() const;

const ::IceInternal::ReferencePtr _reference;
const IceInternal::ReferencePtr _reference;
::IceInternal::RequestHandlerPtr _requestHandler;
::IceInternal::BatchRequestQueuePtr _batchRequestQueue;
const IceInternal::BatchRequestQueuePtr _batchRequestQueue;
mutable std::mutex _mutex;
};

Expand Down
21 changes: 7 additions & 14 deletions cpp/src/Ice/Proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,13 @@ operator==(const ObjectPrx& lhs, const ObjectPrx& rhs)

}

Ice::ObjectPrx::ObjectPrx(const ObjectPrx& other) noexcept :
enable_shared_from_this<ObjectPrx>(), // the copy is independent of other
_reference(other._reference)
Ice::ObjectPrx::ObjectPrx(const ReferencePtr& ref) noexcept :
_reference(ref),
_batchRequestQueue(ref->isBatch() ? _reference->getBatchRequestQueue() : nullptr)
{
}

Ice::ObjectPrx::ObjectPrx(const ObjectPrx& other) noexcept : ObjectPrx(other._reference)
{
lock_guard lock(other._mutex);
_requestHandler = other._requestHandler;
Expand Down Expand Up @@ -501,17 +505,6 @@ Ice::ObjectPrx::_getRequestHandler()
return _reference->getRequestHandler(shared_from_this());
}

IceInternal::BatchRequestQueuePtr
Ice::ObjectPrx::_getBatchRequestQueue()
{
lock_guard lock(_mutex);
if(!_batchRequestQueue)
{
_batchRequestQueue = _reference->getBatchRequestQueue();
}
return _batchRequestQueue;
}

::IceInternal::RequestHandlerPtr
Ice::ObjectPrx::_setRequestHandler(const ::IceInternal::RequestHandlerPtr& handler)
{
Expand Down
1 change: 1 addition & 0 deletions cpp/src/Ice/Reference.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class Reference : public std::enable_shared_from_this<Reference>
};

Mode getMode() const { return _mode; }
bool isBatch() const { return _mode == ModeBatchOneway || _mode == ModeBatchDatagram; }
bool getSecure() const { return _secure; }
const Ice::ProtocolVersion& getProtocol() const { return _protocol; }
const Ice::EncodingVersion& getEncoding() const { return _encoding; }
Expand Down

0 comments on commit 2d3a545

Please sign in to comment.