summaryrefslogtreecommitdiffstats
path: root/ksysguard/gui/ksgrd/SensorAgent.h
blob: b9871f9f0ec5eb90ebdace93c18795f7e06f54d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
    KSysGuard, the KDE System Guard
   
    Copyright (c) 1999, 2000 Chris Schlaeger <[email protected]>
    
    This program is free software; you can redistribute it and/or
    modify it under the terms of version 2 of the GNU General Public
    License as published by the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

*/

#ifndef KSG_SENSORAGENT_H
#define KSG_SENSORAGENT_H

#include <tqobject.h>
#include <tqptrlist.h>

class TDEProcess;
class KShellProcess;

class TQString;

namespace KSGRD {

class SensorClient;
class SensorManager;
class SensorRequest;

/**
  The SensorAgent depending on the type of requested connection
  starts a ksysguardd process or connects through a tcp connection to
  a running ksysguardd and handles the asynchronous communication. It
  keeps a list of pending requests that have not been answered yet by
  ksysguardd. The current implementation only allowes one pending
  requests. Incoming requests are queued in an input FIFO.
*/
class KDE_EXPORT SensorAgent : public QObject
{
  TQ_OBJECT

  public:
    SensorAgent( SensorManager *sm );
    virtual ~SensorAgent();

    virtual bool start( const TQString &host, const TQString &shell,
                        const TQString &command = "", int port = -1 ) = 0;

    /**
      This function should only be used by the the SensorManager and
      never by the SensorClients directly since the pointer returned by
      engaged is not guaranteed to be valid. Only the SensorManager knows
      whether a SensorAgent pointer is still valid or not.

      This function sends out a command to the sensor and notifies the
      agent to return the answer to 'client'. The 'id' can be used by the
      client to identify the answer. It is only passed through and never
      used by the SensorAgent. So it can be any value the client suits to
      use.
     */
    bool sendRequest( const TQString &req, SensorClient *client, int id = 0 );

    virtual void hostInfo( TQString &sh, TQString &cmd, int &port ) const = 0;

    void disconnectClient( SensorClient *client );

    const TQString &hostName() const;
	
  signals:
    void reconfigure( const SensorAgent* );

  protected:
    void processAnswer( const TQString &buffer );
    void executeCommand();

    SensorManager *sensorManager();

    void setDaemonOnLine( bool value );
    bool daemonOnLine() const;

    void setTransmitting( bool value );
    bool transmitting() const;

    void setHostName( const TQString &hostName );

  private:
    virtual bool writeMsg( const char *msg, int len ) = 0;
    virtual bool txReady() = 0;

    int mState;
    TQPtrList<SensorRequest> mInputFIFO;
    TQPtrList<SensorRequest> mProcessingFIFO;
    TQString mAnswerBuffer;
    TQString mErrorBuffer;

    SensorManager *mSensorManager;

    bool mDaemonOnLine;
    bool mTransmitting;
    TQString mHostName;
};

/**
  This auxilliary class is used to store requests during their processing.
*/
class SensorRequest
{
  public:
    SensorRequest( const TQString &request, SensorClient *client, int id );
    ~SensorRequest();

    void setRequest( const TQString& );
    TQString request() const;

    void setClient( SensorClient* );
    SensorClient *client();

    void setId( int );
    int id();

  private:
    TQString mRequest;
    SensorClient *mClient;
    int mId;
};

}
	
#endif