nuclear@1: /************************************************************************************ nuclear@1: nuclear@1: PublicHeader: OVR.h nuclear@1: Filename : OVR_DeviceHandle.h nuclear@1: Content : Handle to a device that was enumerated nuclear@1: Created : February 5, 2013 nuclear@1: Authors : Lee Cooper nuclear@1: nuclear@1: Copyright : Copyright 2013 Oculus VR, Inc. All Rights reserved. nuclear@1: nuclear@1: Use of this software is subject to the terms of the Oculus license nuclear@1: agreement provided at the time of installation or download, or which nuclear@1: otherwise accompanies this software in either electronic or hard copy form. nuclear@1: nuclear@1: *************************************************************************************/ nuclear@1: nuclear@1: #ifndef OVR_DeviceHandle_h nuclear@1: #define OVR_DeviceHandle_h nuclear@1: nuclear@1: #include "OVR_DeviceConstants.h" nuclear@1: nuclear@1: namespace OVR { nuclear@1: nuclear@1: class DeviceBase; nuclear@1: class DeviceInfo; nuclear@1: nuclear@1: // Internal nuclear@1: class DeviceCreateDesc; nuclear@1: class DeviceEnumerationArgs; nuclear@1: nuclear@1: nuclear@1: //------------------------------------------------------------------------------------- nuclear@1: // ***** DeviceHandle nuclear@1: nuclear@1: // DeviceHandle references a specific device that was enumerated; it can be assigned nuclear@1: // directly from DeviceEnumerator. nuclear@1: // nuclear@1: // Devices represented by DeviceHandle are not necessarily created or available. nuclear@1: // A device may become unavailable if, for example, it its unplugged. If the device nuclear@1: // is available, it can be created by calling CreateDevice. nuclear@1: // nuclear@1: nuclear@1: class DeviceHandle nuclear@1: { nuclear@1: friend class DeviceManager; nuclear@1: friend class DeviceManagerImpl; nuclear@1: template friend class HIDDeviceImpl; nuclear@1: nuclear@1: public: nuclear@1: DeviceHandle() : pImpl(0) { } nuclear@1: DeviceHandle(const DeviceHandle& src); nuclear@1: ~DeviceHandle(); nuclear@1: nuclear@1: void operator = (const DeviceHandle& src); nuclear@1: nuclear@1: bool operator == (const DeviceHandle& other) const { return pImpl == other.pImpl; } nuclear@1: bool operator != (const DeviceHandle& other) const { return pImpl != other.pImpl; } nuclear@1: nuclear@1: // operator bool() returns true if Handle/Enumerator points to a valid device. nuclear@1: operator bool () const { return GetType() != Device_None; } nuclear@1: nuclear@1: // Returns existing device, or NULL if !IsCreated. The returned ptr is nuclear@1: // addref-ed. nuclear@1: DeviceBase* GetDevice_AddRef() const; nuclear@1: DeviceType GetType() const; nuclear@1: bool GetDeviceInfo(DeviceInfo* info) const; nuclear@1: bool IsAvailable() const; nuclear@1: bool IsCreated() const; nuclear@1: // Returns true, if the handle contains the same device ptr nuclear@1: // as specified in the parameter. nuclear@1: bool IsDevice(DeviceBase*) const; nuclear@1: nuclear@1: // Creates a device, or returns AddRefed pointer if one is already created. nuclear@1: // New devices start out with RefCount of 1. nuclear@1: DeviceBase* CreateDevice(); nuclear@1: nuclear@1: // Creates a device, or returns AddRefed pointer if one is already created. nuclear@1: // New devices start out with RefCount of 1. DeviceT is used to cast the nuclear@1: // DeviceBase* to a concreete type. nuclear@1: template nuclear@1: DeviceT* CreateDeviceTyped() const nuclear@1: { nuclear@1: return static_cast(DeviceHandle(*this).CreateDevice()); nuclear@1: } nuclear@1: nuclear@1: // Resets the device handle to uninitialized state. nuclear@1: void Clear(); nuclear@1: nuclear@1: protected: nuclear@1: explicit DeviceHandle(DeviceCreateDesc* impl); nuclear@1: bool enumerateNext(const DeviceEnumerationArgs& args); nuclear@1: DeviceCreateDesc* pImpl; nuclear@1: }; nuclear@1: nuclear@1: } // namespace OVR nuclear@1: nuclear@1: #endif