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;
60 "%s is new exclusive controller (ID %s)",
62 new_controller.c_str());
65 write_interface =
true;
69 "%s steals exclusive control (ID %s)",
71 new_controller.c_str());
74 write_interface =
true;
78 "%s tried to acquire exclusive control, but another controller exists already",
88 "%s tried to release exclusive control, but it's not the controller",
98 "More than one skill string enqueued, ignoring previous string (%s).",
103 if (sender ==
"Unknown") {
107 "%s executed '%s' without any exclusive controller",
114 if (skiller_if_->
status() == SkillerInterface::S_RUNNING) {
116 "Aborting execution of previous skill string '%s' for new goal",
122 skiller_if_->
set_status(SkillerInterface::S_RUNNING);
123 current_skill_runtime_ = get_skill_runtime(m->
skill_string());
125 "Executing '%s', will take %.2f seconds",
127 current_skill_runtime_);
128 skill_starttime_ =
Time();
129 write_interface =
true;
130 skill_enqueued =
true;
136 "Stopping execution of '%s' on request",
141 skiller_if_->
set_status(SkillerInterface::S_INACTIVE);
144 if (sender ==
"Unknown") {
147 logger->
log_debug(
name(),
"%s sent stop without any exclusive controller", sender.c_str());
155 if (!skill_enqueued) {
156 if (skiller_if_->
status() == SkillerInterface::S_RUNNING) {
158 if (
Time() > skill_starttime_ + current_skill_runtime_) {
160 auto [exec_status, error] = execute_skill(skiller_if_->
skill_string());
164 write_interface =
true;
169 if (write_interface) {
170 skiller_if_->
write();
181 SkillerSimulatorExecutionThread::get_skill_runtime(
const std::string &skill)
const
184 return provider->get_execution_time(skill);
187 std::pair<fawkes::SkillerInterface::SkillStatusEnum, std::string>
188 SkillerSimulatorExecutionThread::execute_skill(
const std::string &skill)
191 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.
Uuid source_id() const
Get ID of the original source of the message.
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.
void set_error(const char *new_error)
Set error 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.
void set_exclusive_controller(const char *new_exclusive_controller)
Set exclusive_controller value.
char * skill_string() const
Get skill_string value.
char * exclusive_controller() const
Get exclusive_controller value.
Thread class encapsulation of pthreads.
const char * name() const
Get name of thread.
A class for handling time.
std::string get_string() const
Get the string representation of the Uuid.
Fawkes library namespace.