40 lines
881 B
C++
40 lines
881 B
C++
|
|
#ifndef CALLBACK_H
|
||
|
|
#define CALLBACK_H
|
||
|
|
|
||
|
|
#include <memory>
|
||
|
|
#include <functional>
|
||
|
|
|
||
|
|
namespace smo {
|
||
|
|
|
||
|
|
// Forward declaration
|
||
|
|
class AsyncContinuation;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Callback class that wraps a function and its caller continuation
|
||
|
|
*
|
||
|
|
* This class provides a way to pass both a callback function and the
|
||
|
|
* caller's continuation in a single object, enabling deadlock detection
|
||
|
|
* by walking the chain of continuations.
|
||
|
|
*/
|
||
|
|
template<typename CbFnT>
|
||
|
|
class Callback
|
||
|
|
{
|
||
|
|
public:
|
||
|
|
/**
|
||
|
|
* @brief Constructor
|
||
|
|
* @param caller The caller's continuation
|
||
|
|
* @param cb The callback function to invoke
|
||
|
|
*/
|
||
|
|
Callback(std::shared_ptr<AsyncContinuation> caller, std::function<CbFnT> cb)
|
||
|
|
: callerContinuation(std::move(caller)), callback(std::move(cb))
|
||
|
|
{}
|
||
|
|
|
||
|
|
public:
|
||
|
|
std::shared_ptr<AsyncContinuation> callerContinuation;
|
||
|
|
std::function<CbFnT> callback;
|
||
|
|
};
|
||
|
|
|
||
|
|
} // namespace smo
|
||
|
|
|
||
|
|
#endif // CALLBACK_H
|