Skip to content

Migrate simple WMI Windows classes to FFM - #3175

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:simple-wmi-windows-ffm
Apr 19, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:simple-wmi-windows-ffm

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Apr 19, 2026 •

Copy link
Copy Markdown
Member

Create FFM implementations for WindowsBaseboard, WindowsFirmware, WindowsComputerSystem, and WindowsPrinter. These classes only depend on WMI queries, so the migration is a straightforward driver swap.

Changes

oshi-common (new):

  • oshi.hardware.common.platform.windows.WindowsPrinter — abstract superclass with shared parseStatus(), parseErrorState(), and ERROR_STATE_NAMES

oshi-core (renames):

  • WindowsBaseboard → WindowsBaseboardJNA
  • WindowsFirmware → WindowsFirmwareJNA
  • WindowsComputerSystem → WindowsComputerSystemJNA (factory methods create JNA Firmware/Baseboard)
  • WindowsPrinter → WindowsPrinterJNA (extends common WindowsPrinter)
  • WindowsHardwareAbstractionLayer updated to use JNA-suffixed names

oshi-core-java25 (new):

  • WindowsBaseboardFFM — WMI via Win32BaseBoardFFM / WmiUtilFFM
  • WindowsFirmwareFFM — WMI via Win32BiosFFM / WmiUtilFFM
  • WindowsComputerSystemFFM — WMI via FFM drivers; creates FFM Firmware/Baseboard
  • WindowsPrinterFFM — WMI via Win32PrinterFFM / WmiUtilFFM
  • WindowsHardwareAbstractionLayerFFM overrides createComputerSystem() and getPrinters()

Summary by CodeRabbit

  • Refactor

    • Migrated remaining Windows WMI hardware drivers to a unified three-tier (legacy/JNA/FFM) pattern and added modern FFM implementations for baseboard, firmware, and computer system.
  • Improvements

    • Improved Windows printer detection and status/error-state reporting for more accurate results.
  • Changelog

    • Added two entries documenting the above migrations and FFM adoption.
  • Tests

    • Relaxed memory-comparison tolerances and minor test assertion cleanup.

@coderabbitai

coderabbitai Bot commented Apr 19, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d2837a3c-5796-4138-9e4f-6b3b9f588adf

📥 Commits

Reviewing files that changed from the base of the PR and between 36e3104 and 3ba7bc8.

📒 Files selected for processing (15)
  • CHANGELOG.md
  • oshi-benchmark/src/test/java/oshi/comparison/RegistryComparisonTest.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsPrinter.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsBaseboardFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsComputerSystemFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsFirmwareFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayerFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsPrinterFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsBaseboardJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsComputerSystemJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsFirmwareJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayer.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsPrinter.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsPrinterJNA.java
  • oshi-core/src/test/java/oshi/driver/mac/IOReportClientTest.java
💤 Files with no reviewable changes (1)
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsPrinter.java
✅ Files skipped from review due to trivial changes (3)
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayer.java
  • oshi-core/src/test/java/oshi/driver/mac/IOReportClientTest.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsFirmwareFFM.java
🚧 Files skipped from review as they are similar to previous changes (7)
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayerFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsFirmwareJNA.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsPrinter.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsPrinterFFM.java
  • CHANGELOG.md
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsBaseboardFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsComputerSystemJNA.java
📜 Recent review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (8)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3173
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java:107-193
Timestamp: 2026-04-18T22:53:49.248Z
Learning: In OSHI's `WmiQueryHandlerFFM` (oshi-core-java25) and the JNA `WmiQueryHandler` (oshi-core), the `failedWmiClassNames` cache intentionally keys failures by WMI class name only (not namespace). This is a pre-existing, accepted pattern shared between both implementations. Do not flag this as a bug in future reviews — the project maintainer (dbwiddis) confirmed it does not impact callers and the added complexity of a composite namespace+class key is not warranted.
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:51.516Z
Learning: In the oshi/oshi project, the public API is strictly limited to interfaces and classes in the `oshi`, `oshi.hardware`, and `oshi.software.os` packages. All platform-specific code under subpackages like `oshi.software.os.linux`, `oshi.hardware.platform.linux`, etc., is considered implementation detail — not public API. Do not flag changes to platform-specific classes (e.g., making `LinuxOperatingSystem` abstract, narrowing constructor visibility, adding abstract methods) as public API breaks.
📚 Learning: 2026-04-18T03:18:03.725Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3170
File: oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java:177-183
Timestamp: 2026-04-18T03:18:03.725Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`, GPU engine PDH instance counts (from `GpuInformationJNA.queryGpuEngineCounters()` / `GpuInformationFFM.queryGpuEngineCounters()`) are highly volatile — counts can differ dramatically (e.g., 53 vs 40) even between queries taken milliseconds apart. Do not assert instance count equality or exact instance list matching between JNA and FFM results. The only reliable assertion is that both are empty or both are non-empty (`assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())`).

Applied to files:

  • oshi-benchmark/src/test/java/oshi/comparison/RegistryComparisonTest.java
📚 Learning: 2026-04-19T01:28:43.529Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3174
File: oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java:237-257
Timestamp: 2026-04-19T01:28:43.529Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java`, the WMI comparison tests (e.g., `testProcessor`) intentionally validate only index 0 and a few representative fields per WMI data type (String, uint16, uint32, uint64). Exhaustive row-by-row comparison is deliberately avoided for numerically heavy multi-row tables. The design rationale is: matching row counts + a few selected fields covering each data type is sufficient to verify JNA vs FFM driver parity. Do not suggest looping over all rows for these tests.

Applied to files:

  • oshi-benchmark/src/test/java/oshi/comparison/RegistryComparisonTest.java
📚 Learning: 2026-04-15T04:56:18.352Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3163
File: oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java:97-103
Timestamp: 2026-04-15T04:56:18.352Z
Learning: In CoreFoundationTest.java (oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java), asserting exact CFGetRetainCount deltas (+1 after retain, -1 after release) is intentional and considered reliable for freshly created CF objects (e.g., CFStringRef via CFStringRef.createCFString) where the test holds sole ownership. Do not flag these assertions as flaky — the Apple "avoid CFGetRetainCount" advisory applies to shared/framework-managed objects, not exclusively owned objects in unit tests.

Applied to files:

  • oshi-benchmark/src/test/java/oshi/comparison/RegistryComparisonTest.java
📚 Learning: 2026-04-18T22:53:49.248Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3173
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java:107-193
Timestamp: 2026-04-18T22:53:49.248Z
Learning: In OSHI's `WmiQueryHandlerFFM` (oshi-core-java25) and the JNA `WmiQueryHandler` (oshi-core), the `failedWmiClassNames` cache intentionally keys failures by WMI class name only (not namespace). This is a pre-existing, accepted pattern shared between both implementations. Do not flag this as a bug in future reviews — the project maintainer (dbwiddis) confirmed it does not impact callers and the added complexity of a composite namespace+class key is not warranted.

Applied to files:

  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsBaseboardJNA.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsComputerSystemFFM.java
📚 Learning: 2026-04-06T04:45:47.644Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:47.644Z
Learning: In the oshi/oshi project, only interfaces and classes in the root packages `oshi`, `oshi.hardware`, and `oshi.software.os` are considered the public API. Code in subpackages that represent specific implementations/platforms (e.g., `oshi.software.os.linux`, `oshi.hardware.platform.linux`, and similar subpackages) is implementation detail. When reviewing, do not treat changes to classes in these platform-specific subpackages as public API breaks (for example: making `LinuxOperatingSystem` abstract, narrowing constructor visibility, or adding/removing abstract methods should not be flagged as breaking public API).

Applied to files:

  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsBaseboardJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsPrinterJNA.java
📚 Learning: 2026-04-08T00:58:10.736Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3125
File: oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsPowerSourceFFM.java:131-133
Timestamp: 2026-04-08T00:58:10.736Z
Learning: In `oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsPowerSourceJNA.java` and `oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsPowerSourceFFM.java`, the `getPowerSources()` method intentionally returns a singleton list wrapping a single `getPowerSource("System Battery")` call, and the enumeration loop short-circuits after the first eligible battery pack. This matches the longstanding JNA behavior and is not a bug. A broader refactor to support zero-or-more batteries across both implementations is planned for a later date. Do not flag this as an issue.

Applied to files:

  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsPrinterJNA.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsComputerSystemFFM.java
📚 Learning: 2026-04-03T02:07:47.621Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3110
File: oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java:119-121
Timestamp: 2026-04-03T02:07:47.621Z
Learning: In OSHI’s Java FFM/API implementation classes (e.g., *FFM.java) that implement/override `updateAttributes()`, preserve the intentional failure-handling pattern: catch `Throwable` and return `false` without logging. `updateAttributes()` is a public API whose contract is to signal failure via the boolean return value, and callers rely on that return value (so emitting logs from this path is not desired and should not be introduced during review unless the method contract changes).

Applied to files:

  • oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsComputerSystemFFM.java
🔇 Additional comments (7)
oshi-benchmark/src/test/java/oshi/comparison/RegistryComparisonTest.java (1)

65-69: LGTM — sensible CI tolerance bump.

Widening the memory-gauge ratio to 0.50 is a reasonable accommodation for transient fluctuations between the registry read and the PDH read on CI. The static/cumulative-counter assertions above remain strict, so parity coverage isn't materially weakened.

oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsComputerSystemFFM.java (1)

31-109: LGTM — clean FFM mirror of the JNA implementation.

The class faithfully mirrors the JNA WindowsComputerSystemJNA structure: memoized suppliers, blank-to-UNKNOWN normalization, BIOS serial fallback, and FFM-wired createFirmware() / createBaseboard() returning WindowsFirmwareFFM / WindowsBaseboardFFM. Consistent with the sibling WindowsFirmwareFFM and WindowsBaseboardFFM patterns shown in the context snippets.

oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsBaseboardJNA.java (2)

26-26: Rename looks consistent.

Line 26 correctly identifies this as the JNA-backed implementation, and the provided WindowsComputerSystemJNA#createBaseboard() context is updated to instantiate it.


28-29: Memoized supplier update is correct.

The method reference now points to the renamed class while preserving the existing lazy WMI query behavior.

oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsPrinterJNA.java (3)

23-28: Class shape and constructor forwarding look good.

The package-private immutable JNA implementation cleanly delegates shared printer state to the common Windows printer base. Based on learnings, only interfaces/classes in root packages oshi, oshi.hardware, and oshi.software.os are public API; platform-specific subpackages are implementation detail.


35-53: WMI mapping looks consistent with the migration goal.

The method keeps discovery local to the JNA implementation while reusing the shared parseStatus() / parseErrorState() logic, which should preserve behavior across JNA and FFM implementations.


55-61: Defensive Boolean parsing looks safe.

Defaulting non-Boolean or missing WMI values to false avoids cast failures and matches the conservative behavior expected for these flags.


📝 Walkthrough

Walkthrough

Refactors Windows hardware drivers into a three-tier pattern: common abstract bases in oshi-common, JNA concrete implementations in oshi-core, and FFM concrete implementations in oshi-core-java25; adds new WindowsPrinter base and JNA/FFM printer implementations, renames several JNA classes, and updates HAL wiring and CHANGELOG entries.

Changes

Cohort / File(s) Summary
Changelog
CHANGELOG.md
Added two entries documenting migration of remaining Windows WMI drivers to the common/JNA/FFM pattern and migration of specific simple WMI-only hardware classes (Baseboard, Firmware, ComputerSystem) to FFM.
Common Base Classes
oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsPrinter.java
New abstract WindowsPrinter with ERROR_STATE_NAMES and protected helpers parseStatus and parseErrorState; centralizes Windows printer parsing/representation.
JNA Implementations (renames/updates)
oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsBaseboardJNA.java, .../WindowsComputerSystemJNA.java, .../WindowsFirmwareJNA.java
Renamed former JNA classes (WindowsBaseboard → WindowsBaseboardJNA, WindowsComputerSystem → WindowsComputerSystemJNA, WindowsFirmware → WindowsFirmwareJNA) and updated supplier/method references and factory returns accordingly.
JNA Printer Implementation
oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsPrinterJNA.java
New JNA-based concrete printer extending common WindowsPrinter; implements getPrinters() querying Win32PrinterJNA, parses status/error, and normalizes boolean fields.
Removed Legacy JNA Printer
oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsPrinter.java
Deleted legacy monolithic WindowsPrinter implementation; functionality migrated to common base and WindowsPrinterJNA.
JNA HAL Wiring
oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayer.java
Now returns WindowsComputerSystemJNA from createComputerSystem() and delegates printers to WindowsPrinterJNA.getPrinters().
FFM Implementations
oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsBaseboardFFM.java, .../WindowsFirmwareFFM.java, .../WindowsComputerSystemFFM.java, .../WindowsPrinterFFM.java
Added FFM-based concrete implementations for Baseboard, Firmware, ComputerSystem, and Printer that use memoized suppliers to query WMI via FFM utilities and expose the corresponding getters.
FFM HAL Wiring
oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsHardwareAbstractionLayerFFM.java
Now returns WindowsComputerSystemFFM from createComputerSystem() and delegates printers to WindowsPrinterFFM.getPrinters().
Tests / Benchmarks
oshi-benchmark/src/test/.../RegistryComparisonTest.java, oshi-core/src/test/.../IOReportClientTest.java
Adjusted memory-gauge tolerances and minor test refactor (local variable for summed ticks) to stabilize CI expectations.

Sequence Diagram(s)

sequenceDiagram
    participant App as Client/App
    participant HAL as WindowsHAL
    participant Impl as WindowsPrinterJNA / WindowsPrinterFFM
    participant Win32 as Win32PrinterJNA / Win32PrinterFFM
    participant WMI as WMI

    App->>HAL: request getPrinters()
    HAL->>Impl: WindowsPrinter*/getPrinters()
    Impl->>Win32: queryPrinters()
    Win32->>WMI: execute Win32_Printer query
    WMI-->>Win32: rows of printer properties
    Win32-->>Impl: parsed WmiResult rows
    Impl-->>HAL: List<Printer> (constructed via parseStatus/parseErrorState)
    HAL-->>App: return printers list
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

Poem

🧩 New layers stack, each role defined,
Common roots and drivers aligned,
JNA, FFM join the band—
Windows printers now well planned. 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.30% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main objective of this changeset: migrating simple Windows WMI classes (Baseboard, Firmware, ComputerSystem, Printer) from JNA to FFM implementations.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Apr 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 72.22222% with 40 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.43%. Comparing base (5dd6341) to head (3ba7bc8).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...are/platform/windows/WindowsComputerSystemFFM.java 58.82% 7 Missing and 7 partials ⚠️
...rdware/common/platform/windows/WindowsPrinter.java 33.33% 7 Missing and 3 partials ⚠️
...hardware/platform/windows/WindowsBaseboardFFM.java 72.72% 0 Missing and 6 partials ⚠️
.../hardware/platform/windows/WindowsFirmwareFFM.java 75.00% 0 Missing and 6 partials ⚠️
...i/hardware/platform/windows/WindowsPrinterFFM.java 90.00% 1 Missing and 1 partial ⚠️
...i/hardware/platform/windows/WindowsPrinterJNA.java 90.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3175      +/-   ##
==========================================
+ Coverage   58.41%   58.43%   +0.01%     
==========================================
  Files         390      395       +5     
  Lines       18191    18295     +104     
  Branches     3183     3205      +22     
==========================================
+ Hits        10627    10691      +64     
- Misses       5992     6009      +17     
- Partials     1572     1595      +23     
Flag Coverage Δ
linux 25.24% <0.00%> (-0.19%) ⬇️
macos 28.34% <0.00%> (-0.16%) ⬇️
windows 33.62% <72.22%> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Create FFM implementations for WindowsBaseboard, WindowsFirmware,
WindowsComputerSystem, and WindowsPrinter. These classes only depend
on WMI queries, so the migration is a straightforward driver swap.

- Rename JNA classes to *JNA suffix (WindowsBaseboardJNA, etc.)
- Extract shared printer parsing logic to common superclass
  WindowsPrinter in oshi.hardware.common.platform.windows
- Create FFM counterparts using WmiUtilFFM and FFM WMI drivers
- Wire up FFM HAL to use new FFM implementations
@dbwiddis
dbwiddis force-pushed the simple-wmi-windows-ffm branch from 36e3104 to 3ba7bc8 Compare April 19, 2026 03:49
@dbwiddis
dbwiddis merged commit d0ea166 into oshi:master Apr 19, 2026
16 of 17 checks passed
@dbwiddis
dbwiddis deleted the simple-wmi-windows-ffm branch April 19, 2026 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant