Repository navigation
Consolidate Windows UsbDevice twin and simplify getUsbDevices() OS-wide - #3447
Conversation
Third subsystem in the cross-OS consistency audit. Three coordinated changes: - Merge WindowsUsbDeviceJNA/FFM into a single WindowsUsbDevice (oshi-common). The WinAPI device tree is already abstracted in the DeviceTree/DeviceTreeFFM drivers, so the merged class takes the query as a Supplier passed by the HAL (the AixUsbDevice pattern); each Windows HAL passes its JNA/FFM driver + GUID. - Simplify getUsbDevices() across every platform. Since #3443 moved the tree/flat derivation into AbstractHardwareAbstractionLayer (which always calls the platform method with tree=true and flattens itself), the boolean tree parameter and the identical flatten branch in each platform static method were dead. Drop them: each returns the controller tree; the HAL derives flat. Updated all HAL createUsbDevices() callers. - Dedup the flatten helper: AbstractHardwareAbstractionLayer's private addDevicesToList duplicated AbstractUsbDevice.addDevicesToList; reuse the latter (same package). No user-facing change: the public HardwareAbstractionLayer.getUsbDevices(tree) is unchanged. Linux/Mac JNA/FFM twins keep their classes; their udev/IORegistry native abstraction is a careful follow-up.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (30)
💤 Files with no reviewable changes (1)
📜 Recent review details⏰ Context from checks skipped due to timeout. (12)
🧰 Additional context used🧠 Learnings (5)📚 Learning: 2026-04-06T04:45:47.644ZApplied to files:
📚 Learning: 2026-07-06T19:25:59.225ZApplied to files:
📚 Learning: 2026-04-12T19:22:09.716ZApplied to files:
📚 Learning: 2026-04-06T21:48:09.616ZApplied to files:
📚 Learning: 2026-04-05T15:37:16.042ZApplied to files:
🔇 Additional comments (32)
📝 WalkthroughWalkthroughUSB enumeration now consistently exposes controller-rooted trees, with flat-list derivation centralized in the HAL. Linux, macOS, BSD, AIX, Solaris, and Windows callers use simplified APIs, while Windows shares tree construction across FFM and JNA backends. ChangesUSB enumeration refactor
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant WindowsHAL
participant DeviceTree
participant WindowsUsbDevice
WindowsHAL->>DeviceTree: query host-controller device tree
DeviceTree-->>WindowsHAL: controller IDs and lookup maps
WindowsHAL->>WindowsUsbDevice: supply device-tree data
WindowsUsbDevice-->>WindowsHAL: recursively assembled USB tree
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3447 +/- ##
============================================
- Coverage 74.53% 74.44% -0.09%
Complexity 76 76
============================================
Files 581 582 +1
Lines 21903 21913 +10
Branches 3669 3669
============================================
- Hits 16325 16313 -12
- Misses 3543 3562 +19
- Partials 2035 2038 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Third subsystem in the cross-OS consistency/dedup audit. No user-facing change — the public
HardwareAbstractionLayer.getUsbDevices(tree)is unchanged; this is internal consolidation.Three coordinated changes:
1. Merge the Windows JNA↔FFM twin
WindowsUsbDeviceJNAandWindowsUsbDeviceFFMwere fully-duplicated value + tree-building classes (Windows was the only USB platform without a shared class). The WinAPI device tree is already abstracted behind theDeviceTree/DeviceTreeFFMdrivers, so they differed only in which driver they call + the GUID type. Merged into oneWindowsUsbDevice(oshi-common) that takes the device-tree query as aSupplier— the same "pass the query in" patternAixUsbDevicealready uses. Each Windows HAL passes its JNA/FFM driver + GUID. −2 classes.2. Simplify
getUsbDevices()OS-widePR #3443 moved the tree→flat derivation into
AbstractHardwareAbstractionLayer.getUsbDevices(tree)(which always calls the platform method withtree=trueand flattens itself). That made theboolean treeparameter + the identicalif(!tree){ flatten }branch in every platform static method dead code. Dropped them — each platform now returns the controller tree; the HAL derives flat. Updated all ~17 HALcreateUsbDevices()callers (getUsbDevices(true)→getUsbDevices(), AIX keeps itslscfg).3. Dedup the flatten helper
AbstractHardwareAbstractionLayerhad a privateaddDevicesToListidentical toAbstractUsbDevice.addDevicesToList. Collapsed to the latter (same package).Scope / deferred
udev/IORegistry enumeration is inline (no pre-existing driver) with different native APIs and different resource lifecycles (JNAtry/finally+unrefvs FFMNativeHandle/arena). That's a real native abstraction (aUdevProvider-style hook), not a mechanical merge — split to a focused follow-up (#3b). Mac IORegistry after that.31 files, large net reduction. Gate + clean full build green. Part of the subsystem-by-subsystem audit; follows #3445 (FileSystem) and #3446 (OSThread).
Summary by CodeRabbit
New Features
Bug Fixes