OVR_Linux_HIDDevice.h
Go to the documentation of this file.
00001 /************************************************************************************
00002 Filename    :   OVR_Linux_HIDDevice.h
00003 Content     :   Linux HID device implementation.
00004 Created     :   June 13, 2013
00005 Authors     :   Brant Lewis
00006 
00007 Copyright   :   Copyright 2013 Oculus VR, Inc. All Rights reserved.
00008 
00009 Use of this software is subject to the terms of the Oculus license
00010 agreement provided at the time of installation or download, or which
00011 otherwise accompanies this software in either electronic or hard copy form.
00012 
00013 *************************************************************************************/
00014 
00015 #ifndef OVR_LINUX_HIDDevice_h
00016 #define OVR_LINUX_HIDDevice_h
00017 
00018 #include "OVR_HIDDevice.h"
00019 #include "OVR_Linux_DeviceManager.h"
00020 #include <libudev.h>
00021 
00022 namespace OVR { namespace Linux {
00023 
00024 class HIDDeviceManager;
00025 
00026 //-------------------------------------------------------------------------------------
00027 // ***** Linux HIDDevice
00028 
00029 class HIDDevice : public OVR::HIDDevice, public DeviceManagerThread::Notifier
00030 {
00031 private:
00032     friend class HIDDeviceManager;
00033 
00034 public:
00035     HIDDevice(HIDDeviceManager* manager);
00036 
00037     // This is a minimal constructor used during enumeration for us to pass
00038     // a HIDDevice to the visit function (so that it can query feature reports).
00039     HIDDevice(HIDDeviceManager* manager, int device_handle);
00040     
00041     virtual ~HIDDevice();
00042 
00043     bool HIDInitialize(const String& path);
00044     void HIDShutdown();
00045     
00046     virtual bool SetFeatureReport(UByte* data, UInt32 length);
00047         virtual bool GetFeatureReport(UByte* data, UInt32 length);
00048 
00049     // DeviceManagerThread::Notifier
00050     void OnEvent(int i, int fd);
00051     UInt64 OnTicks(UInt64 ticksMks);
00052 
00053     bool OnDeviceNotification(MessageType messageType,
00054                               HIDDeviceDesc* device_info,
00055                               bool* error);
00056 
00057 private:
00058     bool initInfo();
00059     bool openDevice(const char* dev_path);
00060     void closeDevice(bool wasUnplugged);
00061     void closeDeviceOnIOError();
00062     bool setupDevicePluggedInNotification();
00063 
00064     bool                    InMinimalMode;
00065     HIDDeviceManager*       HIDManager;
00066     int                     DeviceHandle;     // file handle to the device
00067     HIDDeviceDesc           DevDesc;
00068     
00069     enum { ReadBufferSize = 96 };
00070     UByte                   ReadBuffer[ReadBufferSize];
00071 
00072     UInt16                  InputReportBufferLength;
00073     UInt16                  OutputReportBufferLength;
00074     UInt16                  FeatureReportBufferLength;
00075 };
00076 
00077 
00078 //-------------------------------------------------------------------------------------
00079 // ***** Linux HIDDeviceManager
00080 
00081 class HIDDeviceManager : public OVR::HIDDeviceManager, public DeviceManagerThread::Notifier
00082 {
00083         friend class HIDDevice;
00084 
00085 public:
00086     HIDDeviceManager(Linux::DeviceManager* Manager);
00087     virtual ~HIDDeviceManager();
00088 
00089     virtual bool Initialize();
00090     virtual void Shutdown();
00091 
00092     virtual bool Enumerate(HIDEnumerateVisitor* enumVisitor);
00093     virtual OVR::HIDDevice* Open(const String& path);
00094 
00095     static HIDDeviceManager* CreateInternal(DeviceManager* manager);
00096 
00097     void OnEvent(int i, int fd);
00098     
00099 private:
00100     bool initializeManager();
00101     bool initVendorProductVersion(udev_device* device, HIDDeviceDesc* pDevDesc);
00102     bool getPath(udev_device* device, String* pPath);
00103     bool getIntProperty(udev_device* device, const char* key, int32_t* pResult);
00104     bool getStringProperty(udev_device* device,
00105                            const char* propertyName,
00106                            OVR::String* pResult);
00107     bool getFullDesc(udev_device* device, HIDDeviceDesc* desc);
00108     bool GetDescriptorFromPath(const char* dev_path, HIDDeviceDesc* desc);
00109     
00110     bool AddNotificationDevice(HIDDevice* device);
00111     bool RemoveNotificationDevice(HIDDevice* device);
00112     
00113     DeviceManager*           DevManager;
00114 
00115     udev*                    UdevInstance;     // a handle to the udev library instance
00116     udev_monitor*            HIDMonitor;
00117     int                      HIDMonHandle;     // the udev_monitor file handle
00118 
00119     Array<HIDDevice*>        NotificationDevices;
00120 };
00121 
00122 }} // namespace OVR::Linux
00123 
00124 #endif // OVR_Linux_HIDDevice_h


oculus_sdk
Author(s):
autogenerated on Mon Oct 6 2014 03:01:18