// Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef DEVICE_HID_HID_SERVICE_LINUX_H_ #define DEVICE_HID_HID_SERVICE_LINUX_H_ #include #include #include #include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "base/message_loop/message_pump_libevent.h" #include "device/hid/hid_device_info.h" #include "device/hid/hid_service.h" namespace device { class HidConnection; template void DiscardReturnType(T* arg) { func(arg); } template void DiscardReturnType(T* arg) { func(arg); } template struct Deleter { void operator()(T* enumerate) const { if (enumerate != NULL) func(enumerate); } }; typedef Deleter< udev_enumerate, DiscardReturnType > UdevEnumerateDeleter; typedef Deleter< udev_device, DiscardReturnType > UdevDeviceDeleter; typedef Deleter > UdevDeleter; typedef Deleter< udev_monitor, DiscardReturnType > UdevMonitorDeleter; typedef scoped_ptr ScopedUdevDevicePtr; typedef scoped_ptr ScopedUdevEnumeratePtr; class HidServiceLinux : public HidService, public base::MessagePumpLibevent::Watcher { public: HidServiceLinux(); virtual scoped_refptr Connect(const HidDeviceId& device_id) OVERRIDE; // Implements base::MessagePumpLibevent::Watcher virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE; private: virtual ~HidServiceLinux(); void Enumerate(); void PlatformAddDevice(udev_device* device); void PlatformRemoveDevice(udev_device* raw_dev); scoped_ptr udev_; scoped_ptr monitor_; int monitor_fd_; base::MessagePumpLibevent::FileDescriptorWatcher monitor_watcher_; DISALLOW_COPY_AND_ASSIGN(HidServiceLinux); }; } // namespace device #endif // DEVICE_HID_HID_SERVICE_LINUX_H_