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>
153 std::lock_guard<std::recursive_mutex> guard {classMutex};
157 onExcept(*exception);
163 callbacks.emplace_back(CallbackHolder {std::move(onRespond), std::move(onExcept)});
168 template<
class OnCloseExceptionT>
171 std::lock_guard<std::recursive_mutex> guard {classMutex};
175 currentMode = Mode::Respond;
180 if (currentMode == Mode::Respond)
182 storeFurtherCallbacks();
186 template<
class OnCloseExceptionT>
189 std::lock_guard<std::recursive_mutex> guard {classMutex};
190 for (std::size_t i = 0; i < n && !callbacks.empty(); ++i)
192 callbacks.at(0).onRespond();
193 callbacks.pop_front();
197 template<
class OnCloseExceptionT>
200 std::lock_guard<std::recursive_mutex> guard {classMutex};
201 for (
auto& cb : callbacks)
208 template<
class OnCloseExceptionT>
211 std::lock_guard<std::recursive_mutex> guard {classMutex};
216 currentMode = Mode::Except;
217 throwAll(*exception);
220 if (currentMode == Mode::Except)
223 storeFurtherCallbacks();
227 template<
class OnCloseExceptionT>
230 std::lock_guard<std::recursive_mutex> guard {classMutex};
231 for (
auto& cb : callbacks)
238 template<
class OnCloseExceptionT>
241 std::lock_guard<std::recursive_mutex> guard {classMutex};
243 currentMode = Mode::Store;
246 template<
class OnCloseExceptionT>
247 template<
class IceCallbackT>
250 addCallback([cb] {cb->ice_response();}, [cb](
const std::exception & e)
252 cb->ice_exception(e);