You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
AppFlow/FITK_Kernel/FITKAppFramework/FITKAbstractCommandRunner.h

271 lines
7.5 KiB
C

/**
*
* @file FITKAbstractCommandRunner
* @brief
* @author fulipeng (fulipengqd@yeah.net)
* @date 2024-07-19
*
*/
#ifndef FITKAbstractCommandRunner_H
#define FITKAbstractCommandRunner_H
#include "FITKAppFrameworkAPI.h"
#include "FITK_Kernel/FITKCore/FITKThreadTask.h"
#include <QObject>
#include <QString>
#ifdef Q_OS_LINUX
#include <sys/types.h>
#endif
namespace AppFrame
{
/**
* @brief
* @author fulipeng (fulipengqd@yeah.net)
* @date 2024-07-23
*/
enum class RunStatus
{
None = 0,
Run = 1,
Stop = 2,
RunError = 3,
};
/**
* @brief
* @author fulipeng (fulipengqd@yeah.net)
* @date 2024-07-19
*/
class FITKAppFrameworkAPI FITKAbstractCommandRunner : public Core::FITKThreadTask
{
Q_OBJECT
public:
explicit FITKAbstractCommandRunner(QObject *parent = nullptr);
virtual ~FITKAbstractCommandRunner() = default;
/**
* @brief
* @param dicFilePaths
* @return true false
* @author fulipeng (fulipengqd@yeah.net)
* @date 2024-07-19
*/
virtual bool isExistDictionary(const QStringList &FilePaths);
/**
* @brief
* @param dicFilePaths
* @param indexError
* @return true false
* @author fulipeng (fulipengqd@yeah.net)
* @date 2024-07-19
*/
virtual bool isExistDictionary(const QStringList &FilePaths, int &indexError);
/**
* @brief
* @param pid id
* @return true false
* @author fulipeng (fulipengqd@yeah.net)
* @date 2024-07-19
*/
virtual bool isProcessRunning(qint64 pid) { return false; };
/**
* @brief
* @param pid ID
* @return true
* @author fulipeng (fulipengqd@yeah.net)
* @date 2024-07-19
*/
virtual bool killProcess(qint64 pid) { return false; };
/**
* @brief
* @param command
* @author fulipeng (fulipengqd@yeah.net)
* @date 2024-07-29
*/
virtual void setExecuteCommand(const QString &command);
/**
* @brief
* @return
* @author fulipeng (fulipengqd@yeah.net)
* @date 2024-07-29
*/
qint64 getID();
/**
* @brief
* @return
* @author fulipeng (fulipengqd@yeah.net)
* @date 2024-07-29
*/
QString getOutput();
/**
* @brief 线
* @author fulipeng (fulipengqd@yeah.net)
* @date 2024-07-29
*/
void push2ThreadPool();
/**
* @brief
* @param command
* @param pid ID
* @return
* @author fulipeng (fulipengqd@yeah.net)
* @date 2024-07-19
*/
virtual void run() override;
/**
* @brief
* @param command
* @param pid ID
* @param runStatus
* @return
* @author fulipeng (fulipengqd@yeah.net)
* @date 2024-07-19
*/
virtual QString executeCommand(const QString &command, qint64 &pid, RunStatus &runStatus) { return ""; };
signals:
/**
* @brief
* @param output
* @author fulipeng (fulipengqd@yeah.net)
* @date 2024-07-19
*/
void commandOutput(const QString &output);
/**
* @brief
* @param error
* @author fulipeng (fulipengqd@yeah.net)
* @date 2024-07-19
*/
void commandError(const QString &error);
protected:
/**
* @brief
* @param path
* @author fulipeng (fulipengqd@yeah.net)
* @date 2024-07-01
*/
virtual void setWorkDirect(const QString &path);
/**
* @brief
* @param path
* @author fulipeng (fulipengqd@yeah.net)
* @date 2024-07-19
*/
virtual void changeDirectory(const QString &path);
protected:
/**
* @brief ID
* @author fulipeng (fulipengqd@yeah.net)
* @date 2024-07-19
*/
qint64 processId = -1;
/**
* @brief
* @author fulipeng (fulipengqd@yeah.net)
* @date 2024-07-01
*/
QString _workDirect{};
/**
* @brief
* @author fulipeng (fulipengqd@yeah.net)
* @date 2024-07-29
*/
QString _command;
/**
* @brief
* @author fulipeng (fulipengqd@yeah.net)
* @date 2024-07-29
*/
QString _output;
};
/**
* @brief Linux
* @author fulipeng (fulipengqd@yeah.net)
* @date 2024-07-19
*/
class FITKAppFrameworkAPI FITKLinuxCommandRunner : public FITKAbstractCommandRunner
{
Q_OBJECT
public:
explicit FITKLinuxCommandRunner(QObject *parent = nullptr);
virtual ~FITKLinuxCommandRunner() = default;
#ifdef Q_OS_LINUX
/**
* @brief
* @param pid id
* @return true falseFITKAbstractCommandRunner::
* @author fulipeng (fulipengqd@yeah.net)
* @date 2024-07-19
*/
virtual bool isProcessRunning(qint64 pid) override;
/**
* @brief
* @param pid ID
* @return true
* @author fulipeng (fulipengqd@yeah.net)
* @date 2024-07-19
*/
virtual bool killProcess(qint64 pid) override;
/**
* @brief
* @param command FITKAbstractCommandRunner::
* @param pid ID
* @param runStatus
* @return
* @author fulipeng (fulipengqd@yeah.net)
* @date 2024-07-19
*/
virtual QString executeCommand(const QString &command, qint64 &pid, RunStatus &runStatus) override;
protected:
/**
* @brief ID
* @author fulipeng (fulipengqd@yeah.net)
* @date 2024-07-19
*/
qint64 processId = -1;
/**
* @brief
* @author fulipeng (fulipengqd@yeah.net)
* @date 2024-07-01
*/
QString _workDirect{};
#endif
};
}
#endif // FITKAbstractCommandRunner_H