ui: split steps of indexing files and saving the last few batches of data

* implemented showing dialog for database injection
* implemented easy-to-read way of creating behavior tree structures
* moved injector wait logic out of injection task
This commit is contained in:
malte_langkabel
2016-11-11 15:40:28 +01:00
parent 65eca50be4
commit fb72f73567
20 changed files with 431 additions and 108 deletions
@@ -7,3 +7,9 @@ TaskDecorator::TaskDecorator()
TaskDecorator::~TaskDecorator()
{
}
std::shared_ptr<TaskDecorator> TaskDecorator::addChildTask(std::shared_ptr<Task> child)
{
setTask(child);
return shared_from_this();
}
@@ -7,10 +7,12 @@
class TaskDecorator
: public Task
, public std::enable_shared_from_this<TaskDecorator>
{
public:
TaskDecorator();
virtual ~TaskDecorator();
std::shared_ptr<TaskDecorator> addChildTask(std::shared_ptr<Task> child);
virtual void setTask(std::shared_ptr<Task> task) = 0;
};
@@ -0,0 +1,50 @@
#include "utility/scheduling/TaskDecoratorRepeat.h"
TaskDecoratorRepeat::TaskDecoratorRepeat(ConditionType condition, TaskState exitState)
: m_condition(condition)
, m_exitState(exitState)
{
}
void TaskDecoratorRepeat::setTask(std::shared_ptr<Task> task)
{
if (task)
{
m_taskRunner = std::make_shared<TaskRunner>(task);
}
}
void TaskDecoratorRepeat::doEnter(std::shared_ptr<Blackboard> blackboard)
{
}
Task::TaskState TaskDecoratorRepeat::doUpdate(std::shared_ptr<Blackboard> blackboard)
{
TaskState state = m_taskRunner->update(blackboard);
switch (m_condition)
{
case CONDITION_WHILE_SUCCESS:
if (state == Task::STATE_SUCCESS)
{
m_taskRunner->reset();
state = Task::STATE_RUNNING;
}
else if (state == Task::STATE_FAILURE)
{
state = m_exitState;
}
break;
}
return state;
}
void TaskDecoratorRepeat::doExit(std::shared_ptr<Blackboard> blackboard)
{
}
void TaskDecoratorRepeat::doReset(std::shared_ptr<Blackboard> blackboard)
{
m_taskRunner->reset();
}
@@ -1,16 +1,21 @@
#ifndef TASK_REPEAT_WHILE_SUCCESS_H
#define TASK_REPEAT_WHILE_SUCCESS_H
#ifndef TASK_DECORATOR_REPEAT_H
#define TASK_DECORATOR_REPEAT_H
#include <vector>
#include "utility/scheduling/TaskDecorator.h"
#include "utility/scheduling/TaskRunner.h"
class TaskRepeatWhileSuccess
class TaskDecoratorRepeat
: public TaskDecorator
{
public:
TaskRepeatWhileSuccess(TaskState exitState);
enum ConditionType
{
CONDITION_WHILE_SUCCESS
};
TaskDecoratorRepeat(ConditionType condition, TaskState exitState);
virtual void setTask(std::shared_ptr<Task> task);
@@ -21,7 +26,8 @@ private:
virtual void doReset(std::shared_ptr<Blackboard> blackboard);
std::shared_ptr<TaskRunner> m_taskRunner;
const ConditionType m_condition;
const TaskState m_exitState;
};
#endif // TASK_REPEAT_WHILE_SUCCESS_H
#endif // TASK_DECORATOR_REPEAT_H
+21
View File
@@ -7,3 +7,24 @@ TaskGroup::TaskGroup()
TaskGroup::~TaskGroup()
{
}
std::shared_ptr<TaskGroup> TaskGroup::addChildTasks(std::shared_ptr<Task> child1)
{
addTask(child1);
return shared_from_this();
}
std::shared_ptr<TaskGroup> TaskGroup::addChildTasks(std::shared_ptr<Task> child1, std::shared_ptr<Task> child2)
{
addTask(child1);
addTask(child2);
return shared_from_this();
}
std::shared_ptr<TaskGroup> TaskGroup::addChildTasks(std::shared_ptr<Task> child1, std::shared_ptr<Task> child2, std::shared_ptr<Task> child3)
{
addTask(child1);
addTask(child2);
addTask(child3);
return shared_from_this();
}
+6
View File
@@ -8,12 +8,18 @@
class TaskGroup
: public Task
, public std::enable_shared_from_this<TaskGroup>
{
public:
TaskGroup();
virtual ~TaskGroup();
std::shared_ptr<TaskGroup> addChildTasks(std::shared_ptr<Task> child1);
std::shared_ptr<TaskGroup> addChildTasks(std::shared_ptr<Task> child1, std::shared_ptr<Task> child2);
std::shared_ptr<TaskGroup> addChildTasks(std::shared_ptr<Task> child1, std::shared_ptr<Task> child2, std::shared_ptr<Task> child3);
virtual void addTask(std::shared_ptr<Task> task) = 0;
};
#endif // TASK_GROUP_H
@@ -0,0 +1,56 @@
#include "utility/scheduling/TaskGroupSelector.h"
TaskGroupSelector::TaskGroupSelector()
{
}
TaskGroupSelector::~TaskGroupSelector()
{
}
void TaskGroupSelector::addTask(std::shared_ptr<Task> task)
{
m_taskRunners.push_back(std::make_shared<TaskRunner>(task));
}
void TaskGroupSelector::doEnter(std::shared_ptr<Blackboard> blackboard)
{
m_taskIndex = 0;
}
Task::TaskState TaskGroupSelector::doUpdate(std::shared_ptr<Blackboard> blackboard)
{
if (m_taskIndex >= int(m_taskRunners.size()))
{
return STATE_FAILURE;
}
else if (m_taskIndex < 0)
{
return STATE_SUCCESS;
}
TaskState state = m_taskRunners[m_taskIndex]->update(blackboard);
if (state == STATE_FAILURE)
{
m_taskIndex++;
}
else if (state == STATE_SUCCESS)
{
m_taskIndex = -1;
}
return STATE_RUNNING;
}
void TaskGroupSelector::doExit(std::shared_ptr<Blackboard> blackboard)
{
}
void TaskGroupSelector::doReset(std::shared_ptr<Blackboard> blackboard)
{
for (size_t i = 0; i < m_taskRunners.size(); i++)
{
m_taskRunners[i]->reset();
}
}
@@ -1,15 +1,15 @@
#ifndef TASK_GROUP_SEQUENTIAL_H
#define TASK_GROUP_SEQUENTIAL_H
#ifndef TASK_GROUP_SELECTOR_H
#define TASK_GROUP_SELECTOR_H
#include "utility/scheduling/TaskGroup.h"
#include "utility/scheduling/TaskRunner.h"
class TaskGroupSequential
class TaskGroupSelector
: public TaskGroup
{
public:
TaskGroupSequential();
virtual ~TaskGroupSequential();
TaskGroupSelector();
virtual ~TaskGroupSelector();
virtual void addTask(std::shared_ptr<Task> task);
@@ -23,4 +23,4 @@ private:
int m_taskIndex;
};
#endif // TASK_GROUP_SEQUENTIAL_H
#endif // TASK_GROUP_SELECTOR_H
@@ -1,25 +1,24 @@
#include "utility/scheduling/TaskGroupSequential.h"
#include <iostream>
#include "utility/scheduling/TaskGroupSequence.h"
TaskGroupSequential::TaskGroupSequential()
TaskGroupSequence::TaskGroupSequence()
{
}
TaskGroupSequential::~TaskGroupSequential()
TaskGroupSequence::~TaskGroupSequence()
{
}
void TaskGroupSequential::addTask(std::shared_ptr<Task> task)
void TaskGroupSequence::addTask(std::shared_ptr<Task> task)
{
m_taskRunners.push_back(std::make_shared<TaskRunner>(task));
}
void TaskGroupSequential::doEnter(std::shared_ptr<Blackboard> blackboard)
void TaskGroupSequence::doEnter(std::shared_ptr<Blackboard> blackboard)
{
m_taskIndex = 0;
}
Task::TaskState TaskGroupSequential::doUpdate(std::shared_ptr<Blackboard> blackboard)
Task::TaskState TaskGroupSequence::doUpdate(std::shared_ptr<Blackboard> blackboard)
{
if (m_taskIndex >= int(m_taskRunners.size()))
{
@@ -44,11 +43,11 @@ Task::TaskState TaskGroupSequential::doUpdate(std::shared_ptr<Blackboard> blackb
return STATE_RUNNING;
}
void TaskGroupSequential::doExit(std::shared_ptr<Blackboard> blackboard)
void TaskGroupSequence::doExit(std::shared_ptr<Blackboard> blackboard)
{
}
void TaskGroupSequential::doReset(std::shared_ptr<Blackboard> blackboard)
void TaskGroupSequence::doReset(std::shared_ptr<Blackboard> blackboard)
{
for (size_t i = 0; i < m_taskRunners.size(); i++)
{
@@ -0,0 +1,26 @@
#ifndef TASK_GROUP_SEQUENCE_H
#define TASK_GROUP_SEQUENCE_H
#include "utility/scheduling/TaskGroup.h"
#include "utility/scheduling/TaskRunner.h"
class TaskGroupSequence
: public TaskGroup
{
public:
TaskGroupSequence();
virtual ~TaskGroupSequence();
virtual void addTask(std::shared_ptr<Task> task);
private:
virtual void doEnter(std::shared_ptr<Blackboard> blackboard);
virtual TaskState doUpdate(std::shared_ptr<Blackboard> blackboard);
virtual void doExit(std::shared_ptr<Blackboard> blackboard);
virtual void doReset(std::shared_ptr<Blackboard> blackboard);
std::vector<std::shared_ptr<TaskRunner>> m_taskRunners;
int m_taskIndex;
};
#endif // TASK_GROUP_SEQUENCE_H
@@ -1,44 +0,0 @@
#include "utility/scheduling/TaskRepeatWhileSuccess.h"
TaskRepeatWhileSuccess::TaskRepeatWhileSuccess(TaskState exitState)
: m_exitState(exitState)
{
}
void TaskRepeatWhileSuccess::setTask(std::shared_ptr<Task> task)
{
if (task)
{
m_taskRunner = std::make_shared<TaskRunner>(task);
}
}
void TaskRepeatWhileSuccess::doEnter(std::shared_ptr<Blackboard> blackboard)
{
}
Task::TaskState TaskRepeatWhileSuccess::doUpdate(std::shared_ptr<Blackboard> blackboard)
{
TaskState state = m_taskRunner->update(blackboard);
if (state == Task::STATE_SUCCESS)
{
m_taskRunner->reset();
state = Task::STATE_RUNNING;
}
else if (state == Task::STATE_FAILURE)
{
state = m_exitState;
}
return state;
}
void TaskRepeatWhileSuccess::doExit(std::shared_ptr<Blackboard> blackboard)
{
}
void TaskRepeatWhileSuccess::doReset(std::shared_ptr<Blackboard> blackboard)
{
m_taskRunner->reset();
}
@@ -0,0 +1,78 @@
#ifndef TASK_RETURN_SUCCESS_WHILE_H
#define TASK_RETURN_SUCCESS_WHILE_H
#include <vector>
#include "utility/scheduling/Task.h"
#include "utility/scheduling/Blackboard.h"
template <typename T>
class TaskReturnSuccessWhile:
public Task
{
public:
enum ConditionType
{
CONDITION_GREATER_THAN,
CONDITION_EQUALS
};
TaskReturnSuccessWhile(const std::string& lhsValueName, ConditionType condition, T rhsValue);
private:
virtual void doEnter(std::shared_ptr<Blackboard> blackboard);
virtual TaskState doUpdate(std::shared_ptr<Blackboard> blackboard);
virtual void doExit(std::shared_ptr<Blackboard> blackboard);
virtual void doReset(std::shared_ptr<Blackboard> blackboard);
const std::string m_lhsValueName;
const ConditionType m_condition;
const T m_rhsValue;
};
template <typename T>
TaskReturnSuccessWhile<T>::TaskReturnSuccessWhile(const std::string& lhsValueName, ConditionType condition, T rhsValue)
: m_lhsValueName(lhsValueName)
, m_condition(condition)
, m_rhsValue(rhsValue)
{
}
template <typename T>
void TaskReturnSuccessWhile<T>::doEnter(std::shared_ptr<Blackboard> blackboard)
{
}
template <typename T>
Task::TaskState TaskReturnSuccessWhile<T>::doUpdate(std::shared_ptr<Blackboard> blackboard)
{
const int SLEEP_TIME_MS = 25;
std::this_thread::sleep_for(std::chrono::microseconds(SLEEP_TIME_MS));
T lhsValue = 0;
blackboard->get<T>(m_lhsValueName, lhsValue);
switch (m_condition)
{
case CONDITION_GREATER_THAN:
if (lhsValue > m_rhsValue)
{
return STATE_SUCCESS;
}
break;
}
return STATE_FAILURE;
}
template <typename T>
void TaskReturnSuccessWhile<T>::doExit(std::shared_ptr<Blackboard> blackboard)
{
}
template <typename T>
void TaskReturnSuccessWhile<T>::doReset(std::shared_ptr<Blackboard> blackboard)
{
}
#endif // TASK_RETURN_SUCCESS_WHILE_H