small fix for initialization of host address in case not actual address could be obtained

This commit is contained in:
Volker Fischer 2012-07-09 12:49:47 +00:00
parent d0b017df54
commit b625a77521

View File

@ -1,491 +1,494 @@
/******************************************************************************\ /******************************************************************************\
* Copyright (c) 2004-2011 * Copyright (c) 2004-2011
* *
* Author(s): * Author(s):
* Volker Fischer * Volker Fischer
* *
****************************************************************************** ******************************************************************************
* *
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software * the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later * Foundation; either version 2 of the License, or (at your option) any later
* version. * version.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * 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 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details. * details.
* *
* You should have received a copy of the GNU General Public License along with * 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., * this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* *
\******************************************************************************/ \******************************************************************************/
#include "util.h" #include "util.h"
/* Implementation *************************************************************/ /* Implementation *************************************************************/
// Input level meter implementation -------------------------------------------- // Input level meter implementation --------------------------------------------
void CStereoSignalLevelMeter::Update ( CVector<short>& vecsAudio ) void CStereoSignalLevelMeter::Update ( CVector<short>& vecsAudio )
{ {
// get the stereo vector size // get the stereo vector size
const int iStereoVecSize = vecsAudio.Size(); const int iStereoVecSize = vecsAudio.Size();
// Get maximum of current block // Get maximum of current block
// //
// Speed optimization: // Speed optimization:
// - we only make use of the positive values and ignore the negative ones // - we only make use of the positive values and ignore the negative ones
// -> we do not need to call the fabs() function // -> we do not need to call the fabs() function
// - we only evaluate every third sample // - we only evaluate every third sample
// //
// With these speed optimizations we might loose some information in // With these speed optimizations we might loose some information in
// special cases but for the average music signals the following code // special cases but for the average music signals the following code
// should give good results. // should give good results.
// //
short sMaxL = 0; short sMaxL = 0;
short sMaxR = 0; short sMaxR = 0;
for ( int i = 0; i < iStereoVecSize; i += 6 ) // 2 * 3 = 6 -> stereo for ( int i = 0; i < iStereoVecSize; i += 6 ) // 2 * 3 = 6 -> stereo
{ {
// left channel // left channel
if ( sMaxL < vecsAudio[i] ) if ( sMaxL < vecsAudio[i] )
{ {
sMaxL = vecsAudio[i]; sMaxL = vecsAudio[i];
} }
// right channel // right channel
if ( sMaxR < vecsAudio[i + 1] ) if ( sMaxR < vecsAudio[i + 1] )
{ {
sMaxR = vecsAudio[i + 1]; sMaxR = vecsAudio[i + 1];
} }
} }
dCurLevelL = UpdateCurLevel ( dCurLevelL, sMaxL ); dCurLevelL = UpdateCurLevel ( dCurLevelL, sMaxL );
dCurLevelR = UpdateCurLevel ( dCurLevelR, sMaxR ); dCurLevelR = UpdateCurLevel ( dCurLevelR, sMaxR );
} }
double CStereoSignalLevelMeter::UpdateCurLevel ( double dCurLevel, double CStereoSignalLevelMeter::UpdateCurLevel ( double dCurLevel,
const short& sMax ) const short& sMax )
{ {
// decrease max with time // decrease max with time
if ( dCurLevel >= METER_FLY_BACK ) if ( dCurLevel >= METER_FLY_BACK )
{ {
// TODO calculate factor from sample rate // TODO calculate factor from sample rate
dCurLevel *= 0.95; dCurLevel *= 0.95;
} }
else else
{ {
dCurLevel = 0; dCurLevel = 0;
} }
// update current level -> only use maximum // update current level -> only use maximum
if ( static_cast<double> ( sMax ) > dCurLevel ) if ( static_cast<double> ( sMax ) > dCurLevel )
{ {
return static_cast<double> ( sMax ); return static_cast<double> ( sMax );
} }
else else
{ {
return dCurLevel; return dCurLevel;
} }
} }
double CStereoSignalLevelMeter::CalcLogResult ( const double& dLinearLevel ) double CStereoSignalLevelMeter::CalcLogResult ( const double& dLinearLevel )
{ {
const double dNormMicLevel = dLinearLevel / _MAXSHORT; const double dNormMicLevel = dLinearLevel / _MAXSHORT;
// logarithmic measure // logarithmic measure
if ( dNormMicLevel > 0 ) if ( dNormMicLevel > 0 )
{ {
return 20.0 * log10 ( dNormMicLevel ); return 20.0 * log10 ( dNormMicLevel );
} }
else else
{ {
return -100000.0; // large negative value return -100000.0; // large negative value
} }
} }
// CRC ------------------------------------------------------------------------- // CRC -------------------------------------------------------------------------
void CCRC::Reset() void CCRC::Reset()
{ {
// init state shift-register with ones. Set all registers to "1" with // init state shift-register with ones. Set all registers to "1" with
// bit-wise not operation // bit-wise not operation
iStateShiftReg = ~uint32_t ( 0 ); iStateShiftReg = ~uint32_t ( 0 );
} }
void CCRC::AddByte ( const uint8_t byNewInput ) void CCRC::AddByte ( const uint8_t byNewInput )
{ {
for ( int i = 0; i < 8; i++ ) for ( int i = 0; i < 8; i++ )
{ {
// shift bits in shift-register for transistion // shift bits in shift-register for transistion
iStateShiftReg <<= 1; iStateShiftReg <<= 1;
// take bit, which was shifted out of the register-size and place it // take bit, which was shifted out of the register-size and place it
// at the beginning (LSB) // at the beginning (LSB)
// (If condition is not satisfied, implicitely a "0" is added) // (If condition is not satisfied, implicitely a "0" is added)
if ( ( iStateShiftReg & iBitOutMask) > 0 ) if ( ( iStateShiftReg & iBitOutMask) > 0 )
{ {
iStateShiftReg |= 1; iStateShiftReg |= 1;
} }
// add new data bit to the LSB // add new data bit to the LSB
if ( ( byNewInput & ( 1 << ( 8 - i - 1 ) ) ) > 0 ) if ( ( byNewInput & ( 1 << ( 8 - i - 1 ) ) ) > 0 )
{ {
iStateShiftReg ^= 1; iStateShiftReg ^= 1;
} }
// add mask to shift-register if first bit is true // add mask to shift-register if first bit is true
if ( iStateShiftReg & 1 ) if ( iStateShiftReg & 1 )
{ {
iStateShiftReg ^= iPoly; iStateShiftReg ^= iPoly;
} }
} }
} }
uint32_t CCRC::GetCRC() uint32_t CCRC::GetCRC()
{ {
// return inverted shift-register (1's complement) // return inverted shift-register (1's complement)
iStateShiftReg = ~iStateShiftReg; iStateShiftReg = ~iStateShiftReg;
// remove bit which where shifted out of the shift-register frame // remove bit which where shifted out of the shift-register frame
return iStateShiftReg & ( iBitOutMask - 1 ); return iStateShiftReg & ( iBitOutMask - 1 );
} }
/******************************************************************************\ /******************************************************************************\
* Audio Reverberation * * Audio Reverberation *
\******************************************************************************/ \******************************************************************************/
/* /*
The following code is based on "JCRev: John Chowning's reverberator class" The following code is based on "JCRev: John Chowning's reverberator class"
by Perry R. Cook and Gary P. Scavone, 1995 - 2004 by Perry R. Cook and Gary P. Scavone, 1995 - 2004
which is in "The Synthesis ToolKit in C++ (STK)" which is in "The Synthesis ToolKit in C++ (STK)"
http://ccrma.stanford.edu/software/stk http://ccrma.stanford.edu/software/stk
Original description: Original description:
This class is derived from the CLM JCRev function, which is based on the use This class is derived from the CLM JCRev function, which is based on the use
of networks of simple allpass and comb delay filters. This class implements of networks of simple allpass and comb delay filters. This class implements
three series allpass units, followed by four parallel comb filters, and two three series allpass units, followed by four parallel comb filters, and two
decorrelation delay lines in parallel at the output. decorrelation delay lines in parallel at the output.
*/ */
void CAudioReverb::Init ( const int iSampleRate, const double rT60 ) void CAudioReverb::Init ( const int iSampleRate, const double rT60 )
{ {
int delay, i; int delay, i;
// delay lengths for 44100 Hz sample rate // delay lengths for 44100 Hz sample rate
int lengths[9] = { 1777, 1847, 1993, 2137, 389, 127, 43, 211, 179 }; int lengths[9] = { 1777, 1847, 1993, 2137, 389, 127, 43, 211, 179 };
const double scaler = (double) iSampleRate / 44100.0; const double scaler = (double) iSampleRate / 44100.0;
if ( scaler != 1.0 ) if ( scaler != 1.0 )
{ {
for ( i = 0; i < 9; i++ ) for ( i = 0; i < 9; i++ )
{ {
delay = (int) floor ( scaler * lengths[i] ); delay = (int) floor ( scaler * lengths[i] );
if ( ( delay & 1 ) == 0 ) if ( ( delay & 1 ) == 0 )
{ {
delay++; delay++;
} }
while ( !isPrime ( delay ) ) while ( !isPrime ( delay ) )
{ {
delay += 2; delay += 2;
} }
lengths[i] = delay; lengths[i] = delay;
} }
} }
for ( i = 0; i < 3; i++ ) for ( i = 0; i < 3; i++ )
{ {
allpassDelays_[i].Init ( lengths[i + 4] ); allpassDelays_[i].Init ( lengths[i + 4] );
} }
for ( i = 0; i < 4; i++ ) for ( i = 0; i < 4; i++ )
{ {
combDelays_[i].Init ( lengths[i] ); combDelays_[i].Init ( lengths[i] );
} }
setT60 ( rT60, iSampleRate ); setT60 ( rT60, iSampleRate );
allpassCoefficient_ = (double) 0.7; allpassCoefficient_ = (double) 0.7;
Clear(); Clear();
} }
bool CAudioReverb::isPrime ( const int number ) bool CAudioReverb::isPrime ( const int number )
{ {
/* /*
Returns true if argument value is prime. Taken from "class Effect" in Returns true if argument value is prime. Taken from "class Effect" in
"STK abstract effects parent class". "STK abstract effects parent class".
*/ */
if ( number == 2 ) if ( number == 2 )
{ {
return true; return true;
} }
if ( number & 1 ) if ( number & 1 )
{ {
for ( int i = 3; i < (int) sqrt ( (double) number ) + 1; i += 2 ) for ( int i = 3; i < (int) sqrt ( (double) number ) + 1; i += 2 )
{ {
if ( ( number % i ) == 0 ) if ( ( number % i ) == 0 )
{ {
return false; return false;
} }
} }
return true; // prime return true; // prime
} }
else else
{ {
return false; // even return false; // even
} }
} }
void CAudioReverb::Clear() void CAudioReverb::Clear()
{ {
// reset and clear all internal state // reset and clear all internal state
allpassDelays_[0].Reset ( 0 ); allpassDelays_[0].Reset ( 0 );
allpassDelays_[1].Reset ( 0 ); allpassDelays_[1].Reset ( 0 );
allpassDelays_[2].Reset ( 0 ); allpassDelays_[2].Reset ( 0 );
combDelays_[0].Reset ( 0 ); combDelays_[0].Reset ( 0 );
combDelays_[1].Reset ( 0 ); combDelays_[1].Reset ( 0 );
combDelays_[2].Reset ( 0 ); combDelays_[2].Reset ( 0 );
combDelays_[3].Reset ( 0 ); combDelays_[3].Reset ( 0 );
} }
void CAudioReverb::setT60 ( const double rT60, void CAudioReverb::setT60 ( const double rT60,
const int iSampleRate ) const int iSampleRate )
{ {
// set the reverberation T60 decay time // set the reverberation T60 decay time
for ( int i = 0; i < 4; i++ ) for ( int i = 0; i < 4; i++ )
{ {
combCoefficient_[i] = pow ( (double) 10.0, (double) ( -3.0 * combCoefficient_[i] = pow ( (double) 10.0, (double) ( -3.0 *
combDelays_[i].Size() / ( rT60 * iSampleRate ) ) ); combDelays_[i].Size() / ( rT60 * iSampleRate ) ) );
} }
} }
double CAudioReverb::ProcessSample ( const double input ) double CAudioReverb::ProcessSample ( const double input )
{ {
// compute one output sample // compute one output sample
double temp, temp0, temp1, temp2; double temp, temp0, temp1, temp2;
temp = allpassDelays_[0].Get(); temp = allpassDelays_[0].Get();
temp0 = allpassCoefficient_ * temp; temp0 = allpassCoefficient_ * temp;
temp0 += input; temp0 += input;
allpassDelays_[0].Add ( (int) temp0 ); allpassDelays_[0].Add ( (int) temp0 );
temp0 = - ( allpassCoefficient_ * temp0 ) + temp; temp0 = - ( allpassCoefficient_ * temp0 ) + temp;
temp = allpassDelays_[1].Get(); temp = allpassDelays_[1].Get();
temp1 = allpassCoefficient_ * temp; temp1 = allpassCoefficient_ * temp;
temp1 += temp0; temp1 += temp0;
allpassDelays_[1].Add ( (int) temp1 ); allpassDelays_[1].Add ( (int) temp1 );
temp1 = - ( allpassCoefficient_ * temp1 ) + temp; temp1 = - ( allpassCoefficient_ * temp1 ) + temp;
temp = allpassDelays_[2].Get(); temp = allpassDelays_[2].Get();
temp2 = allpassCoefficient_ * temp; temp2 = allpassCoefficient_ * temp;
temp2 += temp1; temp2 += temp1;
allpassDelays_[2].Add ( (int) temp2 ); allpassDelays_[2].Add ( (int) temp2 );
temp2 = - ( allpassCoefficient_ * temp2 ) + temp; temp2 = - ( allpassCoefficient_ * temp2 ) + temp;
const double temp3 = temp2 + ( combCoefficient_[0] * combDelays_[0].Get() ); const double temp3 = temp2 + ( combCoefficient_[0] * combDelays_[0].Get() );
const double temp4 = temp2 + ( combCoefficient_[1] * combDelays_[1].Get() ); const double temp4 = temp2 + ( combCoefficient_[1] * combDelays_[1].Get() );
const double temp5 = temp2 + ( combCoefficient_[2] * combDelays_[2].Get() ); const double temp5 = temp2 + ( combCoefficient_[2] * combDelays_[2].Get() );
const double temp6 = temp2 + ( combCoefficient_[3] * combDelays_[3].Get() ); const double temp6 = temp2 + ( combCoefficient_[3] * combDelays_[3].Get() );
combDelays_[0].Add ( (int) temp3 ); combDelays_[0].Add ( (int) temp3 );
combDelays_[1].Add ( (int) temp4 ); combDelays_[1].Add ( (int) temp4 );
combDelays_[2].Add ( (int) temp5 ); combDelays_[2].Add ( (int) temp5 );
combDelays_[3].Add ( (int) temp6 ); combDelays_[3].Add ( (int) temp6 );
return ( temp3 + temp4 + temp5 + temp6 ) * (double) 0.5; return ( temp3 + temp4 + temp5 + temp6 ) * (double) 0.5;
} }
/******************************************************************************\ /******************************************************************************\
* GUI Utilities * * GUI Utilities *
\******************************************************************************/ \******************************************************************************/
// About dialog ---------------------------------------------------------------- // About dialog ----------------------------------------------------------------
CAboutDlg::CAboutDlg ( QWidget* parent ) : QDialog ( parent ) CAboutDlg::CAboutDlg ( QWidget* parent ) : QDialog ( parent )
{ {
setupUi ( this ); setupUi ( this );
// set the text for the about dialog html text control // set the text for the about dialog html text control
txvCredits->setOpenExternalLinks ( true ); txvCredits->setOpenExternalLinks ( true );
txvCredits->setText ( txvCredits->setText (
"<p>" // general description of llcon software "<p>" // general description of llcon software
"<big><b>llcon</b> " + tr("The llcon software enables musicians to " "<big><b>llcon</b> " + tr("The llcon software enables musicians to "
"perform real-time jam sessions over the internet. There is a llcon " "perform real-time jam sessions over the internet. There is a llcon "
"server which collects the audio data from each llcon client, " "server which collects the audio data from each llcon client, "
"mixes the audio data and sends the mix back to each client.") + "mixes the audio data and sends the mix back to each client.") +
"</big></p><br>" "</big></p><br>"
"<p><font face=\"courier\">" // GPL header text "<p><font face=\"courier\">" // GPL header text
"This program is free software; you can redistribute it and/or modify " "This program is free software; you can redistribute it and/or modify "
"it under the terms of the GNU General Public License as published by " "it under the terms of the GNU General Public License as published by "
"the Free Software Foundation; either version 2 of the License, or " "the Free Software Foundation; either version 2 of the License, or "
"(at your option) any later version.<br>This program is distributed in " "(at your option) any later version.<br>This program is distributed in "
"the hope that it will be useful, but WITHOUT ANY WARRANTY; without " "the hope that it will be useful, but WITHOUT ANY WARRANTY; without "
"even the implied warranty of MERCHANTABILITY or FITNESS FOR A " "even the implied warranty of MERCHANTABILITY or FITNESS FOR A "
"PARTICULAR PURPOSE. See the GNU General Public License for more " "PARTICULAR PURPOSE. See the GNU General Public License for more "
"details.<br>You should have received a copy of the GNU General Public " "details.<br>You should have received a copy of the GNU General Public "
"License along with his program; if not, write to the Free Software " "License along with his program; if not, write to the Free Software "
"Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 " "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 "
"USA" "USA"
"</font></p><br>" "</font></p><br>"
"<p><b>" + // libraries used by this compilation of llcon "<p><b>" + // libraries used by this compilation of llcon
tr("llcon uses the following libraries, resources or code snippets:") + tr("llcon uses the following libraries, resources or code snippets:") +
"</b></p>" "</b></p>"
"<ul>" "<ul>"
"<li>Qt cross-platform application framework: " "<li>Qt cross-platform application framework: "
"<i><a href=""http://trolltech.com"">http://trolltech.com</a></i></li>" "<i><a href=""http://trolltech.com"">http://trolltech.com</a></i></li>"
"<li>The CELT ultra-low delay audio codec: " "<li>The CELT ultra-low delay audio codec: "
"<i><a href=""http://www.celt-codec.org"">http://www.celt-codec.org</a></i></li>" "<i><a href=""http://www.celt-codec.org"">http://www.celt-codec.org</a></i></li>"
"<li>Audio reverberation code: by Perry R. Cook and Gary P. Scavone, " "<li>Audio reverberation code: by Perry R. Cook and Gary P. Scavone, "
"1995 - 2004 (taken from " "1995 - 2004 (taken from "
"<i><a href=""http://ccrma.stanford.edu/software/stk"">" "<i><a href=""http://ccrma.stanford.edu/software/stk"">"
"The Synthesis ToolKit in C++ (STK)</a></i>)</li>" "The Synthesis ToolKit in C++ (STK)</a></i>)</li>"
"<li>Parts from Dream DRM Receiver by Volker Fischer and Alexander " "<li>Parts from Dream DRM Receiver by Volker Fischer and Alexander "
"Kurpiers: " "Kurpiers: "
"<i><a href=""http://drm.sf.net"">http://drm.sf.net</a></i></li>" "<i><a href=""http://drm.sf.net"">http://drm.sf.net</a></i></li>"
"<li>Some pixmaps are from <i>Clker.com - vector clip art online, " "<li>Some pixmaps are from <i>Clker.com - vector clip art online, "
"royalty free & public domain</i></li>" "royalty free & public domain</i></li>"
"</ul>" "</ul>"
"</center><br>"); "</center><br>");
// set version number in about dialog // set version number in about dialog
lblVersion->setText ( GetVersionAndNameStr() ); lblVersion->setText ( GetVersionAndNameStr() );
} }
QString CAboutDlg::GetVersionAndNameStr ( const bool bWithHtml ) QString CAboutDlg::GetVersionAndNameStr ( const bool bWithHtml )
{ {
QString strVersionText = ""; QString strVersionText = "";
// name, short description and GPL hint // name, short description and GPL hint
if ( bWithHtml ) if ( bWithHtml )
{ {
strVersionText += "<center><b>"; strVersionText += "<center><b>";
} }
else else
{ {
strVersionText += " *** "; strVersionText += " *** ";
} }
strVersionText += tr ( "llcon, Version " ) + VERSION; strVersionText += tr ( "llcon, Version " ) + VERSION;
if ( bWithHtml ) if ( bWithHtml )
{ {
strVersionText += "</b><br>"; strVersionText += "</b><br>";
} }
else else
{ {
strVersionText += "\n *** "; strVersionText += "\n *** ";
} }
strVersionText += tr ( "llcon, Low-Latency (internet) CONnection" ); strVersionText += tr ( "llcon, Low-Latency (internet) CONnection" );
if ( bWithHtml ) if ( bWithHtml )
{ {
strVersionText += "<br>"; strVersionText += "<br>";
} }
else else
{ {
strVersionText += "\n *** "; strVersionText += "\n *** ";
} }
strVersionText += tr ( "Under the GNU General Public License (GPL)" ); strVersionText += tr ( "Under the GNU General Public License (GPL)" );
if ( bWithHtml ) if ( bWithHtml )
{ {
strVersionText += "</center>"; strVersionText += "</center>";
} }
return strVersionText; return strVersionText;
} }
// Help menu ------------------------------------------------------------------- // Help menu -------------------------------------------------------------------
CLlconHelpMenu::CLlconHelpMenu ( QWidget* parent ) : QMenu ( "&?", parent ) CLlconHelpMenu::CLlconHelpMenu ( QWidget* parent ) : QMenu ( "&?", parent )
{ {
// standard help menu consists of about and what's this help // standard help menu consists of about and what's this help
addAction ( tr ( "What's &This" ), this, addAction ( tr ( "What's &This" ), this,
SLOT ( OnHelpWhatsThis() ), QKeySequence ( Qt::SHIFT + Qt::Key_F1 ) ); SLOT ( OnHelpWhatsThis() ), QKeySequence ( Qt::SHIFT + Qt::Key_F1 ) );
addSeparator(); addSeparator();
addAction ( tr ( "&Download Link..." ), this, addAction ( tr ( "&Download Link..." ), this,
SLOT ( OnHelpDownloadLink() ) ); SLOT ( OnHelpDownloadLink() ) );
addSeparator(); addSeparator();
addAction ( tr ( "&About..." ), this, SLOT ( OnHelpAbout() ) ); addAction ( tr ( "&About..." ), this, SLOT ( OnHelpAbout() ) );
} }
/******************************************************************************\ /******************************************************************************\
* Other Classes * * Other Classes *
\******************************************************************************/ \******************************************************************************/
bool LlconNetwUtil::ParseNetworkAddress ( QString strAddress, bool LlconNetwUtil::ParseNetworkAddress ( QString strAddress,
CHostAddress& HostAddress ) CHostAddress& HostAddress )
{ {
QHostAddress InetAddr; QHostAddress InetAddr;
quint16 iNetPort = LLCON_DEFAULT_PORT_NUMBER; quint16 iNetPort = LLCON_DEFAULT_PORT_NUMBER;
// parse input address for the type [IP address]:[port number] // init requested host address with invalid address first
QString strPort = strAddress.section ( ":", 1, 1 ); HostAddress = CHostAddress();
if ( !strPort.isEmpty() )
{ // parse input address for the type [IP address]:[port number]
// a colon is present in the address string, try to extract port number QString strPort = strAddress.section ( ":", 1, 1 );
iNetPort = strPort.toInt(); if ( !strPort.isEmpty() )
{
// extract address port before colon (should be actual internet address) // a colon is present in the address string, try to extract port number
strAddress = strAddress.section ( ":", 0, 0 ); iNetPort = strPort.toInt();
}
// extract address port before colon (should be actual internet address)
// first try if this is an IP number an can directly applied to QHostAddress strAddress = strAddress.section ( ":", 0, 0 );
if ( !InetAddr.setAddress ( strAddress ) ) }
{
// it was no vaild IP address, try to get host by name, assuming // first try if this is an IP number an can directly applied to QHostAddress
// that the string contains a valid host name string if ( !InetAddr.setAddress ( strAddress ) )
const QHostInfo HostInfo = QHostInfo::fromName ( strAddress ); {
// it was no vaild IP address, try to get host by name, assuming
if ( HostInfo.error() == QHostInfo::NoError ) // that the string contains a valid host name string
{ const QHostInfo HostInfo = QHostInfo::fromName ( strAddress );
// apply IP address to QT object
if ( !HostInfo.addresses().isEmpty() ) if ( HostInfo.error() == QHostInfo::NoError )
{ {
// use the first IP address // apply IP address to QT object
InetAddr = HostInfo.addresses().first(); if ( !HostInfo.addresses().isEmpty() )
} {
} // use the first IP address
else InetAddr = HostInfo.addresses().first();
{ }
return false; // invalid address }
} else
} {
return false; // invalid address
HostAddress = CHostAddress ( InetAddr, iNetPort ); }
}
return true;
} HostAddress = CHostAddress ( InetAddr, iNetPort );
return true;
/******************************************************************************\ }
* Global Functions Implementation *
\******************************************************************************/
void DebugError ( const QString& pchErDescr, /******************************************************************************\
const QString& pchPar1Descr, * Global Functions Implementation *
const double dPar1, \******************************************************************************/
const QString& pchPar2Descr, void DebugError ( const QString& pchErDescr,
const double dPar2 ) const QString& pchPar1Descr,
{ const double dPar1,
QFile File ( "DebugError.dat" ); const QString& pchPar2Descr,
if ( File.open ( QIODevice::Append ) ) const double dPar2 )
{ {
// append new line in logging file QFile File ( "DebugError.dat" );
QTextStream out ( &File ); if ( File.open ( QIODevice::Append ) )
out << pchErDescr << " ### " << {
pchPar1Descr << ": " << QString().setNum ( dPar1, 'f', 2 ) << // append new line in logging file
" ### " << QTextStream out ( &File );
pchPar2Descr << ": " << QString().setNum ( dPar2, 'f', 2 ) << out << pchErDescr << " ### " <<
endl; pchPar1Descr << ": " << QString().setNum ( dPar1, 'f', 2 ) <<
" ### " <<
File.close(); pchPar2Descr << ": " << QString().setNum ( dPar2, 'f', 2 ) <<
} endl;
printf ( "\nDebug error! For more information see test/DebugError.dat\n" );
exit ( 1 ); File.close();
} }
printf ( "\nDebug error! For more information see test/DebugError.dat\n" );
exit ( 1 );
}