Go to the documentation of this file.
61 throw LogicError(
"SyncActionNode MUST never return RUNNING");
97 if(
_p->coro ==
nullptr)
101 _p->desc.user_data =
this;
162 throw LogicError(
"StatefulActionNode::onStart() must not return IDLE");
172 throw LogicError(
"StatefulActionNode::onRunning() must not return IDLE");
191 using lock_type = std::unique_lock<std::mutex>;
197 halt_requested_ =
false;
198 thread_handle_ = std::async(std::launch::async, [
this]() {
201 auto status = tick();
202 if(!isHaltRequested())
207 catch(std::exception&)
209 std::cerr <<
"\nUncaught exception from tick(): [" << registrationName() <<
"/"
214 exptr_ = std::current_exception();
226 const auto exptr_copy = exptr_;
228 std::rethrow_exception(exptr_copy);
MCO_API mco_result mco_yield(mco_coro *co)
bool isHaltRequested() const
virtual NodeStatus executeTick() override final
The method that should be used to invoke tick() and setStatus();.
MCO_API mco_state mco_status(mco_coro *co)
virtual BT::NodeStatus executeTick()
The method that should be used to invoke tick() and setStatus();.
void CoroEntry(mco_coro *co)
MCO_API mco_result mco_create(mco_coro **out_co, mco_desc *desc)
MCO_API mco_result mco_resume(mco_coro *co)
virtual void onHalted()=0
ActionNodeBase(const std::string &name, const NodeConfig &config)
virtual NodeStatus executeTick() override
throws if the derived class return RUNNING.
std::atomic_bool halt_requested_
MCO_API mco_desc mco_desc_init(void(*func)(mco_coro *co), size_t stack_size)
NodeStatus status() const
CoroActionNode(const std::string &name, const NodeConfig &config)
void setStatus(NodeStatus new_status)
setStatus changes the status of the node. it will throw if you try to change the status to IDLE,...
std::future< void > thread_handle_
SyncActionNode(const std::string &name, const NodeConfig &config)
TickFunctor tick_functor_
virtual NodeStatus tick() override final
Method to be implemented by the user.
SimpleActionNode(const std::string &name, TickFunctor tick_functor, const NodeConfig &config)
virtual ~CoroActionNode() override
The ActionNodeBase is the base class to use to create any kind of action. A particular derived class ...
NodeStatus tick() override final
Method to be implemented by the user.
virtual NodeStatus onStart()=0
void setStatusRunningAndYield()
Use this method to return RUNNING and temporary "pause" the Action.
virtual void halt() override
std::unique_ptr< Pimpl > _p
void resetStatus()
Set the status to IDLE.
MCO_API mco_result mco_destroy(mco_coro *co)
std::atomic_bool halt_requested_
virtual NodeStatus executeTick() override final
The method that should be used to invoke tick() and setStatus();.
The SyncActionNode is an ActionNode that explicitly prevents the status RUNNING and doesn't require a...
std::function< NodeStatus(TreeNode &)> TickFunctor
void halt() override final
virtual NodeStatus onRunning()=0
method invoked when the action is already in the RUNNING state.
The CoroActionNode class is an a good candidate for asynchronous actions which need to communicate wi...