nuclear@1: /************************************************************************************ nuclear@1: nuclear@1: Filename : OVR_Win32_DeviceStatus.h nuclear@1: Content : Win32-specific DeviceStatus header. nuclear@1: Created : January 24, 2013 nuclear@1: Authors : Lee Cooper nuclear@1: nuclear@1: Copyright : Copyright 2013 Oculus VR, Inc. All Rights reserved. nuclear@1: nuclear@1: Use of this software is subject to the terms of the Oculus license nuclear@1: agreement provided at the time of installation or download, or which nuclear@1: otherwise accompanies this software in either electronic or hard copy form. nuclear@1: nuclear@1: *************************************************************************************/ nuclear@1: nuclear@1: #ifndef OVR_Win32_DeviceStatus_h nuclear@1: #define OVR_Win32_DeviceStatus_h nuclear@1: nuclear@1: #include nuclear@1: #include "Kernel/OVR_String.h" nuclear@1: #include "Kernel/OVR_RefCount.h" nuclear@1: #include "Kernel/OVR_Array.h" nuclear@1: nuclear@1: namespace OVR { namespace Win32 { nuclear@1: nuclear@1: //------------------------------------------------------------------------------------- nuclear@1: // ***** DeviceStatus nuclear@1: // nuclear@1: // DeviceStatus abstracts the handling of windows messages of interest for nuclear@1: // example the WM_DEVICECHANGED message which occurs when a device is plugged/unplugged. nuclear@1: // The device manager thread creates an instance of this class and passes its pointer nuclear@1: // in the constructor. That thread is also responsible for periodically calling 'ProcessMessages' nuclear@1: // to process queued windows messages. The client is notified via the 'OnMessage' method nuclear@1: // declared in the 'DeviceMessages::Notifier' interface. nuclear@1: class DeviceStatus : public RefCountBase nuclear@1: { nuclear@1: public: nuclear@1: nuclear@1: // Notifier used for device messages. nuclear@1: class Notifier nuclear@1: { nuclear@1: public: nuclear@1: enum MessageType nuclear@1: { nuclear@1: DeviceAdded = 0, nuclear@1: DeviceRemoved = 1, nuclear@1: }; nuclear@1: nuclear@1: virtual bool OnMessage(MessageType type, const String& devicePath) nuclear@1: { OVR_UNUSED2(type, devicePath); return true; } nuclear@1: }; nuclear@1: nuclear@1: DeviceStatus(Notifier* const pClient); nuclear@1: ~DeviceStatus(); nuclear@1: nuclear@1: void operator = (const DeviceStatus&); // No assignment implementation. nuclear@1: nuclear@1: bool Initialize(); nuclear@1: void ShutDown(); nuclear@1: nuclear@1: void ProcessMessages(); nuclear@1: nuclear@1: private: nuclear@1: enum nuclear@1: { nuclear@1: MaxUSBRecoveryAttempts = 20, nuclear@1: USBRecoveryTimeInterval = 500 // ms nuclear@1: }; nuclear@1: struct RecoveryTimerDesc nuclear@1: { nuclear@1: UINT_PTR TimerId; nuclear@1: String DevicePath; nuclear@1: unsigned NumAttempts; nuclear@1: }; nuclear@1: nuclear@1: static LRESULT CALLBACK WindowsMessageCallback( HWND hwnd, nuclear@1: UINT message, nuclear@1: WPARAM wParam, nuclear@1: LPARAM lParam); nuclear@1: nuclear@1: bool MessageCallback(WORD messageType, const String& devicePath); nuclear@1: nuclear@1: void CleanupRecoveryTimer(UPInt index); nuclear@1: RecoveryTimerDesc* FindRecoveryTimer(UINT_PTR timerId, UPInt* pindex); nuclear@1: void FindAndCleanupRecoveryTimer(const String& devicePath); nuclear@1: nuclear@1: private: // data nuclear@1: Notifier* const pNotificationClient; // Don't reference count a back-pointer. nuclear@1: nuclear@1: HWND hMessageWindow; nuclear@1: HDEVNOTIFY hDeviceNotify; nuclear@1: nuclear@1: UINT_PTR LastTimerId; nuclear@1: Array RecoveryTimers; nuclear@1: nuclear@1: GUID HidGuid; nuclear@1: }; nuclear@1: nuclear@1: }} // namespace OVR::Win32 nuclear@1: nuclear@1: #endif // OVR_Win32_DeviceStatus_h