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); |
Qijiang Fan | 6bc59e1 | 2020-11-11 02:51:06 +0900 | [diff] [blame^] | 30 | UsbModemSwitcher(const UsbModemSwitcher&) = delete; |
| 31 | UsbModemSwitcher& operator=(const UsbModemSwitcher&) = delete; |
Ben Chan | 62173ed | 2013-06-13 14:16:23 -0700 | [diff] [blame] | 32 | |
| 33 | ~UsbModemSwitcher(); |
| 34 | |
| 35 | // Starts scanning existing USB devices on the system and monitoring new USB |
| 36 | // devices being added to the system. Initiates a switch operation for each |
| 37 | // supported device. |
| 38 | void Start(); |
| 39 | |
| 40 | private: |
| 41 | // Invoked upon the completion of a switch operation where |success| indicates |
| 42 | // whether the operation completed successfully or not. |operation| is deleted |
| 43 | // in this callback. |
| 44 | void OnSwitchOperationCompleted(UsbModemSwitchOperation* operation, |
| 45 | bool success); |
| 46 | |
| 47 | // Implements UsbDeviceEventObserver. |
Ben Chan | 9c1068b | 2014-08-11 21:27:46 -0700 | [diff] [blame] | 48 | void OnUsbDeviceAdded(const std::string& sys_path, |
| 49 | uint8_t bus_number, |
| 50 | uint8_t device_address, |
| 51 | uint16_t vendor_id, |
| 52 | uint16_t product_id) override; |
| 53 | void OnUsbDeviceRemoved(const std::string& sys_path) override; |
Ben Chan | 62173ed | 2013-06-13 14:16:23 -0700 | [diff] [blame] | 54 | |
| 55 | Context* const context_; |
Ben Chan | 62173ed | 2013-06-13 14:16:23 -0700 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | } // namespace mist |
| 59 | |
| 60 | #endif // MIST_USB_MODEM_SWITCHER_H_ |