Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / workspace / ksysguard / gui / ksgrd / SensorAgent.h
blobdea194095378efb893f084779f9ebf09ac40772b
1 /*
2 KSysGuard, the KDE System Guard
4 Copyright (c) 1999, 2000 Chris Schlaeger <cs@kde.org>
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public
8 License version 2 or at your option version 3 as published by
9 the Free Software Foundation.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #ifndef KSG_SENSORAGENT_H
23 #define KSG_SENSORAGENT_H
25 #include <QtCore/QObject>
26 #include <QtCore/QQueue>
27 #include <QtCore/QPointer>
29 #include <kdemacros.h>
31 class QString;
33 namespace KSGRD {
35 class SensorClient;
36 class SensorManager;
37 class SensorRequest;
39 /**
40 The SensorAgent depending on the type of requested connection
41 starts a ksysguardd process or connects through a tcp connection to
42 a running ksysguardd and handles the asynchronous communication. It
43 keeps a list of pending requests that have not been answered yet by
44 ksysguardd. The current implementation only allowes one pending
45 requests. Incoming requests are queued in an input FIFO.
47 class KDE_EXPORT SensorAgent : public QObject
49 Q_OBJECT
51 public:
52 explicit SensorAgent( SensorManager *sm );
53 virtual ~SensorAgent();
55 virtual bool start( const QString &host, const QString &shell,
56 const QString &command = "", int port = -1 ) = 0;
58 /**
59 This function should only be used by the the SensorManager and
60 never by the SensorClients directly since the pointer returned by
61 engaged is not guaranteed to be valid. Only the SensorManager knows
62 whether a SensorAgent pointer is still valid or not.
64 This function sends out a command to the sensor and notifies the
65 agent to return the answer to 'client'. The 'id' can be used by the
66 client to identify the answer. It is only passed through and never
67 used by the SensorAgent. So it can be any value the client suits to
68 use.
70 void sendRequest( const QString &req, SensorClient *client, int id = 0 );
72 virtual void hostInfo( QString &sh, QString &cmd, int &port ) const = 0;
74 void disconnectClient( SensorClient *client );
76 QString hostName() const;
78 bool daemonOnLine() const;
79 QString reasonForOffline() const;
81 Q_SIGNALS:
82 void reconfigure( const SensorAgent* );
84 protected:
85 void processAnswer( const char *buf, int buflen );
86 void executeCommand();
88 SensorManager *sensorManager();
90 void setDaemonOnLine( bool value );
92 void setHostName( const QString &hostName );
93 void setReasonForOffline(const QString &reasonForOffline);
95 private:
96 virtual bool writeMsg( const char *msg, int len ) = 0;
97 QString mReasonForOffline;
99 QQueue< SensorRequest* > mInputFIFO;
100 QQueue< SensorRequest* > mProcessingFIFO;
101 QList<QByteArray> mAnswerBuffer; ///A single reply can be on multiple lines.
102 QString mErrorBuffer;
103 QByteArray mLeftOverBuffer; ///Any data read in but not terminated is copied into here, awaiting the next load of data
105 QPointer<SensorManager> mSensorManager;
107 bool mDaemonOnLine;
108 QString mHostName;
112 This auxilliary class is used to store requests during their processing.
114 class SensorRequest
116 public:
117 SensorRequest( const QString &request, SensorClient *client, int id );
118 ~SensorRequest();
120 void setRequest( const QString& );
121 QString request() const;
123 void setClient( SensorClient* );
124 SensorClient *client();
126 void setId( int );
127 int id();
129 private:
130 QString mRequest;
131 SensorClient *mClient;
132 int mId;
137 #endif