Skip to content

Commit 69246f5

Browse files
committed
Add intermediate refactoring
1 parent 0b6a2bb commit 69246f5

File tree

6 files changed

+46
-39
lines changed

6 files changed

+46
-39
lines changed

src/channel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ EGetDataStat CChannel::GetData ( CVector<uint8_t>& vecbyData, const int iNumByte
654654
Protocol.Reset();
655655

656656
// emit message
657-
emit Disconnected();
657+
emit DisconnectClient();
658658
}
659659

660660
return eGetStatus;

src/channel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public slots:
280280
void LicenceRequired ( ELicenceType eLicenceType );
281281
void VersionAndOSReceived ( COSUtil::EOpSystemType eOSType, QString strVersion );
282282
void RecorderStateReceived ( ERecorderState eRecorderState );
283-
void Disconnected();
283+
void DisconnectClient();
284284

285285
void DetectedCLMessage ( CVector<uint8_t> vecbyMesBodyData, int iRecID, CHostAddress RecHostAddr );
286286

src/client.cpp

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ CClient::CClient ( const quint16 iPortNumber,
122122
QObject::connect ( &Channel, &CChannel::ConClientListMesReceived, this, &CClient::OnConClientListMesReceived );
123123
QObject::connect ( &Channel, &CChannel::ConClientListMesReceived, this, &CClient::ConClientListMesReceived );
124124

125-
QObject::connect ( &Channel, &CChannel::Disconnected, this, &CClient::Disconnected );
125+
QObject::connect ( &Channel, &CChannel::DisconnectClient, this, &CClient::Disconnect );
126126

127127
QObject::connect ( &Channel, &CChannel::NewConnection, this, &CClient::OnNewConnection );
128128

@@ -907,51 +907,48 @@ void CClient::Stop()
907907

908908
/// @method
909909
/// @brief Connects to strServerAddress
910-
/// @emit Connecting (strServerName) if the client wasn't running and SetServerAddr returned true.
910+
/// @emit Connecting (strServerName) if the client wasn't running and SetServerAddr was valid
911+
/// @emit ConnectingFailed (error) if an error occurred
911912
/// @param strServerAddress - the server address to connect to
912913
/// @param strServerName - the String argument to be passed to Connecting()
913-
/// @result true if client wasn't running and SetServerAddr returned true, false otherwise
914-
bool CClient::Connect ( QString strServerAddress, QString strServerName )
914+
void CClient::Connect ( QString strServerAddress, QString strServerName )
915915
{
916-
if ( !IsRunning() )
917-
{
918-
// Set server address and connect if valid address was supplied
919-
if ( SetServerAddr ( strServerAddress ) )
916+
try {
917+
if ( !IsRunning() )
920918
{
921-
922-
Start();
923-
924-
emit Connecting ( strServerName );
925-
926-
return true;
919+
// Set server address and connect if valid address was supplied
920+
if ( SetServerAddr ( strServerAddress ) )
921+
{
922+
Start();
923+
emit Connecting ( strServerName );
924+
}
925+
else {
926+
throw CGenErr ( "Received invalid server address. Please check for typos in the provided server address." );
927+
}
927928
}
928929
}
929-
930-
return false;
930+
catch ( const CGenErr& generr )
931+
{
932+
Disconnect();
933+
emit ConnectingFailed ( generr.GetErrorText() );
934+
}
931935
}
932936

933937
/// @method
934-
/// @brief Disconnects client
938+
/// @brief Disconnects client. If the client is not running, it just stops Sound
935939
/// @emit Disconnected
936-
/// @result true if client wasn't running, false otherwise
937-
bool CClient::Disconnect()
940+
void CClient::Disconnect()
938941
{
939942
if ( IsRunning() )
940943
{
941944
Stop();
942-
943945
emit Disconnected();
944-
945-
return true;
946946
}
947947
else
948948
{
949-
// make sure sound is stopped too
949+
// make sure sound is stopped in any case
950950
Sound.Stop();
951-
952951
emit Disconnected();
953-
954-
return false;
955952
}
956953
}
957954

src/client.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ class CClient : public QObject
121121

122122
void Start();
123123
void Stop();
124-
bool Connect ( QString strServerAddress, QString strServerName );
125-
bool Disconnect();
124+
void Connect ( QString strServerAddress, QString strServerName );
125+
void Disconnect();
126126

127127
bool IsRunning() { return Sound.IsRunning(); }
128128
bool IsCallbackEntered() const { return Sound.IsCallbackEntered(); }
@@ -390,7 +390,7 @@ protected slots:
390390
{
391391
if ( InetAddr == Channel.GetAddress() )
392392
{
393-
emit Disconnected();
393+
Disconnect();
394394
}
395395
}
396396
void OnCLPingReceived ( CHostAddress InetAddr, int iMs );
@@ -430,7 +430,10 @@ protected slots:
430430

431431
void CLChannelLevelListReceived ( CHostAddress InetAddr, CVector<uint16_t> vecLevelList );
432432

433+
void ConnectClient ( QString strServerAddress );
433434
void Connecting ( QString strServerName );
435+
void ConnectingFailed ( QString errorMessage );
436+
void DisconnectClient();
434437
void Disconnected();
435438

436439
void SoundDeviceChanged ( QString strError );

src/clientdlg.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ CClientDlg::CClientDlg ( CClient* pNCliP,
279279
// (no alias))
280280

281281
// initiate connection
282-
// TODO: Refactor this for failing call on Connect()
283282

284283
pClient->Connect ( strConnOnStartupAddress, strConnOnStartupAddress );
285284
// TODO: Find out why without this the mixer status issue still occurs.
@@ -481,6 +480,8 @@ CClientDlg::CClientDlg ( CClient* pNCliP,
481480

482481
QObject::connect ( pClient, &CClient::Connecting, this, &CClientDlg::OnConnect );
483482

483+
QObject::connect ( pClient, &CClient::ConnectingFailed, this, &CClientDlg::OnConnectingFailed );
484+
484485
QObject::connect ( pClient, &CClient::Disconnected, this, &CClientDlg::OnDisconnect );
485486

486487
QObject::connect ( pClient, &CClient::ChatTextReceived, this, &CClientDlg::OnChatTextReceived );
@@ -736,12 +737,8 @@ void CClientDlg::OnConnectDlgAccepted()
736737
}
737738

738739
// initiate connection
739-
// TODO: Refactor this for failing call on Connect()
740740

741-
if ( pClient->Connect ( strSelectedAddress, strMixerBoardLabel ) )
742-
{
743-
OnConnect ( strMixerBoardLabel );
744-
}
741+
pClient->Connect ( strSelectedAddress, strMixerBoardLabel );
745742

746743
// reset flag
747744
bConnectDlgWasShown = false;
@@ -751,9 +748,13 @@ void CClientDlg::OnConnectDlgAccepted()
751748
void CClientDlg::OnConnectDisconBut()
752749
{
753750
// the connect/disconnect button implements a toggle functionality
754-
if ( !pClient->Disconnect() )
751+
if ( pClient->IsRunning() )
755752
{
756-
// If the client didn't disconnect, we assume that we weren't connected. Thus show the connect dialog
753+
pClient->Disconnect();
754+
}
755+
else
756+
{
757+
// If the client isn't running, we assume that we weren't connected. Thus show the connect dialog
757758
// TODO: Refactor to have robust error handling
758759
ShowConnectionSetupDialog();
759760
}
@@ -1221,6 +1222,11 @@ void CClientDlg::OnConnect ( const QString& strMixerBoardLabel )
12211222
}
12221223
}
12231224

1225+
void CClientDlg::OnConnectingFailed ( const QString& strError )
1226+
{
1227+
QMessageBox::critical ( this, APP_NAME, strError, "Close", nullptr );
1228+
}
1229+
12241230
void CClientDlg::OnDisconnect()
12251231
{
12261232
// change connect button text to "connect"

src/clientdlg.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ class CClientDlg : public CBaseDlg, private Ui_CClientDlgBase
126126

127127
public slots:
128128
void OnConnect ( const QString& strServerName );
129+
void OnConnectingFailed ( const QString& strErrorText );
129130
void OnDisconnect();
130131
void OnConnectDisconBut();
131132
void OnTimerSigMet();

0 commit comments

Comments
 (0)