logic: added "serialize" method for indexer commands
This commit is contained in:
@@ -1,7 +1,16 @@
|
||||
#include "data/indexer/IndexerCommand.h"
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "utility/utilityString.h"
|
||||
|
||||
std::wstring IndexerCommand::serialize(std::shared_ptr<const IndexerCommand> indexerCommand, bool compact)
|
||||
{
|
||||
QJsonDocument jsonDocument(indexerCommand->doSerialize());
|
||||
return QString::fromUtf8(jsonDocument.toJson(compact ? QJsonDocument::Compact : QJsonDocument::Indented)).toStdWString();
|
||||
}
|
||||
|
||||
IndexerCommand::IndexerCommand(
|
||||
const FilePath& sourceFilePath
|
||||
)
|
||||
@@ -18,3 +27,17 @@ const FilePath& IndexerCommand::getSourceFilePath() const
|
||||
{
|
||||
return m_sourceFilePath;
|
||||
}
|
||||
|
||||
QJsonObject IndexerCommand::doSerialize() const
|
||||
{
|
||||
QJsonObject jsonObject;
|
||||
|
||||
{
|
||||
jsonObject["type"] = QString::fromStdString(indexerCommandTypeToString(getIndexerCommandType()));
|
||||
}
|
||||
{
|
||||
jsonObject["source_file_path"] = QString::fromStdWString(m_sourceFilePath.wstr());
|
||||
}
|
||||
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
@@ -8,9 +8,13 @@
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "utility/file/FilePathFilter.h"
|
||||
|
||||
class QJsonObject;
|
||||
|
||||
class IndexerCommand
|
||||
{
|
||||
public:
|
||||
static std::wstring serialize(std::shared_ptr<const IndexerCommand> indexerCommand, bool compact = true);
|
||||
|
||||
IndexerCommand(const FilePath& sourceFilePath);
|
||||
virtual ~IndexerCommand() = default;
|
||||
|
||||
@@ -20,6 +24,9 @@ public:
|
||||
|
||||
const FilePath& getSourceFilePath() const;
|
||||
|
||||
protected:
|
||||
virtual QJsonObject doSerialize() const;
|
||||
|
||||
private:
|
||||
FilePath m_sourceFilePath;
|
||||
};
|
||||
|
||||
@@ -5,13 +5,22 @@ std::string indexerCommandTypeToString(IndexerCommandType type)
|
||||
switch(type)
|
||||
{
|
||||
case INDEXER_COMMAND_CXX_EMPTY:
|
||||
return "indexer command cxx empty";
|
||||
return "indexer_command_cxx_empty";
|
||||
case INDEXER_COMMAND_CXX_CDB:
|
||||
return "indexer command cxx cdb";
|
||||
return "indexer_command_cxx_cdb";
|
||||
case INDEXER_COMMAND_JAVA:
|
||||
return "indexer command java";
|
||||
return "indexer_command_java";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return "indexer command unknown";
|
||||
return "indexer_command_unknown";
|
||||
}
|
||||
|
||||
IndexerCommandType stringToIndexerCommandType(const std::string& s)
|
||||
{
|
||||
if (s == indexerCommandTypeToString(INDEXER_COMMAND_CXX_EMPTY)) return INDEXER_COMMAND_CXX_EMPTY;
|
||||
if (s == indexerCommandTypeToString(INDEXER_COMMAND_CXX_CDB)) return INDEXER_COMMAND_CXX_CDB;
|
||||
if (s == indexerCommandTypeToString(INDEXER_COMMAND_JAVA)) return INDEXER_COMMAND_JAVA;
|
||||
return INDEXER_COMMAND_UNKNOWN;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,5 +12,6 @@ enum IndexerCommandType
|
||||
};
|
||||
|
||||
std::string indexerCommandTypeToString(IndexerCommandType type);
|
||||
IndexerCommandType stringToIndexerCommandType(const std::string& s);
|
||||
|
||||
#endif // INDEXER_COMMAND_TYPE_H
|
||||
|
||||
@@ -15,10 +15,6 @@ InterprocessIndexer::InterprocessIndexer(const std::string& uuid, Id processId)
|
||||
{
|
||||
}
|
||||
|
||||
InterprocessIndexer::~InterprocessIndexer()
|
||||
{
|
||||
}
|
||||
|
||||
void InterprocessIndexer::work()
|
||||
{
|
||||
try
|
||||
|
||||
@@ -9,7 +9,6 @@ class InterprocessIndexer
|
||||
{
|
||||
public:
|
||||
InterprocessIndexer(const std::string& uuid, Id processId);
|
||||
~InterprocessIndexer();
|
||||
|
||||
void work();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user