| OLD | NEW |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef DEVICE_HID_HID_SERVICE_LINUX_H_ | 5 #ifndef DEVICE_HID_HID_SERVICE_LINUX_H_ |
| 6 #define DEVICE_HID_HID_SERVICE_LINUX_H_ | 6 #define DEVICE_HID_HID_SERVICE_LINUX_H_ |
| 7 | 7 |
| 8 #include <libudev.h> | 8 #include <libudev.h> |
| 9 | 9 |
| 10 #include <map> |
| 11 #include <string> |
| 12 |
| 10 #include "base/macros.h" | 13 #include "base/macros.h" |
| 11 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/message_loop/message_pump_libevent.h" | 15 #include "base/message_loop/message_pump_libevent.h" |
| 13 #include "device/hid/hid_device_info.h" | 16 #include "device/hid/hid_device_info.h" |
| 17 #include "device/hid/hid_platform_resource_bidi_map.h" |
| 14 #include "device/hid/hid_service.h" | 18 #include "device/hid/hid_service.h" |
| 15 | 19 |
| 16 namespace device { | 20 namespace device { |
| 17 | 21 |
| 18 class HidConnection; | 22 class HidConnection; |
| 19 | 23 |
| 20 template<typename T, void func(T*)> | 24 template<typename T, void func(T*)> |
| 21 void DiscardReturnType(T* arg) { func(arg); } | 25 void DiscardReturnType(T* arg) { func(arg); } |
| 22 template<typename T, T* func(T*)> | 26 template<typename T, T* func(T*)> |
| 23 void DiscardReturnType(T* arg) { func(arg); } | 27 void DiscardReturnType(T* arg) { func(arg); } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 43 DiscardReturnType<udev_monitor, udev_monitor_unref> > UdevMonitorDeleter; | 47 DiscardReturnType<udev_monitor, udev_monitor_unref> > UdevMonitorDeleter; |
| 44 | 48 |
| 45 typedef scoped_ptr<udev_device, UdevDeviceDeleter> ScopedUdevDevicePtr; | 49 typedef scoped_ptr<udev_device, UdevDeviceDeleter> ScopedUdevDevicePtr; |
| 46 typedef scoped_ptr<udev_enumerate, UdevEnumerateDeleter> ScopedUdevEnumeratePtr; | 50 typedef scoped_ptr<udev_enumerate, UdevEnumerateDeleter> ScopedUdevEnumeratePtr; |
| 47 | 51 |
| 48 class HidServiceLinux : public HidService, | 52 class HidServiceLinux : public HidService, |
| 49 public base::MessagePumpLibevent::Watcher { | 53 public base::MessagePumpLibevent::Watcher { |
| 50 public: | 54 public: |
| 51 HidServiceLinux(); | 55 HidServiceLinux(); |
| 52 | 56 |
| 53 virtual scoped_refptr<HidConnection> Connect(std::string device_id) OVERRIDE; | 57 virtual scoped_refptr<HidConnection> Connect(HidDeviceId device_id) OVERRIDE; |
| 54 | 58 |
| 55 // Implements base::MessagePumpLibevent::Watcher | 59 // Implements base::MessagePumpLibevent::Watcher |
| 56 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; | 60 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; |
| 57 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE; | 61 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE; |
| 58 | 62 |
| 59 private: | 63 private: |
| 60 virtual ~HidServiceLinux(); | 64 virtual ~HidServiceLinux(); |
| 61 | 65 |
| 62 void Enumerate(); | 66 void Enumerate(); |
| 63 void PlatformDeviceAdd(udev_device* device); | 67 void PlatformAddDevice(udev_device* device); |
| 64 void PlatformDeviceRemove(udev_device* raw_dev); | 68 void PlatformRemoveDevice(udev_device* raw_dev); |
| 65 | 69 |
| 66 scoped_ptr<udev, UdevDeleter> udev_; | 70 scoped_ptr<udev, UdevDeleter> udev_; |
| 67 scoped_ptr<udev_monitor, UdevMonitorDeleter> monitor_; | 71 scoped_ptr<udev_monitor, UdevMonitorDeleter> monitor_; |
| 68 int monitor_fd_; | 72 int monitor_fd_; |
| 69 base::MessagePumpLibevent::FileDescriptorWatcher monitor_watcher_; | 73 base::MessagePumpLibevent::FileDescriptorWatcher monitor_watcher_; |
| 70 | 74 |
| 75 // A 1:1 mapping between device ID and system path. |
| 76 HidPlatformResourceBidiMap<std::string> platform_resource_map_; |
| 77 |
| 71 DISALLOW_COPY_AND_ASSIGN(HidServiceLinux); | 78 DISALLOW_COPY_AND_ASSIGN(HidServiceLinux); |
| 72 }; | 79 }; |
| 73 | 80 |
| 74 } // namespace device | 81 } // namespace device |
| 75 | 82 |
| 76 #endif // DEVICE_HID_HID_SERVICE_LINUX_H_ | 83 #endif // DEVICE_HID_HID_SERVICE_LINUX_H_ |
| OLD | NEW |