Commit 690c0b3a authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Task: Move ParserStep to a public header

parent dcdb591e
......@@ -22,6 +22,8 @@
#pragma once
#include <cstdint>
namespace medialibrary
{
namespace parser
......@@ -48,5 +50,14 @@ enum class Status
Discarded,
};
enum class Step : uint8_t
{
None = 0,
MetadataExtraction = 1,
MetadataAnalysis = 2,
Completed = 1 | 2,
};
}
}
......@@ -876,9 +876,9 @@ void MetadataParser::onRestarted()
cacheUnknownArtist();
}
parser::Task::ParserStep MetadataParser::targetedStep() const
parser::Step MetadataParser::targetedStep() const
{
return parser::Task::ParserStep::MetadataAnalysis;
return parser::Step::MetadataAnalysis;
}
}
......@@ -43,7 +43,7 @@ protected:
virtual uint8_t nbThreads() const override;
virtual void onFlushing() override;
virtual void onRestarted() override;
virtual parser::Task::ParserStep targetedStep() const override;
virtual parser::Step targetedStep() const override;
bool addPlaylistMedias( parser::IItem& item ) const;
void addPlaylistElement( parser::IItem& item, std::shared_ptr<Playlist> playlistPtr,
......
......@@ -110,9 +110,9 @@ void VLCMetadataService::onRestarted()
{
}
parser::Task::ParserStep VLCMetadataService::targetedStep() const
parser::Step VLCMetadataService::targetedStep() const
{
return parser::Task::ParserStep::MetadataExtraction;
return parser::Step::MetadataExtraction;
}
void VLCMetadataService::mediaToItem( VLC::Media& media, parser::IItem& item )
......
......@@ -48,7 +48,7 @@ private:
virtual uint8_t nbThreads() const override;
virtual void onFlushing() override;
virtual void onRestarted() override;
virtual parser::Task::ParserStep targetedStep() const override;
virtual parser::Step targetedStep() const override;
void mediaToItem( VLC::Media& media, parser::IItem& item );
......
......@@ -22,12 +22,15 @@
#pragma once
#include "Task.h"
#include "medialibrary/Parser.h"
#include "parser/IItem.h"
namespace medialibrary
{
class MediaLibrary;
class IParserService
{
public:
......@@ -56,7 +59,7 @@ public:
/**
* @brief targetedStep Returns the ParserStep targeted by this service.
*/
virtual parser::Task::ParserStep targetedStep() const = 0;
virtual parser::Step targetedStep() const = 0;
/**
* @brief initialize Run service specific initialization.
......
......@@ -215,13 +215,13 @@ bool ParserWorker::handleServiceResult( parser::Task& task, parser::Status statu
// We don't want to save the extraction step in database, as restarting a
// task with extraction completed but analysis uncompleted wouldn't run
// the extraction again, causing the analysis to run with no info.
if ( m_service->targetedStep() != parser::Task::ParserStep::MetadataExtraction )
if ( m_service->targetedStep() != parser::Step::MetadataExtraction )
return task.saveParserStep();
return true;
}
else if ( status == parser::Status::Completed )
{
task.markStepCompleted( parser::Task::ParserStep::Completed );
task.markStepCompleted( parser::Step::Completed );
return task.saveParserStep();
}
else if ( status == parser::Status::Discarded )
......
......@@ -72,16 +72,16 @@ Task::Task( MediaLibraryPtr ml, std::shared_ptr<fs::IFile> fileFs,
unsigned int parentPlaylistIndex )
: currentService( 0 )
, m_ml( ml )
, m_step( ParserStep::None )
, m_step( parser::Step::None )
, m_fileId( 0 )
, m_item( this, std::move( fileFs ), std::move( parentFolder ),
std::move( parentFolderFs ), std::move( parentPlaylist ), parentPlaylistIndex )
{
}
void Task::markStepCompleted( ParserStep stepCompleted )
void Task::markStepCompleted( parser::Step stepCompleted )
{
m_step = static_cast<ParserStep>( static_cast<uint8_t>( m_step ) |
m_step = static_cast<parser::Step>( static_cast<uint8_t>( m_step ) |
static_cast<uint8_t>( stepCompleted ) );
}
......@@ -96,13 +96,13 @@ bool Task::saveParserStep()
bool Task::isCompleted() const
{
using StepType = typename std::underlying_type<ParserStep>::type;
using StepType = typename std::underlying_type<parser::Step>::type;
return ( static_cast<StepType>( m_step ) &
static_cast<StepType>( ParserStep::Completed ) ) ==
static_cast<StepType>( ParserStep::Completed );
static_cast<StepType>( parser::Step::Completed ) ) ==
static_cast<StepType>( parser::Step::Completed );
}
bool Task::isStepCompleted( Task::ParserStep step ) const
bool Task::isStepCompleted( parser::Step step ) const
{
return ( static_cast<uint8_t>( m_step ) & static_cast<uint8_t>( step ) ) != 0;
}
......@@ -434,15 +434,15 @@ void Task::resetRetryCount( MediaLibraryPtr ml )
{
static const std::string req = "UPDATE " + policy::TaskTable::Name + " SET "
"retry_count = 0 WHERE step & ? != ?";
sqlite::Tools::executeUpdate( ml->getConn(), req, parser::Task::ParserStep::Completed,
parser::Task::ParserStep::Completed);
sqlite::Tools::executeUpdate( ml->getConn(), req, parser::Step::Completed,
parser::Step::Completed);
}
void Task::resetParsing( MediaLibraryPtr ml )
{
static const std::string req = "UPDATE " + policy::TaskTable::Name + " SET "
"retry_count = 0, step = ?";
sqlite::Tools::executeUpdate( ml->getConn(), req, parser::Task::ParserStep::None );
sqlite::Tools::executeUpdate( ml->getConn(), req, parser::Step::None );
}
std::vector<std::shared_ptr<Task>> Task::fetchUncompleted( MediaLibraryPtr ml )
......@@ -451,8 +451,8 @@ std::vector<std::shared_ptr<Task>> Task::fetchUncompleted( MediaLibraryPtr ml )
" LEFT JOIN " + policy::FileTable::Name + " f ON f.id_file = t.file_id"
" WHERE step & ? != ? AND retry_count < 3 AND (f.is_present != 0 OR "
" t.file_id IS NULL)";
return Task::fetchAll<Task>( ml, req, parser::Task::ParserStep::Completed,
parser::Task::ParserStep::Completed );
return Task::fetchAll<Task>( ml, req, parser::Step::Completed,
parser::Step::Completed );
}
std::shared_ptr<Task>
......
......@@ -31,6 +31,7 @@
#include "database/DatabaseHelpers.h"
#include "parser/IItem.h"
#include "medialibrary/Parser.h"
namespace medialibrary
{
......@@ -74,15 +75,6 @@ public:
class Task : public DatabaseHelpers<Task, policy::TaskTable, cachepolicy::Uncached<Task>>, private ITaskCb
{
public:
enum class ParserStep : uint8_t
{
None = 0,
MetadataExtraction = 1,
MetadataAnalysis = 2,
Completed = 1 | 2,
};
class Item : public IItem
{
public:
......@@ -179,10 +171,10 @@ public:
* extracted, in case we were to restart the parsing, we would need to
* extract the same information again
*/
void markStepCompleted( ParserStep stepCompleted );
void markStepCompleted( parser::Step stepCompleted );
bool saveParserStep();
bool isCompleted() const;
bool isStepCompleted( ParserStep step ) const;
bool isStepCompleted( parser::Step step ) const;
/**
* @brief startParserStep Do some internal book keeping to avoid restarting a step too many time
*/
......@@ -212,7 +204,7 @@ public:
private:
MediaLibraryPtr m_ml;
int64_t m_id;
ParserStep m_step;
parser::Step m_step;
int m_retryCount;
int64_t m_fileId;
int64_t m_parentFolderId;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment