Skip to content

Fix connection status issue (#2519)#3364

Closed
ann0see wants to merge 7 commits into
jamulussoftware:mainfrom
ann0see:refactoring/RefactorClientConnectionUi
Closed

Fix connection status issue (#2519)#3364
ann0see wants to merge 7 commits into
jamulussoftware:mainfrom
ann0see:refactoring/RefactorClientConnectionUi

Conversation

@ann0see

@ann0see ann0see commented Sep 8, 2024

Copy link
Copy Markdown
Member

This is a manual port of #2550 by @pgScorpio

Short description of changes

First step to get to know the codebase of #2550

CHANGELOG: DO NOT MERGE

Context: Fixes an issue?

Fixes: #2519
Supersedes: #2550

Does this change need documentation? What needs to be documented and how?

No

Status of this Pull Request

Ready for first review and decision on how to move forward.

What is missing until this pull request can be merged?

Review.
It compiles but not every part of the code is fully understood and commented.

Checklist

  • I've verified that this Pull Request follows the general code principles
  • I tested my code and it does what I want
  • My code follows the style guide
  • I waited some time after this Pull Request was opened and all GitHub checks completed without errors.
  • I've filled all the content above

@ann0see
ann0see force-pushed the refactoring/RefactorClientConnectionUi branch 2 times, most recently from b12ce7e to 2b9d985 Compare September 8, 2024 09:58
This is a manual port of jamulussoftware#2550 by @pgScorpio

Co-authored-by: ann0see <20726856+ann0see@users.noreply.github.com>
@ann0see
ann0see force-pushed the refactoring/RefactorClientConnectionUi branch 2 times, most recently from d6e5a6c to 38fb414 Compare September 8, 2024 10:28
@ann0see

ann0see commented Sep 8, 2024

Copy link
Copy Markdown
Member Author

Coding style check also fails on main. Seems to be an unrelated issue?

@ann0see
ann0see marked this pull request as draft September 8, 2024 10:34
@ann0see

ann0see commented Sep 8, 2024

Copy link
Copy Markdown
Member Author

Pasting from previous PR here:

Moved Connect/Disconnect code from CClientdlg to CClient.
Now using the proper connected checks in several places.
Added bDisconnectAndDisable to CChannel. (For a Client now
Channel.Disconnect() will block audio data and auto disable the channel on disconnected)

Comment thread src/client.cpp Outdated
Comment thread src/client.cpp Outdated
@ann0see
ann0see force-pushed the refactoring/RefactorClientConnectionUi branch 3 times, most recently from db402b9 to 10a4d61 Compare September 8, 2024 15:23
@ann0see
ann0see force-pushed the refactoring/RefactorClientConnectionUi branch from 10a4d61 to a5af8cc Compare September 8, 2024 15:25
Comment thread src/main.cpp
Comment thread src/client.cpp
@ann0see
ann0see force-pushed the refactoring/RefactorClientConnectionUi branch 3 times, most recently from f7f0515 to 1614b81 Compare September 8, 2024 16:08
@ann0see
ann0see force-pushed the refactoring/RefactorClientConnectionUi branch from 1614b81 to 535f781 Compare September 8, 2024 16:13
@ann0see

ann0see commented Sep 8, 2024

Copy link
Copy Markdown
Member Author

Ok.

a5af8cc is for having a smaller diff in this PR. The renaming of methods can happen in another PR.

Client.Start() and Client.Stop() have been re-introduced in 535f781, but can be - of course - merged again if wanted.

I think, this PR should now get an in depth review.

Comment thread src/client.h

void Start();
void Stop();
bool Connect ( QString strServerAddress, QString strServerName );

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does make sense to introduce an easy to call Connect() and Disconnect() method IMO, so this is good.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having these in client.cpp rather than clientdlg.cpp is important. It's important enough to be done in a single PR on its own. I think we should start with that.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. That's issue #3367

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Factored out into #3372

Comment thread src/client.h

bool IsRunning() { return Sound.IsRunning(); }
bool IsCallbackEntered() const { return Sound.IsCallbackEntered(); }
bool IsCallbackEntered() const { return Sound.IsCallbackEntered(); } // For OnTimerCheckAudioDeviceOk only

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted naming. May need some in depth review and discussion.

Comment thread src/client.h

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

void Connecting ( QString strServerName );

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a missing slot.

Comment thread src/client.h Outdated
void Connecting ( QString strServerName );
void Disconnected();
void SoundDeviceChanged ( QString strError );
void SoundDeviceChanged();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel strongly about removing the error message handling. Could be reverted.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above:

  • split this out to a separate PR
  • have two slots, one for GUI, one for headless, and pass the error to each

Comment thread src/clientdlg.cpp

// initiate connection
Connect ( strSelectedAddress, strMixerBoardLabel );
// TODO: investigate and add error handling on failed Connect() call.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO as commented in code.

Comment thread src/client.cpp
{
// make sure we are running and the server address is correct
if ( IsRunning() && ( InetAddr == Channel.GetAddress() ) )
if ( Channel.IsEnabled() && ( InetAddr == Channel.GetAddress() ) )

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't about the channel being enabled. It's about whether the client is running. It's a different intent.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the initial PR confused active channel and active client: #2550 (comment)

This difference needs documentation. IMO: Add (like for JSON-RPC) respective technical documentation before the respective methods. As end goal: Write them for every function, for now: Write docs while changing.

Comment thread src/client.cpp Outdated
Comment thread src/client.cpp Outdated
Comment thread src/client.cpp Outdated
Comment thread src/client.cpp
Sound.Stop();
// start disconnection
// Channel.Disconnect() should automatically disable Channel as soon as disconnected.
// Note that this only works if sound is active!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So why make the changes here?

@ann0see ann0see Sep 13, 2024

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it's mainly moving around the Channel.Disconnect() and Sound.Stop() code around.

This may be the actual bug fix?

Comment thread src/clientdlg.cpp
}

void CClientDlg::Disconnect()
void CClientDlg::OnDisconnect()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tidying up the mixer board should go in here, I guess.

@ann0see

ann0see commented Sep 13, 2024

Copy link
Copy Markdown
Member Author

Thanks for the review! I'll go through what I can answer later.

Comment thread src/clientsettingsdlg.cpp Outdated
Comment thread src/main.cpp
// show dialog
ClientDlg.show();

// Connect on startup

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These shouldn't be in main.cpp.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's up to discussion. I do understand that one could put this functionality here. How it's handled currently also seems somewhat messy.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is messy. But that's a bigger issue with how start up works.

@ann0see
ann0see force-pushed the refactoring/RefactorClientConnectionUi branch from 2633d3c to 66edab5 Compare September 13, 2024 19:33
Comment thread src/clientdlg.cpp
// disconnect the old server first
if ( pClient->IsRunning() )
// initiate connection
if ( pClient->Connect ( strSelectedAddress, strMixerBoardLabel ) )

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be refactored imo. Feels very clumsy.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UI should simply pass any captured details to Client and await feedback. There shouldn't be any testing of the response. (Any input validation should be factored out of Client if it needs sharing between Client and ClientDlg.)

@ann0see ann0see added this to the Release 4.0.0 milestone Dec 23, 2024
@ann0see ann0see added the refactoring Non-behavioural changes, Code cleanup label Dec 23, 2024
@ann0see

ann0see commented Dec 23, 2024

Copy link
Copy Markdown
Member Author

Tagged for Jamulus 4. This PR should NOT be merged. However, the comments are still valuable.

@pljones pljones moved this from Waiting on Team to Triage in Tracking Apr 26, 2026
@pljones

pljones commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator

@mcfnord did you have a reworking of this? (I've lost a few PRs somewhere.)

@pljones pljones modified the milestones: Release 4.0.0, Release 4.1.0 Jul 20, 2026
@mcfnord

mcfnord commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Note

📡 STAND BY FOR AN LLM-AUTHORED MESSAGE.

@pljones — yes. The reworking is #3805 ("Refactor Connect/Disconnect out to CClient with an explicit connection state"), open and awaiting review. It's the same line of work as this PR: both descend from @pgScorpio's #2550. This PR ports #2550 directly onto main; #3805 goes through @ann0see's #3372 extract, finishes it, and adds a state machine on top. It's the one to carry forward.

Structurally #3805 does what #3367 asks for: Connect() / Disconnect() move out of CClientDlg into CClient, and the dialog only reacts to signals (OnConnecting / OnConnectingFailed / OnDisconnect). It adds an explicit EConnectionState (CS_DISCONNECTED / CS_CONNECTING / CS_CONNECTED) owned by CClient as the single source of truth, with every transition emitting ConnectionStateChanged. Connect-on-startup also moves into main.cpp, so it behaves the same under --nogui.

That structural change is what actually resolves #2519, and it answers the doubt @ann0see raised in the review here — "check if the changed conditions in the if statements are really correct or if the bug lays elsewhere." It does lie elsewhere. The GUI's "connected" is CClient::IsRunning(), which is Sound.IsRunning() — audio-device state, not network state (src/client.h:162). The real network predicate IsConnected() = Channel.IsConnected() exists (src/client.h:174) but the connect/disconnect UI never reads it: OnConnectDisconBut() (src/clientdlg.cpp:786), OnConnectDlgAccepted(), and closeEvent() all key off IsRunning(). So a device error while connected flips the button to "Connect" over a live connection, and audio starting before the server answers shows "Disconnect" while nothing is connected — both reported directions. (Full trace in #2519.)

This PR refines the conditions inside that dialog-centric model; #3805 replaces the model with the single EConnectionState source of truth, which is the durable version. Once #3805 lands, I'd suggest this one can be closed in its favor — your call.

@pljones

pljones commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

@ann0see are you okay we can close this in favour of #3372 and #3805 ? I'd like to pick both up together in a single release (i.e. 4.1.0 now).

@ann0see

ann0see commented Jul 22, 2026

Copy link
Copy Markdown
Member Author

Yes.

@ann0see ann0see closed this Jul 22, 2026
@github-project-automation github-project-automation Bot moved this from Triage to Done in Tracking Jul 22, 2026
@pljones pljones removed this from the Release 4.1.0 milestone Jul 23, 2026
@pljones pljones removed this from Tracking Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactoring Non-behavioural changes, Code cleanup

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Connection status client and gui can get out of sync.

5 participants