Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef OVR_Win32_DeviceManager_h
00017 #define OVR_Win32_DeviceManager_h
00018
00019 #include "OVR_DeviceImpl.h"
00020 #include "OVR_Win32_DeviceStatus.h"
00021
00022 #include "Kernel/OVR_Timer.h"
00023
00024
00025 namespace OVR { namespace Win32 {
00026
00027 class DeviceManagerThread;
00028
00029
00030
00031
00032 class DeviceManager : public DeviceManagerImpl
00033 {
00034 public:
00035 DeviceManager();
00036 ~DeviceManager();
00037
00038
00039 virtual bool Initialize(DeviceBase* parent);
00040 virtual void Shutdown();
00041
00042 virtual ThreadCommandQueue* GetThreadQueue();
00043 virtual ThreadId GetThreadId() const;
00044
00045 virtual DeviceEnumerator<> EnumerateDevicesEx(const DeviceEnumerationArgs& args);
00046
00047 virtual bool GetDeviceInfo(DeviceInfo* info) const;
00048
00049
00050
00051 bool GetHIDDeviceDesc(const String& path, HIDDeviceDesc* pdevDesc) const;
00052
00053 Ptr<DeviceManagerThread> pThread;
00054 };
00055
00056
00057
00058
00059 class DeviceManagerThread : public Thread, public ThreadCommandQueue, public DeviceStatus::Notifier
00060 {
00061 friend class DeviceManager;
00062 enum { ThreadStackSize = 32 * 1024 };
00063 public:
00064 DeviceManagerThread(DeviceManager* pdevMgr);
00065 ~DeviceManagerThread();
00066
00067 virtual int Run();
00068
00069
00070 virtual void OnPushNonEmpty_Locked() { ::SetEvent(hCommandEvent); }
00071 virtual void OnPopEmpty_Locked() { ::ResetEvent(hCommandEvent); }
00072
00073
00074
00075 class Notifier
00076 {
00077 public:
00078
00079 virtual void OnOverlappedEvent(HANDLE hevent) { OVR_UNUSED1(hevent); }
00080
00081
00082
00083
00084 virtual UInt64 OnTicks(UInt64 ticksMks)
00085 { OVR_UNUSED1(ticksMks); return Timer::MksPerSecond * 1000; }
00086
00087 enum DeviceMessageType
00088 {
00089 DeviceMessage_DeviceAdded = 0,
00090 DeviceMessage_DeviceRemoved = 1,
00091 };
00092
00093
00094 virtual bool OnDeviceMessage(DeviceMessageType messageType,
00095 const String& devicePath,
00096 bool* error)
00097 { OVR_UNUSED3(messageType, devicePath, error); return false; }
00098 };
00099
00100
00101
00102
00103 bool AddOverlappedEvent(Notifier* notify, HANDLE hevent);
00104 bool RemoveOverlappedEvent(Notifier* notify, HANDLE hevent);
00105
00106
00107 bool AddTicksNotifier(Notifier* notify);
00108 bool RemoveTicksNotifier(Notifier* notify);
00109
00110 bool AddMessageNotifier(Notifier* notify);
00111 bool RemoveMessageNotifier(Notifier* notify);
00112
00113
00114 bool OnMessage(MessageType type, const String& devicePath);
00115
00116 void DetachDeviceManager();
00117
00118 private:
00119 bool threadInitialized() { return hCommandEvent != 0; }
00120
00121
00122 HANDLE hCommandEvent;
00123
00124
00125
00126
00127 Array<HANDLE> WaitHandles;
00128 Array<Notifier*> WaitNotifiers;
00129
00130
00131 Array<Notifier*> TicksNotifiers;
00132
00133
00134 Array<Notifier*> MessageNotifiers;
00135
00136
00137 Ptr<DeviceStatus> pStatusObject;
00138
00139 Lock DevMgrLock;
00140
00141 DeviceManager* pDeviceMgr;
00142 };
00143
00144 }}
00145
00146 #endif // OVR_Win32_DeviceManager_h