oculus1
diff libovr/Src/OVR_DeviceHandle.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/OVR_DeviceHandle.h Sat Sep 14 16:14:59 2013 +0300 1.3 @@ -0,0 +1,97 @@ 1.4 +/************************************************************************************ 1.5 + 1.6 +PublicHeader: OVR.h 1.7 +Filename : OVR_DeviceHandle.h 1.8 +Content : Handle to a device that was enumerated 1.9 +Created : February 5, 2013 1.10 +Authors : Lee Cooper 1.11 + 1.12 +Copyright : Copyright 2013 Oculus VR, Inc. All Rights reserved. 1.13 + 1.14 +Use of this software is subject to the terms of the Oculus license 1.15 +agreement provided at the time of installation or download, or which 1.16 +otherwise accompanies this software in either electronic or hard copy form. 1.17 + 1.18 +*************************************************************************************/ 1.19 + 1.20 +#ifndef OVR_DeviceHandle_h 1.21 +#define OVR_DeviceHandle_h 1.22 + 1.23 +#include "OVR_DeviceConstants.h" 1.24 + 1.25 +namespace OVR { 1.26 + 1.27 +class DeviceBase; 1.28 +class DeviceInfo; 1.29 + 1.30 +// Internal 1.31 +class DeviceCreateDesc; 1.32 +class DeviceEnumerationArgs; 1.33 + 1.34 + 1.35 +//------------------------------------------------------------------------------------- 1.36 +// ***** DeviceHandle 1.37 + 1.38 +// DeviceHandle references a specific device that was enumerated; it can be assigned 1.39 +// directly from DeviceEnumerator. 1.40 +// 1.41 +// Devices represented by DeviceHandle are not necessarily created or available. 1.42 +// A device may become unavailable if, for example, it its unplugged. If the device 1.43 +// is available, it can be created by calling CreateDevice. 1.44 +// 1.45 + 1.46 +class DeviceHandle 1.47 +{ 1.48 + friend class DeviceManager; 1.49 + friend class DeviceManagerImpl; 1.50 + template<class B> friend class HIDDeviceImpl; 1.51 + 1.52 +public: 1.53 + DeviceHandle() : pImpl(0) { } 1.54 + DeviceHandle(const DeviceHandle& src); 1.55 + ~DeviceHandle(); 1.56 + 1.57 + void operator = (const DeviceHandle& src); 1.58 + 1.59 + bool operator == (const DeviceHandle& other) const { return pImpl == other.pImpl; } 1.60 + bool operator != (const DeviceHandle& other) const { return pImpl != other.pImpl; } 1.61 + 1.62 + // operator bool() returns true if Handle/Enumerator points to a valid device. 1.63 + operator bool () const { return GetType() != Device_None; } 1.64 + 1.65 + // Returns existing device, or NULL if !IsCreated. The returned ptr is 1.66 + // addref-ed. 1.67 + DeviceBase* GetDevice_AddRef() const; 1.68 + DeviceType GetType() const; 1.69 + bool GetDeviceInfo(DeviceInfo* info) const; 1.70 + bool IsAvailable() const; 1.71 + bool IsCreated() const; 1.72 + // Returns true, if the handle contains the same device ptr 1.73 + // as specified in the parameter. 1.74 + bool IsDevice(DeviceBase*) const; 1.75 + 1.76 + // Creates a device, or returns AddRefed pointer if one is already created. 1.77 + // New devices start out with RefCount of 1. 1.78 + DeviceBase* CreateDevice(); 1.79 + 1.80 + // Creates a device, or returns AddRefed pointer if one is already created. 1.81 + // New devices start out with RefCount of 1. DeviceT is used to cast the 1.82 + // DeviceBase* to a concreete type. 1.83 + template <class DeviceT> 1.84 + DeviceT* CreateDeviceTyped() const 1.85 + { 1.86 + return static_cast<DeviceT*>(DeviceHandle(*this).CreateDevice()); 1.87 + } 1.88 + 1.89 + // Resets the device handle to uninitialized state. 1.90 + void Clear(); 1.91 + 1.92 +protected: 1.93 + explicit DeviceHandle(DeviceCreateDesc* impl); 1.94 + bool enumerateNext(const DeviceEnumerationArgs& args); 1.95 + DeviceCreateDesc* pImpl; 1.96 +}; 1.97 + 1.98 +} // namespace OVR 1.99 + 1.100 +#endif