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_SENSORSOCKETAGENT_H
0011 #define KSG_SENSORSOCKETAGENT_H
0012 
0013 #include <QTcpSocket>
0014 
0015 #include "SensorAgent.h"
0016 
0017 class QString;
0018 
0019 namespace KSGRD
0020 {
0021 /**
0022   The SensorSocketAgent connects to a ksysguardd via a TCP
0023   connection. It keeps a list of pending requests that have not been
0024   answered yet by ksysguard. The current implementation only allows
0025   one pending requests. Incoming requests are queued in an input
0026   FIFO.
0027  */
0028 class SensorSocketAgent : public SensorAgent
0029 {
0030     Q_OBJECT
0031 
0032 public:
0033     explicit SensorSocketAgent(SensorManager *sm);
0034     ~SensorSocketAgent() override;
0035 
0036     bool start(const QString &host, const QString &shell, const QString &command = QLatin1String(""), int port = -1) override;
0037 
0038     void hostInfo(QString &shell, QString &command, int &port) const override;
0039 
0040 private Q_SLOTS:
0041     void connectionClosed();
0042     void msgSent();
0043     void msgRcvd();
0044     void error(QAbstractSocket::SocketError);
0045 
0046 private:
0047     bool writeMsg(const char *msg, int len) override;
0048 
0049     QTcpSocket mSocket;
0050     int mPort;
0051 };
0052 
0053 }
0054 
0055 #endif