src: cleaned up code of Tasks and IndexerCommands
This commit is contained in:
@@ -529,8 +529,8 @@ add_files(
|
||||
utility/scheduling/TaskDecoratorRepeat.h
|
||||
utility/scheduling/TaskDecoratorDelay.cpp
|
||||
utility/scheduling/TaskDecoratorDelay.h
|
||||
utility/scheduling/TaskFindValue.cpp
|
||||
utility/scheduling/TaskFindValue.h
|
||||
utility/scheduling/TaskFindKeyOnBlackboard.cpp
|
||||
utility/scheduling/TaskFindKeyOnBlackboard.h
|
||||
utility/scheduling/TaskGroup.cpp
|
||||
utility/scheduling/TaskGroup.h
|
||||
utility/scheduling/TaskGroupParallel.cpp
|
||||
@@ -541,7 +541,7 @@ add_files(
|
||||
utility/scheduling/TaskGroupSequence.h
|
||||
utility/scheduling/TaskLambda.cpp
|
||||
utility/scheduling/TaskLambda.h
|
||||
utility/scheduling/TaskReturnSuccessWhile.h
|
||||
utility/scheduling/TaskReturnSuccessIf.h
|
||||
utility/scheduling/TaskRunner.cpp
|
||||
utility/scheduling/TaskRunner.h
|
||||
utility/scheduling/TaskScheduler.cpp
|
||||
|
||||
@@ -12,20 +12,13 @@ class Indexer
|
||||
: public IndexerBase
|
||||
{
|
||||
public:
|
||||
virtual ~Indexer();
|
||||
IndexerCommandType getSupportedIndexerCommandType() const override;
|
||||
|
||||
virtual IndexerCommandType getSupportedIndexerCommandType() const;
|
||||
|
||||
virtual std::shared_ptr<IntermediateStorage> index(std::shared_ptr<IndexerCommand> indexerCommand);
|
||||
std::shared_ptr<IntermediateStorage> index(std::shared_ptr<IndexerCommand> indexerCommand) override;
|
||||
|
||||
virtual std::shared_ptr<IntermediateStorage> doIndex(std::shared_ptr<T> indexerCommand) = 0;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
Indexer<T>::~Indexer()
|
||||
{
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
IndexerCommandType Indexer<T>::getSupportedIndexerCommandType() const
|
||||
{
|
||||
|
||||
@@ -29,13 +29,13 @@ public:
|
||||
);
|
||||
|
||||
protected:
|
||||
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);
|
||||
virtual void terminate();
|
||||
void doEnter(std::shared_ptr<Blackboard> blackboard) override;
|
||||
TaskState doUpdate(std::shared_ptr<Blackboard> blackboard) override;
|
||||
void doExit(std::shared_ptr<Blackboard> blackboard) override;
|
||||
void doReset(std::shared_ptr<Blackboard> blackboard) override;
|
||||
void terminate() override;
|
||||
|
||||
virtual void handleMessage(MessageInterruptTasks* message);
|
||||
void handleMessage(MessageInterruptTasks* message) override;
|
||||
|
||||
void runIndexerProcess(int processId, const std::wstring& logFilePath);
|
||||
void runIndexerThread(int processId);
|
||||
|
||||
@@ -23,12 +23,12 @@ public:
|
||||
);
|
||||
|
||||
protected:
|
||||
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);
|
||||
void doEnter(std::shared_ptr<Blackboard> blackboard) override;
|
||||
TaskState doUpdate(std::shared_ptr<Blackboard> blackboard) override;
|
||||
void doExit(std::shared_ptr<Blackboard> blackboard) override;
|
||||
void doReset(std::shared_ptr<Blackboard> blackboard) override;
|
||||
|
||||
virtual void handleMessage(MessageInterruptTasks* message);
|
||||
void handleMessage(MessageInterruptTasks* message) override;
|
||||
|
||||
void fillCommandQueue();
|
||||
|
||||
|
||||
@@ -19,10 +19,10 @@ public:
|
||||
TaskParseWrapper(std::weak_ptr<PersistentStorage> storage, std::shared_ptr<DialogView> dialogView);
|
||||
|
||||
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);
|
||||
void doEnter(std::shared_ptr<Blackboard> blackboard) override;
|
||||
TaskState doUpdate(std::shared_ptr<Blackboard> blackboard) override;
|
||||
void doExit(std::shared_ptr<Blackboard> blackboard) override;
|
||||
void doReset(std::shared_ptr<Blackboard> blackboard) override;
|
||||
|
||||
std::weak_ptr<PersistentStorage> m_storage;
|
||||
std::shared_ptr<DialogView> m_dialogView;
|
||||
|
||||
+10
-10
@@ -29,12 +29,12 @@
|
||||
#include "utility/messaging/type/MessageRefresh.h"
|
||||
#include "utility/messaging/type/MessageStatus.h"
|
||||
#include "utility/scheduling/TaskDecoratorRepeat.h"
|
||||
#include "utility/scheduling/TaskFindValue.h"
|
||||
#include "utility/scheduling/TaskFindKeyOnBlackboard.h"
|
||||
#include "utility/scheduling/TaskGroupSelector.h"
|
||||
#include "utility/scheduling/TaskGroupSequence.h"
|
||||
#include "utility/scheduling/TaskGroupParallel.h"
|
||||
#include "utility/scheduling/TaskLambda.h"
|
||||
#include "utility/scheduling/TaskReturnSuccessWhile.h"
|
||||
#include "utility/scheduling/TaskReturnSuccessIf.h"
|
||||
#include "utility/scheduling/TaskSetValue.h"
|
||||
#include "utility/ScopedFunctor.h"
|
||||
#include "utility/text/TextAccess.h"
|
||||
@@ -488,7 +488,7 @@ void Project::buildIndex(const RefreshInfo& info, std::shared_ptr<DialogView> di
|
||||
std::make_shared<TaskGroupSequence>()->addChildTasks(
|
||||
// block until there are indexer commands to process
|
||||
std::make_shared<TaskDecoratorRepeat>(TaskDecoratorRepeat::CONDITION_WHILE_SUCCESS, Task::STATE_SUCCESS)->addChildTask(
|
||||
std::make_shared<TaskReturnSuccessWhile<bool>>("indexer_command_queue_started", TaskReturnSuccessWhile<bool>::CONDITION_EQUALS, false)
|
||||
std::make_shared<TaskReturnSuccessIf<bool>>("indexer_command_queue_started", TaskReturnSuccessIf<bool>::CONDITION_EQUALS, false)
|
||||
),
|
||||
std::make_shared<TaskDecoratorRepeat>(TaskDecoratorRepeat::CONDITION_WHILE_SUCCESS, Task::STATE_SUCCESS)->addChildTask(
|
||||
std::make_shared<TaskBuildIndex>(indexerThreadCount, storageProvider, dialogView, m_appUUID, multiProcess)
|
||||
@@ -507,13 +507,13 @@ void Project::buildIndex(const RefreshInfo& info, std::shared_ptr<DialogView> di
|
||||
std::make_shared<TaskGroupSequence>()->addChildTasks(
|
||||
// block until there are indexers running
|
||||
std::make_shared<TaskDecoratorRepeat>(TaskDecoratorRepeat::CONDITION_WHILE_SUCCESS, Task::STATE_SUCCESS)->addChildTask(
|
||||
std::make_shared<TaskReturnSuccessWhile<int>>("indexer_count", TaskReturnSuccessWhile<int>::CONDITION_EQUALS, 0)
|
||||
std::make_shared<TaskReturnSuccessIf<int>>("indexer_count", TaskReturnSuccessIf<int>::CONDITION_EQUALS, 0)
|
||||
),
|
||||
// merge until all indexers stopped and nothing left to merge
|
||||
std::make_shared<TaskDecoratorRepeat>(TaskDecoratorRepeat::CONDITION_WHILE_SUCCESS, Task::STATE_SUCCESS)->addChildTask(
|
||||
std::make_shared<TaskGroupSelector>()->addChildTasks(
|
||||
std::make_shared<TaskMergeStorages>(storageProvider),
|
||||
std::make_shared<TaskReturnSuccessWhile<int>>("indexer_count", TaskReturnSuccessWhile<int>::CONDITION_GREATER_THAN, 0)
|
||||
std::make_shared<TaskReturnSuccessIf<int>>("indexer_count", TaskReturnSuccessIf<int>::CONDITION_GREATER_THAN, 0)
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -524,16 +524,16 @@ void Project::buildIndex(const RefreshInfo& info, std::shared_ptr<DialogView> di
|
||||
std::make_shared<TaskGroupSequence>()->addChildTasks(
|
||||
// block until there are indexers running
|
||||
std::make_shared<TaskDecoratorRepeat>(TaskDecoratorRepeat::CONDITION_WHILE_SUCCESS, Task::STATE_SUCCESS)->addChildTask(
|
||||
std::make_shared<TaskReturnSuccessWhile<int>>("indexer_count", TaskReturnSuccessWhile<int>::CONDITION_EQUALS, 0)
|
||||
std::make_shared<TaskReturnSuccessIf<int>>("indexer_count", TaskReturnSuccessIf<int>::CONDITION_EQUALS, 0)
|
||||
),
|
||||
std::make_shared<TaskDecoratorRepeat>(TaskDecoratorRepeat::CONDITION_WHILE_SUCCESS, Task::STATE_SUCCESS)->addChildTask(
|
||||
std::make_shared<TaskGroupSequence>()->addChildTasks(
|
||||
// stopping when indexer count is zero, regardless wether there are still storages left to insert.
|
||||
std::make_shared<TaskReturnSuccessWhile<int>>("indexer_count", TaskReturnSuccessWhile<int>::CONDITION_GREATER_THAN, 0),
|
||||
std::make_shared<TaskReturnSuccessIf<int>>("indexer_count", TaskReturnSuccessIf<int>::CONDITION_GREATER_THAN, 0),
|
||||
std::make_shared<TaskGroupSelector>()->addChildTasks(
|
||||
std::make_shared<TaskInjectStorage>(storageProvider, tempStorage),
|
||||
// continuing when indexer count is greater than zero, even if there are no storages right now.
|
||||
std::make_shared<TaskReturnSuccessWhile<int>>("indexer_count", TaskReturnSuccessWhile<int>::CONDITION_GREATER_THAN, 0)
|
||||
std::make_shared<TaskReturnSuccessIf<int>>("indexer_count", TaskReturnSuccessIf<int>::CONDITION_GREATER_THAN, 0)
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -563,7 +563,7 @@ void Project::buildIndex(const RefreshInfo& info, std::shared_ptr<DialogView> di
|
||||
|
||||
taskSequential->addTask(std::make_shared<TaskGroupSelector>()->addChildTasks(
|
||||
std::make_shared<TaskGroupSequence>()->addChildTasks(
|
||||
std::make_shared<TaskFindValue>("keep_database"),
|
||||
std::make_shared<TaskFindKeyOnBlackboard>("keep_database"),
|
||||
std::make_shared<TaskLambda>([dialogView, this]() {
|
||||
Task::dispatch(std::make_shared<TaskLambda>([dialogView, this]() {
|
||||
swapToTempStorage(dialogView);
|
||||
@@ -571,7 +571,7 @@ void Project::buildIndex(const RefreshInfo& info, std::shared_ptr<DialogView> di
|
||||
})
|
||||
),
|
||||
std::make_shared<TaskGroupSequence>()->addChildTasks(
|
||||
std::make_shared<TaskFindValue>("discard_database"),
|
||||
std::make_shared<TaskFindKeyOnBlackboard>("discard_database"),
|
||||
std::make_shared<TaskLambda>([this]() {
|
||||
Task::dispatch(std::make_shared<TaskLambda>([this]() {
|
||||
discardTempStorage();
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
#include "utility/scheduling/TaskFindKeyOnBlackboard.h"
|
||||
|
||||
#include "utility/scheduling/Blackboard.h"
|
||||
|
||||
TaskFindKeyOnBlackboard::TaskFindKeyOnBlackboard(const std::string& key)
|
||||
: m_key(key)
|
||||
{
|
||||
}
|
||||
|
||||
void TaskFindKeyOnBlackboard::doEnter(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
}
|
||||
|
||||
Task::TaskState TaskFindKeyOnBlackboard::doUpdate(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
return (blackboard->exists(m_key)) ? STATE_SUCCESS : STATE_FAILURE;
|
||||
}
|
||||
|
||||
void TaskFindKeyOnBlackboard::doExit(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
}
|
||||
|
||||
void TaskFindKeyOnBlackboard::doReset(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
}
|
||||
+6
-6
@@ -1,5 +1,5 @@
|
||||
#ifndef TASK_FIND_VALUE_H
|
||||
#define TASK_FIND_VALUE_H
|
||||
#ifndef TASK_FIND_KEY_ON_BLACKBOARD_H
|
||||
#define TASK_FIND_KEY_ON_BLACKBOARD_H
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
|
||||
class Blackboard;
|
||||
|
||||
class TaskFindValue:
|
||||
class TaskFindKeyOnBlackboard:
|
||||
public Task
|
||||
{
|
||||
public:
|
||||
TaskFindValue(const std::string& valueName);
|
||||
TaskFindKeyOnBlackboard(const std::string& valueName);
|
||||
|
||||
private:
|
||||
void doEnter(std::shared_ptr<Blackboard> blackboard) override;
|
||||
@@ -19,7 +19,7 @@ private:
|
||||
void doExit(std::shared_ptr<Blackboard> blackboard) override;
|
||||
void doReset(std::shared_ptr<Blackboard> blackboard) override;
|
||||
|
||||
const std::string m_valueName;
|
||||
const std::string m_key;
|
||||
};
|
||||
|
||||
#endif // TASK_FIND_VALUE_H
|
||||
#endif // TASK_FIND_KEY_ON_BLACKBOARD_H
|
||||
@@ -1,25 +0,0 @@
|
||||
#include "utility/scheduling/TaskFindValue.h"
|
||||
|
||||
#include "utility/scheduling/Blackboard.h"
|
||||
|
||||
TaskFindValue::TaskFindValue(const std::string& valueName)
|
||||
: m_valueName(valueName)
|
||||
{
|
||||
}
|
||||
|
||||
void TaskFindValue::doEnter(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
}
|
||||
|
||||
Task::TaskState TaskFindValue::doUpdate(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
return (blackboard->exists(m_valueName)) ? STATE_SUCCESS : STATE_FAILURE;
|
||||
}
|
||||
|
||||
void TaskFindValue::doExit(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
}
|
||||
|
||||
void TaskFindValue::doReset(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
}
|
||||
@@ -11,10 +11,6 @@ TaskGroupParallel::TaskGroupParallel()
|
||||
{
|
||||
}
|
||||
|
||||
TaskGroupParallel::~TaskGroupParallel()
|
||||
{
|
||||
}
|
||||
|
||||
void TaskGroupParallel::addTask(std::shared_ptr<Task> task)
|
||||
{
|
||||
m_tasks.push_back(std::make_shared<TaskInfo>(std::make_shared<TaskRunner>(task)));
|
||||
|
||||
@@ -13,7 +13,6 @@ class TaskGroupParallel
|
||||
{
|
||||
public:
|
||||
TaskGroupParallel();
|
||||
virtual ~TaskGroupParallel();
|
||||
|
||||
void addTask(std::shared_ptr<Task> task) override;
|
||||
|
||||
|
||||
+10
-10
@@ -1,11 +1,11 @@
|
||||
#ifndef TASK_RETURN_SUCCESS_WHILE_H
|
||||
#define TASK_RETURN_SUCCESS_WHILE_H
|
||||
#ifndef TASK_RETURN_SUCCESS_IF_H
|
||||
#define TASK_RETURN_SUCCESS_IF_H
|
||||
|
||||
#include "utility/scheduling/Task.h"
|
||||
#include "utility/scheduling/Blackboard.h"
|
||||
|
||||
template <typename T>
|
||||
class TaskReturnSuccessWhile:
|
||||
class TaskReturnSuccessIf:
|
||||
public Task
|
||||
{
|
||||
public:
|
||||
@@ -15,7 +15,7 @@ public:
|
||||
CONDITION_EQUALS
|
||||
};
|
||||
|
||||
TaskReturnSuccessWhile(const std::string& lhsValueName, ConditionType condition, T rhsValue);
|
||||
TaskReturnSuccessIf(const std::string& lhsValueName, ConditionType condition, T rhsValue);
|
||||
|
||||
private:
|
||||
void doEnter(std::shared_ptr<Blackboard> blackboard) override;
|
||||
@@ -29,7 +29,7 @@ private:
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
TaskReturnSuccessWhile<T>::TaskReturnSuccessWhile(const std::string& lhsValueName, ConditionType condition, T rhsValue)
|
||||
TaskReturnSuccessIf<T>::TaskReturnSuccessIf(const std::string& lhsValueName, ConditionType condition, T rhsValue)
|
||||
: m_lhsValueName(lhsValueName)
|
||||
, m_condition(condition)
|
||||
, m_rhsValue(rhsValue)
|
||||
@@ -37,12 +37,12 @@ TaskReturnSuccessWhile<T>::TaskReturnSuccessWhile(const std::string& lhsValueNam
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void TaskReturnSuccessWhile<T>::doEnter(std::shared_ptr<Blackboard> blackboard)
|
||||
void TaskReturnSuccessIf<T>::doEnter(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Task::TaskState TaskReturnSuccessWhile<T>::doUpdate(std::shared_ptr<Blackboard> blackboard)
|
||||
Task::TaskState TaskReturnSuccessIf<T>::doUpdate(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
const int SLEEP_TIME_MS = 25;
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(SLEEP_TIME_MS));
|
||||
@@ -69,13 +69,13 @@ Task::TaskState TaskReturnSuccessWhile<T>::doUpdate(std::shared_ptr<Blackboard>
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void TaskReturnSuccessWhile<T>::doExit(std::shared_ptr<Blackboard> blackboard)
|
||||
void TaskReturnSuccessIf<T>::doExit(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void TaskReturnSuccessWhile<T>::doReset(std::shared_ptr<Blackboard> blackboard)
|
||||
void TaskReturnSuccessIf<T>::doReset(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
}
|
||||
|
||||
#endif // TASK_RETURN_SUCCESS_WHILE_H
|
||||
#endif // TASK_RETURN_SUCCESS_IF_H
|
||||
@@ -26,8 +26,8 @@ public:
|
||||
const std::vector<FilePath>& frameworkSearchPaths,
|
||||
const std::vector<std::wstring>& compilerFlags);
|
||||
|
||||
virtual IndexerCommandType getIndexerCommandType() const override;
|
||||
virtual size_t getByteSize(size_t stringSize) const override;
|
||||
IndexerCommandType getIndexerCommandType() const override;
|
||||
size_t getByteSize(size_t stringSize) const override;
|
||||
|
||||
const std::set<FilePath>& getIndexedPaths() const;
|
||||
const std::set<FilePathFilter>& getExcludeFilters() const;
|
||||
|
||||
@@ -9,8 +9,7 @@
|
||||
class IndexerCxx: public Indexer<IndexerCommandCxx>
|
||||
{
|
||||
public:
|
||||
virtual ~IndexerCxx() = default;
|
||||
virtual std::shared_ptr<IntermediateStorage> doIndex(std::shared_ptr<IndexerCommandCxx> indexerCommand);
|
||||
std::shared_ptr<IntermediateStorage> doIndex(std::shared_ptr<IndexerCommandCxx> indexerCommand) override;
|
||||
};
|
||||
|
||||
#endif // INDEXER_CXX_H
|
||||
|
||||
@@ -19,8 +19,8 @@ public:
|
||||
const std::wstring& languageStandard,
|
||||
const std::vector<FilePath>& classPath);
|
||||
|
||||
virtual IndexerCommandType getIndexerCommandType() const override;
|
||||
virtual size_t getByteSize(size_t stringSize) const override;
|
||||
IndexerCommandType getIndexerCommandType() const override;
|
||||
size_t getByteSize(size_t stringSize) const override;
|
||||
|
||||
std::wstring getLanguageStandard() const;
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ class IndexerJava: public Indexer<IndexerCommandJava>
|
||||
{
|
||||
public:
|
||||
virtual ~IndexerJava();
|
||||
virtual std::shared_ptr<IntermediateStorage> doIndex(std::shared_ptr<IndexerCommandJava> indexerCommand);
|
||||
std::shared_ptr<IntermediateStorage> doIndex(std::shared_ptr<IndexerCommandJava> indexerCommand) override;
|
||||
};
|
||||
|
||||
#endif // INDEXER_JAVA_H
|
||||
|
||||
Reference in New Issue
Block a user