oculus1

diff libovr/Src/win32/OVR_Win32_DeviceManager.h @ 1:e2f9e4603129

added LibOVR and started a simple vr wrapper.
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 14 Sep 2013 16:14:59 +0300
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libovr/Src/win32/OVR_Win32_DeviceManager.h	Sat Sep 14 16:14:59 2013 +0300
     1.3 @@ -0,0 +1,146 @@
     1.4 +/************************************************************************************
     1.5 +
     1.6 +Filename    :   OVR_Win32_DeviceManager.h
     1.7 +Content     :   Win32-specific DeviceManager header.
     1.8 +Created     :   September 21, 2012
     1.9 +Authors     :   Michael Antonov
    1.10 +
    1.11 +Copyright   :   Copyright 2012 Oculus VR, Inc. All Rights reserved.
    1.12 +
    1.13 +Use of this software is subject to the terms of the Oculus license
    1.14 +agreement provided at the time of installation or download, or which
    1.15 +otherwise accompanies this software in either electronic or hard copy form.
    1.16 +
    1.17 +*************************************************************************************/
    1.18 +
    1.19 +#ifndef OVR_Win32_DeviceManager_h
    1.20 +#define OVR_Win32_DeviceManager_h
    1.21 +
    1.22 +#include "OVR_DeviceImpl.h"
    1.23 +#include "OVR_Win32_DeviceStatus.h"
    1.24 +
    1.25 +#include "Kernel/OVR_Timer.h"
    1.26 +
    1.27 +
    1.28 +namespace OVR { namespace Win32 {
    1.29 +
    1.30 +class DeviceManagerThread;
    1.31 +
    1.32 +//-------------------------------------------------------------------------------------
    1.33 +// ***** Win32 DeviceManager
    1.34 +
    1.35 +class DeviceManager : public DeviceManagerImpl
    1.36 +{
    1.37 +public:
    1.38 +    DeviceManager();
    1.39 +    ~DeviceManager();
    1.40 +
    1.41 +    // Initialize/Shutdowncreate and shutdown manger thread.
    1.42 +    virtual bool Initialize(DeviceBase* parent);
    1.43 +    virtual void Shutdown();
    1.44 +
    1.45 +    virtual ThreadCommandQueue* GetThreadQueue();
    1.46 +    virtual ThreadId GetThreadId() const;
    1.47 +
    1.48 +    virtual DeviceEnumerator<> EnumerateDevicesEx(const DeviceEnumerationArgs& args);    
    1.49 +
    1.50 +    virtual bool  GetDeviceInfo(DeviceInfo* info) const;
    1.51 +
    1.52 +    // Fills HIDDeviceDesc by using the path.
    1.53 +    // Returns 'true' if successful, 'false' otherwise.
    1.54 +    bool GetHIDDeviceDesc(const String& path, HIDDeviceDesc* pdevDesc) const;
    1.55 +    
    1.56 +    Ptr<DeviceManagerThread> pThread;
    1.57 +};
    1.58 +
    1.59 +//-------------------------------------------------------------------------------------
    1.60 +// ***** Device Manager Background Thread
    1.61 +
    1.62 +class DeviceManagerThread : public Thread, public ThreadCommandQueue, public DeviceStatus::Notifier
    1.63 +{
    1.64 +    friend class DeviceManager;
    1.65 +    enum { ThreadStackSize = 32 * 1024 };
    1.66 +public:
    1.67 +    DeviceManagerThread(DeviceManager* pdevMgr);
    1.68 +    ~DeviceManagerThread();
    1.69 +
    1.70 +    virtual int Run();
    1.71 +
    1.72 +    // ThreadCommandQueue notifications for CommandEvent handling.
    1.73 +    virtual void OnPushNonEmpty_Locked() { ::SetEvent(hCommandEvent); }
    1.74 +    virtual void OnPopEmpty_Locked()     { ::ResetEvent(hCommandEvent); }
    1.75 +
    1.76 +
    1.77 +    // Notifier used for different updates (EVENT or regular timing or messages).
    1.78 +    class Notifier
    1.79 +    {
    1.80 +    public:
    1.81 +		// Called when overlapped I/O handle is signaled.
    1.82 +        virtual void    OnOverlappedEvent(HANDLE hevent) { OVR_UNUSED1(hevent); }
    1.83 +
    1.84 +        // Called when timing ticks are updated.
    1.85 +        // Returns the largest number of microseconds this function can
    1.86 +        // wait till next call.
    1.87 +        virtual UInt64  OnTicks(UInt64 ticksMks)
    1.88 +        { OVR_UNUSED1(ticksMks);  return Timer::MksPerSecond * 1000; }
    1.89 +
    1.90 +		enum DeviceMessageType
    1.91 +		{
    1.92 +			DeviceMessage_DeviceAdded     = 0,
    1.93 +			DeviceMessage_DeviceRemoved   = 1,
    1.94 +		};
    1.95 +
    1.96 +		// Called to notify device object.
    1.97 +		virtual bool    OnDeviceMessage(DeviceMessageType messageType, 
    1.98 +										const String& devicePath,
    1.99 +										bool* error) 
   1.100 +        { OVR_UNUSED3(messageType, devicePath, error); return false; }
   1.101 +    };
   1.102 +
   1.103 + 
   1.104 +    // Adds device's OVERLAPPED structure for I/O.
   1.105 +    // After it's added, Overlapped object will be signaled if a message arrives.
   1.106 +    bool AddOverlappedEvent(Notifier* notify, HANDLE hevent);
   1.107 +    bool RemoveOverlappedEvent(Notifier* notify, HANDLE hevent);
   1.108 +
   1.109 +    // Add notifier that will be called at regular intervals. 
   1.110 +    bool AddTicksNotifier(Notifier* notify);
   1.111 +    bool RemoveTicksNotifier(Notifier* notify);
   1.112 +
   1.113 +	bool AddMessageNotifier(Notifier* notify);
   1.114 +	bool RemoveMessageNotifier(Notifier* notify);
   1.115 +
   1.116 +    // DeviceStatus::Notifier interface.
   1.117 +	bool OnMessage(MessageType type, const String& devicePath);
   1.118 +
   1.119 +    void DetachDeviceManager();
   1.120 +
   1.121 +private:
   1.122 +    bool threadInitialized() { return hCommandEvent != 0; }
   1.123 +
   1.124 +    // Event used to wake us up thread commands are enqueued.    
   1.125 +    HANDLE                  hCommandEvent;
   1.126 +
   1.127 +    // Event notifications for devices whose OVERLAPPED I/O we service.
   1.128 +    // This list is modified through AddDeviceOverlappedEvent.
   1.129 +    // WaitHandles[0] always == hCommandEvent, with null device.
   1.130 +    Array<HANDLE>           WaitHandles;
   1.131 +    Array<Notifier*>        WaitNotifiers;
   1.132 +
   1.133 +    // Ticks notifiers - used for time-dependent events such as keep-alive.
   1.134 +    Array<Notifier*>        TicksNotifiers;
   1.135 +
   1.136 +	// Message notifiers.
   1.137 +    Array<Notifier*>        MessageNotifiers;
   1.138 +
   1.139 +	// Object that manages notifications originating from Windows messages.
   1.140 +	Ptr<DeviceStatus>		pStatusObject;
   1.141 +
   1.142 +    Lock                    DevMgrLock;
   1.143 +    // pDeviceMgr should be accessed under DevMgrLock
   1.144 +    DeviceManager*          pDeviceMgr; // back ptr, no addref. 
   1.145 +};
   1.146 +
   1.147 +}} // namespace Win32::OVR
   1.148 +
   1.149 +#endif // OVR_Win32_DeviceManager_h