All Downloads are FREE. Search and download functionalities are using the official Maven repository.

oshi.software.os.windows.WindowsOSSystemInfo Maven / Gradle / Ivy

package oshi.software.os.windows;

import oshi.jna.platform.windows.Kernel32;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.sun.jna.platform.win32.WinBase;
import com.sun.jna.platform.win32.WinNT;
import com.sun.jna.ptr.IntByReference;

/**
 * @author angju
 *
 */
public class WindowsOSSystemInfo {
    private final static Logger LOG = LoggerFactory.getLogger(WindowsOSSystemInfo.class.getName());

    private WinBase.SYSTEM_INFO _si = null;

    public WindowsOSSystemInfo() {

        WinBase.SYSTEM_INFO si = new WinBase.SYSTEM_INFO();
        Kernel32.INSTANCE.GetSystemInfo(si);

        try {
            IntByReference isWow64 = new IntByReference();
            WinNT.HANDLE hProcess = Kernel32.INSTANCE.GetCurrentProcess();
            if (Kernel32.INSTANCE.IsWow64Process(hProcess, isWow64) && isWow64.getValue() > 0) {
                Kernel32.INSTANCE.GetNativeSystemInfo(si);
            }
        } catch (UnsatisfiedLinkError e) {
            // no WOW64 support
            LOG.trace("", e);
        }

        this._si = si;
        LOG.debug("Initialized OSNativeSystemInfo");
    }

    public WindowsOSSystemInfo(WinBase.SYSTEM_INFO si) {
        this._si = si;
    }

    /**
     * Number of processors.
     *
     * @return Integer.
     */
    public int getNumberOfProcessors() {
        return this._si.dwNumberOfProcessors.intValue();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy