diff --git a/CMakeLists.txt b/CMakeLists.txt index 9af43d3..e3f9111 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -209,6 +209,7 @@ add_library(boo lib/inputdev/DualshockPad.cpp include/boo/inputdev/DualshockPad.hpp lib/inputdev/GenericPad.cpp include/boo/inputdev/GenericPad.hpp lib/inputdev/DeviceSignature.cpp include/boo/inputdev/DeviceSignature.hpp + lib/inputdev/DeviceFinder.cpp include/boo/inputdev/DeviceFinder.hpp lib/inputdev/IHIDDevice.hpp lib/audiodev/WAVOut.cpp lib/audiodev/AudioMatrix.hpp diff --git a/include/boo/System.hpp b/include/boo/System.hpp index 6992d26..a9073d9 100644 --- a/include/boo/System.hpp +++ b/include/boo/System.hpp @@ -54,6 +54,8 @@ namespace boo } #ifdef _WIN32 +#include +#include #include template using ComPtr = Microsoft::WRL::ComPtr; diff --git a/include/boo/graphicsdev/D3D.hpp b/include/boo/graphicsdev/D3D.hpp index e5f23dc..55b946d 100644 --- a/include/boo/graphicsdev/D3D.hpp +++ b/include/boo/graphicsdev/D3D.hpp @@ -7,7 +7,6 @@ #include "IGraphicsCommandQueue.hpp" #include "boo/IGraphicsContext.hpp" #include "boo/System.hpp" -#include #include #include diff --git a/include/boo/inputdev/DeviceFinder.hpp b/include/boo/inputdev/DeviceFinder.hpp index 9d084ec..5cf1bbd 100644 --- a/include/boo/inputdev/DeviceFinder.hpp +++ b/include/boo/inputdev/DeviceFinder.hpp @@ -15,7 +15,6 @@ #define WIN32_LEAN_AND_MEAN 1 #endif #include -#include #endif namespace boo @@ -30,20 +29,20 @@ public: friend class HIDListenerUdev; friend class HIDListenerWinUSB; static inline DeviceFinder* instance() {return skDevFinder;} - + private: - + /* Types this finder is interested in (immutable) */ DeviceSignature::TDeviceSignatureSet m_types; - + /* Platform-specific USB event registration * (for auto-scanning, NULL if not registered) */ IHIDListener* m_listener; - + /* Set of presently-connected device tokens */ TDeviceTokens m_tokens; std::mutex m_tokensLock; - + /* Friend methods for platform-listener to find/insert/remove * tokens with type-filtering */ inline bool _hasToken(const std::string& path) @@ -80,9 +79,9 @@ private: m_tokensLock.unlock(); } } - + public: - + class CDeviceTokensHandle { DeviceFinder& m_finder; @@ -93,7 +92,7 @@ public: inline TDeviceTokens::iterator begin() {return m_finder.m_tokens.begin();} inline TDeviceTokens::iterator end() {return m_finder.m_tokens.end();} }; - + /* Application must specify its interested device-types */ DeviceFinder(std::unordered_set types) : m_listener(NULL) @@ -122,13 +121,13 @@ public: delete m_listener; skDevFinder = NULL; } - + /* Get interested device-type mask */ inline const DeviceSignature::TDeviceSignatureSet& getTypes() const {return m_types;} - + /* Iterable set of tokens */ inline CDeviceTokensHandle getTokens() {return CDeviceTokensHandle(*this);} - + /* Automatic device scanning */ inline bool startScanning() { @@ -156,51 +155,15 @@ public: return m_listener->scanNow(); return false; } - + virtual void deviceConnected(DeviceToken&) {} virtual void deviceDisconnected(DeviceToken&, DeviceBase*) {} #if _WIN32 /* Windows-specific WM_DEVICECHANGED handler */ - static LRESULT winDevChangedHandler(WPARAM wParam, LPARAM lParam) - { - PDEV_BROADCAST_HDR dbh = (PDEV_BROADCAST_HDR)lParam; - PDEV_BROADCAST_DEVICEINTERFACE dbhi = (PDEV_BROADCAST_DEVICEINTERFACE)lParam; - DeviceFinder* finder = instance(); - if (!finder) - return 0; + static LRESULT winDevChangedHandler(WPARAM wParam, LPARAM lParam); +#endif - if (wParam == DBT_DEVICEARRIVAL) - { - if (dbh->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) - { -#ifdef UNICODE - char devPath[1024]; - wcstombs(devPath, dbhi->dbcc_name, 1024); - finder->m_listener->_extDevConnect(devPath); -#else - finder->m_listener->_extDevConnect(dbhi->dbcc_name); -#endif - } - } - else if (wParam == DBT_DEVICEREMOVECOMPLETE) - { - if (dbh->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) - { -#ifdef UNICODE - char devPath[1024]; - wcstombs(devPath, dbhi->dbcc_name, 1024); - finder->m_listener->_extDevDisconnect(devPath); -#else - finder->m_listener->_extDevDisconnect(dbhi->dbcc_name); -#endif - } - } - - return 0; - } -#endif - }; } diff --git a/lib/inputdev/DeviceFinder.cpp b/lib/inputdev/DeviceFinder.cpp new file mode 100644 index 0000000..7c3eaa9 --- /dev/null +++ b/lib/inputdev/DeviceFinder.cpp @@ -0,0 +1,51 @@ +#include "boo/inputdev/DeviceFinder.hpp" + +#if _WIN32 +#include +#endif + +namespace boo +{ + +#if _WIN32 +/* Windows-specific WM_DEVICECHANGED handler */ +LRESULT DeviceFinder::winDevChangedHandler(WPARAM wParam, LPARAM lParam) +{ + PDEV_BROADCAST_HDR dbh = (PDEV_BROADCAST_HDR)lParam; + PDEV_BROADCAST_DEVICEINTERFACE dbhi = (PDEV_BROADCAST_DEVICEINTERFACE)lParam; + DeviceFinder* finder = instance(); + if (!finder) + return 0; + + if (wParam == DBT_DEVICEARRIVAL) + { + if (dbh->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) + { +#ifdef UNICODE + char devPath[1024]; + wcstombs(devPath, dbhi->dbcc_name, 1024); + finder->m_listener->_extDevConnect(devPath); +#else + finder->m_listener->_extDevConnect(dbhi->dbcc_name); +#endif + } + } + else if (wParam == DBT_DEVICEREMOVECOMPLETE) + { + if (dbh->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) + { +#ifdef UNICODE + char devPath[1024]; + wcstombs(devPath, dbhi->dbcc_name, 1024); + finder->m_listener->_extDevDisconnect(devPath); +#else + finder->m_listener->_extDevDisconnect(dbhi->dbcc_name); +#endif + } + } + + return 0; +} +#endif + +} diff --git a/lib/win/ApplicationWin32.cpp b/lib/win/ApplicationWin32.cpp index a04d538..afd35f6 100644 --- a/lib/win/ApplicationWin32.cpp +++ b/lib/win/ApplicationWin32.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #if _DEBUG #define D3D11_CREATE_DEVICE_FLAGS D3D11_CREATE_DEVICE_DEBUG