Class WmiQueryHandlerFFM

java.lang.Object
oshi.util.platform.windows.WmiQueryHandlerFFM

@ThreadSafe public class WmiQueryHandlerFFM extends Object
FFM-based utility to handle WMI Queries.

This class provides a high-level API for executing WMI queries using the Foreign Function and Memory API.

  • Constructor Details

    • WmiQueryHandlerFFM

      protected WmiQueryHandlerFFM()
  • Method Details

    • createInstance

      public static WmiQueryHandlerFFM createInstance()
      Factory method to create an instance of this class. To override this class, use setInstanceClass(Class) to define a subclass which extends WmiQueryHandlerFFM.
      Returns:
      an instance of this class or a class defined by setInstanceClass(Class)
    • setInstanceClass

      public static void setInstanceClass(Class<? extends WmiQueryHandlerFFM> instanceClass)
      Define a subclass to be instantiated by createInstance(). The class must extend WmiQueryHandlerFFM.
      Parameters:
      instanceClass - the class to instantiate with createInstance()
    • queryWMI

      public <T> List<T> queryWMI(String namespace, String wmiClassName, String whereClause, Supplier<T> resultFactory, WmiQueryHandlerFFM.TriConsumer<MemorySegment, Arena, T> rowProcessor)
      Executes a WMI query and processes each result row.
      Type Parameters:
      T - the type of result object
      Parameters:
      namespace - the WMI namespace (e.g., "ROOT\\CIMV2")
      wmiClassName - the WMI class name (e.g., "Win32_LogicalDisk")
      whereClause - optional WHERE clause (null for none)
      resultFactory - factory to create result objects
      rowProcessor - processor to populate result object from WMI row
      Returns:
      list of result objects, empty list if query fails
    • queryWMI

      public <T> List<T> queryWMI(String wmiClassName, String whereClause, Supplier<T> resultFactory, WmiQueryHandlerFFM.TriConsumer<MemorySegment, Arena, T> rowProcessor)
      Executes a WMI query in the default CIMV2 namespace.
      Type Parameters:
      T - the type of result object
      Parameters:
      wmiClassName - the WMI class name
      whereClause - optional WHERE clause
      resultFactory - factory to create result objects
      rowProcessor - processor to populate result object from WMI row
      Returns:
      list of result objects
    • initCOM

      public boolean initCOM()
      Initializes COM library.
      Returns:
      true if COM was initialized and needs to be uninitialized
      Throws:
      FfmComException - if COM initialization fails with an unexpected error
    • unInitCOM

      public void unInitCOM()
      Uninitializes COM library.
    • switchComThreadingFrom

      public int switchComThreadingFrom(int expected)
      Switches the COM threading model only if it still matches the expected value.
      Parameters:
      expected - the threading model we observed before the failed initCOM attempt
      Returns:
      the new threading model if switched, or the current value if already switched by another thread
    • getComThreading

      public int getComThreading()
      Returns the current threading model for COM initialization, as OSHI is required to match if an external program has COM initialized already.
      Returns:
      the current threading model
    • switchComThreading

      public int switchComThreading()
      Switches the current threading model for COM initialization, as OSHI is required to match if an external program has COM initialized already.
      Returns:
      the new threading model after switching
    • getWmiTimeout

      public int getWmiTimeout()
      Gets the current WMI timeout in milliseconds.
      Returns:
      the current timeout (-1 for infinite)
    • setWmiTimeout

      public void setWmiTimeout(int wmiTimeout)
      Sets the WMI timeout in milliseconds.
      Parameters:
      wmiTimeout - the timeout to set (-1 for infinite)