oculus1

view libovr/Src/win32/OVR_Win32_DeviceStatus.h @ 9:b66b54a68dfd

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