oculus1

view libovr/Src/win32/OVR_Win32_DeviceManager.h @ 3:b069a5c27388

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