kpmcore/src/util/externalcommand.h

106 lines
3.1 KiB
C
Raw Normal View History

/*
SPDX-FileCopyrightText: 2008-2010 Volker Lanz <vl@fidra.de>
SPDX-FileCopyrightText: 2013-2020 Andrius Štikonas <andrius@stikonas.eu>
SPDX-FileCopyrightText: 2015 Teo Mrnjavac <teo@kde.org>
SPDX-FileCopyrightText: 2018 Huzaifa Faruqui <huzaifafaruqui@gmail.com>
SPDX-FileCopyrightText: 2018 Harald Sitter <sitter@kde.org>
SPDX-FileCopyrightText: 2019 Shubham Jangra <aryan100jangid@gmail.com>
SPDX-License-Identifier: GPL-3.0-or-later
*/
2018-04-11 22:47:40 +01:00
#ifndef KPMCORE_EXTERNALCOMMAND_H
#define KPMCORE_EXTERNALCOMMAND_H
#include "util/libpartitionmanagerexport.h"
#include <QDebug>
#include <QProcess>
#include <QString>
#include <QStringList>
2018-01-27 18:54:48 +00:00
#include <QtGlobal>
#include <QThread>
#include <QVariant>
2018-04-11 22:47:40 +01:00
#include <memory>
class KJob;
class Report;
class CopySource;
class CopyTarget;
class QDBusInterface;
class QDBusPendingCall;
class OrgKdeKpmcoreExternalcommandInterface;
2018-04-11 22:47:40 +01:00
struct ExternalCommandPrivate;
/** An external command.
2015-07-13 15:16:36 +01:00
Runs an external command as a child process.
2015-07-13 15:16:36 +01:00
@author Volker Lanz <vl@fidra.de>
@author Andrius Štikonas <andrius@stikonas.eu>
*/
class LIBKPMCORE_EXPORT ExternalCommand : public QObject
{
Q_OBJECT
2015-07-13 15:16:36 +01:00
Q_DISABLE_COPY(ExternalCommand)
public:
explicit ExternalCommand(const QString& cmd = QString(), const QStringList& args = QStringList(), const QProcess::ProcessChannelMode processChannelMode = QProcess::MergedChannels);
explicit ExternalCommand(Report& report, const QString& cmd = QString(), const QStringList& args = QStringList(), const QProcess::ProcessChannelMode processChannelMode = QProcess::MergedChannels);
2015-07-13 15:16:36 +01:00
2020-10-24 01:33:52 +01:00
~ExternalCommand() override;
2018-04-11 22:47:40 +01:00
2015-07-13 15:16:36 +01:00
public:
bool copyBlocks(const CopySource& source, CopyTarget& target);
bool writeData(Report& commandReport, const QByteArray& buffer, const QString& deviceNode, const quint64 firstByte); // same as copyBlocks but from QByteArray
bool createFile(const QByteArray& filePath, const QString& fileContents); // similar to writeData but creates a new file
2015-07-13 15:16:36 +01:00
2018-04-11 22:47:40 +01:00
/**< @param cmd the command to run */
void setCommand(const QString& cmd);
/**< @return the command to run */
const QString& command() const;
/**< @return the arguments */
const QStringList& args() const;
/**< @param s the argument to add */
void addArg(const QString& s);
/**< @param args the new arguments */
void setArgs(const QStringList& args);
bool write(const QByteArray& input); /**< @param input the input for the program */
2015-07-13 15:16:36 +01:00
bool startCopyBlocks();
2015-07-13 15:16:36 +01:00
bool start(int timeout = 30000);
bool run(int timeout = 30000);
2018-04-11 22:47:40 +01:00
/**< @return the exit code */
int exitCode() const;
2018-04-11 22:47:40 +01:00
/**< @return the command output */
const QString output() const;
/**< @return the command output */
const QByteArray& rawOutput() const;
2015-07-13 15:16:36 +01:00
2018-04-11 22:47:40 +01:00
/**< @return pointer to the Report or nullptr */
Report* report();
2015-07-13 15:16:36 +01:00
Q_SIGNALS:
void progress(int);
2020-10-11 23:46:20 +01:00
void reportSignal(const QString&);
private:
2018-04-11 22:47:40 +01:00
void setExitCode(int i);
2015-07-13 15:16:36 +01:00
void onReadOutput();
bool waitForDbusReply(QDBusPendingCall &pcall);
OrgKdeKpmcoreExternalcommandInterface* helperInterface();
2015-07-13 15:16:36 +01:00
private:
2018-04-11 22:47:40 +01:00
std::unique_ptr<ExternalCommandPrivate> d;
};
#endif