oculus1

annotate 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
rev   line source
nuclear@1 1 /************************************************************************************
nuclear@1 2
nuclear@1 3 Filename : OVR_Win32_DeviceStatus.h
nuclear@1 4 Content : Win32-specific DeviceStatus header.
nuclear@1 5 Created : January 24, 2013
nuclear@1 6 Authors : Lee Cooper
nuclear@1 7
nuclear@1 8 Copyright : Copyright 2013 Oculus VR, Inc. All Rights reserved.
nuclear@1 9
nuclear@1 10 Use of this software is subject to the terms of the Oculus license
nuclear@1 11 agreement provided at the time of installation or download, or which
nuclear@1 12 otherwise accompanies this software in either electronic or hard copy form.
nuclear@1 13
nuclear@1 14 *************************************************************************************/
nuclear@1 15
nuclear@1 16 #ifndef OVR_Win32_DeviceStatus_h
nuclear@1 17 #define OVR_Win32_DeviceStatus_h
nuclear@1 18
nuclear@1 19 #include <windows.h>
nuclear@1 20 #include "Kernel/OVR_String.h"
nuclear@1 21 #include "Kernel/OVR_RefCount.h"
nuclear@1 22 #include "Kernel/OVR_Array.h"
nuclear@1 23
nuclear@1 24 namespace OVR { namespace Win32 {
nuclear@1 25
nuclear@1 26 //-------------------------------------------------------------------------------------
nuclear@1 27 // ***** DeviceStatus
nuclear@1 28 //
nuclear@1 29 // DeviceStatus abstracts the handling of windows messages of interest for
nuclear@1 30 // example the WM_DEVICECHANGED message which occurs when a device is plugged/unplugged.
nuclear@1 31 // The device manager thread creates an instance of this class and passes its pointer
nuclear@1 32 // in the constructor. That thread is also responsible for periodically calling 'ProcessMessages'
nuclear@1 33 // to process queued windows messages. The client is notified via the 'OnMessage' method
nuclear@1 34 // declared in the 'DeviceMessages::Notifier' interface.
nuclear@1 35 class DeviceStatus : public RefCountBase<DeviceStatus>
nuclear@1 36 {
nuclear@1 37 public:
nuclear@1 38
nuclear@1 39 // Notifier used for device messages.
nuclear@1 40 class Notifier
nuclear@1 41 {
nuclear@1 42 public:
nuclear@1 43 enum MessageType
nuclear@1 44 {
nuclear@1 45 DeviceAdded = 0,
nuclear@1 46 DeviceRemoved = 1,
nuclear@1 47 };
nuclear@1 48
nuclear@1 49 virtual bool OnMessage(MessageType type, const String& devicePath)
nuclear@1 50 { OVR_UNUSED2(type, devicePath); return true; }
nuclear@1 51 };
nuclear@1 52
nuclear@1 53 DeviceStatus(Notifier* const pClient);
nuclear@1 54 ~DeviceStatus();
nuclear@1 55
nuclear@1 56 void operator = (const DeviceStatus&); // No assignment implementation.
nuclear@1 57
nuclear@1 58 bool Initialize();
nuclear@1 59 void ShutDown();
nuclear@1 60
nuclear@1 61 void ProcessMessages();
nuclear@1 62
nuclear@1 63 private:
nuclear@1 64 enum
nuclear@1 65 {
nuclear@1 66 MaxUSBRecoveryAttempts = 20,
nuclear@1 67 USBRecoveryTimeInterval = 500 // ms
nuclear@1 68 };
nuclear@1 69 struct RecoveryTimerDesc
nuclear@1 70 {
nuclear@1 71 UINT_PTR TimerId;
nuclear@1 72 String DevicePath;
nuclear@1 73 unsigned NumAttempts;
nuclear@1 74 };
nuclear@1 75
nuclear@1 76 static LRESULT CALLBACK WindowsMessageCallback( HWND hwnd,
nuclear@1 77 UINT message,
nuclear@1 78 WPARAM wParam,
nuclear@1 79 LPARAM lParam);
nuclear@1 80
nuclear@1 81 bool MessageCallback(WORD messageType, const String& devicePath);
nuclear@1 82
nuclear@1 83 void CleanupRecoveryTimer(UPInt index);
nuclear@1 84 RecoveryTimerDesc* FindRecoveryTimer(UINT_PTR timerId, UPInt* pindex);
nuclear@1 85 void FindAndCleanupRecoveryTimer(const String& devicePath);
nuclear@1 86
nuclear@1 87 private: // data
nuclear@1 88 Notifier* const pNotificationClient; // Don't reference count a back-pointer.
nuclear@1 89
nuclear@1 90 HWND hMessageWindow;
nuclear@1 91 HDEVNOTIFY hDeviceNotify;
nuclear@1 92
nuclear@1 93 UINT_PTR LastTimerId;
nuclear@1 94 Array<RecoveryTimerDesc> RecoveryTimers;
nuclear@1 95
nuclear@1 96 GUID HidGuid;
nuclear@1 97 };
nuclear@1 98
nuclear@1 99 }} // namespace OVR::Win32
nuclear@1 100
nuclear@1 101 #endif // OVR_Win32_DeviceStatus_h