oculus1

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