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

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

Issue 161823002: Clean up HID backend and API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: for reals Created 6 years, 10 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
OLDNEW
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 #include <libudev.h> 5 #include <libudev.h>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 return; 103 return;
104 } 104 }
105 105
106 // This list is managed by |enumerate|. 106 // This list is managed by |enumerate|.
107 udev_list_entry* devices = udev_enumerate_get_list_entry(enumerate.get()); 107 udev_list_entry* devices = udev_enumerate_get_list_entry(enumerate.get());
108 for (udev_list_entry* i = devices; i != NULL; 108 for (udev_list_entry* i = devices; i != NULL;
109 i = udev_list_entry_get_next(i)) { 109 i = udev_list_entry_get_next(i)) {
110 ScopedUdevDevicePtr hid_dev( 110 ScopedUdevDevicePtr hid_dev(
111 udev_device_new_from_syspath(udev_.get(), udev_list_entry_get_name(i))); 111 udev_device_new_from_syspath(udev_.get(), udev_list_entry_get_name(i)));
112 if (hid_dev) { 112 if (hid_dev) {
113 PlatformDeviceAdd(hid_dev.get()); 113 PlatformAddDevice(hid_dev.get());
114 } 114 }
115 } 115 }
116 116
117 initialized_ = true; 117 initialized_ = true;
118 } 118 }
119 119
120 void HidServiceLinux::PlatformDeviceAdd(udev_device* device) { 120 void HidServiceLinux::PlatformAddDevice(udev_device* device) {
121 if (!device) 121 if (!device)
122 return; 122 return;
123 123
124 const char* device_id = udev_device_get_syspath(device); 124 const char* device_id = udev_device_get_syspath(device);
125 if (!device_id) 125 if (!device_id)
126 return; 126 return;
127 127
128 128
129 HidDeviceInfo device_info; 129 HidDeviceInfo device_info;
130 device_info.device_id = device_id; 130 device_info.device_id = device_id;
(...skipping 23 matching lines...) Expand all
154 if (str_property != NULL) 154 if (str_property != NULL)
155 device_info.serial_number = str_property; 155 device_info.serial_number = str_property;
156 156
157 str_property = udev_device_get_property_value(device, kHIDName); 157 str_property = udev_device_get_property_value(device, kHIDName);
158 if (str_property != NULL) 158 if (str_property != NULL)
159 device_info.product_name = str_property; 159 device_info.product_name = str_property;
160 160
161 AddDevice(device_info); 161 AddDevice(device_info);
162 } 162 }
163 163
164 void HidServiceLinux::PlatformDeviceRemove(udev_device* raw_dev) { 164 void HidServiceLinux::PlatformRemoveDevice(udev_device* raw_dev) {
165 // The returned the device is not referenced. 165 // The returned the device is not referenced.
166 udev_device* hid_dev = 166 udev_device* hid_dev =
167 udev_device_get_parent_with_subsystem_devtype(raw_dev, "hid", NULL); 167 udev_device_get_parent_with_subsystem_devtype(raw_dev, "hid", NULL);
168 168
169 if (!hid_dev) 169 if (!hid_dev)
170 return; 170 return;
171 171
172 const char* device_id = NULL; 172 const char* device_id = NULL;
173 device_id = udev_device_get_syspath(hid_dev); 173 device_id = udev_device_get_syspath(hid_dev);
174 if (device_id == NULL) 174 if (device_id == NULL)
175 return; 175 return;
176 176
177 RemoveDevice(device_id); 177 RemoveDevice(device_id);
178 } 178 }
179 179
180 scoped_refptr<HidConnection> HidServiceLinux::Connect(std::string device_id) { 180 scoped_refptr<HidConnection> HidServiceLinux::Connect(
181 const std::string& device_id) {
181 if (!ContainsKey(devices_, device_id)) 182 if (!ContainsKey(devices_, device_id))
182 return NULL; 183 return NULL;
183 ScopedUdevDevicePtr hid_device( 184 ScopedUdevDevicePtr hid_device(
184 udev_device_new_from_syspath(udev_.get(), device_id.c_str())); 185 udev_device_new_from_syspath(udev_.get(), device_id.c_str()));
185 if (hid_device) { 186 if (hid_device) {
186 scoped_refptr<HidConnectionLinux> connection = 187 scoped_refptr<HidConnectionLinux> connection =
187 new HidConnectionLinux(devices_[device_id], hid_device.Pass()); 188 new HidConnectionLinux(devices_[device_id], hid_device.Pass());
188 if (connection->initialized()) 189 if (connection->initialized())
189 return connection; 190 return connection;
190 } 191 }
191 return NULL; 192 return NULL;
192 } 193 }
193 194
194 void HidServiceLinux::OnFileCanReadWithoutBlocking(int fd) { 195 void HidServiceLinux::OnFileCanReadWithoutBlocking(int fd) {
195 DCHECK_EQ(monitor_fd_, fd); 196 DCHECK_EQ(monitor_fd_, fd);
196 197
197 ScopedUdevDevicePtr dev(udev_monitor_receive_device(monitor_.get())); 198 ScopedUdevDevicePtr dev(udev_monitor_receive_device(monitor_.get()));
198 if (!dev) 199 if (!dev)
199 return; 200 return;
200 201
201 std::string action(udev_device_get_action(dev.get())); 202 std::string action(udev_device_get_action(dev.get()));
202 if (action == kUdevActionAdd) { 203 if (action == kUdevActionAdd) {
203 PlatformDeviceAdd(dev.get()); 204 PlatformAddDevice(dev.get());
204 } else if (action == kUdevActionRemove) { 205 } else if (action == kUdevActionRemove) {
205 PlatformDeviceRemove(dev.get()); 206 PlatformRemoveDevice(dev.get());
206 } 207 }
207 } 208 }
208 209
209 void HidServiceLinux::OnFileCanWriteWithoutBlocking(int fd) {} 210 void HidServiceLinux::OnFileCanWriteWithoutBlocking(int fd) {}
210 211
211 } // namespace dev 212 } // namespace dev
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698