Async: Move callOriginalCb out of AsyncCont base, into NonPostedAC
The reasoning here is to prevent silent invocations of callOriginalCb from a base class pointer/ref.
This commit is contained in:
@@ -33,23 +33,6 @@ public:
|
|||||||
std::shared_ptr<AsynchronousContinuation<OriginalCbFnT>>
|
std::shared_ptr<AsynchronousContinuation<OriginalCbFnT>>
|
||||||
lifetimePreservingConveyance);
|
lifetimePreservingConveyance);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Call the original callback with perfect forwarding
|
|
||||||
*
|
|
||||||
* IMPORTANT: This method cannot be virtual because templates cannot be
|
|
||||||
* virtual in C++. Therefore, this method MUST be called from the
|
|
||||||
* most-derived class reference/pointer context. Never call this method
|
|
||||||
* through a polymorphic base class reference/pointer, as it will not
|
|
||||||
* dispatch to the correct derived class implementation.
|
|
||||||
*
|
|
||||||
* @param args Arguments to forward to the original callback
|
|
||||||
*/
|
|
||||||
template<typename... Args>
|
|
||||||
void callOriginalCb(Args&&... args)
|
|
||||||
{
|
|
||||||
if (originalCbFn) { originalCbFn(std::forward<Args>(args)...); }
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
OriginalCbFnT originalCbFn;
|
OriginalCbFnT originalCbFn;
|
||||||
};
|
};
|
||||||
@@ -73,8 +56,24 @@ public:
|
|||||||
: AsynchronousContinuation<OriginalCbFnT>(originalCbFn)
|
: AsynchronousContinuation<OriginalCbFnT>(originalCbFn)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
public:
|
/**
|
||||||
using AsynchronousContinuation<OriginalCbFnT>::callOriginalCb;
|
* @brief Call the original callback with perfect forwarding
|
||||||
|
* (immediate execution)
|
||||||
|
*
|
||||||
|
* This implementation calls the original callback immediately without
|
||||||
|
* posting to any thread or queue. Used for non-posted continuations.
|
||||||
|
*
|
||||||
|
* @param args Arguments to forward to the original callback
|
||||||
|
*/
|
||||||
|
template<typename... Args>
|
||||||
|
void callOriginalCb(Args&&... args)
|
||||||
|
{
|
||||||
|
if (AsynchronousContinuation<OriginalCbFnT>::originalCbFn)
|
||||||
|
{
|
||||||
|
AsynchronousContinuation<OriginalCbFnT>::originalCbFn(
|
||||||
|
std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class OriginalCbFnT>
|
template <class OriginalCbFnT>
|
||||||
@@ -92,7 +91,8 @@ public:
|
|||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
void callOriginalCb(Args&&... args)
|
void callOriginalCb(Args&&... args)
|
||||||
{
|
{
|
||||||
if (AsynchronousContinuation<OriginalCbFnT>::originalCbFn) {
|
if (AsynchronousContinuation<OriginalCbFnT>::originalCbFn)
|
||||||
|
{
|
||||||
caller->getIoService().post(
|
caller->getIoService().post(
|
||||||
std::bind(
|
std::bind(
|
||||||
AsynchronousContinuation<OriginalCbFnT>::originalCbFn,
|
AsynchronousContinuation<OriginalCbFnT>::originalCbFn,
|
||||||
@@ -102,7 +102,6 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
std::shared_ptr<ComponentThread> caller;
|
std::shared_ptr<ComponentThread> caller;
|
||||||
using AsynchronousContinuation<OriginalCbFnT>::callOriginalCb;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class OriginalCbFnT>
|
template <class OriginalCbFnT>
|
||||||
@@ -125,9 +124,6 @@ public:
|
|||||||
PostedAsynchronousContinuation<OriginalCbFnT>::callOriginalCb(
|
PostedAsynchronousContinuation<OriginalCbFnT>::callOriginalCb(
|
||||||
std::forward<Args>(args)...);
|
std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
|
||||||
using AsynchronousContinuation<OriginalCbFnT>::callOriginalCb;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace smo
|
} // namespace smo
|
||||||
|
|||||||
Reference in New Issue
Block a user