213 lines
4.6 KiB
C++
213 lines
4.6 KiB
C++
|
/**
|
|||
|
* brief 程序比较小,将接口层和控制层合到一起;主要做一些任务分发,状态监控等一些简单工作;复杂的耗时的逻辑放到任务中moveToThread中去执行
|
|||
|
*/
|
|||
|
|
|||
|
#include <mutex>
|
|||
|
#include "mybackupmanager.h"
|
|||
|
#include "../common/utils.h"
|
|||
|
#include "mymountproxy.h"
|
|||
|
#include "workerfactory.h"
|
|||
|
|
|||
|
/**
|
|||
|
* @brief 构造函数
|
|||
|
*/
|
|||
|
MyBackupManager::MyBackupManager()
|
|||
|
{
|
|||
|
// 注册BackupWrapper类型,之后qdbus接口才能使用
|
|||
|
BackupWrapper::registerMetaType();
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* @brief 析构函数
|
|||
|
*/
|
|||
|
MyBackupManager::~MyBackupManager()
|
|||
|
{
|
|||
|
if (workerThread.isRunning()) {
|
|||
|
workerThread.quit();
|
|||
|
workerThread.wait();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* @brief 挂载backup分区,兼容提供给自动更新模块的老接口
|
|||
|
* @return
|
|||
|
*/
|
|||
|
int MyBackupManager::Mount_backup_partition()
|
|||
|
{
|
|||
|
MyMountProxy mymount;
|
|||
|
return int(mymount.mountBackupPartition());
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* @brief 环境检测
|
|||
|
* @param backupWrapper,参数
|
|||
|
* @return
|
|||
|
*/
|
|||
|
int MyBackupManager::checkEnv(const BackupWrapper& backupWrapper)
|
|||
|
{
|
|||
|
if (m_isActive || !lock(backupWrapper.m_frontUid)) {
|
|||
|
emit sendEnvCheckResult(int(BackupResult::LOCK_PROGRAM_FAIL));
|
|||
|
return int(BackupResult::LOCK_PROGRAM_FAIL);
|
|||
|
}
|
|||
|
|
|||
|
Worker* worker = WorkerFactory::createWorker(backupWrapper.m_type, backupWrapper.m_iPosition);
|
|||
|
if (nullptr == worker) {
|
|||
|
emit sendEnvCheckResult(int(BackupResult::NO_FOUND_DEALCLASS));
|
|||
|
return int(BackupResult::NO_FOUND_DEALCLASS);
|
|||
|
}
|
|||
|
|
|||
|
worker->setParam(backupWrapper);
|
|||
|
connect(worker, &Worker::checkResult, this, &MyBackupManager::sendEnvCheckResult);
|
|||
|
connect(worker, &Worker::checkResult, this, &MyBackupManager::finished);
|
|||
|
worker->moveToThread(&workerThread);
|
|||
|
connect(&workerThread, &QThread::started, worker, &Worker::checkEnv);
|
|||
|
connect(&workerThread, &QThread::finished, worker, &Worker::deleteLater);
|
|||
|
|
|||
|
return int(BackupResult::BACKUP_RESULT_INIT);
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* @brief 备份
|
|||
|
* @param backupWrapper
|
|||
|
* @return
|
|||
|
*/
|
|||
|
int MyBackupManager::goBackup(const BackupWrapper& backupWrapper)
|
|||
|
{
|
|||
|
Q_UNUSED(backupWrapper)
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* @brief 还原
|
|||
|
* @param backupWrapper
|
|||
|
* @return
|
|||
|
*/
|
|||
|
int MyBackupManager::goRestore(const BackupWrapper& backupWrapper)
|
|||
|
{
|
|||
|
Q_UNUSED(backupWrapper)
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* @brief 删除备份
|
|||
|
* @param backupWrapper
|
|||
|
* @return
|
|||
|
*/
|
|||
|
int MyBackupManager::deleteBackupPoint(const BackupWrapper& backupWrapper)
|
|||
|
{
|
|||
|
Q_UNUSED(backupWrapper)
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* @brief ghost镜像
|
|||
|
* @param backupWrapper
|
|||
|
* @return
|
|||
|
*/
|
|||
|
int MyBackupManager::ghostBackup(const BackupWrapper& backupWrapper)
|
|||
|
{
|
|||
|
Q_UNUSED(backupWrapper)
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* @brief 控制面板调用的备份接口,重构暂时先兼容以前的老接口
|
|||
|
* @param autobackup_name 备份名称
|
|||
|
* @param create_note 创建时备注
|
|||
|
* @param inc_note 增量备注
|
|||
|
* @param frontUserName 前端用户名
|
|||
|
* @param frontUid 前端用户id
|
|||
|
*/
|
|||
|
void MyBackupManager::autoBackUpForSystemUpdate_noreturn(const QString& autobackup_name, const QString& create_note, const QString& inc_note, const QString& frontUserName, int frontUid)
|
|||
|
{
|
|||
|
Q_UNUSED(autobackup_name)
|
|||
|
Q_UNUSED(create_note)
|
|||
|
Q_UNUSED(inc_note)
|
|||
|
Q_UNUSED(frontUserName)
|
|||
|
Q_UNUSED(frontUid)
|
|||
|
|
|||
|
return ;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* @brief 控制面板调用的获取系统备份接口
|
|||
|
* @param state
|
|||
|
* @return
|
|||
|
*/
|
|||
|
QString MyBackupManager::getBackupCommentForSystemUpdate(QString& state)
|
|||
|
{
|
|||
|
Q_UNUSED(state)
|
|||
|
return "";
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* @brief 获取备份状态
|
|||
|
* @param isActive,是否活动状态
|
|||
|
* @return
|
|||
|
*/
|
|||
|
int MyBackupManager::getBackupState(bool& isActive)
|
|||
|
{
|
|||
|
Q_UNUSED(isActive)
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* @brief 取消操作
|
|||
|
*/
|
|||
|
int MyBackupManager::cancel()
|
|||
|
{
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* @brief 任务结束
|
|||
|
*/
|
|||
|
void MyBackupManager::finished()
|
|||
|
{
|
|||
|
if (workerThread.isRunning()) {
|
|||
|
workerThread.quit();
|
|||
|
workerThread.wait();
|
|||
|
}
|
|||
|
|
|||
|
unlock();
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* @brief 锁定应用
|
|||
|
* @param frontUid,锁定应用的用户id
|
|||
|
* @return bool
|
|||
|
*/
|
|||
|
bool MyBackupManager::lock(int frontUid)
|
|||
|
{
|
|||
|
std::lock_guard<spinlock_mutex> lock(m_mutex);
|
|||
|
|
|||
|
int lock_file_fd = Utils::lockProgram(frontUid);
|
|||
|
if (lock_file_fd < 0) {
|
|||
|
Utils::rmLockFile();
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
m_fdLockFile = lock_file_fd;
|
|||
|
m_backupState = BackupState::PREPARING;
|
|||
|
m_isActive = true;
|
|||
|
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* @brief 解锁应用
|
|||
|
* @return bool
|
|||
|
*/
|
|||
|
bool MyBackupManager::unlock()
|
|||
|
{
|
|||
|
std::lock_guard<spinlock_mutex> lock(m_mutex);
|
|||
|
|
|||
|
Utils::unLockProgram(m_fdLockFile);
|
|||
|
|
|||
|
m_fdLockFile = -1;
|
|||
|
m_backupState = BackupState::BACKUP_STATE_INIT;
|
|||
|
m_isActive = false;
|
|||
|
|
|||
|
return true;
|
|||
|
}
|