2
KSysGuard, the KDE System Guard
4
Copyright (c) 1999 - 2001 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.
27
#include "SensorClient.h"
28
#include "SensorManager.h"
30
#include "SensorSocketAgent.h"
32
using namespace KSGRD;
34
SensorSocketAgent::SensorSocketAgent( SensorManager *sm )
38
connect( &mSocket, SIGNAL( error( QAbstractSocket::SocketError ) ), SLOT( error( QAbstractSocket::SocketError ) ) );
39
connect( &mSocket, SIGNAL( bytesWritten( qint64 ) ), SLOT( msgSent( ) ) );
40
connect( &mSocket, SIGNAL( readyRead() ), SLOT( msgRcvd() ) );
41
connect( &mSocket, SIGNAL( disconnected() ), SLOT( connectionClosed() ) );
44
SensorSocketAgent::~SensorSocketAgent()
46
mSocket.write( "quit\n", sizeof( "quit\n" ) );
50
bool SensorSocketAgent::start( const QString &host, const QString&,
51
const QString&, int port )
54
kDebug(1215) << "SensorSocketAgent::start: Invalid port " << port;
59
mSocket.connectToHost( hostName(), mPort );
64
void SensorSocketAgent::hostInfo( QString &shell, QString &command, int &port ) const
71
void SensorSocketAgent::msgSent( )
73
if ( mSocket.bytesToWrite() != 0 )
76
// Try to send next request if available.
80
void SensorSocketAgent::msgRcvd()
82
int buflen = mSocket.bytesAvailable();
83
char* buffer = new char[ buflen ];
85
mSocket.read( buffer, buflen );
87
processAnswer( buffer, buflen );
91
void SensorSocketAgent::connectionClosed()
93
setDaemonOnLine( false );
95
sensorManager()->disengage( this ); //delete ourselves
99
void SensorSocketAgent::error( QAbstractSocket::SocketError id )
102
case QAbstractSocket::ConnectionRefusedError:
103
SensorMgr->notify( i18n( "Connection to %1 refused" ,
106
case QAbstractSocket::HostNotFoundError:
107
SensorMgr->notify( i18n( "Host %1 not found" ,
110
case QAbstractSocket::NetworkError:
111
SensorMgr->notify( i18n( "An error occurred with the network (e.g. the network cable was accidentally unplugged) for host %1.",
115
SensorMgr->notify( i18n( "Error for host %1: %2",
116
hostName(), mSocket.errorString() ) );
119
setDaemonOnLine( false );
121
sensorManager()->disengage( this );
124
bool SensorSocketAgent::writeMsg( const char *msg, int len )
126
int writtenLength = mSocket.write( msg, len );
128
return writtenLength == len;
131
#include "SensorSocketAgent.moc"