oculus1

view libovr/Src/linux/OVR_Linux_HIDDevice.h @ 24:8419d8a13cee

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 04 Oct 2013 14:50:26 +0300
parents
children
line source
1 /************************************************************************************
2 Filename : OVR_Linux_HIDDevice.h
3 Content : Linux HID device implementation.
4 Created : June 13, 2013
5 Authors : Brant Lewis
7 Copyright : Copyright 2013 Oculus VR, Inc. All Rights reserved.
9 Use of this software is subject to the terms of the Oculus license
10 agreement provided at the time of installation or download, or which
11 otherwise accompanies this software in either electronic or hard copy form.
13 *************************************************************************************/
15 #ifndef OVR_LINUX_HIDDevice_h
16 #define OVR_LINUX_HIDDevice_h
18 #include "OVR_HIDDevice.h"
19 #include "OVR_Linux_DeviceManager.h"
20 #include <libudev.h>
22 namespace OVR { namespace Linux {
24 class HIDDeviceManager;
26 //-------------------------------------------------------------------------------------
27 // ***** Linux HIDDevice
29 class HIDDevice : public OVR::HIDDevice, public DeviceManagerThread::Notifier
30 {
31 private:
32 friend class HIDDeviceManager;
34 public:
35 HIDDevice(HIDDeviceManager* manager);
37 // This is a minimal constructor used during enumeration for us to pass
38 // a HIDDevice to the visit function (so that it can query feature reports).
39 HIDDevice(HIDDeviceManager* manager, int device_handle);
41 virtual ~HIDDevice();
43 bool HIDInitialize(const String& path);
44 void HIDShutdown();
46 virtual bool SetFeatureReport(UByte* data, UInt32 length);
47 virtual bool GetFeatureReport(UByte* data, UInt32 length);
49 // DeviceManagerThread::Notifier
50 void OnEvent(int i, int fd);
51 UInt64 OnTicks(UInt64 ticksMks);
53 bool OnDeviceNotification(MessageType messageType,
54 HIDDeviceDesc* device_info,
55 bool* error);
57 private:
58 bool initInfo();
59 bool openDevice(const char* dev_path);
60 void closeDevice(bool wasUnplugged);
61 void closeDeviceOnIOError();
62 bool setupDevicePluggedInNotification();
64 bool InMinimalMode;
65 HIDDeviceManager* HIDManager;
66 int DeviceHandle; // file handle to the device
67 HIDDeviceDesc DevDesc;
69 enum { ReadBufferSize = 96 };
70 UByte ReadBuffer[ReadBufferSize];
72 UInt16 InputReportBufferLength;
73 UInt16 OutputReportBufferLength;
74 UInt16 FeatureReportBufferLength;
75 };
78 //-------------------------------------------------------------------------------------
79 // ***** Linux HIDDeviceManager
81 class HIDDeviceManager : public OVR::HIDDeviceManager, public DeviceManagerThread::Notifier
82 {
83 friend class HIDDevice;
85 public:
86 HIDDeviceManager(Linux::DeviceManager* Manager);
87 virtual ~HIDDeviceManager();
89 virtual bool Initialize();
90 virtual void Shutdown();
92 virtual bool Enumerate(HIDEnumerateVisitor* enumVisitor);
93 virtual OVR::HIDDevice* Open(const String& path);
95 static HIDDeviceManager* CreateInternal(DeviceManager* manager);
97 void OnEvent(int i, int fd);
99 private:
100 bool initializeManager();
101 bool initVendorProductVersion(udev_device* device, HIDDeviceDesc* pDevDesc);
102 bool getPath(udev_device* device, String* pPath);
103 bool getIntProperty(udev_device* device, const char* key, int32_t* pResult);
104 bool getStringProperty(udev_device* device,
105 const char* propertyName,
106 OVR::String* pResult);
107 bool getFullDesc(udev_device* device, HIDDeviceDesc* desc);
108 bool GetDescriptorFromPath(const char* dev_path, HIDDeviceDesc* desc);
110 bool AddNotificationDevice(HIDDevice* device);
111 bool RemoveNotificationDevice(HIDDevice* device);
113 DeviceManager* DevManager;
115 udev* UdevInstance; // a handle to the udev library instance
116 udev_monitor* HIDMonitor;
117 int HIDMonHandle; // the udev_monitor file handle
119 Array<HIDDevice*> NotificationDevices;
120 };
122 }} // namespace OVR::Linux
124 #endif // OVR_Linux_HIDDevice_h