@@ -33,44 +33,50 @@ std::vector<std::string> HotplugWindows::SplitDeviceList(const std::string &list
3333 return result;
3434}
3535
36- void HotplugWindows::CheckForEvents ()
36+ size_t HotplugWindows::Enumerate ( const char *guid);
3737{
3838 /* We check for events by polling the Windows kernel for devices
3939 - present on the system; and
40- - matching the setup class GUID for a TSPD digitizer.
41-
42- We simply take the difference between the number of devices we got in the
43- last call and the number we get from a new call. This obviously misses
44- the case when a digitizer gets removed and added between polling events
45- but that's so rare that it basically shouldn't happen in practice. */
40+ - matching the target setup class GUID. */
4641
4742 const ULONG LIST_FLAGS = CM_GETIDLIST_FILTER_CLASS | CM_GETIDLIST_FILTER_PRESENT;
4843 ULONG list_size = 0 ;
4944
50- CONFIGRET result = CM_Get_Device_ID_List_SizeA (&list_size, GUID , LIST_FLAGS);
45+ CONFIGRET result = CM_Get_Device_ID_List_SizeA (&list_size, guid , LIST_FLAGS);
5146 if (result != CR_SUCCESS)
5247 {
5348 Log::log->error (" CM_Get_Device_ID_List_SizeA failed, code {}." , result);
54- return ;
49+ return 0 ;
5550 }
5651
5752 /* Allocate a string of the prescribed size (includes the NULL terminator). */
5853 auto list = std::string (list_size, ' \0 ' );
5954
60- result = CM_Get_Device_ID_ListA (GUID , (PZZSTR)list.data (), (ULONG)list.capacity (), LIST_FLAGS);
55+ result = CM_Get_Device_ID_ListA (guid , (PZZSTR)list.data (), (ULONG)list.capacity (), LIST_FLAGS);
6156 if (result != CR_SUCCESS)
6257 {
6358 Log::log->error (" CM_Get_Device_ID_ListA failed, code {}." , result);
64- return ;
59+ return 0 ;
6560 }
6661
67- auto devices = std::move (SplitDeviceList (list));
68- if (devices.size () > m_nof_devices)
62+ return SplitDeviceList (list).size ();
63+ }
64+
65+ void HotplugWindows::CheckForEvents ()
66+ {
67+ size_t nof_devices = Enumerate (GUID_PCI) + Enumerate (GUID_USB);
68+
69+ /* We simply take the difference between the number of devices we got in the
70+ last call and the number we get from a new call. This obviously misses
71+ the case when a digitizer gets removed and added between polling events
72+ but that's so rare that it basically shouldn't happen in practice. */
73+
74+ if (nof_devices > m_nof_devices)
6975 _EmplaceMessage (HotplugEvent::CONNECT);
70- else if (devices. size () < m_nof_devices)
76+ else if (nof_devices < m_nof_devices)
7177 _EmplaceMessage (HotplugEvent::DISCONNECT);
7278
73- m_nof_devices = devices. size () ;
79+ m_nof_devices = nof_devices ;
7480}
7581
7682void HotplugWindows::MainLoop ()
0 commit comments