yhkylin-backup-tools/backup-daemon/workerfactory.cpp

114 lines
2.9 KiB
C++
Raw Normal View History

2022-11-01 10:40:05 +08:00
#include "workerfactory.h"
#include <QString>
Worker::Worker() :
QObject(nullptr),
m_bCancel(false)
{}
Worker::~Worker()
{}
//
/**
* @brief
*/
void Worker::checkEnv()
{
checkEnvEx();
}
/**
* @brief
*/
void Worker::doWork()
{
doWorkEx();
}
// 环境检测,个性化部分派生类去实现
bool Worker::checkEnvEx()
{
return true;
}
// 任务处理,个性化部分派生类去实现
void Worker::doWorkEx()
{}
// 任务取消,个性化部分派生类去实现
void Worker::cancelEx()
{}
/**
* @brief
* @param type ,
* @param position U盘备份: 0-1-
* @return Worker派生类对象指针
*/
Worker * WorkerFactory::createWorker(int type, int position)
{
QString className;
switch (type) {
case BackupType::BACKUP_SYSTEM:
case BackupType::INC_BACKUP_SYSTEM:
if (BackupPosition::UDISK == position) {
className = "UDiskSystemBackupProxy";
} else if (BackupPosition::CUSTOMIZE == position) {
className = "CustomizeSystemBackupProxy";
} else {
className = "SystemBackupProxy";
}
break;
case BackupType::RESTORE_SYSTEM:
case BackupType::RESTORE_SYSTEM_WITH_DATA:
if (BackupPosition::UDISK == position || BackupPosition::OTHER == position) {
className = "UDiskSystemRestoreProxy";
} else if (BackupPosition::CUSTOMIZE == position) {
className = "CustomizeSystemRestoreProxy";
} else {
className = "SystemRestoreProxy";
}
break;
case BackupType::BACKUP_DATA:
case BackupType::INC_BACKUP_DATA:
if (BackupPosition::UDISK == position) {
className = "UDiskDataBackupProxy";
} else if (BackupPosition::CUSTOMIZE == position) {
className = "CustomizeDataBackupProxy";
} else {
className = "DataBackupProxy";
}
break;
case BackupType::RESTORE_DATA:
if (BackupPosition::UDISK == position) {
className = "UDiskDataRestoreProxy";
} else {
className = "DataRestoreProxy";
}
break;
case BackupType::DELETE_BACKUP:
className = "DeleteBackupProxy";
break;
case BackupType::GHOST_IMAGE:
if (BackupPosition::UDISK == position) {
className = "UDiskGhostImageProxy";
} else if (BackupPosition::CUSTOMIZE == position) {
className = "CustomizeGhostImageProxy";
} else {
className = "GhostImageProxy";
}
break;
default:
break;
}
if (className.isEmpty()) {
return nullptr;
}
Worker * p = qobject_cast<Worker *>(Reflect::createObject(className));
return p;
}