Repository navigation
Visit the client's roles through one helper - #284
Merged
Merged
Conversation
Six sites in client.cpp each spelled out the seven roles under their own #ifdef. for_each_role() holds that list once and hands each added role's Impl to a visitor, in the order the sites already used. take_stream_event() does the same for the generation check the four stream events repeated. stop_role_threads() keeps its own list: it stops the roles in a different order.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The change still has three active moderate findings because requires checks allow missing role methods to compile as silent no-ops, risking undetected regressions in draining, state reporting, and stream teardown.
3 open issues
What changed in this PR
This pull request centralizes repeated client-role traversal in SendspinClient, preserving role order and existing behavior while reducing duplicated conditional logic.
Changes:
- Added
for_each_role()to centralize compile-gated visitation of all seven roles. - Converted lifecycle, inbox-draining, hello/state construction, cleanup, and role-removal paths to use the shared visitor.
- Extracted shared stream-event generation and teardown handling into
take_stream_event().
| File | Description |
|---|---|
| src/client.cpp | Implements centralized role visitation and applies it across client lifecycle, inbox, state, hello, cleanup, removal, and stream-event paths. |
| include/sendspin/client.h | Declares and documents the private role-visitation helper template. |
Review effort: Lite (adaptive)
for_each_role() reached the role drains through a requires probe, so a role whose needs_drain() was renamed would be skipped instead of failing to compile. Nothing else names needs_drain(), so the site lists the six roles again.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Five sites in
client.cppeach spelled out the seven roles under their own#ifdef. One private helper now holds that list, and the sites pass it a visitor. No behavior change. Net -88 lines.Change
for_each_role(): a private member template that callsvisit(impl, role)for each added role, in the order player, controller, metadata, color, artwork, visualizer, source. It is the one place inclient.cppthat lists the roles for these sites.catch_up_roles,cleanup_connection_state,build_client_hello,apply_role_removalsandbuild_client_state. Each visits the same roles in the same order with the same calls as before.role_removed()folds intoapply_role_removals.take_stream_event(): a file-local helper for the generation check and teardown catch-up the four stream-event cases repeated.client.hgains the one private template declaration.Reviewer notes
if constexpr (requires { ... }):end_stream(only the source has one) andbuild_state_fields(player, artwork, visualizer, source). A rename of either cannot pass unnoticed:end_streamhas three other callers that name it on the source role, and the role tests callbuild_state_fieldsdirectly on all four roles.drain_inboxkeep their own list. Nothing else namesneeds_drain(), so a probe there would skip a role whose method was renamed instead of failing to compile.stop_role_threads()keeps its own list. It stops the roles in a different order, and converting it would reorder the stops.add_*()bodies are unchanged. A shared helper for them saved about six lines and cost a second template in the public header.Tests