oculus1
diff libovr/Src/win32/OVR_Win32_DeviceStatus.h @ 1:e2f9e4603129
added LibOVR and started a simple vr wrapper.
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 14 Sep 2013 16:14:59 +0300 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libovr/Src/win32/OVR_Win32_DeviceStatus.h Sat Sep 14 16:14:59 2013 +0300 1.3 @@ -0,0 +1,101 @@ 1.4 +/************************************************************************************ 1.5 + 1.6 +Filename : OVR_Win32_DeviceStatus.h 1.7 +Content : Win32-specific DeviceStatus header. 1.8 +Created : January 24, 2013 1.9 +Authors : Lee Cooper 1.10 + 1.11 +Copyright : Copyright 2013 Oculus VR, Inc. All Rights reserved. 1.12 + 1.13 +Use of this software is subject to the terms of the Oculus license 1.14 +agreement provided at the time of installation or download, or which 1.15 +otherwise accompanies this software in either electronic or hard copy form. 1.16 + 1.17 +*************************************************************************************/ 1.18 + 1.19 +#ifndef OVR_Win32_DeviceStatus_h 1.20 +#define OVR_Win32_DeviceStatus_h 1.21 + 1.22 +#include <windows.h> 1.23 +#include "Kernel/OVR_String.h" 1.24 +#include "Kernel/OVR_RefCount.h" 1.25 +#include "Kernel/OVR_Array.h" 1.26 + 1.27 +namespace OVR { namespace Win32 { 1.28 + 1.29 +//------------------------------------------------------------------------------------- 1.30 +// ***** DeviceStatus 1.31 +// 1.32 +// DeviceStatus abstracts the handling of windows messages of interest for 1.33 +// example the WM_DEVICECHANGED message which occurs when a device is plugged/unplugged. 1.34 +// The device manager thread creates an instance of this class and passes its pointer 1.35 +// in the constructor. That thread is also responsible for periodically calling 'ProcessMessages' 1.36 +// to process queued windows messages. The client is notified via the 'OnMessage' method 1.37 +// declared in the 'DeviceMessages::Notifier' interface. 1.38 +class DeviceStatus : public RefCountBase<DeviceStatus> 1.39 +{ 1.40 +public: 1.41 + 1.42 + // Notifier used for device messages. 1.43 + class Notifier 1.44 + { 1.45 + public: 1.46 + enum MessageType 1.47 + { 1.48 + DeviceAdded = 0, 1.49 + DeviceRemoved = 1, 1.50 + }; 1.51 + 1.52 + virtual bool OnMessage(MessageType type, const String& devicePath) 1.53 + { OVR_UNUSED2(type, devicePath); return true; } 1.54 + }; 1.55 + 1.56 + DeviceStatus(Notifier* const pClient); 1.57 + ~DeviceStatus(); 1.58 + 1.59 + void operator = (const DeviceStatus&); // No assignment implementation. 1.60 + 1.61 + bool Initialize(); 1.62 + void ShutDown(); 1.63 + 1.64 + void ProcessMessages(); 1.65 + 1.66 +private: 1.67 + enum 1.68 + { 1.69 + MaxUSBRecoveryAttempts = 20, 1.70 + USBRecoveryTimeInterval = 500 // ms 1.71 + }; 1.72 + struct RecoveryTimerDesc 1.73 + { 1.74 + UINT_PTR TimerId; 1.75 + String DevicePath; 1.76 + unsigned NumAttempts; 1.77 + }; 1.78 + 1.79 + static LRESULT CALLBACK WindowsMessageCallback( HWND hwnd, 1.80 + UINT message, 1.81 + WPARAM wParam, 1.82 + LPARAM lParam); 1.83 + 1.84 + bool MessageCallback(WORD messageType, const String& devicePath); 1.85 + 1.86 + void CleanupRecoveryTimer(UPInt index); 1.87 + RecoveryTimerDesc* FindRecoveryTimer(UINT_PTR timerId, UPInt* pindex); 1.88 + void FindAndCleanupRecoveryTimer(const String& devicePath); 1.89 + 1.90 +private: // data 1.91 + Notifier* const pNotificationClient; // Don't reference count a back-pointer. 1.92 + 1.93 + HWND hMessageWindow; 1.94 + HDEVNOTIFY hDeviceNotify; 1.95 + 1.96 + UINT_PTR LastTimerId; 1.97 + Array<RecoveryTimerDesc> RecoveryTimers; 1.98 + 1.99 + GUID HidGuid; 1.100 +}; 1.101 + 1.102 +}} // namespace OVR::Win32 1.103 + 1.104 +#endif // OVR_Win32_DeviceStatus_h