57
57
namespace moveit {
58
58
namespace task_constructor {
59
59
60
+ // / exception thrown by StagePrivate::runCompute()
61
+ class PreemptStageException : public std ::exception
62
+ {
63
+ public:
64
+ explicit PreemptStageException () {}
65
+ const char * what () const noexcept override {
66
+ static const char * msg = " " ;
67
+ return msg;
68
+ }
69
+ };
70
+
60
71
class ContainerBase ;
61
72
class StagePrivate
62
73
{
@@ -146,6 +157,10 @@ class StagePrivate
146
157
bool storeFailures () const { return introspection_ != nullptr ; }
147
158
void runCompute () {
148
159
ROS_DEBUG_STREAM_NAMED (" Stage" , fmt::format (" Computing stage '{}'" , name ()));
160
+
161
+ if (preempted ())
162
+ throw PreemptStageException ();
163
+
149
164
auto compute_start_time = std::chrono::steady_clock::now ();
150
165
try {
151
166
compute ();
@@ -159,6 +174,10 @@ class StagePrivate
159
174
/* * compute cost for solution through configured CostTerm */
160
175
void computeCost (const InterfaceState& from, const InterfaceState& to, SolutionBase& solution);
161
176
177
+ void setPreemptedCheck (const std::atomic<bool >* preempt_requested);
178
+ // / is the stage preempted ? defaults to false
179
+ bool preempted () const ;
180
+
162
181
protected:
163
182
StagePrivate& operator =(StagePrivate&& other);
164
183
@@ -197,6 +216,8 @@ class StagePrivate
197
216
InterfaceWeakPtr next_starts_; // interface to be used for sendForward()
198
217
199
218
Introspection* introspection_; // task's introspection instance
219
+
220
+ std::atomic<bool > const * preempt_requested_;
200
221
};
201
222
PIMPL_FUNCTIONS (Stage)
202
223
std::ostream& operator <<(std::ostream& os, const StagePrivate& stage);
0 commit comments