Ben Chan | 62173ed | 2013-06-13 14:16:23 -0700 | [diff] [blame] | 1 | // Copyright (c) 2013 The Chromium OS 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 MIST_USB_MODEM_SWITCHER_H_ |
| 6 | #define MIST_USB_MODEM_SWITCHER_H_ |
| 7 | |
Ben Chan | 956f79b | 2014-08-06 17:11:01 -0700 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
Ben Chan | 62173ed | 2013-06-13 14:16:23 -0700 | [diff] [blame] | 10 | #include <string> |
| 11 | |
Ben Chan | 4746c8a | 2014-09-02 20:34:58 -0700 | [diff] [blame] | 12 | #include <base/macros.h> |
Ben Chan | 62173ed | 2013-06-13 14:16:23 -0700 | [diff] [blame] | 13 | |
| 14 | #include "mist/usb_device_event_observer.h" |
| 15 | |
| 16 | namespace mist { |
| 17 | |
| 18 | class Context; |
| 19 | class UsbModemSwitchOperation; |
| 20 | |
| 21 | // A USB modem switcher, which initiates a modem switch operation for each |
| 22 | // supported USB device that currently exists on the system, or when a supported |
| 23 | // USB device is added to the system. |
| 24 | class UsbModemSwitcher : public UsbDeviceEventObserver { |
| 25 | public: |
| 26 | // Constructs a UsbModemSwitcher object by taking a raw pointer to a Context |
Ben Chan | 9bdff61 | 2013-06-17 01:18:15 -0700 | [diff] [blame] | 27 | // object as |context|. The ownership of |context| is not transferred, and |
| 28 | // thus it should outlive this object. |
Ben Chan | 62173ed | 2013-06-13 14:16:23 -0700 | [diff] [blame] | 29 | explicit UsbModemSwitcher(Context* context); |
| 30 | |
| 31 | ~UsbModemSwitcher(); |
| 32 | |
| 33 | // Starts scanning existing USB devices on the system and monitoring new USB |
| 34 | // devices being added to the system. Initiates a switch operation for each |
| 35 | // supported device. |
| 36 | void Start(); |
| 37 | |
| 38 | private: |
| 39 | // Invoked upon the completion of a switch operation where |success| indicates |
| 40 | // whether the operation completed successfully or not. |operation| is deleted |
| 41 | // in this callback. |
| 42 | void OnSwitchOperationCompleted(UsbModemSwitchOperation* operation, |
| 43 | bool success); |
| 44 | |
| 45 | // Implements UsbDeviceEventObserver. |
Ben Chan | 9c1068b | 2014-08-11 21:27:46 -0700 | [diff] [blame] | 46 | void OnUsbDeviceAdded(const std::string& sys_path, |
| 47 | uint8_t bus_number, |
| 48 | uint8_t device_address, |
| 49 | uint16_t vendor_id, |
| 50 | uint16_t product_id) override; |
| 51 | void OnUsbDeviceRemoved(const std::string& sys_path) override; |
Ben Chan | 62173ed | 2013-06-13 14:16:23 -0700 | [diff] [blame] | 52 | |
| 53 | Context* const context_; |
| 54 | |
| 55 | DISALLOW_COPY_AND_ASSIGN(UsbModemSwitcher); |
| 56 | }; |
| 57 | |
| 58 | } // namespace mist |
| 59 | |
| 60 | #endif // MIST_USB_MODEM_SWITCHER_H_ |