diff --git a/src/client.cpp b/src/client.cpp index 6557ef1156..43797f9e3d 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -466,6 +466,26 @@ void CClient::StartDelayTimer() } } +bool CClient::SetServerAddr ( QString strNAddr ) +{ + CHostAddress HostAddress; +#ifdef CLIENT_NO_SRV_CONNECT + if ( NetworkUtil().ParseNetworkAddress ( strNAddr, HostAddress, bEnableIPv6 ) ) +#else + if ( NetworkUtil().ParseNetworkAddressWithSrvDiscovery ( strNAddr, HostAddress, bEnableIPv6 ) ) +#endif + { + // apply address to the channel + Channel.SetAddress ( HostAddress ); + + return true; + } + else + { + return false; // invalid address + } +} + bool CClient::GetAndResetbJitterBufferOKFlag() { // get the socket buffer put status flag and reset it @@ -845,26 +865,65 @@ void CClient::OnClientIDReceived ( int iChanID ) emit ClientIDReceived ( iChanID ); } -bool CClient::Connect ( QString strServerAddress, QString strServerName ) +void CClient::Start() { - if ( !Channel.IsEnabled() ) + // init object + Init(); + + // enable channel + Channel.SetEnable ( true ); + + // start audio interface + Sound.Start(); +} + +void CClient::Stop() +{ + // start disconnection + // Channel.Disconnect() should automatically disable Channel as soon as disconnected. + // Note that this only works if sound is active! + Channel.Disconnect(); + + QTime DieTime = QTime::currentTime().addMSecs ( 500 ); + while ( ( QTime::currentTime() < DieTime ) && Channel.IsEnabled() ) { - CHostAddress HostAddress; + // exclude user input events because if we use AllEvents, it happens + // that if the user initiates a connection and disconnection quickly + // (e.g. quickly pressing enter five times), the software can get into + // an unknown state + QCoreApplication::processEvents ( QEventLoop::ExcludeUserInputEvents, 100 ); + } - if ( NetworkUtil().ParseNetworkAddress ( strServerAddress, HostAddress, bEnableIPv6 ) ) - { - // init object - Init(); - // apply address to the channel - Channel.SetAddress ( HostAddress ); + // Now stop the audio interface + Sound.Stop(); - // enable channel - Channel.SetEnable ( true ); + // in case we timed out, log warning and make sure Channel is disabled + if ( Channel.IsEnabled() ) + { + Channel.SetEnable ( false ); + } - // start audio interface - Sound.Start(); + // Send disconnect message to server (Since we disable our protocol + // receive mechanism with the next command, we do not evaluate any + // respond from the server, therefore we just hope that the message + // gets its way to the server, if not, the old behaviour time-out + // disconnects the connection anyway). + ConnLessProtocol.CreateCLDisconnection ( Channel.GetAddress() ); + + // reset current signal level and LEDs + bJitterBufferOK = true; + SignalLevelMeter.Reset(); +} + +bool CClient::Connect ( QString strServerAddress, QString strServerName ) +{ + if ( !Channel.IsEnabled() ) + { + // Set server address and connect if valid address was supplied + if ( SetServerAddr ( strServerAddress ) ) { + + Start(); - // Notify ClientDlg emit Connecting ( strServerName ); return true; @@ -878,41 +937,7 @@ bool CClient::Disconnect() { if ( Channel.IsEnabled() ) { - // start disconnection - Channel.Disconnect(); - - // Channel.Disconnect() should automatically disable Channel as soon as disconnected. - // Note that this only works if Sound is Active ! - - QTime DieTime = QTime::currentTime().addMSecs ( 500 ); - while ( ( QTime::currentTime() < DieTime ) && Channel.IsEnabled() ) - { - // exclude user input events because if we use AllEvents, it happens - // that if the user initiates a connection and disconnection quickly - // (e.g. quickly pressing enter five times), the software can get into - // an unknown state - QCoreApplication::processEvents ( QEventLoop::ExcludeUserInputEvents, 100 ); - } - - // Now stop the audio interface - Sound.Stop(); - - // in case we timed out, log warning and make sure Channel is disabled - if ( Channel.IsEnabled() ) - { - Channel.SetEnable ( false ); - } - - // Send disconnect message to server (Since we disable our protocol - // receive mechanism with the next command, we do not evaluate any - // respond from the server, therefore we just hope that the message - // gets its way to the server, if not, the old behaviour time-out - // disconnects the connection anyway). - ConnLessProtocol.CreateCLDisconnection ( Channel.GetAddress() ); - - // reset current signal level and LEDs - bJitterBufferOK = true; - SignalLevelMeter.Reset(); + Stop(); emit Disconnected(); diff --git a/src/client.h b/src/client.h index 6f7514fecd..0b5c03c73f 100644 --- a/src/client.h +++ b/src/client.h @@ -118,17 +118,19 @@ class CClient : public QObject virtual ~CClient(); + void Start(); bool Connect ( QString strServerAddress, QString strServerName ); bool Disconnect(); bool IsRunning() { return Sound.IsRunning(); } bool IsCallbackEntered() const { return Sound.IsCallbackEntered(); } // For OnTimerCheckAudioDeviceOk only + bool SetServerAddr ( QString strNAddr ); double GetLevelForMeterdBLeft() { return SignalLevelMeter.GetLevelForMeterdBLeftOrMono(); } double GetLevelForMeterdBRight() { return SignalLevelMeter.GetLevelForMeterdBRight(); } bool GetAndResetbJitterBufferOKFlag(); - + bool IsConnected() { return Channel.IsConnected(); } EGUIDesign GetGUIDesign() const { return eGUIDesign; }