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

Side by Side Diff: chrome/browser/usb/usb_service.h

Issue 10161035: Adding UsbService and UsbDevice constructs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_USB_USB_SERVICE_H_
6 #define CHROME_BROWSER_USB_USB_SERVICE_H_
7 #pragma once
8
9 #include <map>
10 #include <utility>
11
12 #include "base/basictypes.h"
13 #include "base/threading/thread.h"
14 #include "chrome/browser/usb/usb_device.h"
15 #include "third_party/libusb/libusb/libusb.h"
16
17 typedef libusb_context *PlatformUsbContext;
18
19 // The USB service handles creating and managing an event handler thread that is
20 // used to manage and dispatch USB events. It is also responsbile for device
21 // discovery on the system, which allows it to re-use device handles to prevent
22 // competition for the same USB device.
23 class UsbService {
Elliot Glaysher 2012/04/25 21:10:20 Is it safe if there are multiple UsbServices? When
24 public:
25 UsbService();
26 virtual ~UsbService();
27
28 // Cleanup must be invoked before the service is destroyed. It interrupts the
29 // event handling thread and disposes of open devices.
30 void Cleanup();
31
32 // Find the (topologically) first USB device identified by vendor_id and
33 // product_id. The created device is associated with this service, so that
34 // it can be used to close the device later.
35 UsbDevice *FindDevice(const uint16 vendor_id, const uint16 product_id);
miket_OOO 2012/04/25 21:24:36 Why const a primitive parameter? (not entirely a r
Garret Kelly 2012/04/26 02:21:42 My justification's a little weak. :) I'm in the h
36
37 // This function should not be called by normal code. It is invoked by a
38 // UsbDevice's Close function and disposes of the associated platform handle.
39 void CloseDevice(scoped_refptr<UsbDevice> device);
40
41 private:
42 // Posts a HandleEvent task to the event handling thread.
43 void PostHandleEventTask();
44
45 // Handles a single USB event. If the service is still running after the event
46 // is handled, posts another HandleEvent callback to the thread.
47 void HandleEvent();
48
49 // Shutdown is invoked after event handling has been suspended and is used to
50 // free the platform resources associated with the service.
51 void Shutdown();
52
53 bool running_;
54 PlatformUsbContext context_;
55 base::Thread thread_;
56
57 // The devices_ map contains scoped_refptrs to all open devices, indicated by
58 // their vendor and product id. This allows for reusing an open device without
59 // creating another platform handle for it.
60 typedef std::map<std::pair<uint16, uint16>, scoped_refptr<UsbDevice> >
61 DeviceMap;
62 DeviceMap devices_;
63
64 DISALLOW_EVIL_CONSTRUCTORS(UsbService);
65 };
66
67 #endif // CHROME_BROWSER_USB_USB_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698