setupapi: trim "Get" from getters

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
Simon Rozman 2019-05-22 19:31:52 +02:00
parent a6dbe4f475
commit dc9bbec9db
5 changed files with 53 additions and 53 deletions

View file

@ -185,7 +185,7 @@ func (tun *NativeTun) getTUN() (read *os.File, write *os.File, err error) {
}
func (tun *NativeTun) Name() (string, error) {
return tun.wt.GetInterfaceName()
return tun.wt.InterfaceName()
}
func (tun *NativeTun) File() *os.File {

View file

@ -40,8 +40,8 @@ func SetupDiGetDeviceInfoListDetail(deviceInfoSet DevInfo) (deviceInfoSetDetailD
return data, setupDiGetDeviceInfoListDetail(deviceInfoSet, data)
}
// GetDeviceInfoListDetail method retrieves information associated with a device information set including the class GUID, remote computer handle, and remote computer name.
func (deviceInfoSet DevInfo) GetDeviceInfoListDetail() (*DevInfoListDetailData, error) {
// DeviceInfoListDetail method retrieves information associated with a device information set including the class GUID, remote computer handle, and remote computer name.
func (deviceInfoSet DevInfo) DeviceInfoListDetail() (*DevInfoListDetailData, error) {
return SetupDiGetDeviceInfoListDetail(deviceInfoSet)
}
@ -135,8 +135,8 @@ func SetupDiGetSelectedDriver(deviceInfoSet DevInfo, deviceInfoData *DevInfoData
return data, setupDiGetSelectedDriver(deviceInfoSet, deviceInfoData, data)
}
// GetSelectedDriver method retrieves the selected driver for a device information set or a particular device information element.
func (deviceInfoSet DevInfo) GetSelectedDriver(deviceInfoData *DevInfoData) (*DrvInfoData, error) {
// SelectedDriver method retrieves the selected driver for a device information set or a particular device information element.
func (deviceInfoSet DevInfo) SelectedDriver(deviceInfoData *DevInfoData) (*DrvInfoData, error) {
return SetupDiGetSelectedDriver(deviceInfoSet, deviceInfoData)
}
@ -181,8 +181,8 @@ func SetupDiGetDriverInfoDetail(deviceInfoSet DevInfo, deviceInfoData *DevInfoDa
return nil, err
}
// GetDriverInfoDetail method retrieves driver information detail for a device information set or a particular device information element in the device information set.
func (deviceInfoSet DevInfo) GetDriverInfoDetail(deviceInfoData *DevInfoData, driverInfoData *DrvInfoData) (*DrvInfoDetailData, error) {
// DriverInfoDetail method retrieves driver information detail for a device information set or a particular device information element in the device information set.
func (deviceInfoSet DevInfo) DriverInfoDetail(deviceInfoData *DevInfoData, driverInfoData *DrvInfoData) (*DrvInfoDetailData, error) {
return SetupDiGetDriverInfoDetail(deviceInfoSet, deviceInfoData, driverInfoData)
}
@ -323,8 +323,8 @@ func wcslen(str []uint16) int {
return len(str)
}
// GetDeviceRegistryProperty method retrieves a specified Plug and Play device property.
func (deviceInfoSet DevInfo) GetDeviceRegistryProperty(deviceInfoData *DevInfoData, property SPDRP) (interface{}, error) {
// DeviceRegistryProperty method retrieves a specified Plug and Play device property.
func (deviceInfoSet DevInfo) DeviceRegistryProperty(deviceInfoData *DevInfoData, property SPDRP) (interface{}, error) {
return SetupDiGetDeviceRegistryProperty(deviceInfoSet, deviceInfoData, property)
}
@ -360,16 +360,16 @@ func SetupDiGetDeviceInstallParams(deviceInfoSet DevInfo, deviceInfoData *DevInf
return params, setupDiGetDeviceInstallParams(deviceInfoSet, deviceInfoData, params)
}
// GetDeviceInstallParams method retrieves device installation parameters for a device information set or a particular device information element.
func (deviceInfoSet DevInfo) GetDeviceInstallParams(deviceInfoData *DevInfoData) (*DevInstallParams, error) {
// DeviceInstallParams method retrieves device installation parameters for a device information set or a particular device information element.
func (deviceInfoSet DevInfo) DeviceInstallParams(deviceInfoData *DevInfoData) (*DevInstallParams, error) {
return SetupDiGetDeviceInstallParams(deviceInfoSet, deviceInfoData)
}
// SetupDiGetClassInstallParams function retrieves class installation parameters for a device information set or a particular device information element.
//sys SetupDiGetClassInstallParams(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, classInstallParams *ClassInstallHeader, classInstallParamsSize uint32, requiredSize *uint32) (err error) = setupapi.SetupDiGetClassInstallParamsW
// GetClassInstallParams method retrieves class installation parameters for a device information set or a particular device information element.
func (deviceInfoSet DevInfo) GetClassInstallParams(deviceInfoData *DevInfoData, classInstallParams *ClassInstallHeader, classInstallParamsSize uint32, requiredSize *uint32) error {
// ClassInstallParams method retrieves class installation parameters for a device information set or a particular device information element.
func (deviceInfoSet DevInfo) ClassInstallParams(deviceInfoData *DevInfoData, classInstallParams *ClassInstallHeader, classInstallParamsSize uint32, requiredSize *uint32) error {
return SetupDiGetClassInstallParams(deviceInfoSet, deviceInfoData, classInstallParams, classInstallParamsSize, requiredSize)
}
@ -460,8 +460,8 @@ func SetupDiGetSelectedDevice(deviceInfoSet DevInfo) (*DevInfoData, error) {
return data, setupDiGetSelectedDevice(deviceInfoSet, data)
}
// GetSelectedDevice method retrieves the selected device information element in a device information set.
func (deviceInfoSet DevInfo) GetSelectedDevice() (*DevInfoData, error) {
// SelectedDevice method retrieves the selected device information element in a device information set.
func (deviceInfoSet DevInfo) SelectedDevice() (*DevInfoData, error) {
return SetupDiGetSelectedDevice(deviceInfoSet)
}

View file

@ -52,7 +52,7 @@ func TestSetupDiGetDeviceInfoListDetail(t *testing.T) {
}
defer devInfoList.Close()
data, err := devInfoList.GetDeviceInfoListDetail()
data, err := devInfoList.DeviceInfoListDetail()
if err != nil {
t.Errorf("Error calling SetupDiGetDeviceInfoListDetail: %s", err.Error())
} else {
@ -64,7 +64,7 @@ func TestSetupDiGetDeviceInfoListDetail(t *testing.T) {
t.Error("SetupDiGetDeviceInfoListDetail returned non-NULL remote machine handle")
}
if data.GetRemoteMachineName() != "" {
if data.RemoteMachineName() != "" {
t.Error("SetupDiGetDeviceInfoListDetail returned non-NULL remote machine name")
}
}
@ -75,7 +75,7 @@ func TestSetupDiGetDeviceInfoListDetail(t *testing.T) {
}
defer devInfoList.Close()
data, err = devInfoList.GetDeviceInfoListDetail()
data, err = devInfoList.DeviceInfoListDetail()
if err != nil {
t.Errorf("Error calling SetupDiGetDeviceInfoListDetail: %s", err.Error())
} else {
@ -87,14 +87,14 @@ func TestSetupDiGetDeviceInfoListDetail(t *testing.T) {
t.Error("SetupDiGetDeviceInfoListDetail returned NULL remote machine handle")
}
if data.GetRemoteMachineName() != computerName {
if data.RemoteMachineName() != computerName {
t.Error("SetupDiGetDeviceInfoListDetail returned different remote machine name")
}
}
data = &DevInfoListDetailData{}
data.SetRemoteMachineName("foobar")
if data.GetRemoteMachineName() != "foobar" {
if data.RemoteMachineName() != "foobar" {
t.Error("DevInfoListDetailData.(Get|Set)RemoteMachineName() differ")
}
}
@ -210,7 +210,7 @@ func TestDevInfo_BuildDriverInfoList(t *testing.T) {
selectedDriverData = driverData
}
driverDetailData, err := devInfoList.GetDriverInfoDetail(deviceData, driverData)
driverDetailData, err := devInfoList.DriverInfoDetail(deviceData, driverData)
if err != nil {
t.Errorf("Error calling SetupDiGetDriverInfoDetail: %s", err.Error())
}
@ -218,10 +218,10 @@ func TestDevInfo_BuildDriverInfoList(t *testing.T) {
if driverDetailData.IsCompatible("foobar-aab6e3a4-144e-4786-88d3-6cec361e1edd") {
t.Error("Invalid HWID compatibitlity reported")
}
if !driverDetailData.IsCompatible(strings.ToUpper(driverDetailData.GetHardwareID())) {
if !driverDetailData.IsCompatible(strings.ToUpper(driverDetailData.HardwareID())) {
t.Error("HWID compatibitlity missed")
}
a := driverDetailData.GetCompatIDs()
a := driverDetailData.CompatIDs()
for k := range a {
if !driverDetailData.IsCompatible(strings.ToUpper(a[k])) {
t.Error("HWID compatibitlity missed")
@ -229,7 +229,7 @@ func TestDevInfo_BuildDriverInfoList(t *testing.T) {
}
}
selectedDriverData2, err := devInfoList.GetSelectedDriver(deviceData)
selectedDriverData2, err := devInfoList.SelectedDriver(deviceData)
if err != nil {
t.Errorf("Error calling SetupDiGetSelectedDriver: %s", err.Error())
} else if *selectedDriverData != *selectedDriverData2 {
@ -239,15 +239,15 @@ func TestDevInfo_BuildDriverInfoList(t *testing.T) {
data := &DrvInfoData{}
data.SetDescription("foobar")
if data.GetDescription() != "foobar" {
if data.Description() != "foobar" {
t.Error("DrvInfoData.(Get|Set)Description() differ")
}
data.SetMfgName("foobar")
if data.GetMfgName() != "foobar" {
if data.MfgName() != "foobar" {
t.Error("DrvInfoData.(Get|Set)MfgName() differ")
}
data.SetProviderName("foobar")
if data.GetProviderName() != "foobar" {
if data.ProviderName() != "foobar" {
t.Error("DrvInfoData.(Get|Set)ProviderName() differ")
}
}
@ -311,14 +311,14 @@ func TestSetupDiGetDeviceRegistryProperty(t *testing.T) {
continue
}
val, err := devInfoList.GetDeviceRegistryProperty(data, SPDRP_CLASS)
val, err := devInfoList.DeviceRegistryProperty(data, SPDRP_CLASS)
if err != nil {
t.Errorf("Error calling SetupDiGetDeviceRegistryProperty(SPDRP_CLASS): %s", err.Error())
} else if class, ok := val.(string); !ok || strings.ToLower(class) != "net" {
t.Errorf("SetupDiGetDeviceRegistryProperty(SPDRP_CLASS) should return \"Net\"")
}
val, err = devInfoList.GetDeviceRegistryProperty(data, SPDRP_CLASSGUID)
val, err = devInfoList.DeviceRegistryProperty(data, SPDRP_CLASSGUID)
if err != nil {
t.Errorf("Error calling SetupDiGetDeviceRegistryProperty(SPDRP_CLASSGUID): %s", err.Error())
} else if valStr, ok := val.(string); !ok {
@ -332,7 +332,7 @@ func TestSetupDiGetDeviceRegistryProperty(t *testing.T) {
}
}
val, err = devInfoList.GetDeviceRegistryProperty(data, SPDRP_COMPATIBLEIDS)
val, err = devInfoList.DeviceRegistryProperty(data, SPDRP_COMPATIBLEIDS)
if err != nil {
// Some devices have no SPDRP_COMPATIBLEIDS.
if errWin, ok := err.(syscall.Errno); !ok || errWin != windows.ERROR_INVALID_DATA {
@ -340,12 +340,12 @@ func TestSetupDiGetDeviceRegistryProperty(t *testing.T) {
}
}
val, err = devInfoList.GetDeviceRegistryProperty(data, SPDRP_CONFIGFLAGS)
val, err = devInfoList.DeviceRegistryProperty(data, SPDRP_CONFIGFLAGS)
if err != nil {
t.Errorf("Error calling SetupDiGetDeviceRegistryProperty(SPDRP_CONFIGFLAGS): %s", err.Error())
}
val, err = devInfoList.GetDeviceRegistryProperty(data, SPDRP_DEVICE_POWER_DATA)
val, err = devInfoList.DeviceRegistryProperty(data, SPDRP_DEVICE_POWER_DATA)
if err != nil {
t.Errorf("Error calling SetupDiGetDeviceRegistryProperty(SPDRP_DEVICE_POWER_DATA): %s", err.Error())
}
@ -368,7 +368,7 @@ func TestSetupDiGetDeviceInstallParams(t *testing.T) {
continue
}
_, err = devInfoList.GetDeviceInstallParams(data)
_, err = devInfoList.DeviceInstallParams(data)
if err != nil {
t.Errorf("Error calling SetupDiGetDeviceInstallParams: %s", err.Error())
}
@ -376,7 +376,7 @@ func TestSetupDiGetDeviceInstallParams(t *testing.T) {
params := &DevInstallParams{}
params.SetDriverPath("foobar")
if params.GetDriverPath() != "foobar" {
if params.DriverPath() != "foobar" {
t.Error("DevInstallParams.(Get|Set)DriverPath() differ")
}
}
@ -452,7 +452,7 @@ func TestSetupDiGetSelectedDevice(t *testing.T) {
t.Errorf("Error calling SetupDiSetSelectedDevice: %s", err.Error())
}
data2, err := devInfoList.GetSelectedDevice()
data2, err := devInfoList.SelectedDevice()
if err != nil {
t.Errorf("Error calling SetupDiGetSelectedDevice: %s", err.Error())
} else if *data != *data2 {

View file

@ -66,7 +66,7 @@ type DevInfoListDetailData struct {
remoteMachineName [SP_MAX_MACHINENAME_LENGTH]uint16
}
func (data *DevInfoListDetailData) GetRemoteMachineName() string {
func (data *DevInfoListDetailData) RemoteMachineName() string {
return windows.UTF16ToString(data.remoteMachineName[:])
}
@ -138,7 +138,7 @@ type DevInstallParams struct {
driverPath [windows.MAX_PATH]uint16
}
func (params *DevInstallParams) GetDriverPath() string {
func (params *DevInstallParams) DriverPath() string {
return windows.UTF16ToString(params.driverPath[:])
}
@ -304,7 +304,7 @@ type DrvInfoData struct {
DriverVersion uint64
}
func (data *DrvInfoData) GetDescription() string {
func (data *DrvInfoData) Description() string {
return windows.UTF16ToString(data.description[:])
}
@ -317,7 +317,7 @@ func (data *DrvInfoData) SetDescription(description string) error {
return nil
}
func (data *DrvInfoData) GetMfgName() string {
func (data *DrvInfoData) MfgName() string {
return windows.UTF16ToString(data.mfgName[:])
}
@ -330,7 +330,7 @@ func (data *DrvInfoData) SetMfgName(mfgName string) error {
return nil
}
func (data *DrvInfoData) GetProviderName() string {
func (data *DrvInfoData) ProviderName() string {
return windows.UTF16ToString(data.providerName[:])
}
@ -382,19 +382,19 @@ type DrvInfoDetailData struct {
hardwareID [ANYSIZE_ARRAY]uint16
}
func (data *DrvInfoDetailData) GetSectionName() string {
func (data *DrvInfoDetailData) SectionName() string {
return windows.UTF16ToString(data.sectionName[:])
}
func (data *DrvInfoDetailData) GetInfFileName() string {
func (data *DrvInfoDetailData) InfFileName() string {
return windows.UTF16ToString(data.infFileName[:])
}
func (data *DrvInfoDetailData) GetDrvDescription() string {
func (data *DrvInfoDetailData) DrvDescription() string {
return windows.UTF16ToString(data.drvDescription[:])
}
func (data *DrvInfoDetailData) GetHardwareID() string {
func (data *DrvInfoDetailData) HardwareID() string {
if data.compatIDsOffset > 1 {
bufW := data.getBuf()
return windows.UTF16ToString(bufW[:wcslen(bufW)])
@ -403,7 +403,7 @@ func (data *DrvInfoDetailData) GetHardwareID() string {
return ""
}
func (data *DrvInfoDetailData) GetCompatIDs() []string {
func (data *DrvInfoDetailData) CompatIDs() []string {
a := make([]string, 0)
if data.compatIDsLength > 0 {
@ -434,10 +434,10 @@ func (data *DrvInfoDetailData) getBuf() []uint16 {
// IsCompatible method tests if given hardware ID matches the driver or is listed on the compatible ID list.
func (data *DrvInfoDetailData) IsCompatible(hwid string) bool {
hwidLC := strings.ToLower(hwid)
if strings.ToLower(data.GetHardwareID()) == hwidLC {
if strings.ToLower(data.HardwareID()) == hwidLC {
return true
}
a := data.GetCompatIDs()
a := data.CompatIDs()
for i := range a {
if strings.ToLower(a[i]) == hwidLC {
return true

View file

@ -125,7 +125,7 @@ func GetInterface(ifname string, hwndParent uintptr) (*Wintun, error) {
//TODO: is there a better way than comparing ifnames?
// Get interface name.
ifname2, err := wintun.GetInterfaceName()
ifname2, err := wintun.InterfaceName()
if err != nil {
continue
}
@ -151,7 +151,7 @@ func GetInterface(ifname string, hwndParent uintptr) (*Wintun, error) {
}
// Get driver info details.
driverDetailData, err := devInfoList.GetDriverInfoDetail(deviceData, driverData)
driverDetailData, err := devInfoList.DriverInfoDetail(deviceData, driverData)
if err != nil {
// Something is wrong with this driver. Skip it.
continue
@ -241,7 +241,7 @@ func CreateInterface(description string, hwndParent uintptr) (*Wintun, bool, err
// Check the driver version first, since the check is trivial and will save us iterating over hardware IDs for any driver versioned prior our best match.
if driverData.IsNewer(driverDate, driverVersion) {
// Get driver info details.
driverDetailData, err := devInfoList.GetDriverInfoDetail(deviceData, driverData)
driverDetailData, err := devInfoList.DriverInfoDetail(deviceData, driverData)
if err != nil {
// Something is wrong with this driver. Skip it.
continue
@ -474,7 +474,7 @@ func (wintun *Wintun) DeleteInterface(hwndParent uintptr) (bool, bool, error) {
// checkReboot checks device install parameters if a system reboot is required.
//
func checkReboot(deviceInfoSet setupapi.DevInfo, deviceInfoData *setupapi.DevInfoData) (bool, error) {
devInstallParams, err := deviceInfoSet.GetDeviceInstallParams(deviceInfoData)
devInstallParams, err := deviceInfoSet.DeviceInstallParams(deviceInfoData)
if err != nil {
return false, err
}
@ -487,9 +487,9 @@ func checkReboot(deviceInfoSet setupapi.DevInfo, deviceInfoData *setupapi.DevInf
}
//
// GetInterfaceName returns network interface name.
// InterfaceName returns network interface name.
//
func (wintun *Wintun) GetInterfaceName() (string, error) {
func (wintun *Wintun) InterfaceName() (string, error) {
key, err := registry.OpenKey(registry.LOCAL_MACHINE, wintun.netRegKeyName(), registry.QUERY_VALUE)
if err != nil {
return "", fmt.Errorf("Network-specific registry key open failed: %v", err)