File indexing completed on 2024-05-05 05:34:26

0001 /*
0002     KSysGuard, the KDE System Guard
0003 
0004     SPDX-FileCopyrightText: 1999, 2000 Chris Schlaeger <cs@kde.org>
0005 
0006     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0007 
0008 */
0009 
0010 #ifndef KSG_SENSORSHELLAGENT_H
0011 #define KSG_SENSORSHELLAGENT_H
0012 
0013 #include <QObject>
0014 #include <QPointer>
0015 #include <QProcess>
0016 
0017 #include "SensorAgent.h"
0018 
0019 class QString;
0020 
0021 class KProcess;
0022 
0023 namespace KSGRD
0024 {
0025 class SensorManager;
0026 
0027 /**
0028   The SensorShellAgent starts a ksysguardd process and handles the
0029   asynchronous communication. It keeps a list of pending requests
0030   that have not been answered yet by ksysguard. The current
0031   implementation only allows one pending requests. Incoming requests
0032   are queued in an input FIFO.
0033  */
0034 class SensorShellAgent : public SensorAgent
0035 {
0036     Q_OBJECT
0037 
0038 public:
0039     explicit SensorShellAgent(SensorManager *sm);
0040     ~SensorShellAgent() override;
0041 
0042     bool start(const QString &host, const QString &shell, const QString &command = QLatin1String(""), int port = -1) override;
0043 
0044     void hostInfo(QString &shell, QString &command, int &port) const override;
0045 
0046 private Q_SLOTS:
0047     void msgRcvd();
0048     void errMsgRcvd();
0049     void daemonExited(int exitCode, QProcess::ExitStatus exitStatus);
0050     void daemonError(QProcess::ProcessError errorStatus);
0051 
0052 private:
0053     bool writeMsg(const char *msg, int len) override;
0054     int mRetryCount;
0055     QPointer<KProcess> mDaemon;
0056     QString mShell;
0057     QString mCommand;
0058 };
0059 
0060 }
0061 
0062 #endif