oculus1

annotate libovr/Src/OVR_DeviceHandle.h @ 17:cfe4979ab3eb

ops, minor error in the last commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 21 Sep 2013 07:09:48 +0300
parents
children
rev   line source
nuclear@1 1 /************************************************************************************
nuclear@1 2
nuclear@1 3 PublicHeader: OVR.h
nuclear@1 4 Filename : OVR_DeviceHandle.h
nuclear@1 5 Content : Handle to a device that was enumerated
nuclear@1 6 Created : February 5, 2013
nuclear@1 7 Authors : Lee Cooper
nuclear@1 8
nuclear@1 9 Copyright : Copyright 2013 Oculus VR, Inc. All Rights reserved.
nuclear@1 10
nuclear@1 11 Use of this software is subject to the terms of the Oculus license
nuclear@1 12 agreement provided at the time of installation or download, or which
nuclear@1 13 otherwise accompanies this software in either electronic or hard copy form.
nuclear@1 14
nuclear@1 15 *************************************************************************************/
nuclear@1 16
nuclear@1 17 #ifndef OVR_DeviceHandle_h
nuclear@1 18 #define OVR_DeviceHandle_h
nuclear@1 19
nuclear@1 20 #include "OVR_DeviceConstants.h"
nuclear@1 21
nuclear@1 22 namespace OVR {
nuclear@1 23
nuclear@1 24 class DeviceBase;
nuclear@1 25 class DeviceInfo;
nuclear@1 26
nuclear@1 27 // Internal
nuclear@1 28 class DeviceCreateDesc;
nuclear@1 29 class DeviceEnumerationArgs;
nuclear@1 30
nuclear@1 31
nuclear@1 32 //-------------------------------------------------------------------------------------
nuclear@1 33 // ***** DeviceHandle
nuclear@1 34
nuclear@1 35 // DeviceHandle references a specific device that was enumerated; it can be assigned
nuclear@1 36 // directly from DeviceEnumerator.
nuclear@1 37 //
nuclear@1 38 // Devices represented by DeviceHandle are not necessarily created or available.
nuclear@1 39 // A device may become unavailable if, for example, it its unplugged. If the device
nuclear@1 40 // is available, it can be created by calling CreateDevice.
nuclear@1 41 //
nuclear@1 42
nuclear@1 43 class DeviceHandle
nuclear@1 44 {
nuclear@1 45 friend class DeviceManager;
nuclear@1 46 friend class DeviceManagerImpl;
nuclear@1 47 template<class B> friend class HIDDeviceImpl;
nuclear@1 48
nuclear@1 49 public:
nuclear@1 50 DeviceHandle() : pImpl(0) { }
nuclear@1 51 DeviceHandle(const DeviceHandle& src);
nuclear@1 52 ~DeviceHandle();
nuclear@1 53
nuclear@1 54 void operator = (const DeviceHandle& src);
nuclear@1 55
nuclear@1 56 bool operator == (const DeviceHandle& other) const { return pImpl == other.pImpl; }
nuclear@1 57 bool operator != (const DeviceHandle& other) const { return pImpl != other.pImpl; }
nuclear@1 58
nuclear@1 59 // operator bool() returns true if Handle/Enumerator points to a valid device.
nuclear@1 60 operator bool () const { return GetType() != Device_None; }
nuclear@1 61
nuclear@1 62 // Returns existing device, or NULL if !IsCreated. The returned ptr is
nuclear@1 63 // addref-ed.
nuclear@1 64 DeviceBase* GetDevice_AddRef() const;
nuclear@1 65 DeviceType GetType() const;
nuclear@1 66 bool GetDeviceInfo(DeviceInfo* info) const;
nuclear@1 67 bool IsAvailable() const;
nuclear@1 68 bool IsCreated() const;
nuclear@1 69 // Returns true, if the handle contains the same device ptr
nuclear@1 70 // as specified in the parameter.
nuclear@1 71 bool IsDevice(DeviceBase*) const;
nuclear@1 72
nuclear@1 73 // Creates a device, or returns AddRefed pointer if one is already created.
nuclear@1 74 // New devices start out with RefCount of 1.
nuclear@1 75 DeviceBase* CreateDevice();
nuclear@1 76
nuclear@1 77 // Creates a device, or returns AddRefed pointer if one is already created.
nuclear@1 78 // New devices start out with RefCount of 1. DeviceT is used to cast the
nuclear@1 79 // DeviceBase* to a concreete type.
nuclear@1 80 template <class DeviceT>
nuclear@1 81 DeviceT* CreateDeviceTyped() const
nuclear@1 82 {
nuclear@1 83 return static_cast<DeviceT*>(DeviceHandle(*this).CreateDevice());
nuclear@1 84 }
nuclear@1 85
nuclear@1 86 // Resets the device handle to uninitialized state.
nuclear@1 87 void Clear();
nuclear@1 88
nuclear@1 89 protected:
nuclear@1 90 explicit DeviceHandle(DeviceCreateDesc* impl);
nuclear@1 91 bool enumerateNext(const DeviceEnumerationArgs& args);
nuclear@1 92 DeviceCreateDesc* pImpl;
nuclear@1 93 };
nuclear@1 94
nuclear@1 95 } // namespace OVR
nuclear@1 96
nuclear@1 97 #endif