21 #include "exec_thread.h"
36 :
Thread(
"SkillerSimulatorExecutionThread",
Thread::OPMODE_WAITFORWAKEUP),
45 skill_starttime_ =
Time();
51 bool skill_enqueued =
false;
52 bool write_interface =
false;
59 "%s is new exclusive controller (ID %u)",
63 write_interface =
true;
68 write_interface =
true;
72 "%s tried to acquire exclusive control, but another controller exists already",
82 "%s tried to release exclusive control, but it's not the controller",
92 "More than one skill string enqueued, ignoring previous string (%s).",
97 if (sender ==
"Unknown") {
101 "%s executed '%s' without any exclusive controller",
108 if (skiller_if_->
status() == SkillerInterface::S_RUNNING) {
110 "Aborting execution of previous skill string '%s' for new goal",
116 skiller_if_->
set_status(SkillerInterface::S_RUNNING);
117 current_skill_runtime_ = get_skill_runtime(m->
skill_string());
119 "Executing '%s', will take %.2f seconds",
121 current_skill_runtime_);
122 skill_starttime_ =
Time();
123 write_interface =
true;
124 skill_enqueued =
true;
130 "Stopping execution of '%s' on request",
135 skiller_if_->
set_status(SkillerInterface::S_INACTIVE);
138 if (sender ==
"Unknown") {
141 logger->
log_debug(
name(),
"%s sent stop without any exclusive controller", sender.c_str());
149 if (!skill_enqueued) {
150 if (skiller_if_->
status() == SkillerInterface::S_RUNNING) {
152 if (
Time() > skill_starttime_ + current_skill_runtime_) {
154 auto [exec_status, error] = execute_skill(skiller_if_->
skill_string());
158 write_interface =
true;
163 if (write_interface) {
164 skiller_if_->
write();
175 SkillerSimulatorExecutionThread::get_skill_runtime(
const std::string &skill)
const
178 return provider->get_execution_time(skill);
181 std::pair<fawkes::SkillerInterface::SkillStatusEnum, std::string>
182 SkillerSimulatorExecutionThread::execute_skill(
const std::string &skill)
185 return provider->execute(skill);
virtual void finalize()
Finalize the thread.
virtual void init()
Initialize the thread.
SkillerSimulatorExecutionThread()
Constructor.
virtual void loop()
Code to execute in the thread.
BlackBoard * blackboard
This is the BlackBoard instance you can use to interact with the BlackBoard.
virtual Interface * open_for_writing(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for writing.
virtual void close(Interface *interface)=0
Close interface.
Thread aspect to use blocked timing.
std::shared_ptr< ExecutionTimeEstimator > get_provider(const std::string &skill_string) const
Get the execution time provider for the given skill string.
ExecutionTimeEstimatorManager * execution_time_estimator_manager_
The ExecutionTimeEstimatorManager that is used to manage the estimators.
bool msgq_first_is()
Check if first message has desired type.
void msgq_pop()
Erase first message from queue.
Message * msgq_first()
Get the first message from the message queue.
void write()
Write from local copy into BlackBoard memory.
bool msgq_empty()
Check if queue is empty.
virtual void log_debug(const char *component, const char *format,...)=0
Log debug message.
virtual void log_warn(const char *component, const char *format,...)=0
Log warning message.
virtual void log_info(const char *component, const char *format,...)=0
Log informational message.
Logger * logger
This is the Logger member used to access the logger.
unsigned int sender_id() const
Get ID of sender.
const char * sender_thread_name() const
Get sender of message.
unsigned int id() const
Get message ID.
AcquireControlMessage Fawkes BlackBoard Interface Message.
bool is_steal_control() const
Get steal_control value.
ExecSkillMessage Fawkes BlackBoard Interface Message.
char * skill_string() const
Get skill_string value.
ReleaseControlMessage Fawkes BlackBoard Interface Message.
StopExecMessage Fawkes BlackBoard Interface Message.
SkillerInterface Fawkes BlackBoard Interface.
void set_skill_string(const char *new_skill_string)
Set skill_string value.
uint32_t exclusive_controller() const
Get exclusive_controller value.
void set_error(const char *new_error)
Set error value.
void set_exclusive_controller(const uint32_t new_exclusive_controller)
Set exclusive_controller value.
SkillStatusEnum status() const
Get status value.
void set_msgid(const uint32_t new_msgid)
Set msgid value.
void set_status(const SkillStatusEnum new_status)
Set status value.
char * skill_string() const
Get skill_string value.
Thread class encapsulation of pthreads.
const char * name() const
Get name of thread.
A class for handling time.
Fawkes library namespace.