Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: device/hid/hid_service_linux.h

Issue 230503003: Udev-related methods are extracted from HidServiceLinux into individual service. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « device/hid/hid_connection_linux.h ('k') | device/hid/hid_service_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 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 "base/compiler_specific.h"
9
10 #include <map>
11 #include <string>
12
13 #include "base/macros.h" 9 #include "base/macros.h"
14 #include "base/memory/scoped_ptr.h" 10 #include "device/hid/device_monitor_linux.h"
15 #include "base/message_loop/message_pump_libevent.h"
16 #include "device/hid/hid_device_info.h" 11 #include "device/hid/hid_device_info.h"
17 #include "device/hid/hid_service.h" 12 #include "device/hid/hid_service.h"
18 13
14 struct udev_device;
15
19 namespace device { 16 namespace device {
20 17
21 class HidConnection; 18 class HidConnection;
22 19
23 template<typename T, void func(T*)>
24 void DiscardReturnType(T* arg) { func(arg); }
25 template<typename T, T* func(T*)>
26 void DiscardReturnType(T* arg) { func(arg); }
27
28 template<typename T, void func(T*)>
29 struct Deleter {
30 void operator()(T* enumerate) const {
31 if (enumerate != NULL)
32 func(enumerate);
33 }
34 };
35
36 typedef Deleter<
37 udev_enumerate,
38 DiscardReturnType<udev_enumerate, udev_enumerate_unref> >
39 UdevEnumerateDeleter;
40 typedef Deleter<
41 udev_device,
42 DiscardReturnType<udev_device, udev_device_unref> > UdevDeviceDeleter;
43 typedef Deleter<udev, DiscardReturnType<udev, udev_unref> > UdevDeleter;
44 typedef Deleter<
45 udev_monitor,
46 DiscardReturnType<udev_monitor, udev_monitor_unref> > UdevMonitorDeleter;
47
48 typedef scoped_ptr<udev_device, UdevDeviceDeleter> ScopedUdevDevicePtr;
49 typedef scoped_ptr<udev_enumerate, UdevEnumerateDeleter> ScopedUdevEnumeratePtr;
50
51 class HidServiceLinux : public HidService, 20 class HidServiceLinux : public HidService,
52 public base::MessagePumpLibevent::Watcher { 21 public DeviceMonitorLinux::Observer {
53 public: 22 public:
54 HidServiceLinux(); 23 HidServiceLinux();
55 24
56 virtual scoped_refptr<HidConnection> Connect(const HidDeviceId& device_id) 25 virtual scoped_refptr<HidConnection> Connect(const HidDeviceId& device_id)
57 OVERRIDE; 26 OVERRIDE;
58 27
59 // Implements base::MessagePumpLibevent::Watcher 28 // Implements base::DeviceMonitorLinux::Observer:
60 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; 29 virtual void OnDeviceAdded(udev_device* device) OVERRIDE;
61 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE; 30 virtual void OnDeviceRemoved(udev_device* device) OVERRIDE;
62 31
63 private: 32 private:
64 virtual ~HidServiceLinux(); 33 virtual ~HidServiceLinux();
65 34
66 void Enumerate();
67 void PlatformAddDevice(udev_device* device);
68 void PlatformRemoveDevice(udev_device* raw_dev);
69
70 scoped_ptr<udev, UdevDeleter> udev_;
71 scoped_ptr<udev_monitor, UdevMonitorDeleter> monitor_;
72 int monitor_fd_;
73 base::MessagePumpLibevent::FileDescriptorWatcher monitor_watcher_;
74
75 DISALLOW_COPY_AND_ASSIGN(HidServiceLinux); 35 DISALLOW_COPY_AND_ASSIGN(HidServiceLinux);
76 }; 36 };
77 37
78 } // namespace device 38 } // namespace device
79 39
80 #endif // DEVICE_HID_HID_SERVICE_LINUX_H_ 40 #endif // DEVICE_HID_HID_SERVICE_LINUX_H_
OLDNEW
« no previous file with comments | « device/hid/hid_connection_linux.h ('k') | device/hid/hid_service_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698