Explicitly add python-numpy dependency to install-build-deps.
[chromium-blink-merge.git] / device / usb / usb_device.h
blob8b8ec6232134ba9f3b184c42214197222ebea142
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
3 // found in the LICENSE file.
5 #ifndef DEVICE_USB_USB_DEVICE_H_
6 #define DEVICE_USB_USB_DEVICE_H_
8 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/observer_list.h"
12 #include "base/strings/string16.h"
14 namespace device {
16 class UsbDeviceHandle;
17 struct UsbConfigDescriptor;
19 // A UsbDevice object represents a detected USB device, providing basic
20 // information about it. For further manipulation of the device, a
21 // UsbDeviceHandle must be created from Open() method.
22 class UsbDevice : public base::RefCountedThreadSafe<UsbDevice> {
23 public:
24 class Observer {
25 public:
26 virtual void OnDisconnect(scoped_refptr<UsbDevice> device) = 0;
29 // Accessors to basic information.
30 uint16 vendor_id() const { return vendor_id_; }
31 uint16 product_id() const { return product_id_; }
32 uint32 unique_id() const { return unique_id_; }
34 #if defined(OS_CHROMEOS)
35 // On ChromeOS, if an interface of a claimed device is not claimed, the
36 // permission broker can change the owner of the device so that the unclaimed
37 // interfaces can be used. If this argument is missing, permission broker will
38 // not be used and this method fails if the device is claimed.
39 virtual void RequestUsbAccess(
40 int interface_id,
41 const base::Callback<void(bool success)>& callback) = 0;
42 #endif // OS_CHROMEOS
44 // Creates a UsbDeviceHandle for further manipulation.
45 // Blocking method. Must be called on FILE thread.
46 virtual scoped_refptr<UsbDeviceHandle> Open() = 0;
48 // Explicitly closes a device handle. This method will be automatically called
49 // by the destructor of a UsbDeviceHandle as well.
50 // Closing a closed handle is a safe
51 // Blocking method. Must be called on FILE thread.
52 virtual bool Close(scoped_refptr<UsbDeviceHandle> handle) = 0;
54 // Gets the UsbConfigDescriptor for the active device configuration.
55 // Blocking method. Must be called on FILE thread.
56 virtual const UsbConfigDescriptor& GetConfiguration() = 0;
58 // Gets the manufacturer string of the device, or returns false.
59 // Blocking method. Must be called on FILE thread.
60 // TODO(reillyg): Make this available from the UI thread. crbug.com/427985
61 virtual bool GetManufacturer(base::string16* manufacturer) = 0;
63 // Gets the product string of the device, or returns false.
64 // Blocking method. Must be called on FILE thread.
65 // TODO(reillyg): Make this available from the UI thread. crbug.com/427985
66 virtual bool GetProduct(base::string16* product) = 0;
68 // Gets the serial number string of the device, or returns false.
69 // Blocking method. Must be called on FILE thread.
70 // TODO(reillyg): Make this available from the UI thread. crbug.com/427985
71 virtual bool GetSerialNumber(base::string16* serial) = 0;
73 void AddObserver(Observer* obs) { observer_list_.AddObserver(obs); }
74 void RemoveObserver(Observer* obs) { observer_list_.RemoveObserver(obs); }
76 protected:
77 UsbDevice(uint16 vendor_id, uint16 product_id, uint32 unique_id);
78 virtual ~UsbDevice();
80 void NotifyDisconnect();
82 private:
83 friend class base::RefCountedThreadSafe<UsbDevice>;
85 const uint16 vendor_id_;
86 const uint16 product_id_;
87 const uint32 unique_id_;
89 ObserverList<Observer> observer_list_;
91 DISALLOW_COPY_AND_ASSIGN(UsbDevice);
94 } // namespace device
96 #endif // DEVICE_USB_USB_DEVICE_H_