@ -17,10 +17,10 @@
# include "knutnet.h"
# include < qtextstream.h>
# include < qstring.h>
# include < qcstring.h>
# include < qtimer.h>
# include < t qtextstream.h>
# include < t qstring.h>
# include < t qcstring.h>
# include < t qtimer.h>
# include <unistd.h> // for function sleep
@ -31,12 +31,12 @@
/****** CONSTS ***********/
//const Q_ULONG rBufferLen = 1024;
//const T Q_ULONG rBufferLen = 1024;
KNutNet : : KNutNet ( const QString upsAddress , const QString upsName , const unsigned short port , unsigned int countRepeat , const unsigned int delay )
: QObject( ) , m_upsAddress ( upsAddress ) , m_upsName ( upsName ) , m_countRepeat ( countRepeat ) , m_port ( port ) , m_delay ( delay ) {
KNutNet : : KNutNet ( const T QString upsAddress , const T QString upsName , const unsigned short port , unsigned int countRepeat , const unsigned int delay )
: T QObject( ) , m_upsAddress ( upsAddress ) , m_upsName ( upsName ) , m_countRepeat ( countRepeat ) , m_port ( port ) , m_delay ( delay ) {
//qDebug ("KNutNet::KNutNet");
@ -52,22 +52,22 @@ KNutNet::KNutNet (const QString upsAddress, const QString upsName, const unsigne
m_description = false ; // popis neni natazen - description is not loaded
m_unConnectTimer = new QTimer( this ) ;
connect ( m_unConnectTimer , SIGNAL( timeout ( ) ) , this , SLOT( slotTimerReconnect ( ) ) ) ;
m_unConnectTimer = new T QTimer( this ) ;
connect ( m_unConnectTimer , TQT_ SIGNAL( timeout ( ) ) , this , TQT_ SLOT( slotTimerReconnect ( ) ) ) ;
m_error = NoError ;
m_commandSocket = new QSocket( this ) ;
connect ( m_commandSocket , SIGNAL( hostFound ( ) ) , this , SLOT( slotHostFound ( ) ) ) ;
connect ( m_commandSocket , SIGNAL( connected ( ) ) , this , SLOT( slotConnected ( ) ) ) ;
connect ( m_commandSocket , SIGNAL( connectionClosed ( ) ) , this , SLOT( slotConnectionClosed ( ) ) ) ;
connect ( m_commandSocket , SIGNAL( error ( int ) ) , this , SLOT( slotConnectionError ( int ) ) ) ;
m_commandSocket = new T QSocket( this ) ;
connect ( m_commandSocket , TQT_ SIGNAL( hostFound ( ) ) , this , TQT_ SLOT( slotHostFound ( ) ) ) ;
connect ( m_commandSocket , TQT_ SIGNAL( connected ( ) ) , this , TQT_ SLOT( slotConnected ( ) ) ) ;
connect ( m_commandSocket , TQT_ SIGNAL( connectionClosed ( ) ) , this , TQT_ SLOT( slotConnectionClosed ( ) ) ) ;
connect ( m_commandSocket , TQT_ SIGNAL( error ( int ) ) , this , TQT_ SLOT( slotConnectionError ( int ) ) ) ;
}
KNutNet : : ~ KNutNet ( ) {
QCString inBuffer ;
QString outBuffer ;
T QCString inBuffer ;
T QString outBuffer ;
close ( ) ; // close connetion when is existed
while ( m_state = = Closing ) {
@ -79,8 +79,8 @@ KNutNet::~KNutNet(){
void KNutNet : : close ( void ) {
// std::cout << "--KNutNet::close" << std::endl;
QCString inBuffer ;
QString outBuffer ;
T QCString inBuffer ;
T QString outBuffer ;
m_unConnectTimer - > stop ( ) ;
deleteVars ( ) ;
@ -96,8 +96,8 @@ void KNutNet::close (void) {
m_commandSocket - > clearPendingData ( ) ; // data in output buffer will be errased
m_commandSocket - > close ( ) ; // closes the socket
if ( m_commandSocket - > state ( ) = = QSocket: : Closing ) {
connect ( m_commandSocket , SIGNAL( delayedCloseFinished ( ) ) , this , SLOT( slotClosed ( ) ) ) ;
if ( m_commandSocket - > state ( ) = = T QSocket: : Closing ) {
connect ( m_commandSocket , TQT_ SIGNAL( delayedCloseFinished ( ) ) , this , TQT_ SLOT( slotClosed ( ) ) ) ;
}
else {
slotClosed ( ) ;
@ -107,15 +107,15 @@ void KNutNet::close (void) {
void KNutNet : : slotClosed ( void ) {
disconnect ( m_commandSocket , SIGNAL( delayedCloseFinished ( ) ) , this , SLOT( slotClosed ( ) ) ) ;
disconnect ( m_commandSocket , TQT_ SIGNAL( delayedCloseFinished ( ) ) , this , TQT_ SLOT( slotClosed ( ) ) ) ;
m_state = Idle ;
}
void KNutNet : : open ( void ) {
QCString inBuffer ;
QString outBuffer ;
T QCString inBuffer ;
T QString outBuffer ;
if ( ( m_state = = Connected ) | | ( m_state = = Connecting ) ) close ( ) ; // close connetion when is existed
else {
@ -124,7 +124,7 @@ void KNutNet::open (void) {
}
}
if ( m_upsAddress ! = " " ) {
if ( m_commandSocket - > state ( ) ! = QSocket: : Connecting ) {
if ( m_commandSocket - > state ( ) ! = T QSocket: : Connecting ) {
m_firstConnect = true ;
m_numberConnection = 0 ;
m_state = HostLookup ;
@ -136,7 +136,7 @@ void KNutNet::open (void) {
}
void KNutNet : : newUPS ( const QString upsAddress , const QString upsName , const unsigned short port ) {
void KNutNet : : newUPS ( const T QString upsAddress , const T QString upsName , const unsigned short port ) {
if ( ( m_state = = Connected ) | | ( m_state = = Connecting ) ) {
close ( ) ;
@ -201,7 +201,7 @@ int KNutNet::getUpsVars ( void) {
default :
return 0 ;
}
if ( read Status( ) ! = KNutNet : : WAIT ) return returnValue ;
if ( read tq Status( ) ! = KNutNet : : WAIT ) return returnValue ;
countWaitRevision - - ;
if ( countWaitRevision ) sleep ( 2 ) ;
}
@ -256,11 +256,11 @@ int KNutNet::getDescription (bool always) {
}
int KNutNet : : instantCommand ( const QString command , const QString userName , const QString password , const bool onlyCommand ) {
int KNutNet : : instantCommand ( const T QString command , const T QString userName , const T QString password , const bool onlyCommand ) {
m_error = 0 ; // vynulujeme chyby
if ( m_state = = Connected ) {
QString outBuffer ;
T QString outBuffer ;
// funkce sendComm sama mastavi promenou error
if ( onlyCommand ) {
@ -301,11 +301,11 @@ int KNutNet::instantCommand (const QString command, const QString userName, cons
}
int KNutNet : : setVariable ( const QString variable , const QString value , const QString userName , const QString password , const bool onlyVariable ) {
int KNutNet : : setVariable ( const T QString variable , const T QString value , const T QString userName , const T QString password , const bool onlyVariable ) {
m_error = 0 ; // vynulujeme chyby
if ( m_state = = Connected ) {
QString outBuffer ;
QString setCommand ;
T QString outBuffer ;
T QString setCommand ;
switch ( m_nutProtocol ) {
case 1 : setCommand = " SET " ;
@ -387,10 +387,10 @@ int KNutNet::readIComm (const int seqNumber, upsICommDef& upsIComm) {
}
int KNutNet : : readVars ( const QString name , struct upsVarDef & allVar ) {
int KNutNet : : readVars ( const T QString name , struct upsVarDef & allVar ) {
m_error = 0 ;
if ( m_state = = Connected ) {
QValueVector< upsVarDef > : : const_iterator it ;
T QValueVector< upsVarDef > : : const_iterator it ;
for ( it = m_listVars . begin ( ) ; it ! = m_listVars . end ( ) ; it + + ) {
if ( ( * it ) . upsVarName = = name ) {
allVar = ( * it ) ;
@ -408,7 +408,7 @@ int KNutNet::readVars (const QString name, struct upsVarDef& allVar) {
m_error = 0 ;
if ( m_state = = Connected ) {
int n = 1 ;
QValueVector< upsVarDef > : : const_iterator it ;
T QValueVector< upsVarDef > : : const_iterator it ;
for ( it = m_listVars . begin ( ) ; it ! = m_listVars . end ( ) ; it + + ) {
if ( ( typVar = = AllVars ) | | ( ( typVar = = ROVars ) & & ( ( * it ) . upsVarType ) ) | |
@ -427,11 +427,11 @@ int KNutNet::readVars (const QString name, struct upsVarDef& allVar) {
}
QString KNutNet : : readStringVar ( const QString name ) {
T QString KNutNet : : readStringVar ( const T QString name ) {
m_error = 0 ;
if ( m_state = = Connected ) {
QValueVector< upsVarDef > : : const_iterator it ;
T QValueVector< upsVarDef > : : const_iterator it ;
for ( it = m_listVars . begin ( ) ; it ! = m_listVars . end ( ) ; it + + ) {
if ( ( * it ) . upsVarName = = name ) return ( * it ) . upsValue ;
}
@ -442,18 +442,18 @@ QString KNutNet::readStringVar (const QString name) {
}
QString KNutNet : : readEnumValueVar ( const QString name , const int valueNumber ) {
T QString KNutNet : : readEnumValueVar ( const T QString name , const int valueNumber ) {
m_error = 0 ;
if ( m_state = = Connected ) {
// #if defined (KDE_VERSION_MAJOR)
// #if KDE_VERSION_MAJOR >= 3
QValueVector< upsVarDef > : : const_iterator it ;
T QValueVector< upsVarDef > : : const_iterator it ;
// #else
// QValueList<upsVar>::ConstIterator it;
// T QValueList<upsVar>::ConstIterator it;
// #endif
// #else
// QValueList<upsVar>::ConstIterator it;
// T QValueList<upsVar>::ConstIterator it;
// #endif
@ -474,19 +474,19 @@ QString KNutNet::readEnumValueVar (const QString name, const int valueNumber) {
}
int KNutNet : : read Status( void ) {
int KNutNet : : read tq Status( void ) {
m_error = 0 ;
return m_upsStatusVar ;
}
int KNutNet : : setActivate ( const QString name ) {
int KNutNet : : setActivate ( const T QString name ) {
return activate ( name , true ) ;
}
int KNutNet : : unSetActivate ( const QString name ) {
int KNutNet : : unSetActivate ( const T QString name ) {
return activate ( name , false ) ;
}
@ -496,11 +496,11 @@ int KNutNet::unSetActivateAll ( void ) {
}
int KNutNet : : existName ( const QString name ) {
int KNutNet : : existName ( const T QString name ) {
m_error = 0 ;
if ( m_state = = Connected ) {
QValueVector< upsVarDef > : : const_iterator it ;
T QValueVector< upsVarDef > : : const_iterator it ;
for ( it = m_listVars . begin ( ) ; it ! = m_listVars . end ( ) ; it + + ) {
if ( ( * it ) . upsVarName = = name ) return 0 ;
}
@ -518,8 +518,8 @@ int KNutNet::existName ( const QString name ) {
int KNutNet : : version ( int countRepeat , const int delay ) {
QCString inBuffer ;
QString outBuffer ;
T QCString inBuffer ;
T QString outBuffer ;
m_error = 0 ;
do {
@ -528,12 +528,12 @@ int KNutNet::version (int countRepeat, const int delay) {
outBuffer = outBuffer . stripWhiteSpace ( ) ;
if ( outBuffer . length ( ) > 0 ) {
outBuffer = outBuffer . mid ( outBuffer . find( " upsd " ) + 4 ) ;
int n = outBuffer . find( " . " ) ;
outBuffer = outBuffer . mid ( outBuffer . tq find( " upsd " ) + 4 ) ;
int n = outBuffer . tq find( " . " ) ;
if ( n > 0 ) {
QString firstNumber = outBuffer . left ( n ) ;
QString secondNumber = outBuffer . mid ( n + 1 ) ;
int n = secondNumber . find( " . " ) ;
T QString firstNumber = outBuffer . left ( n ) ;
T QString secondNumber = outBuffer . mid ( n + 1 ) ;
int n = secondNumber . tq find( " . " ) ;
if ( n > 0 ) {
bool ok ;
secondNumber = secondNumber . left ( n ) ;
@ -567,20 +567,20 @@ int KNutNet::version (int countRepeat, const int delay) {
int KNutNet : : getFirstUpsName ( QString& firstUpsName ) {
QCString inBuffer ;
QString outBuffer ;
QString varOutBuffer ;
int KNutNet : : getFirstUpsName ( T QString& firstUpsName ) {
T QCString inBuffer ;
T QString outBuffer ;
T QString varOutBuffer ;
int lenString ;
m_error = 0 ;
inBuffer = " LIST UPS \n " ;
if ( ! ( m_error = getUpsData ( inBuffer , outBuffer , " END LIST UPS " ) ) ) {
QString inLine , upsNameRet , varName , value ;
T QString inLine , upsNameRet , varName , value ;
int key , typeValue ;
bool beginList = false ;
QTextIStream varInputStream ( & outBuffer ) ;
T QTextIStream varInputStream ( & outBuffer ) ;
while ( ! ( inLine = varInputStream . readLine ( ) ) . isNull ( ) ) {
key = parseLine ( inLine , upsNameRet , varName , value , typeValue , lenString ) ;
switch ( key ) {
@ -612,9 +612,9 @@ int KNutNet::getFirstUpsName (QString& firstUpsName) {
int KNutNet : : setKey ( const QString line ) {
int KNutNet : : setKey ( const T QString line ) {
QString myLine = line . stripWhiteSpace ( ) ;
T QString myLine = line . stripWhiteSpace ( ) ;
if ( myLine = = " OK " ) return OK ;
if ( myLine = = " ERR " ) return ERR ;
if ( myLine = = " BEGIN " ) return BEGIN ;
@ -633,16 +633,16 @@ int KNutNet::setKey (const QString line) {
return NONE ;
}
QString KNutNet : : parseValue ( const QString line ) {
T QString KNutNet : : parseValue ( const T QString line ) {
if ( line . isEmpty ( ) ) return " " ;
if ( line [ 0 ] ! = " \" " ) {
if ( ( m_posChar = line . find( ' ' ) ) = = - 1 ) return line ;
if ( ( m_posChar = line . tq find( ' ' ) ) = = - 1 ) return line ;
else return line . left ( m_posChar + 1 ) ;
}
else {
int len = line . length ( ) ;
QString outString = " " ;
T QString outString = " " ;
for ( int i = 1 ; i < len ; i + + ) {
if ( line [ i ] = = " \\ " ) {
if ( ( i + 1 ) < len ) {
@ -665,18 +665,18 @@ QString KNutNet::parseValue (const QString line) {
return " " ;
}
int KNutNet : : parseTypeValue ( QString line , int & lenString ) {
int KNutNet : : parseTypeValue ( T QString line , int & lenString ) {
int ret = 0 ;
QString word ;
T QString word ;
lenString = 0 ;
if ( line . isEmpty ( ) ) return 0 ;
QTextIStream inputStream ( & line ) ;
T QTextIStream inputStream ( & line ) ;
while ( ! inputStream . atEnd ( ) ) {
inputStream > > word ;
if ( word = = " RW " ) ret + = RW_FLAG ;
if ( word = = " ENUM " ) ret + = ENUM_FLAG ;
if ( word . find( " STRING: " ) ! = - 1 ) {
if ( word . tq find( " STRING: " ) ! = - 1 ) {
word = word . mid ( 7 ) ;
ret + = STRING_FLAG ;
lenString = word . toInt ( ) ;
@ -686,9 +686,9 @@ int KNutNet::parseTypeValue (QString line, int& lenString ) {
}
int KNutNet : : parseLine ( QString& line , QString& upsName , QString& varName , QString& value , int & typeValue , int & lenString ) {
int KNutNet : : parseLine ( T QString& line , T QString& upsName , T QString& varName , T QString& value , int & typeValue , int & lenString ) {
int posChar ;
QString word1 , word2 , word3 ;
T QString word1 , word2 , word3 ;
int key1 , key2 , key3 ;
line = line . stripWhiteSpace ( ) ;
@ -700,7 +700,7 @@ int KNutNet::parseLine(QString& line, QString& upsName ,QString& varName, QStrin
if ( line . isEmpty ( ) ) return NONE ;
if ( ( posChar = line . find( ' ' ) ) = = - 1 ) {
if ( ( posChar = line . tq find( ' ' ) ) = = - 1 ) {
if ( setKey ( line ) = = OK ) return OK ;
else return NONE ;
}
@ -718,7 +718,7 @@ int KNutNet::parseLine(QString& line, QString& upsName ,QString& varName, QStrin
value = parseValue ( line ) ;
return key1 ;
default :
if ( ( posChar = line . find( ' ' ) ) = = - 1 ) return NONE ;
if ( ( posChar = line . tq find( ' ' ) ) = = - 1 ) return NONE ;
word2 = line . left ( posChar ) ;
key2 = setKey ( word2 ) ;
line = line . mid ( posChar + 1 ) ;
@ -740,7 +740,7 @@ int KNutNet::parseLine(QString& line, QString& upsName ,QString& varName, QStrin
return key1 ;
}
if ( ( posChar = line . find( ' ' ) ) = = - 1 ) return NONE ;
if ( ( posChar = line . tq find( ' ' ) ) = = - 1 ) return NONE ;
word3 = line . left ( posChar ) ;
key3 = setKey ( word3 ) ;
@ -787,7 +787,7 @@ int KNutNet::parseLine(QString& line, QString& upsName ,QString& varName, QStrin
return BEGIN_LIST_CMD ;
}
if ( key3 = = ENUM ) {
if ( ( posChar = line . find( ' ' ) ) = = - 1 ) return NONE ;
if ( ( posChar = line . tq find( ' ' ) ) = = - 1 ) return NONE ;
upsName = line . left ( posChar ) ;
line = line . mid ( posChar + 1 ) ;
varName = line . stripWhiteSpace ( ) ;
@ -809,7 +809,7 @@ int KNutNet::parseLine(QString& line, QString& upsName ,QString& varName, QStrin
return END_LIST_CMD ;
}
if ( key3 = = ENUM ) {
if ( ( posChar = line . find( ' ' ) ) = = - 1 ) return NONE ;
if ( ( posChar = line . tq find( ' ' ) ) = = - 1 ) return NONE ;
upsName = line . left ( posChar ) ;
line = line . mid ( posChar + 1 ) ;
varName = line . stripWhiteSpace ( ) ;
@ -824,25 +824,25 @@ int KNutNet::parseLine(QString& line, QString& upsName ,QString& varName, QStrin
}
int KNutNet : : newDescription ( const QCString inBuffer , QString& upsDescription ) {
QString outBuffer ;
int KNutNet : : newDescription ( const T QCString inBuffer , T QString& upsDescription ) {
T QString outBuffer ;
if ( ! ( m_error = getUpsData ( inBuffer , outBuffer ) ) ) {
outBuffer = outBuffer . stripWhiteSpace ( ) ;
QString word1 , word2 , word3 ;
T QString word1 , word2 , word3 ;
if ( ( m_posChar = outBuffer . find( ' ' ) ) = = - 1 )
if ( ( m_posChar = outBuffer . tq find( ' ' ) ) = = - 1 )
word1 = outBuffer ;
else {
word1 = outBuffer . left ( m_posChar ) ;
word2 = outBuffer . mid ( m_posChar + 1 ) ;
}
if ( word1 = = " DESC " ) {
if ( ( m_posChar = word2 . find( ' \" ' ) ) = = - 1 ) word3 = " " ;
if ( ( m_posChar = word2 . tq find( ' \" ' ) ) = = - 1 ) word3 = " " ;
else
{
word3 = word2 . mid ( m_posChar + 1 ) ;
if ( ( m_posChar = word3 . find( ' \" ' ) ) ! = - 1 ) word3 = word3 . left ( m_posChar ) ;
if ( ( m_posChar = word3 . tq find( ' \" ' ) ) ! = - 1 ) word3 = word3 . left ( m_posChar ) ;
}
if ( ! word3 . isEmpty ( ) ) upsDescription = word3 ;
}
@ -857,9 +857,9 @@ int KNutNet::newDescription (const QCString inBuffer, QString& upsDescription)
void KNutNet : : cleanConnecting ( void ) {
Q_ULONG rMaxLen ;
QCString recvBuffer ( rBufferLen ) ;
Q_LONG lengthInputData ;
T Q_ULONG rMaxLen ;
T QCString recvBuffer ( rBufferLen ) ;
T Q_LONG lengthInputData ;
int n = 0 ;
while ( m_commandSocket - > bytesAvailable ( ) > 0 ) {
@ -876,15 +876,15 @@ void KNutNet::cleanConnecting (void) {
}
int KNutNet : : getUpsData ( const QCString sBuffer , QString& rBuffer , const QCString endString ) {
int KNutNet : : getUpsData ( const T QCString sBuffer , T QString& rBuffer , const T QCString endString ) {
//rbufferLen a sbufferLen are maximal value of buffers
QCString recvBuffer ( rBufferLen ) ;
Q_LONG lengthInputData ;
Q_ULONG dataAvailable ;
T QCString recvBuffer ( rBufferLen ) ;
T Q_LONG lengthInputData ;
T Q_ULONG dataAvailable ;
QMutexLocker getUpsDataLocker ( & m_getUpsDataMutex ) ;
T QMutexLocker getUpsDataLocker ( & m_getUpsDataMutex ) ;
cleanConnecting ( ) ;
// first we clean input TCP buffer
@ -911,8 +911,8 @@ int KNutNet::getUpsData (const QCString sBuffer, QString& rBuffer, const QCStrin
// recvBuffer[lengthInputData]='\0';
//Problem is that
//for 64bit environment is Q_LONG defined like _int64 and
//for other environments is Q_LONG defined like long
//for 64bit environment is T Q_LONG defined like _int64 and
//for other environments is T Q_LONG defined like long
@ -920,14 +920,14 @@ int KNutNet::getUpsData (const QCString sBuffer, QString& rBuffer, const QCStrin
rBuffer . append ( recvBuffer . data ( ) ) ; // adds reading data to main input buffer
if ( endString . isEmpty ( ) ) endRecv = false ;
else {
if ( recvBuffer . findRev( endString ) = = - 1 ) {
if ( recvBuffer . tq findRev( endString . data ( ) ) = = - 1 ) {
//doesn't find right end of input data
if ( m_commandSocket - > bytesAvailable ( ) = = 0 ) m_commandSocket - > waitForMore ( 1000 ) ;
if ( m_commandSocket - > bytesAvailable ( ) > 0 ) endRecv = true ; // makes other cyckle og while
else endRecv = false ;
}
//finds right end of input data
else endRecv = false ; // we have found what we want to find
else endRecv = false ; // we have found what we want to tq find
}
} while ( endRecv ) ;
return 0 ; // all is OK
@ -935,8 +935,8 @@ int KNutNet::getUpsData (const QCString sBuffer, QString& rBuffer, const QCStrin
void KNutNet : : setRWVars ( const QString varName , const bool valueType , const int varMax , QValueVector< QString> * enumValues ) {
QValueVector< upsVarDef > : : iterator it ;
void KNutNet : : setRWVars ( const T QString varName , const bool valueType , const int varMax , T QValueVector< T QString> * enumValues ) {
T QValueVector< upsVarDef > : : iterator it ;
for ( it = m_listVars . begin ( ) ; it ! = m_listVars . end ( ) ; it + + ) {
if ( ( * it ) . upsVarName = = varName ) {
@ -949,7 +949,7 @@ int KNutNet::getUpsData (const QCString sBuffer, QString& rBuffer, const QCStrin
}
}
void KNutNet : : upsSetType ( struct upsVarDef & upsVar , const QString name , const QString value ) {
void KNutNet : : upsSetType ( struct upsVarDef & upsVar , const T QString name , const T QString value ) {
if ( ( ( m_nutVariables = 2 ) & & ( name = = " STATUS " ) ) | | ( ( m_nutVariables = 2 ) & & ( name = = " ups.status " ) ) )
upsVar . upsVarActivate = true ;
@ -968,12 +968,12 @@ void KNutNet::upsSetType (struct upsVarDef& upsVar, const QString name, const QS
void KNutNet : : deleteVars ( void ) {
// #if defined (KDE_VERSION_MAJOR)
// #if KDE_VERSION_MAJOR >= 3
QValueVector< upsVarDef > : : iterator it ;
T QValueVector< upsVarDef > : : iterator it ;
// #else
// QValueList<upsVar>::Iterator it;
// T QValueList<upsVar>::Iterator it;
// #endif
// #else
// QValueList<upsVar>::Iterator it;
// T QValueList<upsVar>::Iterator it;
// #endif
for ( it = m_listVars . begin ( ) ; it ! = m_listVars . end ( ) ; it + + ) {
if ( ( * it ) . upsEnumValues ! = 0 ) {
@ -985,10 +985,10 @@ void KNutNet::deleteVars (void) {
m_listIComms . clear ( ) ;
}
void KNutNet : : genStatusFlags ( QString value ) {
void KNutNet : : genStatusFlags ( T QString value ) {
m_upsStatusVar = 0 ;
QTextIStream inputStream ( & value ) ;
QString word ;
T QTextIStream inputStream ( & value ) ;
T QString word ;
while ( ! inputStream . atEnd ( ) ) {
inputStream > > word ;
if ( word = = " OFF " ) m_upsStatusVar + = OFF ;
@ -1016,11 +1016,11 @@ void KNutNet::genStatusFlags (QString value) {
int KNutNet : : getDescription1 ( bool always ) {
if ( always | | ( ! m_description ) ) {
QCString inBuffer ;
QString outBuffer ;
T QCString inBuffer ;
T QString outBuffer ;
QValueVector< upsVarDef > : : iterator itv ;
QValueVector< upsICommDef > : : iterator itc ;
T QValueVector< upsVarDef > : : iterator itv ;
T QValueVector< upsICommDef > : : iterator itc ;
for ( itv = m_listVars . begin ( ) ; itv ! = m_listVars . end ( ) ; itv + + ) {
//nacteme promenou
inBuffer = " VARDESC " + ( * itv ) . upsVarName + " \n " ;
@ -1050,16 +1050,16 @@ int KNutNet::getDescription1 (bool always) {
int KNutNet : : getDescription2 ( bool always ) {
if ( always | | ( ! m_description ) ) {
QCString inBuffer ;
QString outBuffer ;
QString upsNameRet ;
QString varName ;
QString value ;
T QCString inBuffer ;
T QString outBuffer ;
T QString upsNameRet ;
T QString varName ;
T QString value ;
int typeValue ;
int lenString ;
QValueVector< upsVarDef > : : iterator itv ;
QValueVector< upsICommDef > : : iterator itc ;
T QValueVector< upsVarDef > : : iterator itv ;
T QValueVector< upsICommDef > : : iterator itc ;
for ( itv = m_listVars . begin ( ) ; itv ! = m_listVars . end ( ) ; itv + + ) {
//nacteme promenou
inBuffer = " GET DESC " + m_upsName + " " + ( * itv ) . upsVarName + " \n " ;
@ -1127,9 +1127,9 @@ int KNutNet::getDescription2 (bool always) {
int KNutNet : : getUpsVars1 ( void ) {
// getUpsVars nacte promene a jejich typ
// vraci kod chyby nebo 0 pokud je vse v poradku
QCString inBuffer ;
QString outBuffer ;
QString varOutBuffer ;
T QCString inBuffer ;
T QString outBuffer ;
T QString varOutBuffer ;
upsVarDef upsVar ;
upsICommDef upsIComm ;
@ -1145,8 +1145,8 @@ int KNutNet::getUpsVars1 ( void) {
outBuffer = outBuffer . stripWhiteSpace ( ) ;
if ( outBuffer . length ( ) > 0 ) {
// precteme data
QTextIStream inputStream ( & outBuffer ) ;
QString word ;
T QTextIStream inputStream ( & outBuffer ) ;
T QString word ;
int count = 1 ;
while ( ! inputStream . atEnd ( ) ) {
inputStream > > word ;
@ -1193,8 +1193,8 @@ int KNutNet::getUpsVars1 ( void) {
outBuffer = outBuffer . stripWhiteSpace ( ) ;
if ( ! outBuffer . isEmpty ( ) ) {
// precteme data
QTextIStream inputStream ( & outBuffer ) ;
QString word ;
T QTextIStream inputStream ( & outBuffer ) ;
T QString word ;
int count = 1 ;
bool valueType ;
int varMax ;
@ -1229,8 +1229,8 @@ int KNutNet::getUpsVars1 ( void) {
if ( ! ( m_error = getUpsData ( inBuffer , varOutBuffer ) ) ) {
varOutBuffer = varOutBuffer . stripWhiteSpace ( ) ;
if ( ! outBuffer . isEmpty ( ) ) {
QTextIStream varInputStream ( & varOutBuffer ) ;
QString word1 , word2 , word3 ;
T QTextIStream varInputStream ( & varOutBuffer ) ;
T QString word1 , word2 , word3 ;
varInputStream > > word1 ;
varInputStream > > word2 ;
varInputStream > > word3 ;
@ -1267,7 +1267,7 @@ int KNutNet::getUpsVars1 ( void) {
else return m_error ;
// ********** ENUM / STRING ******************
QValueVector< QString> * enumString = 0 ;
T QValueVector< T QString> * enumString = 0 ;
if ( ! valueType ) {
// nacteme enum hodnoty
inBuffer = " ENUM " ;
@ -1281,26 +1281,26 @@ int KNutNet::getUpsVars1 ( void) {
if ( ! ( m_error = getUpsData ( inBuffer , varOutBuffer , " END \n " ) ) ) {
// varOutBuffer.stripWhiteSpace(); nemuze provest protoze bychom si odstranili konce radek
if ( ! varOutBuffer . isEmpty ( ) ) {
QString inLine , word1 , word2 ;
QTextIStream varInputStream ( & varOutBuffer ) ;
T QString inLine , word1 , word2 ;
T QTextIStream varInputStream ( & varOutBuffer ) ;
int inCountLine = 1 ;
while ( ! ( inLine = varInputStream . readLine ( ) ) . isNull ( ) ) {
inLine = inLine . stripWhiteSpace ( ) ;
if ( ( m_posChar = inLine . find( ' ' ) ) = = - 1 ) word1 = inLine ;
if ( ( m_posChar = inLine . tq find( ' ' ) ) = = - 1 ) word1 = inLine ;
else {
word1 = inLine . left ( m_posChar ) ;
inLine = inLine . mid ( m_posChar + 1 ) ;
}
if ( word1 . isEmpty ( ) ) { m_error = UnknownFormat ; return m_error ; }
if ( inCountLine = = 1 ) {
if ( ( m_posChar = inLine . find( ' ' ) ) = = - 1 ) word2 = inLine ;
if ( ( m_posChar = inLine . tq find( ' ' ) ) = = - 1 ) word2 = inLine ;
else word2 = inLine . left ( m_posChar ) ;
if ( word1 = = " ENUM " ) {
if ( word2 ! = word ) { m_error = UnknownFormat ; return m_error ; }
varMax = 0 ;
inCountLine + + ;
enumString = new QValueVector< QString> ;
enumString = new T QValueVector< T QString> ;
enumString - > clear ( ) ;
}
else {
@ -1313,10 +1313,10 @@ int KNutNet::getUpsVars1 ( void) {
else {
if ( word1 = = " END " ) break ;
if ( word1 ! = " OPTION " ) { m_error = UnknownFormat ; return m_error ; }
if ( ( m_posChar = inLine . find( ' \" ' ) ) = = - 1 ) word2 = " " ;
if ( ( m_posChar = inLine . tq find( ' \" ' ) ) = = - 1 ) word2 = " " ;
else {
word2 = inLine . mid ( m_posChar + 1 ) ;
if ( ( m_posChar = word2 . find( ' \" ' ) ) ! = - 1 ) word2 = word2 . left ( m_posChar ) ;
if ( ( m_posChar = word2 . tq find( ' \" ' ) ) ! = - 1 ) word2 = word2 . left ( m_posChar ) ;
}
enumString - > push_back ( word2 ) ;
varMax + + ;
@ -1352,8 +1352,8 @@ int KNutNet::getUpsVars1 ( void) {
outBuffer = outBuffer . stripWhiteSpace ( ) ;
if ( ! outBuffer . isEmpty ( ) ) {
// precteme data
QTextIStream inputStream ( & outBuffer ) ;
QString word ;
T QTextIStream inputStream ( & outBuffer ) ;
T QString word ;
int count = 1 ;
while ( ! inputStream . atEnd ( ) ) {
inputStream > > word ;
@ -1392,9 +1392,9 @@ int KNutNet::getUpsVars1 ( void) {
int KNutNet : : getUpsVars2 ( void ) {
QCString inBuffer ;
QString outBuffer ;
QString varOutBuffer ;
T QCString inBuffer ;
T QString outBuffer ;
T QString varOutBuffer ;
upsVarDef upsVar ;
upsICommDef upsIComm ;
int key ;
@ -1402,12 +1402,12 @@ int KNutNet::getUpsVars2 ( void) {
int lenString ;
int varMax = 0 ;
QValueVector< QString> * enumString = 0 ;
T QValueVector< T QString> * enumString = 0 ;
inBuffer = " LIST VAR " + m_upsName + " \n " ;
if ( ! ( m_error = getUpsData ( inBuffer , outBuffer , " END LIST VAR " ) ) ) {
QString inLine , upsNameRet , varName , varNameRet , value ;
T QString inLine , upsNameRet , varName , varNameRet , value ;
bool beginList = false ;
QTextIStream varInputStream ( & outBuffer ) ;
T QTextIStream varInputStream ( & outBuffer ) ;
while ( ! ( inLine = varInputStream . readLine ( ) ) . isNull ( ) ) {
key = parseLine ( inLine , upsNameRet , varName , value , typeValue , lenString ) ;
@ -1434,14 +1434,14 @@ int KNutNet::getUpsVars2 ( void) {
inBuffer = " LIST ENUM " + m_upsName + " " + varName + " \n " ;
if ( ! ( m_error = getUpsData ( inBuffer , varOutBuffer , " END LIST ENUM " ) ) ) {
bool beginEnumList = false ;
QTextIStream varInputStream ( & varOutBuffer ) ;
T QTextIStream varInputStream ( & varOutBuffer ) ;
while ( ! ( inLine = varInputStream . readLine ( ) ) . isNull ( ) ) {
key = parseLine ( inLine , upsNameRet , varName , value , typeValue , lenString ) ;
switch ( key ) {
case BEGIN_LIST_ENUM :
beginEnumList = true ;
varMax = 0 ;
enumString = new QValueVector< QString> ;
enumString = new T QValueVector< T QString> ;
enumString - > clear ( ) ;
upsVar . upsEnumValues = enumString ;
break ;
@ -1503,12 +1503,12 @@ int KNutNet::getUpsVars2 ( void) {
inBuffer = " LIST CMD " + m_upsName + " \n " ;
if ( ! ( m_error = getUpsData ( inBuffer , outBuffer , " END LIST CMD " ) ) ) {
QString inLine , upsNameRet , varName , value ;
T QString inLine , upsNameRet , varName , value ;
int key , typeValue ;
bool beginList = false ;
//std::cout << "CMD Buffer " << outBuffer << std::endl;
QTextIStream varInputStream ( & outBuffer ) ;
T QTextIStream varInputStream ( & outBuffer ) ;
while ( ! ( inLine = varInputStream . readLine ( ) ) . isNull ( ) ) {
key = parseLine ( inLine , upsNameRet , varName , value , typeValue , lenString ) ;
//std::cout << "CMD Line " << inLine << std::endl;
@ -1545,10 +1545,10 @@ int KNutNet::getUpsVars2 ( void) {
int KNutNet : : getUpsValues1 ( const bool allVars ) { // allVars = true vse; allVars = false jen activate
QString endChar ;
QCString inBuffer ;
QString outBuffer ;
QValueVector< upsVarDef > : : iterator it ;
T QString endChar ;
T QCString inBuffer ;
T QString outBuffer ;
T QValueVector< upsVarDef > : : iterator it ;
// Nacte hodnotu promenych
// reads value of variables
@ -1582,8 +1582,8 @@ int KNutNet::getUpsValues1 (const bool allVars ) {// allVars = true vse; allVars
emit getVarDesc ( m_numberVars , numberVar ) ;
if ( ! outBuffer . isEmpty ( ) ) {
QTextIStream inputStream ( & outBuffer ) ;
QString word1 , word2 , word3 ;
T QTextIStream inputStream ( & outBuffer ) ;
T QString word1 , word2 , word3 ;
inputStream > > word1 ;
inputStream > > word2 ;
if ( inputStream . atEnd ( ) ) { // neexistuje treti cast VALUE
@ -1604,7 +1604,7 @@ int KNutNet::getUpsValues1 (const bool allVars ) {// allVars = true vse; allVars
if ( word1 = = " ANS " ) {
// answer - odpoved
// odstranime pripadne jmeno upsky
if ( ( m_posChar = word2 . find( ' @ ' ) ) ! = - 1 ) word2 = word2 . left ( m_posChar ) ;
if ( ( m_posChar = word2 . tq find( ' @ ' ) ) ! = - 1 ) word2 = word2 . left ( m_posChar ) ;
if ( word2 ! = ( * it ) . upsVarName ) {
m_error = UnknownAnswer ;
return m_error ; // neni to odpoved na spravnou promennou
@ -1643,16 +1643,16 @@ int KNutNet::getUpsValues1 (const bool allVars ) {// allVars = true vse; allVars
int KNutNet : : getUpsValues2 ( const bool allVars ) { // allVars = true vse; allVars = false jen activate
QString varName ;
QString upsNameRet ;
QString value ;
T QString varName ;
T QString upsNameRet ;
T QString value ;
int typeValue ;
int lenString ;
// reads value of variables
QCString inBuffer ;
QString outBuffer ;
QValueVector< upsVarDef > : : iterator it ;
T QCString inBuffer ;
T QString outBuffer ;
T QValueVector< upsVarDef > : : iterator it ;
emit getVarDesc ( m_numberVars , 0 ) ;
int numberVar = 0 ;
@ -1704,11 +1704,11 @@ int KNutNet::getUpsValues2 (const bool allVars ) {// allVars = true vse; allVars
}
int KNutNet : : sendComm ( const QString command , const QString arg1 , const QString arg2 , const bool useUpsName ) {
int KNutNet : : sendComm ( const T QString command , const T QString arg1 , const T QString arg2 , const bool useUpsName ) {
int localError ;
// nenastavi promenou error ale nenuluje ji
QCString inBuffer ;
QString outBuffer ;
T QCString inBuffer ;
T QString outBuffer ;
switch ( m_nutProtocol ) {
case 1 :
@ -1728,8 +1728,8 @@ int KNutNet::sendComm (const QString command, const QString arg1, const QString
if ( ! ( localError = getUpsData ( inBuffer , outBuffer ) ) ) {
outBuffer = outBuffer . stripWhiteSpace ( ) ;
QTextIStream inputStream ( & outBuffer ) ;
QString word1 , word2 ;
T QTextIStream inputStream ( & outBuffer ) ;
T QString word1 , word2 ;
inputStream > > word1 ;
inputStream > > word2 ;
if ( word1 . isEmpty ( ) ) return UnknownAnswer ; // zadna odpoved
@ -1744,10 +1744,10 @@ int KNutNet::sendComm (const QString command, const QString arg1, const QString
}
int KNutNet : : activate ( const QString name , const bool setActivate ) {
int KNutNet : : activate ( const T QString name , const bool setActivate ) {
m_error = 0 ;
if ( m_state = = Connected ) {
QValueVector< upsVarDef > : : iterator it ;
T QValueVector< upsVarDef > : : iterator it ;
for ( it = m_listVars . begin ( ) ; it ! = m_listVars . end ( ) ; it + + ) {
if ( ( * it ) . upsVarName = = name ) {
( * it ) . upsVarActivate = setActivate ;
@ -1763,7 +1763,7 @@ int KNutNet::activate ( const QString name, const bool setActivate ) {
int KNutNet : : activateAll ( const bool setActivate ) {
m_error = 0 ;
if ( m_state = = Connected ) {
QValueVector< upsVarDef > : : iterator it ;
T QValueVector< upsVarDef > : : iterator it ;
for ( it = m_listVars . begin ( ) ; it ! = m_listVars . end ( ) ; it + + ) {
( * it ) . upsVarActivate = setActivate ;
}
@ -1773,12 +1773,12 @@ int KNutNet::activateAll ( const bool setActivate ) {
}
int KNutNet : : upsTranslateError ( const QString string ) {
int KNutNet : : upsTranslateError ( const T QString string ) {
if ( string = = " VAR-NOT-SUPPORTED " ) return VarNotSupported ;
if ( string = = " VAR-UNKNOWN " ) return VarUnknown ;
if ( string = = " ACCESS-DENIED " ) return AccessDenied ;
if ( string = = " PASSWORD-RE QUIRED" ) return PasswordRequired ;
if ( string = = " PASSWORD-RE T QUIRED" ) return PasswordRequired ;
if ( string = = " PASSWORD-INCORRECT " ) return PasswordIncorrect ;
if ( string = = " UNKNOWN-UPS " ) return UnknownUps ;
if ( string = = " ALREADY-LOGGED_IN " ) return AlreadyLoggedIn ;
@ -1807,7 +1807,7 @@ int KNutNet::upsTranslateError (const QString string) {
return UnknownErr ;
}
int KNutNet : : upsOldTranslateError ( const QString string ) {
int KNutNet : : upsOldTranslateError ( const T QString string ) {
if ( string = = " NOT-SUPPORTED " ) return VarNotSupported ;
if ( string = = " UNKNOWN " ) return VarUnknown ;
if ( string = = " DATA-STALE " ) return DataStale ;
@ -1823,13 +1823,13 @@ void KNutNet::slotConnectionError(int error) {
m_state = ConnectError ;
m_unConnectTimer - > stop ( ) ;
if ( error = = QSocket: : ErrHostNotFound ) {
if ( error = = T QSocket: : ErrHostNotFound ) {
error = NoSuchHost ;
emit connectionError ( error ) ;
return ;
}
//connection was refused // no connection
if ( ( error = = QSocket: : ErrConnectionRefused ) & & ( m_commandSocket - > state ( ) = = QSocket: : Idle ) ) {
if ( ( error = = T QSocket: : ErrConnectionRefused ) & & ( m_commandSocket - > state ( ) = = T QSocket: : Idle ) ) {
if ( m_firstConnect ) {
if ( m_numberConnection < m_countRepeat ) {
m_numberConnection + + ;
@ -1852,15 +1852,15 @@ void KNutNet::slotConnectionError(int error) {
}
return ;
}
if ( error = = QSocket: : ErrConnectionRefused ) {
if ( error = = T QSocket: : ErrConnectionRefused ) {
error = ConnectionRefused ;
// std::cout << "--KNutNet::connection error ErrConnectionRefused " << QSocket::Idle << " - " << error << std::endl;
// std::cout << "--KNutNet::connection error ErrConnectionRefused " << T QSocket::Idle << " - " << error << std::endl;
emit connectionError ( error ) ;
return ;
}
if ( error = = QSocket: : ErrSocketRead ) {
if ( error = = T QSocket: : ErrSocketRead ) {
error = SocketReadErr ;
// std::cout << "--KNutNet::connection error QSocket::ErrSocketRead " << error << std::endl;
// std::cout << "--KNutNet::connection error T QSocket::ErrSocketRead " << error << std::endl;
emit connectionError ( error ) ;
return ;
}
@ -1875,7 +1875,7 @@ void KNutNet::slotConnected(void) {
m_error = NutProtocolVarErr ;
m_state = Closing ;
m_commandSocket - > close ( ) ;
while ( m_commandSocket - > state ( ) = = QSocket: : Closing ) {
while ( m_commandSocket - > state ( ) = = T QSocket: : Closing ) {
sleep ( 100 ) ;
}
m_state = ConnectError ;
@ -1888,7 +1888,7 @@ void KNutNet::slotConnected(void) {
// upsd server doesn't support any ups
m_state = Closing ;
m_commandSocket - > close ( ) ;
while ( m_commandSocket - > state ( ) = = QSocket: : Closing ) {
while ( m_commandSocket - > state ( ) = = T QSocket: : Closing ) {
sleep ( 100 ) ;
}
m_state = ConnectError ;
@ -1927,12 +1927,12 @@ void KNutNet::slotTimerReconnect(void) {
// std::cout << "--KNutNet::slotTimerReconnect" << std::endl;
m_unConnectTimer - > stop ( ) ;
if ( m_commandSocket - > state ( ) = = QSocket: : Idle ) {
//std::cout << "--KNutNet::slotTimerReconnect QSOcket::Idle" << std::endl;
if ( m_commandSocket - > state ( ) = = T QSocket: : Idle ) {
//std::cout << "--KNutNet::slotTimerReconnect T QSOcket::Idle" << std::endl;
emit tryRepeatFirstConnection ( m_numberConnection ) ;
// std::cout << "KNutNet::emit-tryRepeatFirstConnection" << std::endl;
m_state = Connecting ;
if ( m_commandSocket - > state ( ) ! = QSocket: : Connecting )
if ( m_commandSocket - > state ( ) ! = T QSocket: : Connecting )
m_commandSocket - > connectToHost ( m_upsAddress , m_port ) ;
}
}