logic: indexer commands
* replaced parser arguments by project specific IndexerCommands that know everything the indexer needs to know to do its job * added different language and project specific indexers that know how to handle a certain kind of indexer command * refactored FileManager and FileRegister to have less overhead * removed no-rtti restriction for clang files in lib cxx * uncommented deprecated interprocess code. fortune cookie message = Happiness will bring you good luck.
This commit is contained in:
@@ -8,7 +8,7 @@ int StorageProvider::getStorageCount() const
|
||||
return m_storages.size();
|
||||
}
|
||||
|
||||
void StorageProvider::pushIndexerTarget(std::shared_ptr<IntermediateStorage> storage)
|
||||
void StorageProvider::insert(std::shared_ptr<IntermediateStorage> storage)
|
||||
{
|
||||
const std::size_t storageSize = storage->getSourceLocationCount();
|
||||
std::list<std::shared_ptr<IntermediateStorage>>::iterator it;
|
||||
@@ -24,7 +24,7 @@ void StorageProvider::pushIndexerTarget(std::shared_ptr<IntermediateStorage> sto
|
||||
m_storages.insert(it, storage);
|
||||
}
|
||||
|
||||
std::shared_ptr<IntermediateStorage> StorageProvider::popIndexerTarget()
|
||||
std::shared_ptr<IntermediateStorage> StorageProvider::consumeSecondLargestStorage()
|
||||
{
|
||||
std::shared_ptr<IntermediateStorage> ret;
|
||||
{
|
||||
@@ -36,15 +36,11 @@ std::shared_ptr<IntermediateStorage> StorageProvider::popIndexerTarget()
|
||||
ret = *it;
|
||||
m_storages.erase(it);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = std::make_shared<IntermediateStorage>();
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::shared_ptr<IntermediateStorage> StorageProvider::popInjectionSource()
|
||||
std::shared_ptr<IntermediateStorage> StorageProvider::consumeLargestStorage()
|
||||
{
|
||||
std::shared_ptr<IntermediateStorage> ret;
|
||||
{
|
||||
|
||||
@@ -10,13 +10,14 @@ class StorageProvider
|
||||
{
|
||||
public:
|
||||
int getStorageCount() const;
|
||||
void pushIndexerTarget(std::shared_ptr<IntermediateStorage> storage);
|
||||
|
||||
// always returns a usable storage
|
||||
std::shared_ptr<IntermediateStorage> popIndexerTarget();
|
||||
void insert(std::shared_ptr<IntermediateStorage> storage);
|
||||
|
||||
// returns empty shared_ptr if no storages available
|
||||
std::shared_ptr<IntermediateStorage> popInjectionSource();
|
||||
std::shared_ptr<IntermediateStorage> consumeSecondLargestStorage();
|
||||
|
||||
// returns empty shared_ptr if no storages available
|
||||
std::shared_ptr<IntermediateStorage> consumeLargestStorage();
|
||||
|
||||
void logCurrentState() const;
|
||||
|
||||
|
||||
@@ -10,12 +10,10 @@
|
||||
TaskFinishParsing::TaskFinishParsing(
|
||||
PersistentStorage* storage,
|
||||
StorageAccess* storageAccess,
|
||||
std::shared_ptr<FileRegister> fileRegister,
|
||||
DialogView* dialogView
|
||||
)
|
||||
: m_storage(storage)
|
||||
, m_storageAccess(storageAccess)
|
||||
, m_fileRegister(fileRegister)
|
||||
, m_dialogView(dialogView)
|
||||
{
|
||||
}
|
||||
@@ -58,9 +56,15 @@ Task::TaskState TaskFinishParsing::doUpdate(std::shared_ptr<Blackboard> blackboa
|
||||
time += indexTime;
|
||||
}
|
||||
|
||||
int indexedSourceFileCount = 0;
|
||||
blackboard->get("indexed_source_file_count", indexedSourceFileCount);
|
||||
|
||||
int sourceFileCount = 0;
|
||||
blackboard->get("source_file_count", sourceFileCount);
|
||||
|
||||
m_dialogView->finishedIndexingDialog(
|
||||
m_fileRegister->getParsedSourceFilesCount(),
|
||||
m_fileRegister->getSourceFilesCount(),
|
||||
indexedSourceFileCount,
|
||||
sourceFileCount,
|
||||
time,
|
||||
m_storageAccess->getErrorCount()
|
||||
);
|
||||
|
||||
@@ -18,7 +18,6 @@ public:
|
||||
TaskFinishParsing(
|
||||
PersistentStorage* storage,
|
||||
StorageAccess* storageAccess,
|
||||
std::shared_ptr<FileRegister> fileRegister,
|
||||
DialogView* dialogView
|
||||
);
|
||||
|
||||
@@ -32,7 +31,6 @@ private:
|
||||
|
||||
PersistentStorage* m_storage;
|
||||
StorageAccess* m_storageAccess;
|
||||
std::shared_ptr<FileRegister> m_fileRegister;
|
||||
DialogView* m_dialogView;
|
||||
};
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ Task::TaskState TaskInjectStorage::doUpdate(std::shared_ptr<Blackboard> blackboa
|
||||
{
|
||||
if (m_storageProvider->getStorageCount() > 0)
|
||||
{
|
||||
std::shared_ptr<IntermediateStorage> source = m_storageProvider->popInjectionSource();
|
||||
std::shared_ptr<IntermediateStorage> source = m_storageProvider->consumeLargestStorage();
|
||||
if (source)
|
||||
{
|
||||
m_target->inject(source.get());
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
#include "data/TaskMergeStorages.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
#include "data/StorageProvider.h"
|
||||
|
||||
TaskMergeStorages::TaskMergeStorages(
|
||||
std::shared_ptr<StorageProvider> storageProvider
|
||||
)
|
||||
: m_storageProvider(storageProvider)
|
||||
{
|
||||
}
|
||||
|
||||
void TaskMergeStorages::doEnter(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
}
|
||||
|
||||
Task::TaskState TaskMergeStorages::doUpdate(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
if (m_storageProvider->getStorageCount() > 2) // largest storage won't be touched here
|
||||
{
|
||||
std::shared_ptr<IntermediateStorage> target = m_storageProvider->consumeSecondLargestStorage();
|
||||
std::shared_ptr<IntermediateStorage> source = m_storageProvider->consumeSecondLargestStorage();
|
||||
if (target && source)
|
||||
{
|
||||
target->inject(source.get());
|
||||
m_storageProvider->insert(target);
|
||||
return STATE_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (target)
|
||||
{
|
||||
m_storageProvider->insert(target);
|
||||
}
|
||||
if (source)
|
||||
{
|
||||
m_storageProvider->insert(source);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const int SLEEP_TIME_MS = 25;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS));
|
||||
}
|
||||
|
||||
return STATE_FAILURE;
|
||||
}
|
||||
|
||||
void TaskMergeStorages::doExit(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
}
|
||||
|
||||
void TaskMergeStorages::doReset(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef TASK_MERGE_STORAGES_H
|
||||
#define TASK_MERGE_STORAGES_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "utility/scheduling/Task.h"
|
||||
|
||||
class StorageProvider;
|
||||
|
||||
class TaskMergeStorages
|
||||
: public Task
|
||||
{
|
||||
public:
|
||||
TaskMergeStorages(
|
||||
std::shared_ptr<StorageProvider> storageProvider
|
||||
);
|
||||
|
||||
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<StorageProvider> m_storageProvider;
|
||||
};
|
||||
|
||||
#endif // TASK_MERGE_STORAGES_H
|
||||
@@ -0,0 +1,46 @@
|
||||
#ifndef INDEXER_H
|
||||
#define INDEXER_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "data/indexer/IndexerBase.h"
|
||||
#include "utility/logging/logging.h"
|
||||
|
||||
template <typename IndexerCommandType>
|
||||
class Indexer: public IndexerBase
|
||||
{
|
||||
public:
|
||||
virtual ~Indexer();
|
||||
|
||||
virtual std::string getKindString() const;
|
||||
|
||||
virtual std::shared_ptr<IntermediateStorage> index(std::shared_ptr<IndexerCommand> indexerCommand, std::shared_ptr<FileRegister> fileRegister);
|
||||
|
||||
private:
|
||||
virtual std::shared_ptr<IntermediateStorage> index(std::shared_ptr<IndexerCommandType> indexerCommand, std::shared_ptr<FileRegister> fileRegister) = 0;
|
||||
};
|
||||
|
||||
template <typename IndexerCommandType>
|
||||
Indexer<IndexerCommandType>::~Indexer()
|
||||
{
|
||||
}
|
||||
|
||||
template <typename IndexerCommandType>
|
||||
std::string Indexer<IndexerCommandType>::getKindString() const
|
||||
{
|
||||
return IndexerCommandType::getIndexerKindString();
|
||||
}
|
||||
|
||||
template <typename IndexerCommandType>
|
||||
std::shared_ptr<IntermediateStorage> Indexer<IndexerCommandType>::index(std::shared_ptr<IndexerCommand> indexerCommand, std::shared_ptr<FileRegister> fileRegister)
|
||||
{
|
||||
if (std::shared_ptr<IndexerCommandType> castedCommand = std::dynamic_pointer_cast<IndexerCommandType>(indexerCommand))
|
||||
{
|
||||
return index(castedCommand, fileRegister);
|
||||
}
|
||||
|
||||
LOG_ERROR("Trying to process " + indexerCommand->getKindString() + " indexer command with " + getKindString() + " indexer.");
|
||||
return std::shared_ptr<IntermediateStorage>();
|
||||
}
|
||||
|
||||
#endif // INDEXER_H
|
||||
@@ -0,0 +1,20 @@
|
||||
#include "data/indexer/IndexerBase.h"
|
||||
|
||||
IndexerBase::IndexerBase()
|
||||
: m_interrupted(false)
|
||||
{
|
||||
}
|
||||
|
||||
IndexerBase::~IndexerBase()
|
||||
{
|
||||
}
|
||||
|
||||
void IndexerBase::interrupt()
|
||||
{
|
||||
m_interrupted = true;
|
||||
}
|
||||
|
||||
bool IndexerBase::interrupted() const
|
||||
{
|
||||
return m_interrupted;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifndef INDEXER_BASE_H
|
||||
#define INDEXER_BASE_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "data/indexer/IndexerCommand.h"
|
||||
#include "data/IntermediateStorage.h"
|
||||
|
||||
class FileRegister;
|
||||
|
||||
class IndexerBase
|
||||
{
|
||||
public:
|
||||
IndexerBase();
|
||||
virtual ~IndexerBase();
|
||||
|
||||
virtual std::string getKindString() const = 0;
|
||||
|
||||
virtual std::shared_ptr<IntermediateStorage> index(std::shared_ptr<IndexerCommand> indexerCommand, std::shared_ptr<FileRegister> fileRegister) = 0;
|
||||
|
||||
virtual void interrupt();
|
||||
|
||||
bool interrupted() const;
|
||||
|
||||
private:
|
||||
bool m_interrupted;
|
||||
};
|
||||
|
||||
#endif // INDEXER_BASE_H
|
||||
@@ -0,0 +1,28 @@
|
||||
#include "data/indexer/IndexerCommand.h"
|
||||
|
||||
IndexerCommand::IndexerCommand(const FilePath& sourceFilePath, const std::set<FilePath>& indexedPaths, const std::set<FilePath>& excludedPaths)
|
||||
: m_sourceFilePath(sourceFilePath)
|
||||
, m_indexedPaths(indexedPaths)
|
||||
, m_excludedPaths(excludedPaths)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
IndexerCommand::~IndexerCommand()
|
||||
{
|
||||
}
|
||||
|
||||
FilePath IndexerCommand::getSourceFilePath() const
|
||||
{
|
||||
return m_sourceFilePath;
|
||||
}
|
||||
|
||||
std::set<FilePath> IndexerCommand::getIndexedPaths() const
|
||||
{
|
||||
return m_indexedPaths;
|
||||
}
|
||||
|
||||
std::set<FilePath> IndexerCommand::getExcludedPath() const
|
||||
{
|
||||
return m_excludedPaths;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef INDEXER_COMMAND_H
|
||||
#define INDEXER_COMMAND_H
|
||||
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
|
||||
class IndexerCommand
|
||||
{
|
||||
public:
|
||||
IndexerCommand(const FilePath& sourceFilePath, const std::set<FilePath>& indexedPaths, const std::set<FilePath>& excludedPaths);
|
||||
virtual ~IndexerCommand();
|
||||
|
||||
virtual std::string getKindString() const = 0;
|
||||
|
||||
FilePath getSourceFilePath() const;
|
||||
std::set<FilePath> getIndexedPaths() const;
|
||||
std::set<FilePath> getExcludedPath() const;
|
||||
|
||||
private:
|
||||
FilePath m_sourceFilePath;
|
||||
std::set<FilePath> m_indexedPaths;
|
||||
std::set<FilePath> m_excludedPaths;
|
||||
};
|
||||
|
||||
#endif // INDEXER_COMMAND_H
|
||||
@@ -0,0 +1,34 @@
|
||||
#include "data/indexer/IndexerCommandList.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <random>
|
||||
|
||||
void IndexerCommandList::addCommand(std::shared_ptr<IndexerCommand> command)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_commandsMutex);
|
||||
m_commands.push_back(command);
|
||||
}
|
||||
|
||||
int IndexerCommandList::size() const
|
||||
{
|
||||
return m_commands.size();
|
||||
}
|
||||
|
||||
void IndexerCommandList::shuffle()
|
||||
{
|
||||
srand(unsigned(time(NULL)));
|
||||
std::lock_guard<std::mutex> lock(m_commandsMutex);
|
||||
std::random_shuffle(m_commands.begin(), m_commands.end());
|
||||
}
|
||||
|
||||
std::shared_ptr<IndexerCommand> IndexerCommandList::consumeCommand()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_commandsMutex);
|
||||
std::shared_ptr<IndexerCommand> ret;
|
||||
if (!m_commands.empty())
|
||||
{
|
||||
ret = m_commands.front();
|
||||
m_commands.pop_front();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef INDEXER_COMMAND_LIST_H
|
||||
#define INDEXER_COMMAND_LIST_H
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <deque>
|
||||
|
||||
#include "data/indexer/IndexerCommand.h"
|
||||
|
||||
class IndexerCommandList
|
||||
{
|
||||
public:
|
||||
void addCommand(std::shared_ptr<IndexerCommand> command);
|
||||
|
||||
int size() const;
|
||||
|
||||
void shuffle();
|
||||
|
||||
std::shared_ptr<IndexerCommand> consumeCommand();
|
||||
|
||||
private:
|
||||
std::deque<std::shared_ptr<IndexerCommand>> m_commands;
|
||||
std::mutex m_commandsMutex;
|
||||
};
|
||||
|
||||
#endif // INDEXER_COMMAND_LIST_H
|
||||
@@ -0,0 +1,37 @@
|
||||
#include "data/indexer/IndexerComposite.h"
|
||||
#include "utility/logging/logging.h"
|
||||
|
||||
IndexerComposite::~IndexerComposite()
|
||||
{
|
||||
}
|
||||
|
||||
std::string IndexerComposite::getKindString() const
|
||||
{
|
||||
return "composite";
|
||||
}
|
||||
|
||||
void IndexerComposite::addIndexer(std::shared_ptr<IndexerBase> indexer)
|
||||
{
|
||||
m_indexers.emplace(indexer->getKindString(), indexer);
|
||||
}
|
||||
|
||||
std::shared_ptr<IntermediateStorage> IndexerComposite::index(std::shared_ptr<IndexerCommand> indexerCommand, std::shared_ptr<FileRegister> fileRegister)
|
||||
{
|
||||
auto it = m_indexers.find(indexerCommand->getKindString());
|
||||
if (it != m_indexers.end())
|
||||
{
|
||||
return it->second->index(indexerCommand, fileRegister);
|
||||
}
|
||||
|
||||
LOG_ERROR("No indexer found to handle " + indexerCommand->getKindString() + " indexer command.");
|
||||
return std::shared_ptr<IntermediateStorage>();
|
||||
}
|
||||
|
||||
void IndexerComposite::interrupt()
|
||||
{
|
||||
for (auto it: m_indexers)
|
||||
{
|
||||
it.second->interrupt();
|
||||
}
|
||||
IndexerBase::interrupt();
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef INDEXER_COMPOSITE_H
|
||||
#define INDEXER_COMPOSITE_H
|
||||
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "data/indexer/IndexerBase.h"
|
||||
|
||||
class IndexerComposite: public IndexerBase
|
||||
{
|
||||
public:
|
||||
virtual ~IndexerComposite();
|
||||
|
||||
virtual std::string getKindString() const;
|
||||
|
||||
void addIndexer(std::shared_ptr<IndexerBase> indexer);
|
||||
|
||||
virtual std::shared_ptr<IntermediateStorage> index(std::shared_ptr<IndexerCommand> indexerCommand, std::shared_ptr<FileRegister> fileRegister);
|
||||
|
||||
virtual void interrupt();
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, std::shared_ptr<IndexerBase>> m_indexers;
|
||||
};
|
||||
|
||||
#endif // INDEXER_COMPOSITE_H
|
||||
@@ -0,0 +1,41 @@
|
||||
#include "data/indexer/IndexerFactory.h"
|
||||
|
||||
#include "data/indexer/IndexerBase.h"
|
||||
#include "data/indexer/IndexerComposite.h"
|
||||
#include "IndexerFactoryModule.h"
|
||||
|
||||
std::shared_ptr<IndexerFactory> IndexerFactory::getInstance()
|
||||
{
|
||||
if (!s_instance)
|
||||
{
|
||||
s_instance = std::shared_ptr<IndexerFactory>(new IndexerFactory());
|
||||
}
|
||||
return s_instance;
|
||||
}
|
||||
|
||||
void IndexerFactory::destroyInstance()
|
||||
{
|
||||
s_instance.reset();
|
||||
}
|
||||
|
||||
|
||||
void IndexerFactory::addModule(std::shared_ptr<IndexerFactoryModule> module)
|
||||
{
|
||||
m_modules.push_back(module);
|
||||
}
|
||||
|
||||
std::shared_ptr<IndexerComposite> IndexerFactory::createCompositeIndexerForAllRegisteredModules()
|
||||
{
|
||||
std::shared_ptr<IndexerComposite> composite = std::make_shared<IndexerComposite>();
|
||||
for (auto it: m_modules)
|
||||
{
|
||||
composite->addIndexer(it->createIndexer());
|
||||
}
|
||||
return composite;
|
||||
}
|
||||
|
||||
std::shared_ptr<IndexerFactory> IndexerFactory::s_instance;
|
||||
|
||||
IndexerFactory::IndexerFactory()
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifndef INDEXER_FACTORY_H
|
||||
#define INDEXER_FACTORY_H
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "settings/LanguageType.h"
|
||||
|
||||
class IndexerBase;
|
||||
class IndexerComposite;
|
||||
class IndexerFactoryModule;
|
||||
|
||||
class IndexerFactory
|
||||
{
|
||||
public:
|
||||
static std::shared_ptr<IndexerFactory> getInstance();
|
||||
static void destroyInstance();
|
||||
|
||||
void addModule(std::shared_ptr<IndexerFactoryModule> module);
|
||||
std::shared_ptr<IndexerComposite> createCompositeIndexerForAllRegisteredModules();
|
||||
|
||||
private:
|
||||
static std::shared_ptr<IndexerFactory> s_instance;
|
||||
IndexerFactory();
|
||||
|
||||
std::vector<std::shared_ptr<IndexerFactoryModule>> m_modules;
|
||||
};
|
||||
|
||||
#endif // INDEXER_FACTORY_H
|
||||
@@ -0,0 +1,5 @@
|
||||
#include "data/indexer/IndexerFactoryModule.h"
|
||||
|
||||
IndexerFactoryModule::~IndexerFactoryModule()
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef INDEXER_FACTORY_MODULE_H
|
||||
#define INDEXER_FACTORY_MODULE_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "settings/LanguageType.h"
|
||||
|
||||
class IndexerBase;
|
||||
|
||||
class IndexerFactoryModule
|
||||
{
|
||||
public:
|
||||
virtual ~IndexerFactoryModule();
|
||||
virtual std::shared_ptr<IndexerBase> createIndexer() = 0;
|
||||
};
|
||||
|
||||
#endif // INDEXER_FACTORY_MODULE_H
|
||||
@@ -0,0 +1,109 @@
|
||||
#include "data/indexer/TaskBuildIndex.h"
|
||||
|
||||
#include "data/indexer/IndexerFactory.h"
|
||||
#include "data/indexer/IndexerCommandList.h"
|
||||
#include "data/indexer/IndexerComposite.h"
|
||||
#include "data/StorageProvider.h"
|
||||
#include "component/view/DialogView.h"
|
||||
#include "utility/file/FileRegister.h"
|
||||
#include "utility/file/FileRegisterStateData.h"
|
||||
#include "utility/scheduling/Blackboard.h"
|
||||
#include "ApplicationStateMonitor.h"
|
||||
|
||||
TaskBuildIndex::TaskBuildIndex(
|
||||
std::shared_ptr<IndexerCommandList> indexerCommandList,
|
||||
std::shared_ptr<StorageProvider> storageProvider,
|
||||
std::shared_ptr<FileRegisterStateData> fileRegisterStateData,
|
||||
DialogView* dialogView
|
||||
)
|
||||
: m_indexerCommandList(indexerCommandList)
|
||||
, m_storageProvider(storageProvider)
|
||||
, m_fileRegisterStateData(fileRegisterStateData)
|
||||
, m_dialogView(dialogView)
|
||||
{
|
||||
m_indexer = IndexerFactory::getInstance()->createCompositeIndexerForAllRegisteredModules();
|
||||
}
|
||||
|
||||
void TaskBuildIndex::doEnter(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(blackboard->getMutex());
|
||||
|
||||
int indexerCount = 0;
|
||||
if (blackboard->get("indexer_count", indexerCount))
|
||||
{
|
||||
indexerCount++;
|
||||
blackboard->set("indexer_count", indexerCount);
|
||||
}
|
||||
}
|
||||
|
||||
Task::TaskState TaskBuildIndex::doUpdate(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
std::shared_ptr<IndexerCommand> indexerCommand = m_indexerCommandList->consumeCommand();
|
||||
|
||||
if (!indexerCommand)
|
||||
{
|
||||
return STATE_FAILURE;
|
||||
}
|
||||
else
|
||||
{
|
||||
ApplicationStateMonitor::getInstance()->addIndexingFile(indexerCommand->getSourceFilePath());
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(blackboard->getMutex());
|
||||
|
||||
int sourceFileCount = 0;
|
||||
blackboard->get("source_file_count", sourceFileCount);
|
||||
|
||||
int indexedSourceFileCount = 0;
|
||||
blackboard->get("indexed_source_file_count", indexedSourceFileCount);
|
||||
|
||||
m_dialogView->updateIndexingDialog(
|
||||
indexedSourceFileCount, sourceFileCount, indexerCommand->getSourceFilePath().str()
|
||||
);
|
||||
}
|
||||
|
||||
// file register only copies the DileRegisterStateData
|
||||
std::shared_ptr<FileRegister> fileRegister = std::make_shared<FileRegister>(
|
||||
*(m_fileRegisterStateData.get()), indexerCommand->getIndexedPaths(), indexerCommand->getExcludedPath()
|
||||
);
|
||||
|
||||
std::shared_ptr<IntermediateStorage> storage = m_indexer->index(indexerCommand, fileRegister);
|
||||
if (storage)
|
||||
{
|
||||
// only write back the changes made to FileRegisterStateData if the indexer actually succeeded
|
||||
m_fileRegisterStateData->inject(fileRegister->getStateData());
|
||||
|
||||
m_storageProvider->insert(storage);
|
||||
|
||||
std::lock_guard<std::mutex> lock(blackboard->getMutex());
|
||||
int indexedSourceFileCount = 0;
|
||||
blackboard->get("indexed_source_file_count", indexedSourceFileCount);
|
||||
blackboard->set("indexed_source_file_count", indexedSourceFileCount + 1);
|
||||
}
|
||||
|
||||
ApplicationStateMonitor::getInstance()->removeIndexingFile(indexerCommand->getSourceFilePath());
|
||||
}
|
||||
|
||||
return (m_indexer->interrupted() ? STATE_FAILURE : STATE_SUCCESS);
|
||||
}
|
||||
|
||||
void TaskBuildIndex::doExit(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(blackboard->getMutex());
|
||||
|
||||
int indexerCount = 0;
|
||||
if (blackboard->get("indexer_count", indexerCount))
|
||||
{
|
||||
indexerCount--;
|
||||
blackboard->set("indexer_count", indexerCount);
|
||||
}
|
||||
}
|
||||
|
||||
void TaskBuildIndex::doReset(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
}
|
||||
|
||||
void TaskBuildIndex::handleMessage(MessageInterruptTasks* message)
|
||||
{
|
||||
m_indexer->interrupt();
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef TASK_PARSE_H
|
||||
#define TASK_PARSE_H
|
||||
#ifndef TASK_BUILD_INDEX_H
|
||||
#define TASK_BUILD_INDEX_H
|
||||
|
||||
#include "data/parser/Parser.h"
|
||||
#include "utility/scheduling/Task.h"
|
||||
@@ -8,18 +8,20 @@
|
||||
|
||||
class CxxParser;
|
||||
class DialogView;
|
||||
class FileRegister;
|
||||
class FileRegisterStateData;
|
||||
class StorageProvider;
|
||||
class IndexerCommandList;
|
||||
class IndexerBase;
|
||||
|
||||
class TaskParse
|
||||
class TaskBuildIndex
|
||||
: public Task
|
||||
, public MessageListener<MessageInterruptTasks>
|
||||
{
|
||||
public:
|
||||
TaskParse(
|
||||
TaskBuildIndex(
|
||||
std::shared_ptr<IndexerCommandList> indexerCommandList,
|
||||
std::shared_ptr<StorageProvider> storageProvider,
|
||||
std::shared_ptr<FileRegister> fileRegister,
|
||||
const Parser::Arguments& arguments,
|
||||
std::shared_ptr<FileRegisterStateData> fileRegisterStateData,
|
||||
DialogView* dialogView
|
||||
);
|
||||
|
||||
@@ -30,15 +32,13 @@ protected:
|
||||
virtual void doReset(std::shared_ptr<Blackboard> blackboard);
|
||||
|
||||
virtual void handleMessage(MessageInterruptTasks* message);
|
||||
virtual void indexFile(FilePath sourcePath) = 0;
|
||||
|
||||
std::shared_ptr<IndexerCommandList> m_indexerCommandList;
|
||||
std::shared_ptr<StorageProvider> m_storageProvider;
|
||||
std::shared_ptr<FileRegister> m_fileRegister;
|
||||
|
||||
const Parser::Arguments m_arguments;
|
||||
std::shared_ptr<FileRegisterStateData> m_fileRegisterStateData;
|
||||
DialogView* m_dialogView;
|
||||
|
||||
bool m_interrupted;
|
||||
std::shared_ptr<IndexerBase> m_indexer;
|
||||
};
|
||||
|
||||
#endif // TASK_PARSE_H
|
||||
@@ -1,11 +1,7 @@
|
||||
#include "data/parser/Parser.h"
|
||||
|
||||
Parser::Arguments::Arguments()
|
||||
: logErrors(true)
|
||||
{
|
||||
}
|
||||
|
||||
Parser::Parser(ParserClient* client)
|
||||
Parser::Parser(std::shared_ptr<ParserClient> client)
|
||||
: m_client(client)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -13,33 +13,11 @@ class TextAccess;
|
||||
class Parser
|
||||
{
|
||||
public:
|
||||
struct Arguments
|
||||
{
|
||||
Arguments();
|
||||
|
||||
std::vector<FilePath> javaClassPaths;
|
||||
|
||||
std::vector<FilePath> headerSearchPaths;
|
||||
std::vector<FilePath> systemHeaderSearchPaths;
|
||||
std::vector<FilePath> frameworkSearchPaths;
|
||||
std::vector<std::string> compilerFlags;
|
||||
|
||||
bool logErrors;
|
||||
|
||||
std::string language;
|
||||
std::string languageStandard;
|
||||
|
||||
FilePath compilationDatabasePath;
|
||||
};
|
||||
|
||||
Parser(ParserClient* client);
|
||||
Parser(std::shared_ptr<ParserClient> client);
|
||||
virtual ~Parser();
|
||||
|
||||
virtual void parseFiles(const std::vector<FilePath>& filePaths, const Arguments& arguments) = 0;
|
||||
virtual void parseFile(const FilePath& filePath, std::shared_ptr<TextAccess> textAccess, const Arguments& arguments) = 0;
|
||||
|
||||
protected:
|
||||
ParserClient* m_client;
|
||||
std::shared_ptr<ParserClient> m_client;
|
||||
};
|
||||
|
||||
#endif // PARSER_H
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
#include "data/parser/TaskParse.h"
|
||||
|
||||
#include "component/view/DialogView.h"
|
||||
#include "utility/file/FileRegister.h"
|
||||
#include "utility/scheduling/Blackboard.h"
|
||||
#include "ApplicationStateMonitor.h"
|
||||
|
||||
TaskParse::TaskParse(
|
||||
std::shared_ptr<StorageProvider> storageProvider,
|
||||
std::shared_ptr<FileRegister> fileRegister,
|
||||
const Parser::Arguments& arguments,
|
||||
DialogView* dialogView
|
||||
)
|
||||
: m_storageProvider(storageProvider)
|
||||
, m_fileRegister(fileRegister)
|
||||
, m_arguments(arguments)
|
||||
, m_dialogView(dialogView)
|
||||
, m_interrupted(false)
|
||||
{
|
||||
}
|
||||
|
||||
void TaskParse::doEnter(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(blackboard->getMutex());
|
||||
|
||||
int indexerCount = 0;
|
||||
if (blackboard->get("indexer_count", indexerCount))
|
||||
{
|
||||
indexerCount++;
|
||||
blackboard->set("indexer_count", indexerCount);
|
||||
}
|
||||
}
|
||||
|
||||
Task::TaskState TaskParse::doUpdate(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
FilePath sourcePath = m_fileRegister->consumeSourceFile();
|
||||
|
||||
if (sourcePath.empty())
|
||||
{
|
||||
return STATE_FAILURE;
|
||||
}
|
||||
else
|
||||
{
|
||||
ApplicationStateMonitor::getInstance()->addIndexingFile(sourcePath);
|
||||
m_dialogView->updateIndexingDialog(
|
||||
m_fileRegister->getParsedSourceFilesCount(), m_fileRegister->getSourceFilesCount(), sourcePath.str()
|
||||
);
|
||||
|
||||
indexFile(sourcePath);
|
||||
ApplicationStateMonitor::getInstance()->removeIndexingFile(sourcePath);
|
||||
}
|
||||
|
||||
return (m_interrupted ? STATE_FAILURE : STATE_SUCCESS);
|
||||
}
|
||||
|
||||
void TaskParse::doExit(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(blackboard->getMutex());
|
||||
|
||||
int indexerCount = 0;
|
||||
if (blackboard->get("indexer_count", indexerCount))
|
||||
{
|
||||
indexerCount--;
|
||||
blackboard->set("indexer_count", indexerCount);
|
||||
}
|
||||
}
|
||||
|
||||
void TaskParse::doReset(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
}
|
||||
|
||||
void TaskParse::handleMessage(MessageInterruptTasks* message)
|
||||
{
|
||||
m_interrupted = true;
|
||||
}
|
||||
@@ -2,17 +2,14 @@
|
||||
|
||||
#include "component/view/DialogView.h"
|
||||
#include "data/PersistentStorage.h"
|
||||
#include "utility/file/FileRegister.h"
|
||||
#include "utility/scheduling/Blackboard.h"
|
||||
#include "utility/utility.h"
|
||||
|
||||
TaskParseWrapper::TaskParseWrapper(
|
||||
PersistentStorage* storage,
|
||||
std::shared_ptr<FileRegister> fileRegister,
|
||||
DialogView* dialogView
|
||||
)
|
||||
: m_storage(storage)
|
||||
, m_fileRegister(fileRegister)
|
||||
, m_dialogView(dialogView)
|
||||
{
|
||||
}
|
||||
@@ -31,9 +28,8 @@ void TaskParseWrapper::setTask(std::shared_ptr<Task> task)
|
||||
|
||||
void TaskParseWrapper::doEnter(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
blackboard->set("indexer_count", 0);
|
||||
|
||||
const size_t sourceFileCount = m_fileRegister->getSourceFilesCount();
|
||||
int sourceFileCount = 0;
|
||||
blackboard->get("source_file_count", sourceFileCount);
|
||||
m_dialogView->updateIndexingDialog(0, sourceFileCount, "");
|
||||
|
||||
m_start = utility::durationStart();
|
||||
@@ -51,7 +47,6 @@ Task::TaskState TaskParseWrapper::doUpdate(std::shared_ptr<Blackboard> blackboar
|
||||
|
||||
void TaskParseWrapper::doExit(std::shared_ptr<Blackboard> blackboard)
|
||||
{
|
||||
blackboard->clear("indexer_count");
|
||||
blackboard->set("index_time", utility::duration(m_start));
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ class TaskParseWrapper
|
||||
public:
|
||||
TaskParseWrapper(
|
||||
PersistentStorage* storage,
|
||||
std::shared_ptr<FileRegister> fileRegister,
|
||||
DialogView* dialogView
|
||||
);
|
||||
virtual ~TaskParseWrapper();
|
||||
@@ -34,7 +33,6 @@ private:
|
||||
virtual void doReset(std::shared_ptr<Blackboard> blackboard);
|
||||
|
||||
PersistentStorage* m_storage;
|
||||
std::shared_ptr<FileRegister> m_fileRegister;
|
||||
DialogView* m_dialogView;
|
||||
|
||||
TimePoint m_start;
|
||||
|
||||
Reference in New Issue
Block a user