24 using boost::property_tree::ptree;
29 : m_state(
TaskState::Waiting), m_start_time(), m_running_time(0), m_tries(0), m_node_ip(
"Unknown"), m_node_port(0)
46 &&
"The task has finished or failed, so changing the state wouldn't make sense.");
48 if (m_state != state) {
50 assert(m_start_time.isValid() &&
"The start time should be valid.");
51 int secs = m_start_time.secsTo(QDateTime::currentDateTime());
52 assert(secs >= 0 &&
"The start time can't be later than the current time.");
53 m_running_time += secs;
54 m_start_time = QDateTime();
57 assert(!m_start_time.isValid()
58 &&
"The start time shouldn't have been set when the task wasn't running.");
59 m_start_time = QDateTime::currentDateTime();
69 assert(m_start_time.isValid() &&
"The start time should be valid.");
70 int secs = m_start_time.secsTo(QDateTime::currentDateTime());
71 assert(secs >= 0 &&
"The start time can't be later than the current time.");
72 return m_running_time + secs;
74 return m_running_time;
83 void ExplorationTask::ReadPtree(
const boost::property_tree::ptree& pt)
85 m_state =
static_cast<TaskState>(pt.get<
int>(
"state"));
86 if (pt.find(
"start_time") != pt.not_found()) {
87 m_start_time = QDateTime::fromString(QString::fromStdString(pt.get<std::string>(
"start_time")));
89 m_start_time = QDateTime();
91 m_running_time = pt.get<
unsigned int>(
"running_time");
92 m_tries = pt.get<
unsigned int>(
"tries");
94 m_node_ip = pt.get<std::string>(
"node_ip");
95 m_node_port = pt.get<
int>(
"node_port");
101 pt.put(
"state", static_cast<int>(m_state));
102 if (m_start_time.isValid()) {
103 pt.put(
"start_time", m_start_time.toString().toStdString());
105 pt.put(
"running_time", m_running_time);
106 pt.put(
"tries", m_tries);
108 pt.put(
"node_ip", m_node_ip);
109 pt.put(
"node_port", m_node_port);
virtual ~ExplorationTask()
Destructor.
TaskState
Enumeration describing the state of a single task of the exploration.
void IncrementTries()
Increment the tries of running the task.
The task is waiting to be sent for the first time.
boost::property_tree::ptree ToPtree() const
Convert the task to a ptree.
Interface for ExplorationTask.
The task is being executed.
unsigned int GetRunningTime() const
Returns the time the task has run.
ExplorationTask()
Constructs a task in 'Waiting' state.
void ChangeState(const TaskState &state)
Change the state of the task.
Namespace for SimPT parameter explorer package.
The task was cancelled or stopped.