Skip to content

Commit

Permalink
Get rid of EnumerateDevices verbose argument.
Browse files Browse the repository at this point in the history
  • Loading branch information
forderud committed Nov 13, 2024
1 parent 5ef703f commit 0524f9d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
3 changes: 1 addition & 2 deletions DevicePowerQuery/DeviceEnum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@


typedef void (*DeviceVisitor)(int idx, HDEVINFO devInfo, SP_DEVINFO_DATA& devInfoData);
typedef int (*EnumerateFunction)(GUID classGuid, DeviceVisitor visitor, bool verbose);


/** Returns the device count. */
int EnumerateDevices(GUID classGuid, DeviceVisitor visitor, bool /*verbose*/) {
int EnumerateDevices(GUID classGuid, DeviceVisitor visitor) {
DWORD flags = DIGCF_PRESENT;
if (classGuid == GUID_NULL)
flags |= DIGCF_ALLCLASSES; // query all connected devices
Expand Down
18 changes: 11 additions & 7 deletions DevicePowerQuery/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,15 @@ void VisitDevicePowerData(int idx, HDEVINFO devInfo, SP_DEVINFO_DATA& devInfoDat
}
}

enum class EnumType {
Devices,
Interfaces,
};

int wmain(int argc, wchar_t* argv[]) {
GUID device_class = GUID_NULL;
GUID interface_class = GUID_NULL;
EnumerateFunction enumerator = EnumerateDevices;
EnumType enumerator = EnumType::Devices;
DeviceVisitor visitor = VisitDeviceBasic; // only print basic device information

const wchar_t usage_helpstring[] = L"USAGE DevicePowerQuery.exe [--all | --usb | --hid | --battery] [--devices | --interfaces] [--power]\n";
Expand Down Expand Up @@ -82,20 +86,20 @@ int wmain(int argc, wchar_t* argv[]) {
interface_class = GUID_DEVICE_BATTERY; // only detects batteries, and _not_ AC adapters
assert(GUID_DEVCLASS_BATTERY == GUID_DEVICE_BATTERY);
} else if (arg == L"--devices") {
enumerator = EnumerateDevices;
enumerator = EnumType::Devices;
} else if (arg == L"--interfaces") {
enumerator = EnumerateInterfaces;
enumerator = EnumType::Interfaces;
} else {
wprintf(usage_helpstring);
return 1;
}
}

// search for devices or interfaces
if (enumerator == EnumerateDevices)
enumerator(device_class, visitor, true);
else if (enumerator == EnumerateInterfaces)
enumerator(interface_class, visitor, true);
if (enumerator == EnumType::Devices)
EnumerateDevices(device_class, visitor);
else if (enumerator == EnumType::Interfaces)
EnumerateInterfaces(interface_class, visitor, true);

return 0;
}

0 comments on commit 0524f9d

Please sign in to comment.