32#include <ArmarXCore/interface/core/UserException.h>
51 template <
class OnCloseExceptionT = ServerShuttingDown>
72 template <
class IceCallbackT>
100 inline void setAutoThrow(std::unique_ptr<std::exception> except);
106 inline void throwAll(
const std::exception& except);
114 struct CallbackHolder
138 std::deque<CallbackHolder> callbacks;
139 Mode currentMode{Mode::Store};
140 std::unique_ptr<std::exception> exception;
141 std::recursive_mutex classMutex;
144 template <
class OnCloseExceptionT>
147 throwAll(OnCloseExceptionT{
"AMDCallbackCollection dtor."});
150 template <
class OnCloseExceptionT>
156 std::lock_guard<std::recursive_mutex> guard{classMutex};
160 onExcept(*exception);
166 callbacks.emplace_back(CallbackHolder{std::move(onRespond), std::move(onExcept)});
171 template <
class OnCloseExceptionT>
175 std::lock_guard<std::recursive_mutex> guard{classMutex};
179 currentMode = Mode::Respond;
184 if (currentMode == Mode::Respond)
190 template <
class OnCloseExceptionT>
194 std::lock_guard<std::recursive_mutex> guard{classMutex};
195 for (std::size_t i = 0; i < n && !callbacks.empty(); ++i)
197 callbacks.at(0).onRespond();
198 callbacks.pop_front();
202 template <
class OnCloseExceptionT>
206 std::lock_guard<std::recursive_mutex> guard{classMutex};
207 for (
auto& cb : callbacks)
214 template <
class OnCloseExceptionT>
218 std::lock_guard<std::recursive_mutex> guard{classMutex};
223 currentMode = Mode::Except;
227 if (currentMode == Mode::Except)
234 template <
class OnCloseExceptionT>
238 std::lock_guard<std::recursive_mutex> guard{classMutex};
239 for (
auto& cb : callbacks)
246 template <
class OnCloseExceptionT>
250 std::lock_guard<std::recursive_mutex> guard{classMutex};
252 currentMode = Mode::Store;
255 template <
class OnCloseExceptionT>
256 template <
class IceCallbackT>
261 [cb](
const std::exception& e) { cb->ice_exception(e); });
void setAutoThrow(std::unique_ptr< std::exception > except)
If except is null, the mode will be set to Store if it was Except.
void respondeAll()
All currently stored callbacks will receive a response.
void throwAll(const std::exception &except)
All currently stored callbacks will receive the exception.
void addCallback(RespondFunction onRespond, ExceptFunction onExcept)
Adds an callback and processes it depending on the current mode.
void setAutoResponse(bool doAutoResponse=true)
setAutoResponse
std::function< void()> RespondFunction
void respondeN(std::size_t n)
The n oldest callbacks will receive a response.
AMDCallbackCollection()=default
std::function< void(const std::exception &)> ExceptFunction
void storeFurtherCallbacks()
All future callbacks will be stored.
This file offers overloads of toIce() and fromIce() functions for STL container types.