yhkylin-backup-tools/backup-daemon/mybackupmanager.h

104 lines
3.0 KiB
C
Raw Normal View History

2021-08-06 10:20:03 +08:00
#ifndef MYBACKUPMANAGER_H
#define MYBACKUPMANAGER_H
#include <QObject>
#include <QtDBus/QDBusVariant>
#include <QHash>
#include <QDBusUnixFileDescriptor>
2021-11-15 13:36:00 +08:00
#include "mythread.h"
2021-08-06 10:20:03 +08:00
#include "../common/mydefine.h"
#include "../common/spinlock_mutex.h"
class MyBackupManager : public QObject {
Q_OBJECT
2022-04-08 16:03:36 +08:00
Q_CLASSINFO("D-Bus Interface", "com.kylin.backup.manager")
2021-08-06 10:20:03 +08:00
public:
explicit MyBackupManager();
virtual ~MyBackupManager();
signals:
// 这3个信号供控制面板/自动更新等外围模块使用
2021-08-06 10:20:03 +08:00
// 开始备份结果信号
void sendStartBackupResult(int result);
// 备份结果信号
void sendBackupResult(bool result);
// 进度信号
void sendRate(int, int);
// 模块内使用的信号
// 进度信号
void progress(int, int);
// 备份结果信号
void backupFinished(bool result);
// 环境检查结果信号
void sendEnvCheckResult(int result);
2021-08-06 10:20:03 +08:00
// 还原结果信号
void sendRestoreResult(bool result);
// 删除备份结果信号
void sendDeleteResult(bool result);
// ghost备份结果信号
void sendGhostBackupResult(bool result);
public slots:
// 备份分区挂载
int Mount_backup_partition();
2021-10-26 09:24:05 +08:00
// 卸载backup分区
bool umountBackupPartition();
2021-08-06 10:20:03 +08:00
// 环境检测
int checkEnv(const BackupWrapper& backupWrapper);
// 备份
int goBackup(const BackupWrapper& backupWrapper);
// 还原
int goRestore(const BackupWrapper& backupWrapper);
// 删除备份
int deleteBackupPoint(const BackupWrapper& backupWrapper);
// ghost镜像
int ghostBackup(const BackupWrapper& backupWrapper);
// 控制面板调用的备份接口,重构暂时先兼容以前的老接口
void autoBackUpForSystemUpdate_noreturn(const QString& autobackup_name, const QString& create_note, const QString& inc_note, const QString& frontUserName, int frontUid);
// 控制面板调用的获取系统备份接口
QString getBackupCommentForSystemUpdate(QString& state);
// 获取备份状态
int getBackupState(bool& isActive);
// 取消操作
2021-12-28 16:51:35 +08:00
int cancel();
// 重启操作
int reboot();
2021-08-06 10:20:03 +08:00
// 任务结束
void finished();
2021-10-26 09:24:05 +08:00
private slots:
// 卸载backup分区
bool umountBackup();
2021-08-06 10:20:03 +08:00
private:
// 锁定
bool lock(int frontUid);
bool inhibit();
2021-08-06 10:20:03 +08:00
// 解锁
bool unlock();
void uninhibit();
2021-08-06 10:20:03 +08:00
// 自旋锁
spinlock_mutex m_mutex;
2021-10-26 09:24:05 +08:00
// 关闭、开启安全保护
void setKysecStatus(bool status);
2021-08-06 10:20:03 +08:00
private:
// 锁文件描述符
int m_fdLockFile = -1;
QDBusUnixFileDescriptor m_inhibitFileDescriptor;
2021-08-06 10:20:03 +08:00
// 备份还原状态
BackupState m_backupState = BackupState::BACKUP_STATE_INIT;
// 是否活动的,兼容以前用的,和m_backupState的实际使用功能有重复
bool m_isActive = false;
2021-10-26 09:24:05 +08:00
bool m_needUmount = false;
bool m_bOpenKysec = false;
bool m_bStartKysecDeamon = false;
2021-08-06 10:20:03 +08:00
// 工作者线程
2021-11-15 13:36:00 +08:00
MyThread workerThread;
2021-08-06 10:20:03 +08:00
};
#endif // MYBACKUPMANAGER_H