feat: ActionHandler pause/resume + kCancelled status + ABI version guard
- ActionStatus::kCancelled (new, string "CANCELLED"): the missing "stopped on request" terminal status — previously a cancelled action only had Running/Succeeded/Failed to report through, so move_base2's state machine couldn't tell a cancelled action from a failed one. - ActionHandler::cancelNeedsTicks() (default false), pause(now) and resume(now) (default no-ops): lets a handler opt into "I need more ticks to actually stop" (device handshake) instead of being torn down immediately, and gives handlers a real pause/resume contract instead of move_base2 having to freeze/unfreeze them from outside. - action_abi.h (new) + ACTION_CORE_EXPORT_HANDLER macro, same pattern as recovery_core commit 254c7fc: exports a version symbol next to the factory alias; action_registry.cpp refuses a handler .so whose version doesn't match instead of dlsym+reinterpret_cast blindly onto a grown vtable. - frame_sampler / wait / noop handlers implement pause/resume via paused_at_ / started_at_ += (now - paused_at_) so their own internal timers don't count paused time; paused_ is reset on start() so a reused handler instance can't come up already paused. - test/plugins/stale_abi_action_handler.cpp (new) for the registry refusal test. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/dll/alias.hpp>
|
||||
#include <action_core/action_abi.h>
|
||||
#include <robot/robot.h>
|
||||
|
||||
namespace action_core
|
||||
@@ -113,6 +113,7 @@ public:
|
||||
bool start(const robot_protocol_msgs::Action& action, const robot::Time& now) override
|
||||
{
|
||||
started_at_ = now;
|
||||
paused_ = false;
|
||||
action_id_ = action.actionId;
|
||||
|
||||
robot::log_info("[action_core] '%s': starting action '%s' (id '%s'), duration %.3f s.",
|
||||
@@ -154,6 +155,27 @@ public:
|
||||
return tick;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tạm dừng: ghi mốc để resume() dịch started_at_ — quãng đứng không tính vào duration/timeout.
|
||||
*/
|
||||
void pause(const robot::Time& now) override
|
||||
{
|
||||
if (!paused_)
|
||||
{
|
||||
paused_ = true;
|
||||
paused_at_ = now;
|
||||
}
|
||||
}
|
||||
|
||||
void resume(const robot::Time& now) override
|
||||
{
|
||||
if (paused_)
|
||||
{
|
||||
started_at_ += (now - paused_at_);
|
||||
paused_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
void cancel() override
|
||||
{
|
||||
// Không có thiết bị nào để đưa về trạng thái an toàn. Handler thật phải làm việc đó ở đây.
|
||||
@@ -169,9 +191,11 @@ private:
|
||||
bool hang_ = false; ///< true = không bao giờ hoàn tất (fault injection)
|
||||
|
||||
robot::Time started_at_;
|
||||
robot::Time paused_at_; ///< Mốc pause() gần nhất; chỉ có nghĩa khi paused_.
|
||||
bool paused_ = false;
|
||||
std::string action_id_;
|
||||
};
|
||||
|
||||
} // namespace action_core
|
||||
|
||||
BOOST_DLL_ALIAS(action_core::NoopActionHandler::create, NoopActionHandler)
|
||||
ACTION_CORE_EXPORT_HANDLER(action_core::NoopActionHandler::create, NoopActionHandler)
|
||||
|
||||
Reference in New Issue
Block a user