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)
186 storeFurtherCallbacks();
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;
224 throwAll(*exception);
227 if (currentMode == Mode::Except)
230 storeFurtherCallbacks();
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>
260 addCallback([cb] { cb->ice_response(); },
261 [cb](
const std::exception& e) { cb->ice_exception(e); });