logic: improved indexer parallelization
* added task that injects into PersistentStorage parallel to indexer tasks. * added Blackboard for Task classes
This commit is contained in:
@@ -6,8 +6,9 @@
|
|||||||
|
|
||||||
#include "component/view/DialogView.h"
|
#include "component/view/DialogView.h"
|
||||||
#include "data/parser/cxx/CxxParser.h"
|
#include "data/parser/cxx/CxxParser.h"
|
||||||
#include "data/IntermediateStorage.h"
|
#include "data/StorageProvider.h"
|
||||||
#include "utility/file/FileRegister.h"
|
#include "utility/file/FileRegister.h"
|
||||||
|
#include "utility/scheduling/Blackboard.h"
|
||||||
#include "utility/utility.h"
|
#include "utility/utility.h"
|
||||||
|
|
||||||
std::vector<FilePath> TaskParseCxx::getSourceFilesFromCDB(const FilePath& compilationDatabasePath)
|
std::vector<FilePath> TaskParseCxx::getSourceFilesFromCDB(const FilePath& compilationDatabasePath)
|
||||||
@@ -29,12 +30,12 @@ std::vector<FilePath> TaskParseCxx::getSourceFilesFromCDB(const FilePath& compil
|
|||||||
}
|
}
|
||||||
|
|
||||||
TaskParseCxx::TaskParseCxx(
|
TaskParseCxx::TaskParseCxx(
|
||||||
std::shared_ptr<IntermediateStorage> storage,
|
std::shared_ptr<StorageProvider> storageProvider,
|
||||||
std::shared_ptr<FileRegister> fileRegister,
|
std::shared_ptr<FileRegister> fileRegister,
|
||||||
const Parser::Arguments& arguments,
|
const Parser::Arguments& arguments,
|
||||||
DialogView* dialogView
|
DialogView* dialogView
|
||||||
)
|
)
|
||||||
: m_storage(storage)
|
: m_storageProvider(storageProvider)
|
||||||
, m_arguments(arguments)
|
, m_arguments(arguments)
|
||||||
, m_dialogView(dialogView)
|
, m_dialogView(dialogView)
|
||||||
, m_isCDB(false)
|
, m_isCDB(false)
|
||||||
@@ -48,8 +49,15 @@ TaskParseCxx::TaskParseCxx(
|
|||||||
m_parser = std::make_shared<CxxParser>(m_parserClient.get(), fileRegister);
|
m_parser = std::make_shared<CxxParser>(m_parserClient.get(), fileRegister);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskParseCxx::doEnter()
|
void TaskParseCxx::doEnter(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
|
int indexerCount = 0;
|
||||||
|
if (blackboard->get("indexer_count", indexerCount))
|
||||||
|
{
|
||||||
|
indexerCount++;
|
||||||
|
blackboard->set("indexer_count", indexerCount);
|
||||||
|
}
|
||||||
|
|
||||||
if (m_isCDB)
|
if (m_isCDB)
|
||||||
{
|
{
|
||||||
std::string error;
|
std::string error;
|
||||||
@@ -64,20 +72,24 @@ void TaskParseCxx::doEnter()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Task::TaskState TaskParseCxx::doUpdate()
|
Task::TaskState TaskParseCxx::doUpdate(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
FileRegister* fileRegister = m_parser->getFileRegister();
|
FileRegister* fileRegister = m_parser->getFileRegister();
|
||||||
|
|
||||||
FilePath sourcePath = fileRegister->consumeSourceFile();
|
FilePath sourcePath = fileRegister->consumeSourceFile();
|
||||||
|
|
||||||
if (!sourcePath.empty())
|
if (sourcePath.empty())
|
||||||
|
{
|
||||||
|
return STATE_FAILURE;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
m_dialogView->updateIndexingDialog(
|
m_dialogView->updateIndexingDialog(
|
||||||
fileRegister->getParsedSourceFilesCount(), fileRegister->getSourceFilesCount(), sourcePath.str()
|
fileRegister->getParsedSourceFilesCount(), fileRegister->getSourceFilesCount(), sourcePath.str()
|
||||||
);
|
);
|
||||||
|
|
||||||
m_storage->clear();
|
std::shared_ptr<IntermediateStorage> storage = m_storageProvider->popIndexerTarget();
|
||||||
m_parserClient->setStorage(m_storage);
|
m_parserClient->setStorage(storage);
|
||||||
m_parserClient->startParsingFile();
|
m_parserClient->startParsingFile();
|
||||||
|
|
||||||
if (m_isCDB)
|
if (m_isCDB)
|
||||||
@@ -99,17 +111,24 @@ Task::TaskState TaskParseCxx::doUpdate()
|
|||||||
if (!m_interrupted)
|
if (!m_interrupted)
|
||||||
{
|
{
|
||||||
fileRegister->markThreadFilesParsed();
|
fileRegister->markThreadFilesParsed();
|
||||||
|
m_storageProvider->pushIndexerTarget(storage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (m_interrupted ? STATE_FAILURE : STATE_SUCCESS);
|
return (m_interrupted ? STATE_FAILURE : STATE_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskParseCxx::doExit()
|
void TaskParseCxx::doExit(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
|
int indexerCount = 0;
|
||||||
|
if (blackboard->get("indexer_count", indexerCount))
|
||||||
|
{
|
||||||
|
indexerCount--;
|
||||||
|
blackboard->set("indexer_count", indexerCount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskParseCxx::doReset()
|
void TaskParseCxx::doReset(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "data/PersistentStorage.h"
|
#include "data/PersistentStorage.h"
|
||||||
#include "utility/file/FileRegister.h"
|
#include "utility/file/FileRegister.h"
|
||||||
#include "utility/messaging/type/MessageFinishedParsing.h"
|
#include "utility/messaging/type/MessageFinishedParsing.h"
|
||||||
|
#include "utility/scheduling/Blackboard.h"
|
||||||
#include "utility/utility.h"
|
#include "utility/utility.h"
|
||||||
|
|
||||||
TaskParseWrapper::TaskParseWrapper(
|
TaskParseWrapper::TaskParseWrapper(
|
||||||
@@ -29,21 +30,24 @@ void TaskParseWrapper::setTask(std::shared_ptr<Task> task)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskParseWrapper::doEnter()
|
void TaskParseWrapper::doEnter(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
|
blackboard->set("indexer_count", 0);
|
||||||
m_dialogView->updateIndexingDialog(0, m_fileRegister->getSourceFilesCount(), "");
|
m_dialogView->updateIndexingDialog(0, m_fileRegister->getSourceFilesCount(), "");
|
||||||
|
|
||||||
m_start = utility::durationStart();
|
m_start = utility::durationStart();
|
||||||
m_storage->startParsing();
|
m_storage->startParsing();
|
||||||
}
|
}
|
||||||
|
|
||||||
Task::TaskState TaskParseWrapper::doUpdate()
|
Task::TaskState TaskParseWrapper::doUpdate(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
return m_taskRunner->update();
|
return m_taskRunner->update(blackboard);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskParseWrapper::doExit()
|
void TaskParseWrapper::doExit(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
|
blackboard->clear("indexer_count");
|
||||||
|
|
||||||
m_dialogView->showProgressDialog("Finish Indexing", "Optimizing database");
|
m_dialogView->showProgressDialog("Finish Indexing", "Optimizing database");
|
||||||
|
|
||||||
m_storage->optimizeMemory();
|
m_storage->optimizeMemory();
|
||||||
@@ -64,7 +68,7 @@ void TaskParseWrapper::doExit()
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskParseWrapper::doReset()
|
void TaskParseWrapper::doReset(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
m_taskRunner->reset();
|
m_taskRunner->reset();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,19 +3,20 @@
|
|||||||
#include "component/view/DialogView.h"
|
#include "component/view/DialogView.h"
|
||||||
#include "data/parser/java/JavaParser.h"
|
#include "data/parser/java/JavaParser.h"
|
||||||
#include "data/parser/ParserClientImpl.h"
|
#include "data/parser/ParserClientImpl.h"
|
||||||
#include "data/IntermediateStorage.h"
|
#include "data/StorageProvider.h"
|
||||||
#include "utility/file/FileRegister.h"
|
#include "utility/file/FileRegister.h"
|
||||||
#include "utility/messaging/type/MessageFinishedParsing.h"
|
#include "utility/messaging/type/MessageFinishedParsing.h"
|
||||||
|
#include "utility/scheduling/Blackboard.h"
|
||||||
#include "utility/text/TextAccess.h"
|
#include "utility/text/TextAccess.h"
|
||||||
#include "utility/utility.h"
|
#include "utility/utility.h"
|
||||||
|
|
||||||
TaskParseJava::TaskParseJava(
|
TaskParseJava::TaskParseJava(
|
||||||
std::shared_ptr<IntermediateStorage> storage,
|
std::shared_ptr<StorageProvider> storageProvider,
|
||||||
std::shared_ptr<FileRegister> fileRegister,
|
std::shared_ptr<FileRegister> fileRegister,
|
||||||
const Parser::Arguments& arguments,
|
const Parser::Arguments& arguments,
|
||||||
DialogView* dialogView
|
DialogView* dialogView
|
||||||
)
|
)
|
||||||
: m_storage(storage)
|
: m_storageProvider(storageProvider)
|
||||||
, m_fileRegister(fileRegister)
|
, m_fileRegister(fileRegister)
|
||||||
, m_arguments(arguments)
|
, m_arguments(arguments)
|
||||||
, m_dialogView(dialogView)
|
, m_dialogView(dialogView)
|
||||||
@@ -23,25 +24,35 @@ TaskParseJava::TaskParseJava(
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskParseJava::doEnter()
|
void TaskParseJava::doEnter(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
|
int indexerCount = 0;
|
||||||
|
if (blackboard->get("indexer_count", indexerCount))
|
||||||
|
{
|
||||||
|
indexerCount++;
|
||||||
|
blackboard->set("indexer_count", indexerCount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Task::TaskState TaskParseJava::doUpdate()
|
Task::TaskState TaskParseJava::doUpdate(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
std::shared_ptr<ParserClientImpl> parserClient = std::make_shared<ParserClientImpl>();
|
std::shared_ptr<ParserClientImpl> parserClient = std::make_shared<ParserClientImpl>();
|
||||||
std::shared_ptr<JavaParser> parser = std::make_shared<JavaParser>(parserClient.get());
|
std::shared_ptr<JavaParser> parser = std::make_shared<JavaParser>(parserClient.get());
|
||||||
|
|
||||||
FilePath sourcePath = m_fileRegister->consumeSourceFile();
|
FilePath sourcePath = m_fileRegister->consumeSourceFile();
|
||||||
|
|
||||||
if (!sourcePath.empty())
|
if (sourcePath.empty())
|
||||||
|
{
|
||||||
|
return STATE_FAILURE;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
m_dialogView->updateIndexingDialog(
|
m_dialogView->updateIndexingDialog(
|
||||||
m_fileRegister->getParsedSourceFilesCount(), m_fileRegister->getSourceFilesCount(), sourcePath.str()
|
m_fileRegister->getParsedSourceFilesCount(), m_fileRegister->getSourceFilesCount(), sourcePath.str()
|
||||||
);
|
);
|
||||||
|
|
||||||
m_storage->clear();
|
std::shared_ptr<IntermediateStorage> storage = m_storageProvider->popIndexerTarget();
|
||||||
parserClient->setStorage(m_storage);
|
parserClient->setStorage(storage);
|
||||||
parserClient->startParsingFile();
|
parserClient->startParsingFile();
|
||||||
|
|
||||||
parser->parseFile(sourcePath, TextAccess::createFromFile(sourcePath.str()), m_arguments);
|
parser->parseFile(sourcePath, TextAccess::createFromFile(sourcePath.str()), m_arguments);
|
||||||
@@ -49,17 +60,27 @@ Task::TaskState TaskParseJava::doUpdate()
|
|||||||
parserClient->finishParsingFile();
|
parserClient->finishParsingFile();
|
||||||
parserClient->resetStorage();
|
parserClient->resetStorage();
|
||||||
|
|
||||||
m_fileRegister->markThreadFilesParsed(); // todo: rename to markThreadFilesProcessed
|
if (!m_interrupted)
|
||||||
|
{
|
||||||
|
m_fileRegister->markThreadFilesParsed(); // todo: rename to markThreadFilesProcessed
|
||||||
|
m_storageProvider->pushIndexerTarget(storage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (m_interrupted ? STATE_FAILURE : STATE_SUCCESS);
|
return (m_interrupted ? STATE_FAILURE : STATE_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskParseJava::doExit()
|
void TaskParseJava::doExit(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
|
int indexerCount = 0;
|
||||||
|
if (blackboard->get("indexer_count", indexerCount))
|
||||||
|
{
|
||||||
|
indexerCount--;
|
||||||
|
blackboard->set("indexer_count", indexerCount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskParseJava::doReset()
|
void TaskParseJava::doReset(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -188,14 +188,14 @@ add_files(
|
|||||||
data/Storage.h
|
data/Storage.h
|
||||||
data/StorageCache.cpp
|
data/StorageCache.cpp
|
||||||
data/StorageCache.h
|
data/StorageCache.h
|
||||||
|
data/StorageProvider.cpp
|
||||||
|
data/StorageProvider.h
|
||||||
data/StorageTypes.h
|
data/StorageTypes.h
|
||||||
data/StorageStats.h
|
data/StorageStats.h
|
||||||
data/TaskCleanStorage.cpp
|
data/TaskCleanStorage.cpp
|
||||||
data/TaskCleanStorage.h
|
data/TaskCleanStorage.h
|
||||||
data/TaskInjectStorage.cpp
|
data/TaskInjectStorage.cpp
|
||||||
data/TaskInjectStorage.h
|
data/TaskInjectStorage.h
|
||||||
data/TaskRepeatWhileUnparsedSourceFilesAvailable.cpp
|
|
||||||
data/TaskRepeatWhileUnparsedSourceFilesAvailable.h
|
|
||||||
|
|
||||||
settings/ApplicationSettings.cpp
|
settings/ApplicationSettings.cpp
|
||||||
settings/ApplicationSettings.h
|
settings/ApplicationSettings.h
|
||||||
@@ -306,6 +306,8 @@ add_files(
|
|||||||
utility/messaging/MessageQueue.cpp
|
utility/messaging/MessageQueue.cpp
|
||||||
utility/messaging/MessageQueue.h
|
utility/messaging/MessageQueue.h
|
||||||
|
|
||||||
|
utility/scheduling/Blackboard.cpp
|
||||||
|
utility/scheduling/Blackboard.h
|
||||||
utility/scheduling/Task.cpp
|
utility/scheduling/Task.cpp
|
||||||
utility/scheduling/Task.h
|
utility/scheduling/Task.h
|
||||||
utility/scheduling/TaskDecorator.cpp
|
utility/scheduling/TaskDecorator.cpp
|
||||||
@@ -318,6 +320,8 @@ add_files(
|
|||||||
utility/scheduling/TaskGroupSequential.h
|
utility/scheduling/TaskGroupSequential.h
|
||||||
utility/scheduling/TaskLambda.cpp
|
utility/scheduling/TaskLambda.cpp
|
||||||
utility/scheduling/TaskLambda.h
|
utility/scheduling/TaskLambda.h
|
||||||
|
utility/scheduling/TaskRepeatWhileSuccess.cpp
|
||||||
|
utility/scheduling/TaskRepeatWhileSuccess.h
|
||||||
utility/scheduling/TaskRunner.cpp
|
utility/scheduling/TaskRunner.cpp
|
||||||
utility/scheduling/TaskRunner.h
|
utility/scheduling/TaskRunner.h
|
||||||
utility/scheduling/TaskScheduler.cpp
|
utility/scheduling/TaskScheduler.cpp
|
||||||
|
|||||||
@@ -54,11 +54,11 @@ bool CxxProject::prepareRefresh()
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Task> CxxProject::createIndexerTask(
|
std::shared_ptr<Task> CxxProject::createIndexerTask(
|
||||||
std::shared_ptr<IntermediateStorage> storage,
|
std::shared_ptr<StorageProvider> storageProvider,
|
||||||
std::shared_ptr<FileRegister> fileRegister)
|
std::shared_ptr<FileRegister> fileRegister)
|
||||||
{
|
{
|
||||||
return std::make_shared<TaskParseCxx>(
|
return std::make_shared<TaskParseCxx>(
|
||||||
storage,
|
storageProvider,
|
||||||
fileRegister,
|
fileRegister,
|
||||||
getParserArguments(),
|
getParserArguments(),
|
||||||
getDialogView()
|
getDialogView()
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ private:
|
|||||||
virtual bool prepareRefresh();
|
virtual bool prepareRefresh();
|
||||||
|
|
||||||
virtual std::shared_ptr<Task> createIndexerTask(
|
virtual std::shared_ptr<Task> createIndexerTask(
|
||||||
std::shared_ptr<IntermediateStorage> storage,
|
std::shared_ptr<StorageProvider> storageProvider,
|
||||||
std::shared_ptr<FileRegister> fileRegister);
|
std::shared_ptr<FileRegister> fileRegister);
|
||||||
|
|
||||||
virtual void updateFileManager(FileManager& fileManager);
|
virtual void updateFileManager(FileManager& fileManager);
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ bool JavaProject::prepareIndexing()
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Task> JavaProject::createIndexerTask(
|
std::shared_ptr<Task> JavaProject::createIndexerTask(
|
||||||
std::shared_ptr<IntermediateStorage> storage,
|
std::shared_ptr<StorageProvider> storageProvider,
|
||||||
std::shared_ptr<FileRegister> fileRegister)
|
std::shared_ptr<FileRegister> fileRegister)
|
||||||
{
|
{
|
||||||
Parser::Arguments arguments;
|
Parser::Arguments arguments;
|
||||||
@@ -98,7 +98,7 @@ std::shared_ptr<Task> JavaProject::createIndexerTask(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return std::make_shared<TaskParseJava>(
|
return std::make_shared<TaskParseJava>(
|
||||||
storage,
|
storageProvider,
|
||||||
fileRegister,
|
fileRegister,
|
||||||
arguments,
|
arguments,
|
||||||
getDialogView()
|
getDialogView()
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ private:
|
|||||||
virtual bool prepareIndexing();
|
virtual bool prepareIndexing();
|
||||||
|
|
||||||
virtual std::shared_ptr<Task> createIndexerTask(
|
virtual std::shared_ptr<Task> createIndexerTask(
|
||||||
std::shared_ptr<IntermediateStorage> storage,
|
std::shared_ptr<StorageProvider> storageProvider,
|
||||||
std::shared_ptr<FileRegister> fileRegister);
|
std::shared_ptr<FileRegister> fileRegister);
|
||||||
|
|
||||||
virtual void updateFileManager(FileManager& fileManager);
|
virtual void updateFileManager(FileManager& fileManager);
|
||||||
|
|||||||
+11
-12
@@ -4,10 +4,10 @@
|
|||||||
#include "data/access/StorageAccessProxy.h"
|
#include "data/access/StorageAccessProxy.h"
|
||||||
#include "data/parser/cxx/TaskParseWrapper.h"
|
#include "data/parser/cxx/TaskParseWrapper.h"
|
||||||
#include "data/parser/java/TaskParseJava.h"
|
#include "data/parser/java/TaskParseJava.h"
|
||||||
|
#include "data/StorageProvider.h"
|
||||||
#include "data/PersistentStorage.h"
|
#include "data/PersistentStorage.h"
|
||||||
#include "data/TaskCleanStorage.h"
|
#include "data/TaskCleanStorage.h"
|
||||||
#include "data/TaskInjectStorage.h"
|
#include "data/TaskInjectStorage.h"
|
||||||
#include "data/TaskRepeatWhileUnparsedSourceFilesAvailable.h"
|
|
||||||
#include "settings/ApplicationSettings.h"
|
#include "settings/ApplicationSettings.h"
|
||||||
#include "settings/ProjectSettings.h"
|
#include "settings/ProjectSettings.h"
|
||||||
|
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
#include "utility/messaging/type/MessageStatus.h"
|
#include "utility/messaging/type/MessageStatus.h"
|
||||||
#include "utility/scheduling/TaskGroupSequential.h"
|
#include "utility/scheduling/TaskGroupSequential.h"
|
||||||
#include "utility/scheduling/TaskGroupParallel.h"
|
#include "utility/scheduling/TaskGroupParallel.h"
|
||||||
|
#include "utility/scheduling/TaskRepeatWhileSuccess.h"
|
||||||
#include "utility/text/TextAccess.h"
|
#include "utility/text/TextAccess.h"
|
||||||
#include "utility/utility.h"
|
#include "utility/utility.h"
|
||||||
#include "utility/utilityString.h"
|
#include "utility/utilityString.h"
|
||||||
@@ -310,7 +311,7 @@ bool Project::buildIndex(bool forceRefresh)
|
|||||||
taskSequential->addTask(std::make_shared<TaskCleanStorage>(m_storage.get(), filesToClean, m_dialogView));
|
taskSequential->addTask(std::make_shared<TaskCleanStorage>(m_storage.get(), filesToClean, m_dialogView));
|
||||||
}
|
}
|
||||||
|
|
||||||
int indexerThreadCount = ApplicationSettings::getInstance()->getIndexerThreadCount();
|
const int indexerThreadCount = ApplicationSettings::getInstance()->getIndexerThreadCount();
|
||||||
|
|
||||||
std::shared_ptr<FileRegister> fileRegister = std::make_shared<FileRegister>(&m_fileManager, indexerThreadCount > 1);
|
std::shared_ptr<FileRegister> fileRegister = std::make_shared<FileRegister>(&m_fileManager, indexerThreadCount > 1);
|
||||||
fileRegister->setFilePaths(filesToParse);
|
fileRegister->setFilePaths(filesToParse);
|
||||||
@@ -325,22 +326,20 @@ bool Project::buildIndex(bool forceRefresh)
|
|||||||
std::shared_ptr<TaskGroupParallel> taskParallelIndexing = std::make_shared<TaskGroupParallel>();
|
std::shared_ptr<TaskGroupParallel> taskParallelIndexing = std::make_shared<TaskGroupParallel>();
|
||||||
taskParserWrapper->setTask(taskParallelIndexing);
|
taskParserWrapper->setTask(taskParallelIndexing);
|
||||||
|
|
||||||
std::shared_ptr<std::mutex> storageMutex = std::make_shared<std::mutex>();
|
std::shared_ptr<StorageProvider> storageProvider = std::make_shared<StorageProvider>();
|
||||||
|
|
||||||
for (int i = 0; i < indexerThreadCount; i++)
|
for (int i = 0; i < indexerThreadCount; i++)
|
||||||
{
|
{
|
||||||
std::shared_ptr<TaskRepeatWhileUnparsedSourceFilesAvailable> taskRepeat = std::make_shared<TaskRepeatWhileUnparsedSourceFilesAvailable>(fileRegister);
|
std::shared_ptr<TaskRepeatWhileSuccess> taskRepeat = std::make_shared<TaskRepeatWhileSuccess>();
|
||||||
taskParallelIndexing->addTask(taskRepeat);
|
taskParallelIndexing->addTask(taskRepeat);
|
||||||
|
taskRepeat->setTask(createIndexerTask(storageProvider, fileRegister));
|
||||||
std::shared_ptr<TaskGroupSequential> taskRepeatSequential = std::make_shared<TaskGroupSequential>();
|
|
||||||
taskRepeat->setTask(taskRepeatSequential);
|
|
||||||
|
|
||||||
std::shared_ptr<IntermediateStorage> intermediateStorage = std::make_shared<IntermediateStorage>();
|
|
||||||
|
|
||||||
taskRepeatSequential->addTask(createIndexerTask(intermediateStorage, fileRegister));
|
|
||||||
taskRepeatSequential->addTask(std::make_shared<TaskInjectStorage>(intermediateStorage, m_storage));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<TaskRepeatWhileSuccess> taskRepeat = std::make_shared<TaskRepeatWhileSuccess>();
|
||||||
|
taskParallelIndexing->addTask(taskRepeat);
|
||||||
|
taskRepeat->setTask(std::make_shared<TaskInjectStorage>(storageProvider, m_storage));
|
||||||
|
|
||||||
|
|
||||||
Task::dispatch(taskSequential);
|
Task::dispatch(taskSequential);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
+2
-2
@@ -12,7 +12,7 @@
|
|||||||
class DialogView;
|
class DialogView;
|
||||||
class FileRegister;
|
class FileRegister;
|
||||||
class PersistentStorage;
|
class PersistentStorage;
|
||||||
class IntermediateStorage;
|
class StorageProvider;
|
||||||
class ProjectSettings;
|
class ProjectSettings;
|
||||||
class StorageAccessProxy;
|
class StorageAccessProxy;
|
||||||
class Task;
|
class Task;
|
||||||
@@ -63,7 +63,7 @@ private:
|
|||||||
virtual bool prepareIndexing();
|
virtual bool prepareIndexing();
|
||||||
virtual bool prepareRefresh();
|
virtual bool prepareRefresh();
|
||||||
virtual std::shared_ptr<Task> createIndexerTask(
|
virtual std::shared_ptr<Task> createIndexerTask(
|
||||||
std::shared_ptr<IntermediateStorage> storage,
|
std::shared_ptr<StorageProvider> storageProvider,
|
||||||
std::shared_ptr<FileRegister> fileRegister) = 0;
|
std::shared_ptr<FileRegister> fileRegister) = 0;
|
||||||
virtual void updateFileManager(FileManager& fileManager) = 0;
|
virtual void updateFileManager(FileManager& fileManager) = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,11 @@ void IntermediateStorage::clear()
|
|||||||
m_nextId = 1;
|
m_nextId = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t IntermediateStorage::getSourceLocationCount() const
|
||||||
|
{
|
||||||
|
return m_sourceLocations.size();
|
||||||
|
}
|
||||||
|
|
||||||
Id IntermediateStorage::addFile(const std::string& name, const std::string& filePath, const std::string& modificationTime)
|
Id IntermediateStorage::addFile(const std::string& name, const std::string& filePath, const std::string& modificationTime)
|
||||||
{
|
{
|
||||||
std::shared_ptr<StorageFile> file = std::make_shared<StorageFile>(0, name, filePath, modificationTime);
|
std::shared_ptr<StorageFile> file = std::make_shared<StorageFile>(0, name, filePath, modificationTime);
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ public:
|
|||||||
virtual ~IntermediateStorage();
|
virtual ~IntermediateStorage();
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
|
size_t getSourceLocationCount() const;
|
||||||
|
|
||||||
virtual Id addFile(const std::string& name, const std::string& filePath, const std::string& modificationTime);
|
virtual Id addFile(const std::string& name, const std::string& filePath, const std::string& modificationTime);
|
||||||
virtual Id addNode(int type, const std::string& serializedName, int definitionType);
|
virtual Id addNode(int type, const std::string& serializedName, int definitionType);
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
#include "data/StorageProvider.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int StorageProvider::getStorageCount() const
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(m_storagesMutex);
|
||||||
|
return m_storages.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
void StorageProvider::pushIndexerTarget(std::shared_ptr<IntermediateStorage> storage)
|
||||||
|
{
|
||||||
|
const std::size_t storageSize = storage->getSourceLocationCount();
|
||||||
|
std::list<std::shared_ptr<IntermediateStorage>>::iterator it;
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(m_storagesMutex);
|
||||||
|
for (it = m_storages.begin(); it != m_storages.end(); it++)
|
||||||
|
{
|
||||||
|
if ((*it)->getSourceLocationCount() < storageSize)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_storages.insert(it, storage);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<IntermediateStorage> StorageProvider::popIndexerTarget()
|
||||||
|
{
|
||||||
|
std::shared_ptr<IntermediateStorage> ret;
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(m_storagesMutex);
|
||||||
|
if (m_storages.size() > 1)
|
||||||
|
{
|
||||||
|
std::list<std::shared_ptr<IntermediateStorage>>::iterator it = m_storages.begin();
|
||||||
|
it++;
|
||||||
|
ret = *it;
|
||||||
|
m_storages.erase(it);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ret = std::make_shared<IntermediateStorage>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<IntermediateStorage> StorageProvider::popInjectionSource()
|
||||||
|
{
|
||||||
|
std::shared_ptr<IntermediateStorage> ret;
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(m_storagesMutex);
|
||||||
|
if (!m_storages.empty())
|
||||||
|
{
|
||||||
|
ret = m_storages.front();
|
||||||
|
m_storages.pop_front();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
#ifndef STORAGE_PROVIDER_H
|
||||||
|
#define STORAGE_PROVIDER_H
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
|
#include <list>
|
||||||
|
#include "data/IntermediateStorage.h"
|
||||||
|
|
||||||
|
class StorageProvider
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int getStorageCount() const;
|
||||||
|
void pushIndexerTarget(std::shared_ptr<IntermediateStorage> storage);
|
||||||
|
|
||||||
|
// always returns a usable storage
|
||||||
|
std::shared_ptr<IntermediateStorage> popIndexerTarget();
|
||||||
|
|
||||||
|
// returns empty shared_ptr if no storages available
|
||||||
|
std::shared_ptr<IntermediateStorage> popInjectionSource();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::list<std::shared_ptr<IntermediateStorage>> m_storages; // larger storages are in front
|
||||||
|
mutable std::mutex m_storagesMutex;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // STORAGE_PROVIDER_H
|
||||||
@@ -12,12 +12,12 @@ TaskCleanStorage::TaskCleanStorage(
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskCleanStorage::doEnter()
|
void TaskCleanStorage::doEnter(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
m_dialogView->showProgressDialog("Clearing Files", std::to_string(m_filePaths.size()) + " Files");
|
m_dialogView->showProgressDialog("Clearing Files", std::to_string(m_filePaths.size()) + " Files");
|
||||||
}
|
}
|
||||||
|
|
||||||
Task::TaskState TaskCleanStorage::doUpdate()
|
Task::TaskState TaskCleanStorage::doUpdate(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
m_storage->clearFileElements(m_filePaths);
|
m_storage->clearFileElements(m_filePaths);
|
||||||
|
|
||||||
@@ -26,11 +26,11 @@ Task::TaskState TaskCleanStorage::doUpdate()
|
|||||||
return STATE_SUCCESS;
|
return STATE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskCleanStorage::doExit()
|
void TaskCleanStorage::doExit(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
m_dialogView->hideProgressDialog();
|
m_dialogView->hideProgressDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskCleanStorage::doReset()
|
void TaskCleanStorage::doReset(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,10 +20,10 @@ public:
|
|||||||
);
|
);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void doEnter();
|
virtual void doEnter(std::shared_ptr<Blackboard> blackboard);
|
||||||
virtual TaskState doUpdate();
|
virtual TaskState doUpdate(std::shared_ptr<Blackboard> blackboard);
|
||||||
virtual void doExit();
|
virtual void doExit(std::shared_ptr<Blackboard> blackboard);
|
||||||
virtual void doReset();
|
virtual void doReset(std::shared_ptr<Blackboard> blackboard);
|
||||||
|
|
||||||
PersistentStorage* m_storage;
|
PersistentStorage* m_storage;
|
||||||
std::vector<FilePath> m_filePaths;
|
std::vector<FilePath> m_filePaths;
|
||||||
|
|||||||
@@ -1,30 +1,50 @@
|
|||||||
#include "data/TaskInjectStorage.h"
|
#include "data/TaskInjectStorage.h"
|
||||||
|
|
||||||
#include "data/Storage.h"
|
#include "data/Storage.h"
|
||||||
|
#include "data/StorageProvider.h"
|
||||||
|
#include "utility/scheduling/Blackboard.h"
|
||||||
|
|
||||||
TaskInjectStorage::TaskInjectStorage(
|
TaskInjectStorage::TaskInjectStorage(
|
||||||
std::shared_ptr<Storage> source,
|
std::shared_ptr<StorageProvider> storageProvider,
|
||||||
std::shared_ptr<Storage> target
|
std::shared_ptr<Storage> target
|
||||||
)
|
)
|
||||||
: m_source(source)
|
: m_storageProvider(storageProvider)
|
||||||
, m_target(target)
|
, m_target(target)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskInjectStorage::doEnter()
|
void TaskInjectStorage::doEnter(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Task::TaskState TaskInjectStorage::doUpdate()
|
Task::TaskState TaskInjectStorage::doUpdate(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
m_target->inject(m_source.get());
|
if (m_storageProvider->getStorageCount() > 0)
|
||||||
return STATE_SUCCESS;
|
{
|
||||||
|
std::shared_ptr<IntermediateStorage> source = m_storageProvider->popInjectionSource();
|
||||||
|
if (source)
|
||||||
|
{
|
||||||
|
m_target->inject(source.get());
|
||||||
|
return STATE_SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int indexerCount = 0;
|
||||||
|
if (blackboard->get("indexer_count", indexerCount))
|
||||||
|
{
|
||||||
|
if (indexerCount > 0)
|
||||||
|
{
|
||||||
|
return STATE_SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return STATE_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskInjectStorage::doExit()
|
void TaskInjectStorage::doExit(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskInjectStorage::doReset()
|
void TaskInjectStorage::doReset(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,23 +6,24 @@
|
|||||||
#include "utility/scheduling/Task.h"
|
#include "utility/scheduling/Task.h"
|
||||||
|
|
||||||
class Storage;
|
class Storage;
|
||||||
|
class StorageProvider;
|
||||||
|
|
||||||
class TaskInjectStorage
|
class TaskInjectStorage
|
||||||
: public Task
|
: public Task
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TaskInjectStorage(
|
TaskInjectStorage(
|
||||||
std::shared_ptr<Storage> source,
|
std::shared_ptr<StorageProvider> storageProvider,
|
||||||
std::shared_ptr<Storage> target
|
std::shared_ptr<Storage> target
|
||||||
);
|
);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void doEnter();
|
virtual void doEnter(std::shared_ptr<Blackboard> blackboard);
|
||||||
virtual TaskState doUpdate();
|
virtual TaskState doUpdate(std::shared_ptr<Blackboard> blackboard);
|
||||||
virtual void doExit();
|
virtual void doExit(std::shared_ptr<Blackboard> blackboard);
|
||||||
virtual void doReset();
|
virtual void doReset(std::shared_ptr<Blackboard> blackboard);
|
||||||
|
|
||||||
std::shared_ptr<Storage> m_source;
|
std::shared_ptr<StorageProvider> m_storageProvider;
|
||||||
std::shared_ptr<Storage> m_target;
|
std::shared_ptr<Storage> m_target;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,47 +0,0 @@
|
|||||||
#include "data/TaskRepeatWhileUnparsedSourceFilesAvailable.h"
|
|
||||||
|
|
||||||
#include "utility/file/FileRegister.h"
|
|
||||||
|
|
||||||
TaskRepeatWhileUnparsedSourceFilesAvailable::TaskRepeatWhileUnparsedSourceFilesAvailable(
|
|
||||||
std::shared_ptr<FileRegister> fileRegister
|
|
||||||
)
|
|
||||||
: m_fileRegister(fileRegister)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void TaskRepeatWhileUnparsedSourceFilesAvailable::setTask(std::shared_ptr<Task> task)
|
|
||||||
{
|
|
||||||
if (task)
|
|
||||||
{
|
|
||||||
m_taskRunner = std::make_shared<TaskRunner>(task);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TaskRepeatWhileUnparsedSourceFilesAvailable::doEnter()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Task::TaskState TaskRepeatWhileUnparsedSourceFilesAvailable::doUpdate()
|
|
||||||
{
|
|
||||||
TaskState state = m_taskRunner->update();
|
|
||||||
|
|
||||||
if (state == Task::STATE_SUCCESS)
|
|
||||||
{
|
|
||||||
if(m_fileRegister->getUnparsedSourceFilePaths().size() != 0)
|
|
||||||
{
|
|
||||||
state = Task::STATE_RUNNING;
|
|
||||||
m_taskRunner->reset();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TaskRepeatWhileUnparsedSourceFilesAvailable::doExit()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void TaskRepeatWhileUnparsedSourceFilesAvailable::doReset()
|
|
||||||
{
|
|
||||||
m_taskRunner->reset();
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
#ifndef TASK_REPEAT_WHILE_UNPARSED_SOURCE_FILES_AVAILABLE_H
|
|
||||||
#define TASK_REPEAT_WHILE_UNPARSED_SOURCE_FILES_AVAILABLE_H
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "utility/scheduling/TaskDecorator.h"
|
|
||||||
#include "utility/scheduling/TaskRunner.h"
|
|
||||||
|
|
||||||
class FileRegister;
|
|
||||||
|
|
||||||
class TaskRepeatWhileUnparsedSourceFilesAvailable
|
|
||||||
: public TaskDecorator
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
TaskRepeatWhileUnparsedSourceFilesAvailable(
|
|
||||||
std::shared_ptr<FileRegister> fileRegister
|
|
||||||
);
|
|
||||||
|
|
||||||
virtual void setTask(std::shared_ptr<Task> task);
|
|
||||||
|
|
||||||
private:
|
|
||||||
virtual void doEnter();
|
|
||||||
virtual TaskState doUpdate();
|
|
||||||
virtual void doExit();
|
|
||||||
virtual void doReset();
|
|
||||||
|
|
||||||
std::shared_ptr<FileRegister> m_fileRegister;
|
|
||||||
std::shared_ptr<TaskRunner> m_taskRunner;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // TASK_REPEAT_WHILE_UNPARSED_SOURCE_FILES_AVAILABLE_H
|
|
||||||
@@ -2,7 +2,6 @@
|
|||||||
#define TASK_PARSE_CXX_H
|
#define TASK_PARSE_CXX_H
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <mutex>
|
|
||||||
#include <deque>
|
#include <deque>
|
||||||
|
|
||||||
#include "data/parser/Parser.h"
|
#include "data/parser/Parser.h"
|
||||||
@@ -15,7 +14,7 @@
|
|||||||
class CxxParser;
|
class CxxParser;
|
||||||
class DialogView;
|
class DialogView;
|
||||||
class FileRegister;
|
class FileRegister;
|
||||||
class IntermediateStorage;
|
class StorageProvider;
|
||||||
|
|
||||||
namespace clang
|
namespace clang
|
||||||
{
|
{
|
||||||
@@ -33,22 +32,21 @@ public:
|
|||||||
static std::vector<FilePath> getSourceFilesFromCDB(const FilePath& compilationDatabasePath);
|
static std::vector<FilePath> getSourceFilesFromCDB(const FilePath& compilationDatabasePath);
|
||||||
|
|
||||||
TaskParseCxx(
|
TaskParseCxx(
|
||||||
std::shared_ptr<IntermediateStorage> storage,
|
std::shared_ptr<StorageProvider> storageProvider,
|
||||||
std::shared_ptr<FileRegister> fileRegister,
|
std::shared_ptr<FileRegister> fileRegister,
|
||||||
const Parser::Arguments& arguments,
|
const Parser::Arguments& arguments,
|
||||||
DialogView* dialogView
|
DialogView* dialogView
|
||||||
);
|
);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void doEnter();
|
virtual void doEnter(std::shared_ptr<Blackboard> blackboard);
|
||||||
virtual TaskState doUpdate();
|
virtual TaskState doUpdate(std::shared_ptr<Blackboard> blackboard);
|
||||||
virtual void doExit();
|
virtual void doExit(std::shared_ptr<Blackboard> blackboard);
|
||||||
virtual void doReset();
|
virtual void doReset(std::shared_ptr<Blackboard> blackboard);
|
||||||
|
|
||||||
virtual void handleMessage(MessageInterruptTasks* message);
|
virtual void handleMessage(MessageInterruptTasks* message);
|
||||||
|
|
||||||
std::shared_ptr<IntermediateStorage> m_storage;
|
std::shared_ptr<StorageProvider> m_storageProvider;
|
||||||
std::shared_ptr<std::mutex> m_storageMutex;
|
|
||||||
|
|
||||||
const Parser::Arguments m_arguments;
|
const Parser::Arguments m_arguments;
|
||||||
DialogView* m_dialogView;
|
DialogView* m_dialogView;
|
||||||
|
|||||||
@@ -28,10 +28,10 @@ public:
|
|||||||
virtual void setTask(std::shared_ptr<Task> task);
|
virtual void setTask(std::shared_ptr<Task> task);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void doEnter();
|
virtual void doEnter(std::shared_ptr<Blackboard> blackboard);
|
||||||
virtual TaskState doUpdate();
|
virtual TaskState doUpdate(std::shared_ptr<Blackboard> blackboard);
|
||||||
virtual void doExit();
|
virtual void doExit(std::shared_ptr<Blackboard> blackboard);
|
||||||
virtual void doReset();
|
virtual void doReset(std::shared_ptr<Blackboard> blackboard);
|
||||||
|
|
||||||
PersistentStorage* m_storage;
|
PersistentStorage* m_storage;
|
||||||
std::shared_ptr<FileRegister> m_fileRegister;
|
std::shared_ptr<FileRegister> m_fileRegister;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
class DialogView;
|
class DialogView;
|
||||||
class FileRegister;
|
class FileRegister;
|
||||||
class IntermediateStorage;
|
class StorageProvider;
|
||||||
|
|
||||||
class TaskParseJava
|
class TaskParseJava
|
||||||
: public Task
|
: public Task
|
||||||
@@ -18,21 +18,21 @@ class TaskParseJava
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TaskParseJava(
|
TaskParseJava(
|
||||||
std::shared_ptr<IntermediateStorage> storage,
|
std::shared_ptr<StorageProvider> storageProvider,
|
||||||
std::shared_ptr<FileRegister> fileRegister,
|
std::shared_ptr<FileRegister> fileRegister,
|
||||||
const Parser::Arguments& arguments,
|
const Parser::Arguments& arguments,
|
||||||
DialogView* dialogView
|
DialogView* dialogView
|
||||||
);
|
);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void doEnter();
|
virtual void doEnter(std::shared_ptr<Blackboard> blackboard);
|
||||||
virtual TaskState doUpdate();
|
virtual TaskState doUpdate(std::shared_ptr<Blackboard> blackboard);
|
||||||
virtual void doExit();
|
virtual void doExit(std::shared_ptr<Blackboard> blackboard);
|
||||||
virtual void doReset();
|
virtual void doReset(std::shared_ptr<Blackboard> blackboard);
|
||||||
|
|
||||||
virtual void handleMessage(MessageInterruptTasks* message);
|
virtual void handleMessage(MessageInterruptTasks* message);
|
||||||
|
|
||||||
std::shared_ptr<IntermediateStorage> m_storage;
|
std::shared_ptr<StorageProvider> m_storageProvider;
|
||||||
std::shared_ptr<FileRegister> m_fileRegister;
|
std::shared_ptr<FileRegister> m_fileRegister;
|
||||||
Parser::Arguments m_arguments;
|
Parser::Arguments m_arguments;
|
||||||
DialogView* m_dialogView;
|
DialogView* m_dialogView;
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
#include "utility/scheduling/Blackboard.h"
|
||||||
|
|
||||||
|
Blackboard::Blackboard()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Blackboard::Blackboard(std::shared_ptr<Blackboard> parent)
|
||||||
|
: m_parent(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Blackboard::~Blackboard()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Blackboard::exists(const std::string& key)
|
||||||
|
{
|
||||||
|
ItemMap::const_iterator it = m_values.find(key);
|
||||||
|
return (it != m_values.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Blackboard::clear(const std::string& key)
|
||||||
|
{
|
||||||
|
ItemMap::const_iterator it = m_values.find(key);
|
||||||
|
if (it != m_values.end())
|
||||||
|
{
|
||||||
|
m_values.erase(it);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
#ifndef BLACKBOARD_H
|
||||||
|
#define BLACKBOARD_H
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "Utility/UtilityString.h"
|
||||||
|
#include "utility/logging/logging.h"
|
||||||
|
|
||||||
|
struct BlackboardItemBase
|
||||||
|
{
|
||||||
|
virtual ~BlackboardItemBase()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct BlackboardItem: public BlackboardItemBase
|
||||||
|
{
|
||||||
|
BlackboardItem(const T &v)
|
||||||
|
: value(v)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~BlackboardItem()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
T value;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Blackboard
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Blackboard();
|
||||||
|
Blackboard(std::shared_ptr<Blackboard> parent);
|
||||||
|
~Blackboard();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void set(const std::string& key, const T& value);
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
bool get(const std::string& key, T& value);
|
||||||
|
|
||||||
|
bool exists(const std::string& key);
|
||||||
|
bool clear(const std::string& key);
|
||||||
|
|
||||||
|
private:
|
||||||
|
typedef std::map<std::string, std::shared_ptr<BlackboardItemBase>> ItemMap;
|
||||||
|
|
||||||
|
std::shared_ptr<Blackboard> m_parent;
|
||||||
|
ItemMap m_values;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void Blackboard::set(const std::string& key, const T& value)
|
||||||
|
{
|
||||||
|
m_values[key] = std::make_shared<BlackboardItem<T>>(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
bool Blackboard::get(const std::string& key, T& value)
|
||||||
|
{
|
||||||
|
ItemMap::const_iterator it = m_values.find(key);
|
||||||
|
if (it != m_values.end())
|
||||||
|
{
|
||||||
|
std::shared_ptr<BlackboardItem<T>> item = std::dynamic_pointer_cast<BlackboardItem<T>>(it->second);
|
||||||
|
if (item)
|
||||||
|
{
|
||||||
|
value = item->value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (m_parent)
|
||||||
|
{
|
||||||
|
return m_parent->get(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_WARNING("Entry for \"" + key + "\" not found on blackboard.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // BLACKBOARD_H
|
||||||
@@ -23,28 +23,28 @@ Task::~Task()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Task::TaskState Task::update()
|
Task::TaskState Task::update(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
if (!m_enterCalled)
|
if (!m_enterCalled)
|
||||||
{
|
{
|
||||||
doEnter();
|
doEnter(blackboard);
|
||||||
m_enterCalled = true;
|
m_enterCalled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TaskState state = doUpdate();
|
TaskState state = doUpdate(blackboard);
|
||||||
|
|
||||||
if (state != STATE_RUNNING && !m_exitCalled)
|
if (state != STATE_RUNNING && !m_exitCalled)
|
||||||
{
|
{
|
||||||
doExit();
|
doExit(blackboard);
|
||||||
m_exitCalled = true;
|
m_exitCalled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Task::reset()
|
void Task::reset(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
doReset();
|
doReset(blackboard);
|
||||||
m_enterCalled = false;
|
m_enterCalled = false;
|
||||||
m_exitCalled = false;
|
m_exitCalled = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
class Blackboard;
|
||||||
|
|
||||||
class Task
|
class Task
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -19,16 +21,14 @@ public:
|
|||||||
Task();
|
Task();
|
||||||
virtual ~Task();
|
virtual ~Task();
|
||||||
|
|
||||||
// virtual TaskState getState() const = 0;
|
TaskState update(std::shared_ptr<Blackboard> blackboard);
|
||||||
|
void reset(std::shared_ptr<Blackboard> blackboard);
|
||||||
TaskState update();
|
|
||||||
void reset();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void doEnter() = 0;
|
virtual void doEnter(std::shared_ptr<Blackboard> blackboard) = 0;
|
||||||
virtual Task::TaskState doUpdate() = 0;
|
virtual Task::TaskState doUpdate(std::shared_ptr<Blackboard> blackboard) = 0;
|
||||||
virtual void doExit() = 0;
|
virtual void doExit(std::shared_ptr<Blackboard> blackboard) = 0;
|
||||||
virtual void doReset() = 0;
|
virtual void doReset(std::shared_ptr<Blackboard> blackboard) = 0;
|
||||||
|
|
||||||
bool m_enterCalled;
|
bool m_enterCalled;
|
||||||
bool m_exitCalled;
|
bool m_exitCalled;
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ void TaskGroupParallel::addTask(std::shared_ptr<Task> task)
|
|||||||
m_tasks.push_back(std::make_shared<TaskInfo>(std::make_shared<TaskRunner>(task)));
|
m_tasks.push_back(std::make_shared<TaskInfo>(std::make_shared<TaskRunner>(task)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskGroupParallel::doEnter()
|
void TaskGroupParallel::doEnter(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
m_taskFailed = false;
|
m_taskFailed = false;
|
||||||
|
|
||||||
@@ -26,14 +26,14 @@ void TaskGroupParallel::doEnter()
|
|||||||
m_activeTaskCount = 0;
|
m_activeTaskCount = 0;
|
||||||
for (size_t i = 0; i < m_tasks.size(); i++)
|
for (size_t i = 0; i < m_tasks.size(); i++)
|
||||||
{
|
{
|
||||||
m_tasks[i]->thread = std::make_shared<std::thread>(&TaskGroupParallel::processTaskThreaded, this, m_tasks[i]);
|
m_tasks[i]->thread = std::make_shared<std::thread>(&TaskGroupParallel::processTaskThreaded, this, m_tasks[i], blackboard);
|
||||||
m_tasks[i]->active = true;
|
m_tasks[i]->active = true;
|
||||||
m_activeTaskCount++;
|
m_activeTaskCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Task::TaskState TaskGroupParallel::doUpdate()
|
Task::TaskState TaskGroupParallel::doUpdate(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
if (m_tasks.size() != 0 && getActveTaskCount() > 0)
|
if (m_tasks.size() != 0 && getActveTaskCount() > 0)
|
||||||
{
|
{
|
||||||
@@ -43,7 +43,7 @@ Task::TaskState TaskGroupParallel::doUpdate()
|
|||||||
return (m_taskFailed ? STATE_FAILURE : STATE_SUCCESS);
|
return (m_taskFailed ? STATE_FAILURE : STATE_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskGroupParallel::doExit()
|
void TaskGroupParallel::doExit(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < m_tasks.size(); i++)
|
for (size_t i = 0; i < m_tasks.size(); i++)
|
||||||
{
|
{
|
||||||
@@ -52,7 +52,7 @@ void TaskGroupParallel::doExit()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskGroupParallel::doReset()
|
void TaskGroupParallel::doReset(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < m_tasks.size(); i++)
|
for (size_t i = 0; i < m_tasks.size(); i++)
|
||||||
{
|
{
|
||||||
@@ -60,14 +60,14 @@ void TaskGroupParallel::doReset()
|
|||||||
if (!m_tasks[i]->active)
|
if (!m_tasks[i]->active)
|
||||||
{
|
{
|
||||||
m_tasks[i]->thread->join();
|
m_tasks[i]->thread->join();
|
||||||
m_tasks[i]->thread = std::make_shared<std::thread>(&TaskGroupParallel::processTaskThreaded, this, m_tasks[i]);
|
m_tasks[i]->thread = std::make_shared<std::thread>(&TaskGroupParallel::processTaskThreaded, this, m_tasks[i], blackboard);
|
||||||
m_tasks[i]->active = true;
|
m_tasks[i]->active = true;
|
||||||
m_activeTaskCount++;
|
m_activeTaskCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskGroupParallel::processTaskThreaded(std::shared_ptr<TaskInfo> taskInfo)
|
void TaskGroupParallel::processTaskThreaded(std::shared_ptr<TaskInfo> taskInfo, std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
ScopedFunctor functor([&](){
|
ScopedFunctor functor([&](){
|
||||||
std::lock_guard<std::mutex> lock(m_activeTaskCountMutex);
|
std::lock_guard<std::mutex> lock(m_activeTaskCountMutex);
|
||||||
@@ -77,7 +77,7 @@ void TaskGroupParallel::processTaskThreaded(std::shared_ptr<TaskInfo> taskInfo)
|
|||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
TaskState state = taskInfo->taskRunner->update();
|
TaskState state = taskInfo->taskRunner->update(blackboard);
|
||||||
|
|
||||||
if (state != STATE_RUNNING)
|
if (state != STATE_RUNNING)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -29,12 +29,12 @@ private:
|
|||||||
volatile bool active;
|
volatile bool active;
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual void doEnter();
|
virtual void doEnter(std::shared_ptr<Blackboard> blackboard);
|
||||||
virtual TaskState doUpdate();
|
virtual TaskState doUpdate(std::shared_ptr<Blackboard> blackboard);
|
||||||
virtual void doExit();
|
virtual void doExit(std::shared_ptr<Blackboard> blackboard);
|
||||||
virtual void doReset();
|
virtual void doReset(std::shared_ptr<Blackboard> blackboard);
|
||||||
|
|
||||||
void processTaskThreaded(std::shared_ptr<TaskInfo> taskInfo);
|
void processTaskThreaded(std::shared_ptr<TaskInfo> taskInfo, std::shared_ptr<Blackboard> blackboard);
|
||||||
int getActveTaskCount() const;
|
int getActveTaskCount() const;
|
||||||
|
|
||||||
std::vector<std::shared_ptr<TaskInfo>> m_tasks;
|
std::vector<std::shared_ptr<TaskInfo>> m_tasks;
|
||||||
|
|||||||
@@ -14,12 +14,12 @@ void TaskGroupSequential::addTask(std::shared_ptr<Task> task)
|
|||||||
m_taskRunners.push_back(std::make_shared<TaskRunner>(task));
|
m_taskRunners.push_back(std::make_shared<TaskRunner>(task));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskGroupSequential::doEnter()
|
void TaskGroupSequential::doEnter(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
m_taskIndex = 0;
|
m_taskIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Task::TaskState TaskGroupSequential::doUpdate()
|
Task::TaskState TaskGroupSequential::doUpdate(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
if (m_taskIndex >= int(m_taskRunners.size()))
|
if (m_taskIndex >= int(m_taskRunners.size()))
|
||||||
{
|
{
|
||||||
@@ -30,7 +30,7 @@ Task::TaskState TaskGroupSequential::doUpdate()
|
|||||||
return STATE_FAILURE;
|
return STATE_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
TaskState state = m_taskRunners[m_taskIndex]->update();
|
TaskState state = m_taskRunners[m_taskIndex]->update(blackboard);
|
||||||
|
|
||||||
if (state == STATE_SUCCESS)
|
if (state == STATE_SUCCESS)
|
||||||
{
|
{
|
||||||
@@ -44,11 +44,11 @@ Task::TaskState TaskGroupSequential::doUpdate()
|
|||||||
return STATE_RUNNING;
|
return STATE_RUNNING;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskGroupSequential::doExit()
|
void TaskGroupSequential::doExit(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskGroupSequential::doReset()
|
void TaskGroupSequential::doReset(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < m_taskRunners.size(); i++)
|
for (size_t i = 0; i < m_taskRunners.size(); i++)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,10 +14,10 @@ public:
|
|||||||
virtual void addTask(std::shared_ptr<Task> task);
|
virtual void addTask(std::shared_ptr<Task> task);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void doEnter();
|
virtual void doEnter(std::shared_ptr<Blackboard> blackboard);
|
||||||
virtual TaskState doUpdate();
|
virtual TaskState doUpdate(std::shared_ptr<Blackboard> blackboard);
|
||||||
virtual void doExit();
|
virtual void doExit(std::shared_ptr<Blackboard> blackboard);
|
||||||
virtual void doReset();
|
virtual void doReset(std::shared_ptr<Blackboard> blackboard);
|
||||||
|
|
||||||
std::vector<std::shared_ptr<TaskRunner>> m_taskRunners;
|
std::vector<std::shared_ptr<TaskRunner>> m_taskRunners;
|
||||||
int m_taskIndex;
|
int m_taskIndex;
|
||||||
|
|||||||
@@ -9,20 +9,20 @@ TaskLambda::~TaskLambda()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskLambda::doEnter()
|
void TaskLambda::doEnter(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Task::TaskState TaskLambda::doUpdate()
|
Task::TaskState TaskLambda::doUpdate(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
m_func();
|
m_func();
|
||||||
return STATE_SUCCESS;
|
return STATE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskLambda::doExit()
|
void TaskLambda::doExit(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskLambda::doReset()
|
void TaskLambda::doReset(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,10 +13,10 @@ public:
|
|||||||
virtual ~TaskLambda();
|
virtual ~TaskLambda();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void doEnter();
|
virtual void doEnter(std::shared_ptr<Blackboard> blackboard);
|
||||||
virtual TaskState doUpdate();
|
virtual TaskState doUpdate(std::shared_ptr<Blackboard> blackboard);
|
||||||
virtual void doExit();
|
virtual void doExit(std::shared_ptr<Blackboard> blackboard);
|
||||||
virtual void doReset();
|
virtual void doReset(std::shared_ptr<Blackboard> blackboard);
|
||||||
|
|
||||||
std::function<void()> m_func;
|
std::function<void()> m_func;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
#include "utility/scheduling/TaskRepeatWhileSuccess.h"
|
||||||
|
|
||||||
|
TaskRepeatWhileSuccess::TaskRepeatWhileSuccess()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
state = Task::STATE_RUNNING;
|
||||||
|
m_taskRunner->reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TaskRepeatWhileSuccess::doExit(std::shared_ptr<Blackboard> blackboard)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void TaskRepeatWhileSuccess::doReset(std::shared_ptr<Blackboard> blackboard)
|
||||||
|
{
|
||||||
|
m_taskRunner->reset();
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
#ifndef TASK_REPEAT_WHILE_SUCCESS_H
|
||||||
|
#define TASK_REPEAT_WHILE_SUCCESS_H
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "utility/scheduling/TaskDecorator.h"
|
||||||
|
#include "utility/scheduling/TaskRunner.h"
|
||||||
|
|
||||||
|
class TaskRepeatWhileSuccess
|
||||||
|
: public TaskDecorator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TaskRepeatWhileSuccess();
|
||||||
|
|
||||||
|
virtual void setTask(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::shared_ptr<TaskRunner> m_taskRunner;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // TASK_REPEAT_WHILE_SUCCESS_H
|
||||||
@@ -10,20 +10,15 @@ TaskRunner::~TaskRunner()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
//Task::TaskState TaskRunner::getState() const
|
Task::TaskState TaskRunner::update(std::shared_ptr<Blackboard> blackboard)
|
||||||
//{
|
|
||||||
// return m_task->getState();
|
|
||||||
//}
|
|
||||||
|
|
||||||
Task::TaskState TaskRunner::update()
|
|
||||||
{
|
{
|
||||||
if (m_reset)
|
if (m_reset)
|
||||||
{
|
{
|
||||||
m_task->reset();
|
m_task->reset(blackboard);
|
||||||
m_reset = false;
|
m_reset = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_task->update();
|
return m_task->update(blackboard);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskRunner::reset()
|
void TaskRunner::reset()
|
||||||
|
|||||||
@@ -11,9 +11,7 @@ public:
|
|||||||
TaskRunner(std::shared_ptr<Task> task);
|
TaskRunner(std::shared_ptr<Task> task);
|
||||||
~TaskRunner();
|
~TaskRunner();
|
||||||
|
|
||||||
//Task::TaskState getState() const;
|
Task::TaskState update(std::shared_ptr<Blackboard> blackboard);
|
||||||
|
|
||||||
Task::TaskState update();
|
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
#include "utility/logging/logging.h"
|
#include "utility/logging/logging.h"
|
||||||
#include "utility/messaging/type/MessageStatus.h"
|
#include "utility/messaging/type/MessageStatus.h"
|
||||||
|
#include "utility/scheduling/Blackboard.h"
|
||||||
|
#include "utility/ScopedFunctor.h"
|
||||||
|
|
||||||
std::shared_ptr<TaskScheduler> TaskScheduler::getInstance()
|
std::shared_ptr<TaskScheduler> TaskScheduler::getInstance()
|
||||||
{
|
{
|
||||||
@@ -140,15 +142,22 @@ void TaskScheduler::processTasks()
|
|||||||
{
|
{
|
||||||
std::shared_ptr<TaskRunner> runner = m_taskRunners.front();
|
std::shared_ptr<TaskRunner> runner = m_taskRunners.front();
|
||||||
|
|
||||||
m_tasksMutex.unlock();
|
|
||||||
|
|
||||||
Task::TaskState state = runner->update();
|
|
||||||
|
|
||||||
m_tasksMutex.lock();
|
|
||||||
|
|
||||||
if (state != Task::STATE_RUNNING)
|
|
||||||
{
|
{
|
||||||
m_taskRunners.pop_front();
|
m_tasksMutex.unlock();
|
||||||
|
ScopedFunctor functor([this](){
|
||||||
|
m_tasksMutex.lock();
|
||||||
|
});
|
||||||
|
|
||||||
|
std::shared_ptr<Blackboard> blackboard = std::make_shared<Blackboard>();
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
if (runner->update(blackboard) != Task::STATE_RUNNING)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_taskRunners.pop_front();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
|
#include "utility/scheduling/Blackboard.h"
|
||||||
#include "utility/scheduling/Task.h"
|
#include "utility/scheduling/Task.h"
|
||||||
#include "utility/scheduling/TaskGroupSequential.h"
|
#include "utility/scheduling/TaskGroupSequential.h"
|
||||||
#include "utility/scheduling/TaskScheduler.h"
|
#include "utility/scheduling/TaskScheduler.h"
|
||||||
@@ -144,9 +145,10 @@ public:
|
|||||||
private:
|
private:
|
||||||
void executeTask(Task& task)
|
void executeTask(Task& task)
|
||||||
{
|
{
|
||||||
|
std::shared_ptr<Blackboard> blakboard = std::make_shared<Blackboard>();
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
if (task.update() != Task::STATE_RUNNING)
|
if (task.update(blakboard) != Task::STATE_RUNNING)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -167,12 +169,12 @@ private:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void doEnter()
|
virtual void doEnter(std::shared_ptr<Blackboard> blakboard)
|
||||||
{
|
{
|
||||||
enterCallOrder = ++orderCount;
|
enterCallOrder = ++orderCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual TaskState doUpdate()
|
virtual TaskState doUpdate(std::shared_ptr<Blackboard> blakboard)
|
||||||
{
|
{
|
||||||
updateCallOrder = ++orderCount;
|
updateCallOrder = ++orderCount;
|
||||||
|
|
||||||
@@ -191,12 +193,12 @@ private:
|
|||||||
return returnState;
|
return returnState;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void doExit()
|
virtual void doExit(std::shared_ptr<Blackboard> blakboard)
|
||||||
{
|
{
|
||||||
exitCallOrder = ++orderCount;
|
exitCallOrder = ++orderCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void doReset()
|
virtual void doReset(std::shared_ptr<Blackboard> blakboard)
|
||||||
{
|
{
|
||||||
resetCallOrder = ++orderCount;
|
resetCallOrder = ++orderCount;
|
||||||
}
|
}
|
||||||
@@ -219,12 +221,12 @@ private:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual TaskState doUpdate()
|
virtual TaskState doUpdate(std::shared_ptr<Blackboard> blakboard)
|
||||||
{
|
{
|
||||||
subTask = std::make_shared<TestTask>(&orderCount, 1);
|
subTask = std::make_shared<TestTask>(&orderCount, 1);
|
||||||
Task::dispatch(subTask);
|
Task::dispatch(subTask);
|
||||||
|
|
||||||
return TestTask::doUpdate();
|
return TestTask::doUpdate(blakboard);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<TestTask> subTask;
|
std::shared_ptr<TestTask> subTask;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "data/parser/cxx/TaskParseCxx.h"
|
#include "data/parser/cxx/TaskParseCxx.h"
|
||||||
|
|
||||||
TaskParseCxx::TaskParseCxx(
|
TaskParseCxx::TaskParseCxx(
|
||||||
std::shared_ptr<IntermediateStorage> storage,
|
std::shared_ptr<StorageProvider> storageProvider,
|
||||||
std::shared_ptr<FileRegister> fileRegister,
|
std::shared_ptr<FileRegister> fileRegister,
|
||||||
const Parser::Arguments& arguments,
|
const Parser::Arguments& arguments,
|
||||||
DialogView* dialogView
|
DialogView* dialogView
|
||||||
@@ -14,20 +14,20 @@ std::vector<FilePath> TaskParseCxx::getSourceFilesFromCDB(const FilePath& compil
|
|||||||
return std::vector<FilePath>();
|
return std::vector<FilePath>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskParseCxx::doEnter()
|
void TaskParseCxx::doEnter(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Task::TaskState TaskParseCxx::doUpdate()
|
Task::TaskState TaskParseCxx::doUpdate(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
return STATE_SUCCESS;
|
return STATE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskParseCxx::doExit()
|
void TaskParseCxx::doExit(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskParseCxx::doReset()
|
void TaskParseCxx::doReset(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,19 +20,19 @@ void TaskParseWrapper::setTask(std::shared_ptr<Task> task)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskParseWrapper::doEnter()
|
void TaskParseWrapper::doEnter(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Task::TaskState TaskParseWrapper::doUpdate()
|
Task::TaskState TaskParseWrapper::doUpdate(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
return STATE_SUCCESS;
|
return STATE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskParseWrapper::doExit()
|
void TaskParseWrapper::doExit(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskParseWrapper::doReset()
|
void TaskParseWrapper::doReset(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "data/parser/java/TaskParseJava.h"
|
#include "data/parser/java/TaskParseJava.h"
|
||||||
|
|
||||||
TaskParseJava::TaskParseJava(
|
TaskParseJava::TaskParseJava(
|
||||||
std::shared_ptr<IntermediateStorage> storage,
|
std::shared_ptr<StorageProvider> storageProvider,
|
||||||
std::shared_ptr<FileRegister> fileRegister,
|
std::shared_ptr<FileRegister> fileRegister,
|
||||||
const Parser::Arguments& arguments,
|
const Parser::Arguments& arguments,
|
||||||
DialogView* dialogView
|
DialogView* dialogView
|
||||||
@@ -9,20 +9,20 @@ TaskParseJava::TaskParseJava(
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskParseJava::doEnter()
|
void TaskParseJava::doEnter(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Task::TaskState TaskParseJava::doUpdate()
|
Task::TaskState TaskParseJava::doUpdate(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
return STATE_SUCCESS;
|
return STATE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskParseJava::doExit()
|
void TaskParseJava::doExit(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskParseJava::doReset()
|
void TaskParseJava::doReset(std::shared_ptr<Blackboard> blackboard)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user