rev |
line source |
nuclear@1
|
1 /************************************************************************************
|
nuclear@1
|
2
|
nuclear@1
|
3 Filename : OVR_Win32_DeviceManager.h
|
nuclear@1
|
4 Content : Win32-specific DeviceManager header.
|
nuclear@1
|
5 Created : September 21, 2012
|
nuclear@1
|
6 Authors : Michael Antonov
|
nuclear@1
|
7
|
nuclear@1
|
8 Copyright : Copyright 2012 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_DeviceManager_h
|
nuclear@1
|
17 #define OVR_Win32_DeviceManager_h
|
nuclear@1
|
18
|
nuclear@1
|
19 #include "OVR_DeviceImpl.h"
|
nuclear@1
|
20 #include "OVR_Win32_DeviceStatus.h"
|
nuclear@1
|
21
|
nuclear@1
|
22 #include "Kernel/OVR_Timer.h"
|
nuclear@1
|
23
|
nuclear@1
|
24
|
nuclear@1
|
25 namespace OVR { namespace Win32 {
|
nuclear@1
|
26
|
nuclear@1
|
27 class DeviceManagerThread;
|
nuclear@1
|
28
|
nuclear@1
|
29 //-------------------------------------------------------------------------------------
|
nuclear@1
|
30 // ***** Win32 DeviceManager
|
nuclear@1
|
31
|
nuclear@1
|
32 class DeviceManager : public DeviceManagerImpl
|
nuclear@1
|
33 {
|
nuclear@1
|
34 public:
|
nuclear@1
|
35 DeviceManager();
|
nuclear@1
|
36 ~DeviceManager();
|
nuclear@1
|
37
|
nuclear@1
|
38 // Initialize/Shutdowncreate and shutdown manger thread.
|
nuclear@1
|
39 virtual bool Initialize(DeviceBase* parent);
|
nuclear@1
|
40 virtual void Shutdown();
|
nuclear@1
|
41
|
nuclear@1
|
42 virtual ThreadCommandQueue* GetThreadQueue();
|
nuclear@1
|
43 virtual ThreadId GetThreadId() const;
|
nuclear@1
|
44
|
nuclear@1
|
45 virtual DeviceEnumerator<> EnumerateDevicesEx(const DeviceEnumerationArgs& args);
|
nuclear@1
|
46
|
nuclear@1
|
47 virtual bool GetDeviceInfo(DeviceInfo* info) const;
|
nuclear@1
|
48
|
nuclear@1
|
49 // Fills HIDDeviceDesc by using the path.
|
nuclear@1
|
50 // Returns 'true' if successful, 'false' otherwise.
|
nuclear@1
|
51 bool GetHIDDeviceDesc(const String& path, HIDDeviceDesc* pdevDesc) const;
|
nuclear@1
|
52
|
nuclear@1
|
53 Ptr<DeviceManagerThread> pThread;
|
nuclear@1
|
54 };
|
nuclear@1
|
55
|
nuclear@1
|
56 //-------------------------------------------------------------------------------------
|
nuclear@1
|
57 // ***** Device Manager Background Thread
|
nuclear@1
|
58
|
nuclear@1
|
59 class DeviceManagerThread : public Thread, public ThreadCommandQueue, public DeviceStatus::Notifier
|
nuclear@1
|
60 {
|
nuclear@1
|
61 friend class DeviceManager;
|
nuclear@1
|
62 enum { ThreadStackSize = 32 * 1024 };
|
nuclear@1
|
63 public:
|
nuclear@1
|
64 DeviceManagerThread(DeviceManager* pdevMgr);
|
nuclear@1
|
65 ~DeviceManagerThread();
|
nuclear@1
|
66
|
nuclear@1
|
67 virtual int Run();
|
nuclear@1
|
68
|
nuclear@1
|
69 // ThreadCommandQueue notifications for CommandEvent handling.
|
nuclear@1
|
70 virtual void OnPushNonEmpty_Locked() { ::SetEvent(hCommandEvent); }
|
nuclear@1
|
71 virtual void OnPopEmpty_Locked() { ::ResetEvent(hCommandEvent); }
|
nuclear@1
|
72
|
nuclear@1
|
73
|
nuclear@1
|
74 // Notifier used for different updates (EVENT or regular timing or messages).
|
nuclear@1
|
75 class Notifier
|
nuclear@1
|
76 {
|
nuclear@1
|
77 public:
|
nuclear@1
|
78 // Called when overlapped I/O handle is signaled.
|
nuclear@1
|
79 virtual void OnOverlappedEvent(HANDLE hevent) { OVR_UNUSED1(hevent); }
|
nuclear@1
|
80
|
nuclear@1
|
81 // Called when timing ticks are updated.
|
nuclear@1
|
82 // Returns the largest number of microseconds this function can
|
nuclear@1
|
83 // wait till next call.
|
nuclear@1
|
84 virtual UInt64 OnTicks(UInt64 ticksMks)
|
nuclear@1
|
85 { OVR_UNUSED1(ticksMks); return Timer::MksPerSecond * 1000; }
|
nuclear@1
|
86
|
nuclear@1
|
87 enum DeviceMessageType
|
nuclear@1
|
88 {
|
nuclear@1
|
89 DeviceMessage_DeviceAdded = 0,
|
nuclear@1
|
90 DeviceMessage_DeviceRemoved = 1,
|
nuclear@1
|
91 };
|
nuclear@1
|
92
|
nuclear@1
|
93 // Called to notify device object.
|
nuclear@1
|
94 virtual bool OnDeviceMessage(DeviceMessageType messageType,
|
nuclear@1
|
95 const String& devicePath,
|
nuclear@1
|
96 bool* error)
|
nuclear@1
|
97 { OVR_UNUSED3(messageType, devicePath, error); return false; }
|
nuclear@1
|
98 };
|
nuclear@1
|
99
|
nuclear@1
|
100
|
nuclear@1
|
101 // Adds device's OVERLAPPED structure for I/O.
|
nuclear@1
|
102 // After it's added, Overlapped object will be signaled if a message arrives.
|
nuclear@1
|
103 bool AddOverlappedEvent(Notifier* notify, HANDLE hevent);
|
nuclear@1
|
104 bool RemoveOverlappedEvent(Notifier* notify, HANDLE hevent);
|
nuclear@1
|
105
|
nuclear@1
|
106 // Add notifier that will be called at regular intervals.
|
nuclear@1
|
107 bool AddTicksNotifier(Notifier* notify);
|
nuclear@1
|
108 bool RemoveTicksNotifier(Notifier* notify);
|
nuclear@1
|
109
|
nuclear@1
|
110 bool AddMessageNotifier(Notifier* notify);
|
nuclear@1
|
111 bool RemoveMessageNotifier(Notifier* notify);
|
nuclear@1
|
112
|
nuclear@1
|
113 // DeviceStatus::Notifier interface.
|
nuclear@1
|
114 bool OnMessage(MessageType type, const String& devicePath);
|
nuclear@1
|
115
|
nuclear@1
|
116 void DetachDeviceManager();
|
nuclear@1
|
117
|
nuclear@1
|
118 private:
|
nuclear@1
|
119 bool threadInitialized() { return hCommandEvent != 0; }
|
nuclear@1
|
120
|
nuclear@1
|
121 // Event used to wake us up thread commands are enqueued.
|
nuclear@1
|
122 HANDLE hCommandEvent;
|
nuclear@1
|
123
|
nuclear@1
|
124 // Event notifications for devices whose OVERLAPPED I/O we service.
|
nuclear@1
|
125 // This list is modified through AddDeviceOverlappedEvent.
|
nuclear@1
|
126 // WaitHandles[0] always == hCommandEvent, with null device.
|
nuclear@1
|
127 Array<HANDLE> WaitHandles;
|
nuclear@1
|
128 Array<Notifier*> WaitNotifiers;
|
nuclear@1
|
129
|
nuclear@1
|
130 // Ticks notifiers - used for time-dependent events such as keep-alive.
|
nuclear@1
|
131 Array<Notifier*> TicksNotifiers;
|
nuclear@1
|
132
|
nuclear@1
|
133 // Message notifiers.
|
nuclear@1
|
134 Array<Notifier*> MessageNotifiers;
|
nuclear@1
|
135
|
nuclear@1
|
136 // Object that manages notifications originating from Windows messages.
|
nuclear@1
|
137 Ptr<DeviceStatus> pStatusObject;
|
nuclear@1
|
138
|
nuclear@1
|
139 Lock DevMgrLock;
|
nuclear@1
|
140 // pDeviceMgr should be accessed under DevMgrLock
|
nuclear@1
|
141 DeviceManager* pDeviceMgr; // back ptr, no addref.
|
nuclear@1
|
142 };
|
nuclear@1
|
143
|
nuclear@1
|
144 }} // namespace Win32::OVR
|
nuclear@1
|
145
|
nuclear@1
|
146 #endif // OVR_Win32_DeviceManager_h
|