Skip to content

Reduce duplication: extract IOKit iteration into template/callback pattern #3260

Closed

Description

@dbwiddis

Problem

Mac implementations for platformExpert(), queryCompatibleStrings(), and calculateNominalFrequencies() in both MacCentralProcessorJNA and MacCentralProcessorFFM share identical algorithmic structure:

  1. Get matching service/services by name
  2. Iterate IORegistryEntries
  3. Extract byte array properties
  4. Parse and return results

The only difference is the IOKit API used (IOKitUtil/IOKit.IOIterator for JNA vs IOKitUtilFFM/oshi.ffm.mac.IOKit.IOIterator for FFM).

Estimated duplicated code: ~300 lines across Mac platform classes.

Example

Both versions iterate IOPlatformDevice entries looking for CPU nodes and extracting the "compatible" property — same logic, different API calls.

Proposal

Introduce a callback or strategy pattern (e.g., IOKitProvider interface with getMatchingService, getMatchingServices, property extraction methods) that can be injected into the common Mac base classes. The iteration logic would live once in oshi-common, with JNA and FFM each providing their IOKitProvider implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions