Bike-X  0.8
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
OVR_Linux_HIDDevice.h
Go to the documentation of this file.
1 /************************************************************************************
2 Filename : OVR_Linux_HIDDevice.h
3 Content : Linux HID device implementation.
4 Created : June 13, 2013
5 Authors : Brant Lewis
6 
7 Copyright : Copyright 2014 Oculus VR, Inc. All Rights reserved.
8 
9 Licensed under the Oculus VR Rift SDK License Version 3.1 (the "License");
10 you may not use the Oculus VR Rift SDK except in compliance with the License,
11 which is provided at the time of installation or download, or which
12 otherwise accompanies this software in either electronic or hard copy form.
13 
14 You may obtain a copy of the License at
15 
16 http://www.oculusvr.com/licenses/LICENSE-3.1
17 
18 Unless required by applicable law or agreed to in writing, the Oculus VR SDK
19 distributed under the License is distributed on an "AS IS" BASIS,
20 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 See the License for the specific language governing permissions and
22 limitations under the License.
23 
24 *************************************************************************************/
25 
26 #ifndef OVR_LINUX_HIDDevice_h
27 #define OVR_LINUX_HIDDevice_h
28 
29 #include "OVR_HIDDevice.h"
31 #include <libudev.h>
32 
33 namespace OVR { namespace Linux {
34 
35 class HIDDeviceManager;
36 
37 //-------------------------------------------------------------------------------------
38 // ***** Linux HIDDevice
39 
41 {
42 private:
43  friend class HIDDeviceManager;
44 
45 public:
46  HIDDevice(HIDDeviceManager* manager);
47 
48  // This is a minimal constructor used during enumeration for us to pass
49  // a HIDDevice to the visit function (so that it can query feature reports).
50  HIDDevice(HIDDeviceManager* manager, int device_handle);
51 
52  virtual ~HIDDevice();
53 
54  bool HIDInitialize(const String& path);
55  void HIDShutdown();
56 
57  virtual bool SetFeatureReport(UByte* data, UInt32 length);
58  virtual bool GetFeatureReport(UByte* data, UInt32 length);
59 
60  // DeviceManagerThread::Notifier
61  void OnEvent(int i, int fd);
62  double OnTicks(double tickSeconds);
63 
64  bool OnDeviceNotification(MessageType messageType,
65  HIDDeviceDesc* device_info,
66  bool* error);
67 
68 private:
69  bool initInfo();
70  bool openDevice(const char* dev_path);
71  void closeDevice(bool wasUnplugged);
72  void closeDeviceOnIOError();
74 
77  int DeviceHandle; // file handle to the device
79 
80  enum { ReadBufferSize = 96 };
82 
86 };
87 
88 
89 //-------------------------------------------------------------------------------------
90 // ***** Linux HIDDeviceManager
91 
93 {
94  friend class HIDDevice;
95 
96 public:
98  virtual ~HIDDeviceManager();
99 
100  virtual bool Initialize();
101  virtual void Shutdown();
102 
103  virtual bool Enumerate(HIDEnumerateVisitor* enumVisitor);
104  virtual OVR::HIDDevice* Open(const String& path);
105 
107 
108  void OnEvent(int i, int fd);
109 
110 private:
111  bool initializeManager();
112  bool initVendorProductVersion(udev_device* device, HIDDeviceDesc* pDevDesc);
113  bool getPath(udev_device* device, String* pPath);
114  bool getIntProperty(udev_device* device, const char* key, int32_t* pResult);
115  bool getStringProperty(udev_device* device,
116  const char* propertyName,
117  OVR::String* pResult);
118  bool getFullDesc(udev_device* device, HIDDeviceDesc* desc);
119  bool GetDescriptorFromPath(const char* dev_path, HIDDeviceDesc* desc);
120 
121  bool AddNotificationDevice(HIDDevice* device);
122  bool RemoveNotificationDevice(HIDDevice* device);
123 
125 
126  udev* UdevInstance; // a handle to the udev library instance
127  udev_monitor* HIDMonitor;
128  int HIDMonHandle; // the udev_monitor file handle
129 
131 };
132 
133 }} // namespace OVR::Linux
134 
135 #endif // OVR_Linux_HIDDevice_h
bool getStringProperty(udev_device *device, const char *propertyName, OVR::String *pResult)
bool initVendorProductVersion(udev_device *device, HIDDeviceDesc *pDevDesc)
UByte ReadBuffer[ReadBufferSize]
void OnEvent(int i, int fd)
bool getIntProperty(udev_device *device, const char *key, int32_t *pResult)
virtual OVR::HIDDevice * Open(const String &path)
bool GetDescriptorFromPath(const char *dev_path, HIDDeviceDesc *desc)
uint16_t UInt16
Definition: OVR_Types.h:251
uint32_t UInt32
Definition: OVR_Types.h:253
Array< HIDDevice * > NotificationDevices
uint8_t UByte
Definition: OVR_Types.h:249
bool RemoveNotificationDevice(HIDDevice *device)
static HIDDeviceManager * CreateInternal(DeviceManager *manager)
bool setupDevicePluggedInNotification()
bool openDevice(const char *dev_path)
bool OnDeviceNotification(MessageType messageType, HIDDeviceDesc *device_info, bool *error)
bool getFullDesc(udev_device *device, HIDDeviceDesc *desc)
virtual bool GetFeatureReport(UByte *data, UInt32 length)
bool HIDInitialize(const String &path)
double OnTicks(double tickSeconds)
void closeDevice(bool wasUnplugged)
bool AddNotificationDevice(HIDDevice *device)
bool getPath(udev_device *device, String *pPath)
HIDDeviceManager * HIDManager
virtual bool Enumerate(HIDEnumerateVisitor *enumVisitor)
virtual bool SetFeatureReport(UByte *data, UInt32 length)