Repository navigation
cli: let devices refine the product name via getMetadata() - #575
Merged
Merged
Conversation
getMetadata() existed in the device API but was never called from the CLI, so a device that knows more than the USB strings (for example which headset is currently paired to a generic dongle) could not show it. Ask the device once, on the handle already opened for the first feature request; no extra device opens, and the default implementation returns the same HID strings, so other devices are unaffected.
…locale refineProductName() widened the device-supplied name with std::wstring(s.begin(), s.end()). That is wrong in two ways: char is signed on most platforms, so a byte above 0x7F sign-extends into a negative wchar_t, and a multi-byte UTF-8 sequence becomes one wide character per byte rather than one per character. It happens to survive on macOS because wcstombs() masks the value back on the way out, but on Windows the same bytes come out as mojibake and on glibc they hit the '?' fallback. Decoding it properly is not enough on its own: the value is converted straight back with wstring_to_string(), which goes through wcstombs() and so can only represent what the current locale encodes. Nothing calls setlocale(), so in the default C locale every non-ASCII character became '?'. DeviceMetadata and the HID descriptor strings are defined to be UTF-8, so this adds an explicit, locale-independent pair for them - string_to_wstring() and wstring_to_utf8() - and uses it wherever those strings are converted. The pair is an exact inverse, verified in C, en_US.UTF-8 and de_DE.UTF-8. Surrogate pairs are handled for the 16-bit wchar_t on Windows, and malformed input becomes U+FFFD rather than discarding the rest of the name. hid_error() keeps using wstring_to_string(): those really are platform strings in the local encoding, not UTF-8. This also fixes non-ASCII manufacturer and product strings read from the HID descriptor, which were already being mangled before any of this.
ChrisLauinger77
added a commit
to ChrisLauinger77/HeadsetControl
that referenced
this pull request
Oct 22, 2026
Since Sapd#575 the CLI asks a device for its metadata the first time it opens a handle and uses the product name it reports, so a Jabra Link dongle shows the headset paired to it. The library never did: Headset::productName() and hsc_get_product_name() kept returning the dongle's USB string. HeadsetImpl now does the same in getConnection(), once, on the first handle it opens, so the name is refined by whatever call first talks to the device and discovery does no extra I/O. The C wrapper picks up the refined name on the next hsc_get_product_name() call. Both headers and LIBRARY_USAGE.md say when the name changes. The test device opens no handle, so this path is only reachable on hardware.
1 of 2 tasks
ChrisLauinger77
added a commit
to ChrisLauinger77/HeadsetControl
that referenced
this pull request
Oct 22, 2026
Since Sapd#575 the CLI asks a device for its metadata the first time it opens a handle and uses the product name it reports, so a Jabra Link dongle shows the headset paired to it. The library never did: Headset::productName() and hsc_get_product_name() kept returning the dongle's USB string. HeadsetImpl now does the same in getConnection(), once, on the first handle it opens, so the name is refined by whatever call first talks to the device and discovery does no extra I/O. The C wrapper picks up the refined name on the next hsc_get_product_name() call. Both headers and LIBRARY_USAGE.md say when the name changes. The test device opens no handle, so this path is only reachable on hardware.
ChrisLauinger77
added a commit
to ChrisLauinger77/HeadsetControl
that referenced
this pull request
Oct 22, 2026
Since Sapd#575 the CLI asks a device for its metadata the first time it opens a handle and uses the product name it reports, so a Jabra Link dongle shows the headset paired to it. The library never did: Headset::productName() and hsc_get_product_name() kept returning the dongle's USB string. HeadsetImpl now does the same in getConnection(), once, on the first handle it opens, so the name is refined by whatever call first talks to the device and discovery does no extra I/O. The C wrapper picks up the refined name on the next hsc_get_product_name() call. Both headers and LIBRARY_USAGE.md say when the name changes. The test device opens no handle, so this path is only reachable on hardware.
Sapd
pushed a commit
that referenced
this pull request
Oct 22, 2026
Since #575 the CLI asks a device for its metadata on the first open handle and uses the product name it reports, so a Jabra Link dongle shows the headset paired to it. The library kept returning the dongle's USB string. Refinement moves into a ProductName holder that keeps the enumeration name untouched and assigns the refined one at most once, so a view or pointer handed out earlier stays valid and keeps the USB string. Covered against a mock device for the once-only guard, an empty name and a failed query.
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.
Changes made
For Dongles which don't create sub-devices for their paired headsets the HID metadata can give more information about the the headset model.
Checklist