-
Notifications
You must be signed in to change notification settings - Fork 592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preliminary C++ proxy refactoring #1754
Changes from 4 commits
27dddc7
e30b6e0
4885e2d
d096138
83c4ccf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,12 +79,6 @@ typedef IceUtil::Handle<ProxyGetConnection> ProxyGetConnectionPtr; | |
namespace IceInternal | ||
{ | ||
|
||
template<typename P> | ||
::std::shared_ptr<P> createProxy() | ||
{ | ||
return ::std::shared_ptr<P>(new P()); | ||
} | ||
|
||
inline ::std::pair<const Ice::Byte*, const Ice::Byte*> | ||
makePair(const Ice::ByteSeq& seq) | ||
{ | ||
|
@@ -278,10 +272,14 @@ class ICE_API ObjectPrx : public ::std::enable_shared_from_this<ObjectPrx> | |
{ | ||
public: | ||
|
||
ObjectPrx(const ObjectPrx& other) noexcept; | ||
virtual ~ObjectPrx() = default; | ||
|
||
friend ICE_API bool operator<(const ObjectPrx&, const ObjectPrx&); | ||
friend ICE_API bool operator==(const ObjectPrx&, const ObjectPrx&); | ||
/// \cond INTERNAL | ||
ObjectPrx(const IceInternal::ReferencePtr& ref) noexcept : _reference(ref) | ||
{ | ||
} | ||
/// \endcond | ||
|
||
/** | ||
* Obtains the communicator that created this proxy. | ||
|
@@ -1069,8 +1067,6 @@ class ICE_API ObjectPrx : public ::std::enable_shared_from_this<ObjectPrx> | |
|
||
const ::IceInternal::ReferencePtr& _getReference() const { return _reference; } | ||
|
||
void _copyFrom(const std::shared_ptr<::Ice::ObjectPrx>&); | ||
|
||
int _handleException(const ::Ice::Exception&, const ::IceInternal::RequestHandlerPtr&, ::Ice::OperationMode, | ||
bool, int&); | ||
|
||
|
@@ -1089,6 +1085,9 @@ class ICE_API ObjectPrx : public ::std::enable_shared_from_this<ObjectPrx> | |
protected: | ||
|
||
/// \cond INTERNAL | ||
// This constructor is never called; it allows Proxy's default constructor to compile. | ||
ObjectPrx() = default; | ||
|
||
template<typename R, template<typename> class P = ::std::promise, typename Obj, typename Fn, typename... Args> | ||
auto _makePromiseOutgoing(bool sync, Obj obj, Fn fn, Args&&... args) | ||
-> decltype(std::declval<P<R>>().get_future()) | ||
|
@@ -1107,22 +1106,19 @@ class ICE_API ObjectPrx : public ::std::enable_shared_from_this<ObjectPrx> | |
return [outAsync]() { outAsync->cancel(); }; | ||
} | ||
|
||
virtual ::std::shared_ptr<ObjectPrx> _newInstance() const; | ||
ObjectPrx() = default; | ||
friend ::std::shared_ptr<ObjectPrx> IceInternal::createProxy<ObjectPrx>(); | ||
/// \endcond | ||
|
||
private: | ||
|
||
void setup(const ::IceInternal::ReferencePtr&); | ||
friend class ::IceInternal::ProxyFactory; | ||
|
||
::IceInternal::ReferencePtr _reference; | ||
const ::IceInternal::ReferencePtr _reference; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ObjectPrx holding this const reference is the pimpl technique: Note:
|
||
::IceInternal::RequestHandlerPtr _requestHandler; | ||
::IceInternal::BatchRequestQueuePtr _batchRequestQueue; | ||
IceUtil::Mutex _mutex; | ||
mutable std::mutex _mutex; | ||
}; | ||
|
||
ICE_API bool operator<(const ObjectPrx&, const ObjectPrx&); | ||
ICE_API bool operator==(const ObjectPrx&, const ObjectPrx&); | ||
|
||
inline bool | ||
operator>(const ObjectPrx& lhs, const ObjectPrx& rhs) | ||
{ | ||
|
@@ -1163,7 +1159,7 @@ class Proxy : public virtual Bases... | |
*/ | ||
::std::shared_ptr<Prx> ice_context(const ::Ice::Context& context) const | ||
{ | ||
return ::std::dynamic_pointer_cast<Prx>(ObjectPrx::ice_context(context)); | ||
return ::std::make_shared<Prx>(*ObjectPrx::ice_context(context)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before this PR, ObjectPrx::ice_context and friends created a clone of the most derived classes (with virtual newInstance). Now, they just create a new ObjectPrx and we create here the most derived class. It's a bit wasteful but: a) it doesn't matter since these factory functions aren't called very often |
||
} | ||
|
||
/** | ||
|
@@ -1173,7 +1169,7 @@ class Proxy : public virtual Bases... | |
*/ | ||
::std::shared_ptr<Prx> ice_adapterId(const ::std::string& id) const | ||
{ | ||
return ::std::dynamic_pointer_cast<Prx>(ObjectPrx::ice_adapterId(id)); | ||
return ::std::make_shared<Prx>(*ObjectPrx::ice_adapterId(id)); | ||
} | ||
|
||
/** | ||
|
@@ -1183,7 +1179,7 @@ class Proxy : public virtual Bases... | |
*/ | ||
::std::shared_ptr<Prx> ice_endpoints(const ::Ice::EndpointSeq& endpoints) const | ||
{ | ||
return ::std::dynamic_pointer_cast<Prx>(ObjectPrx::ice_endpoints(endpoints)); | ||
return ::std::make_shared<Prx>(*ObjectPrx::ice_endpoints(endpoints)); | ||
} | ||
|
||
/** | ||
|
@@ -1193,7 +1189,7 @@ class Proxy : public virtual Bases... | |
*/ | ||
::std::shared_ptr<Prx> ice_locatorCacheTimeout(int timeout) const | ||
{ | ||
return ::std::dynamic_pointer_cast<Prx>(ObjectPrx::ice_locatorCacheTimeout(timeout)); | ||
return ::std::make_shared<Prx>(*ObjectPrx::ice_locatorCacheTimeout(timeout)); | ||
} | ||
|
||
/** | ||
|
@@ -1203,7 +1199,7 @@ class Proxy : public virtual Bases... | |
*/ | ||
::std::shared_ptr<Prx> ice_connectionCached(bool b) const | ||
{ | ||
return ::std::dynamic_pointer_cast<Prx>(ObjectPrx::ice_connectionCached(b)); | ||
return ::std::make_shared<Prx>(*ObjectPrx::ice_connectionCached(b)); | ||
} | ||
|
||
/** | ||
|
@@ -1213,7 +1209,7 @@ class Proxy : public virtual Bases... | |
*/ | ||
::std::shared_ptr<Prx> ice_endpointSelection(::Ice::EndpointSelectionType type) const | ||
{ | ||
return ::std::dynamic_pointer_cast<Prx>(ObjectPrx::ice_endpointSelection(type)); | ||
return ::std::make_shared<Prx>(*ObjectPrx::ice_endpointSelection(type)); | ||
} | ||
|
||
/** | ||
|
@@ -1224,7 +1220,7 @@ class Proxy : public virtual Bases... | |
*/ | ||
::std::shared_ptr<Prx> ice_secure(bool b) const | ||
{ | ||
return ::std::dynamic_pointer_cast<Prx>(ObjectPrx::ice_secure(b)); | ||
return ::std::make_shared<Prx>(*ObjectPrx::ice_secure(b)); | ||
} | ||
|
||
/** | ||
|
@@ -1236,7 +1232,7 @@ class Proxy : public virtual Bases... | |
*/ | ||
::std::shared_ptr<Prx> ice_preferSecure(bool b) const | ||
{ | ||
return ::std::dynamic_pointer_cast<Prx>(ObjectPrx::ice_preferSecure(b)); | ||
return ::std::make_shared<Prx>(*ObjectPrx::ice_preferSecure(b)); | ||
} | ||
|
||
/** | ||
|
@@ -1246,7 +1242,7 @@ class Proxy : public virtual Bases... | |
*/ | ||
::std::shared_ptr<Prx> ice_router(const ::std::shared_ptr<::Ice::RouterPrx>& router) const | ||
{ | ||
return ::std::dynamic_pointer_cast<Prx>(ObjectPrx::ice_router(router)); | ||
return ::std::make_shared<Prx>(*ObjectPrx::ice_router(router)); | ||
} | ||
|
||
/** | ||
|
@@ -1256,7 +1252,7 @@ class Proxy : public virtual Bases... | |
*/ | ||
::std::shared_ptr<Prx> ice_locator(const ::std::shared_ptr<::Ice::LocatorPrx>& locator) const | ||
{ | ||
return ::std::dynamic_pointer_cast<Prx>(ObjectPrx::ice_locator(locator)); | ||
return ::std::make_shared<Prx>(*ObjectPrx::ice_locator(locator)); | ||
} | ||
|
||
/** | ||
|
@@ -1266,7 +1262,7 @@ class Proxy : public virtual Bases... | |
*/ | ||
::std::shared_ptr<Prx> ice_collocationOptimized(bool b) const | ||
{ | ||
return ::std::dynamic_pointer_cast<Prx>(ObjectPrx::ice_collocationOptimized(b)); | ||
return ::std::make_shared<Prx>(*ObjectPrx::ice_collocationOptimized(b)); | ||
} | ||
|
||
/** | ||
|
@@ -1276,7 +1272,7 @@ class Proxy : public virtual Bases... | |
*/ | ||
::std::shared_ptr<Prx> ice_invocationTimeout(int timeout) const | ||
{ | ||
return ::std::dynamic_pointer_cast<Prx>(ObjectPrx::ice_invocationTimeout(timeout)); | ||
return ::std::make_shared<Prx>(*ObjectPrx::ice_invocationTimeout(timeout)); | ||
} | ||
|
||
/** | ||
|
@@ -1285,7 +1281,7 @@ class Proxy : public virtual Bases... | |
*/ | ||
::std::shared_ptr<Prx> ice_twoway() const | ||
{ | ||
return ::std::dynamic_pointer_cast<Prx>(ObjectPrx::ice_twoway()); | ||
return ::std::make_shared<Prx>(*ObjectPrx::ice_twoway()); | ||
} | ||
|
||
/** | ||
|
@@ -1294,7 +1290,7 @@ class Proxy : public virtual Bases... | |
*/ | ||
::std::shared_ptr<Prx> ice_oneway() const | ||
{ | ||
return ::std::dynamic_pointer_cast<Prx>(ObjectPrx::ice_oneway()); | ||
return ::std::make_shared<Prx>(*ObjectPrx::ice_oneway()); | ||
} | ||
|
||
/** | ||
|
@@ -1303,7 +1299,7 @@ class Proxy : public virtual Bases... | |
*/ | ||
::std::shared_ptr<Prx> ice_batchOneway() const | ||
{ | ||
return ::std::dynamic_pointer_cast<Prx>(ObjectPrx::ice_batchOneway()); | ||
return ::std::make_shared<Prx>(*ObjectPrx::ice_batchOneway()); | ||
} | ||
|
||
/** | ||
|
@@ -1312,7 +1308,7 @@ class Proxy : public virtual Bases... | |
*/ | ||
::std::shared_ptr<Prx> ice_datagram() const | ||
{ | ||
return ::std::dynamic_pointer_cast<Prx>(ObjectPrx::ice_datagram()); | ||
return ::std::make_shared<Prx>(*ObjectPrx::ice_datagram()); | ||
} | ||
|
||
/** | ||
|
@@ -1321,7 +1317,7 @@ class Proxy : public virtual Bases... | |
*/ | ||
::std::shared_ptr<Prx> ice_batchDatagram() const | ||
{ | ||
return ::std::dynamic_pointer_cast<Prx>(ObjectPrx::ice_batchDatagram()); | ||
return ::std::make_shared<Prx>(*ObjectPrx::ice_batchDatagram()); | ||
} | ||
|
||
/** | ||
|
@@ -1332,7 +1328,7 @@ class Proxy : public virtual Bases... | |
*/ | ||
::std::shared_ptr<Prx> ice_compress(bool b) const | ||
{ | ||
return ::std::dynamic_pointer_cast<Prx>(ObjectPrx::ice_compress(b)); | ||
return ::std::make_shared<Prx>(*ObjectPrx::ice_compress(b)); | ||
} | ||
|
||
/** | ||
|
@@ -1343,7 +1339,7 @@ class Proxy : public virtual Bases... | |
*/ | ||
::std::shared_ptr<Prx> ice_timeout(int timeout) const | ||
{ | ||
return ::std::dynamic_pointer_cast<Prx>(ObjectPrx::ice_timeout(timeout)); | ||
return ::std::make_shared<Prx>(*ObjectPrx::ice_timeout(timeout)); | ||
} | ||
|
||
/** | ||
|
@@ -1354,7 +1350,7 @@ class Proxy : public virtual Bases... | |
*/ | ||
::std::shared_ptr<Prx> ice_connectionId(const ::std::string& id) const | ||
{ | ||
return ::std::dynamic_pointer_cast<Prx>(ObjectPrx::ice_connectionId(id)); | ||
return ::std::make_shared<Prx>(*ObjectPrx::ice_connectionId(id)); | ||
} | ||
|
||
/** | ||
|
@@ -1365,7 +1361,7 @@ class Proxy : public virtual Bases... | |
*/ | ||
::std::shared_ptr<Prx> ice_fixed(const ::std::shared_ptr<::Ice::Connection>& connection) const | ||
{ | ||
return ::std::dynamic_pointer_cast<Prx>(ObjectPrx::ice_fixed(connection)); | ||
return ::std::make_shared<Prx>(*ObjectPrx::ice_fixed(connection)); | ||
} | ||
|
||
/** | ||
|
@@ -1376,14 +1372,14 @@ class Proxy : public virtual Bases... | |
*/ | ||
::std::shared_ptr<Prx> ice_encodingVersion(const ::Ice::EncodingVersion& version) const | ||
{ | ||
return ::std::dynamic_pointer_cast<Prx>(ObjectPrx::ice_encodingVersion(version)); | ||
return ::std::make_shared<Prx>(*ObjectPrx::ice_encodingVersion(version)); | ||
} | ||
|
||
protected: | ||
|
||
/// \cond INTERNAL | ||
virtual ::std::shared_ptr<ObjectPrx> _newInstance() const = 0; | ||
/// \endcond | ||
// This constructor never initializes the base classes since they are all virtual and Proxy is never the most | ||
// derived class. | ||
Proxy() = default; | ||
}; | ||
|
||
ICE_API ::std::ostream& operator<<(::std::ostream&, const ::Ice::ObjectPrx&); | ||
|
@@ -1494,8 +1490,7 @@ uncheckedCast(const ::std::shared_ptr<T>& b) | |
r = ::std::dynamic_pointer_cast<P>(b); | ||
if(!r) | ||
{ | ||
r = IceInternal::createProxy<P>(); | ||
r->_copyFrom(b); | ||
r = std::make_shared<P>(*b); | ||
} | ||
} | ||
return r; | ||
|
@@ -1516,8 +1511,7 @@ uncheckedCast(const ::std::shared_ptr<T>& b, const std::string& f) | |
::std::shared_ptr<P> r; | ||
if(b) | ||
{ | ||
r = IceInternal::createProxy<P>(); | ||
r->_copyFrom(b->ice_facet(f)); | ||
r = std::make_shared<P>(*(b->ice_facet(f))); | ||
} | ||
return r; | ||
} | ||
|
@@ -1540,8 +1534,7 @@ checkedCast(const ::std::shared_ptr<T>& b, const ::Ice::Context& context = Ice:: | |
{ | ||
if(b->ice_isA(P::ice_staticId(), context)) | ||
{ | ||
r = IceInternal::createProxy<P>(); | ||
r->_copyFrom(b); | ||
r = std::make_shared<P>(*b); | ||
} | ||
} | ||
return r; | ||
|
@@ -1569,8 +1562,7 @@ checkedCast(const ::std::shared_ptr<T>& b, const std::string& f, const ::Ice::Co | |
::std::shared_ptr<::Ice::ObjectPrx> bb = b->ice_facet(f); | ||
if(bb->ice_isA(P::ice_staticId(), context)) | ||
{ | ||
r = IceInternal::createProxy<P>(); | ||
r->_copyFrom(bb); | ||
r = std::make_shared<P>(*bb); | ||
} | ||
} | ||
catch(const Ice::FacetNotExistException&) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The replacement for _copyFrom .