OVR_Win32_DeviceManager.h
Go to the documentation of this file.
00001 /************************************************************************************
00002 
00003 Filename    :   OVR_Win32_DeviceManager.h
00004 Content     :   Win32-specific DeviceManager header.
00005 Created     :   September 21, 2012
00006 Authors     :   Michael Antonov
00007 
00008 Copyright   :   Copyright 2012 Oculus VR, Inc. All Rights reserved.
00009 
00010 Use of this software is subject to the terms of the Oculus license
00011 agreement provided at the time of installation or download, or which
00012 otherwise accompanies this software in either electronic or hard copy form.
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 // ***** Win32 DeviceManager
00031 
00032 class DeviceManager : public DeviceManagerImpl
00033 {
00034 public:
00035     DeviceManager();
00036     ~DeviceManager();
00037 
00038     // Initialize/Shutdowncreate and shutdown manger thread.
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     // Fills HIDDeviceDesc by using the path.
00050     // Returns 'true' if successful, 'false' otherwise.
00051     bool GetHIDDeviceDesc(const String& path, HIDDeviceDesc* pdevDesc) const;
00052     
00053     Ptr<DeviceManagerThread> pThread;
00054 };
00055 
00056 //-------------------------------------------------------------------------------------
00057 // ***** Device Manager Background Thread
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     // ThreadCommandQueue notifications for CommandEvent handling.
00070     virtual void OnPushNonEmpty_Locked() { ::SetEvent(hCommandEvent); }
00071     virtual void OnPopEmpty_Locked()     { ::ResetEvent(hCommandEvent); }
00072 
00073 
00074     // Notifier used for different updates (EVENT or regular timing or messages).
00075     class Notifier
00076     {
00077     public:
00078                 // Called when overlapped I/O handle is signaled.
00079         virtual void    OnOverlappedEvent(HANDLE hevent) { OVR_UNUSED1(hevent); }
00080 
00081         // Called when timing ticks are updated.
00082         // Returns the largest number of microseconds this function can
00083         // wait till next call.
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                 // Called to notify device object.
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     // Adds device's OVERLAPPED structure for I/O.
00102     // After it's added, Overlapped object will be signaled if a message arrives.
00103     bool AddOverlappedEvent(Notifier* notify, HANDLE hevent);
00104     bool RemoveOverlappedEvent(Notifier* notify, HANDLE hevent);
00105 
00106     // Add notifier that will be called at regular intervals. 
00107     bool AddTicksNotifier(Notifier* notify);
00108     bool RemoveTicksNotifier(Notifier* notify);
00109 
00110         bool AddMessageNotifier(Notifier* notify);
00111         bool RemoveMessageNotifier(Notifier* notify);
00112 
00113     // DeviceStatus::Notifier interface.
00114         bool OnMessage(MessageType type, const String& devicePath);
00115 
00116     void DetachDeviceManager();
00117 
00118 private:
00119     bool threadInitialized() { return hCommandEvent != 0; }
00120 
00121     // Event used to wake us up thread commands are enqueued.    
00122     HANDLE                  hCommandEvent;
00123 
00124     // Event notifications for devices whose OVERLAPPED I/O we service.
00125     // This list is modified through AddDeviceOverlappedEvent.
00126     // WaitHandles[0] always == hCommandEvent, with null device.
00127     Array<HANDLE>           WaitHandles;
00128     Array<Notifier*>        WaitNotifiers;
00129 
00130     // Ticks notifiers - used for time-dependent events such as keep-alive.
00131     Array<Notifier*>        TicksNotifiers;
00132 
00133         // Message notifiers.
00134     Array<Notifier*>        MessageNotifiers;
00135 
00136         // Object that manages notifications originating from Windows messages.
00137         Ptr<DeviceStatus>               pStatusObject;
00138 
00139     Lock                    DevMgrLock;
00140     // pDeviceMgr should be accessed under DevMgrLock
00141     DeviceManager*          pDeviceMgr; // back ptr, no addref. 
00142 };
00143 
00144 }} // namespace Win32::OVR
00145 
00146 #endif // OVR_Win32_DeviceManager_h


oculus_sdk
Author(s):
autogenerated on Mon Oct 6 2014 03:01:19