Bike-X  0.8
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
OVR_DeviceHandle.h
Go to the documentation of this file.
1 /************************************************************************************
2 
3 PublicHeader: OVR.h
4 Filename : OVR_DeviceHandle.h
5 Content : Handle to a device that was enumerated
6 Created : February 5, 2013
7 Authors : Lee Cooper
8 
9 Copyright : Copyright 2014 Oculus VR, Inc. All Rights reserved.
10 
11 Licensed under the Oculus VR Rift SDK License Version 3.1 (the "License");
12 you may not use the Oculus VR Rift SDK except in compliance with the License,
13 which is provided at the time of installation or download, or which
14 otherwise accompanies this software in either electronic or hard copy form.
15 
16 You may obtain a copy of the License at
17 
18 http://www.oculusvr.com/licenses/LICENSE-3.1
19 
20 Unless required by applicable law or agreed to in writing, the Oculus VR SDK
21 distributed under the License is distributed on an "AS IS" BASIS,
22 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 See the License for the specific language governing permissions and
24 limitations under the License.
25 
26 *************************************************************************************/
27 
28 #ifndef OVR_DeviceHandle_h
29 #define OVR_DeviceHandle_h
30 
31 #include "OVR_DeviceConstants.h"
32 
33 namespace OVR {
34 
35 class DeviceBase;
36 class DeviceInfo;
37 
38 // Internal
39 class DeviceCreateDesc;
40 class DeviceEnumerationArgs;
41 
42 
43 //-------------------------------------------------------------------------------------
44 // ***** DeviceHandle
45 
46 // DeviceHandle references a specific device that was enumerated; it can be assigned
47 // directly from DeviceEnumerator.
48 //
49 // Devices represented by DeviceHandle are not necessarily created or available.
50 // A device may become unavailable if, for example, it its unplugged. If the device
51 // is available, it can be created by calling CreateDevice.
52 //
53 
55 {
56  friend class DeviceManager;
57  friend class DeviceManagerImpl;
58  template<class B> friend class HIDDeviceImpl;
59 
60 public:
61  DeviceHandle() : pImpl(0) { }
62  DeviceHandle(const DeviceHandle& src);
63  ~DeviceHandle();
64 
65  void operator = (const DeviceHandle& src);
66 
67  bool operator == (const DeviceHandle& other) const { return pImpl == other.pImpl; }
68  bool operator != (const DeviceHandle& other) const { return pImpl != other.pImpl; }
69 
70  // operator bool() returns true if Handle/Enumerator points to a valid device.
71  operator bool () const { return GetType() != Device_None; }
72 
73  // Returns existing device, or NULL if !IsCreated. The returned ptr is
74  // addref-ed.
76  DeviceType GetType() const;
77  bool GetDeviceInfo(DeviceInfo* info) const;
78  bool IsAvailable() const;
79  bool IsCreated() const;
80  // Returns true, if the handle contains the same device ptr
81  // as specified in the parameter.
82  bool IsDevice(DeviceBase*) const;
83 
84  // Creates a device, or returns AddRefed pointer if one is already created.
85  // New devices start out with RefCount of 1.
87 
88  // Creates a device, or returns AddRefed pointer if one is already created.
89  // New devices start out with RefCount of 1. DeviceT is used to cast the
90  // DeviceBase* to a concreete type.
91  template <class DeviceT>
92  DeviceT* CreateDeviceTyped() const
93  {
94  return static_cast<DeviceT*>(DeviceHandle(*this).CreateDevice());
95  }
96 
97  // Resets the device handle to uninitialized state.
98  void Clear();
99 
100 protected:
101  explicit DeviceHandle(DeviceCreateDesc* impl);
102  bool enumerateNext(const DeviceEnumerationArgs& args);
104 };
105 
106 } // namespace OVR
107 
108 #endif
DeviceCreateDesc * pImpl
DeviceT * CreateDeviceTyped() const
bool GetDeviceInfo(DeviceInfo *info) const
DeviceType GetType() const
bool IsDevice(DeviceBase *) const
void operator=(const DeviceHandle &src)
bool IsAvailable() const
bool operator==(const DeviceHandle &other) const
DeviceBase * GetDevice_AddRef() const
bool enumerateNext(const DeviceEnumerationArgs &args)
bool IsCreated() const
DeviceBase * CreateDevice()
bool operator!=(const DeviceHandle &other) const