blob: ca0bf10e2937bb206d82a81b544b484e5884a6ff [file] [log] [blame]
Ben Chan62173ed2013-06-13 14:16:23 -07001// 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 Chan956f79b2014-08-06 17:11:01 -07008#include <stdint.h>
9
Ben Chan62173ed2013-06-13 14:16:23 -070010#include <string>
11
Ben Chan4746c8a2014-09-02 20:34:58 -070012#include <base/macros.h>
Ben Chan62173ed2013-06-13 14:16:23 -070013
14#include "mist/usb_device_event_observer.h"
15
16namespace mist {
17
18class Context;
19class 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.
24class UsbModemSwitcher : public UsbDeviceEventObserver {
25 public:
26 // Constructs a UsbModemSwitcher object by taking a raw pointer to a Context
Ben Chan9bdff612013-06-17 01:18:15 -070027 // object as |context|. The ownership of |context| is not transferred, and
28 // thus it should outlive this object.
Ben Chan62173ed2013-06-13 14:16:23 -070029 explicit UsbModemSwitcher(Context* context);
Qijiang Fan6bc59e12020-11-11 02:51:06 +090030 UsbModemSwitcher(const UsbModemSwitcher&) = delete;
31 UsbModemSwitcher& operator=(const UsbModemSwitcher&) = delete;
Ben Chan62173ed2013-06-13 14:16:23 -070032
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 Chan9c1068b2014-08-11 21:27:46 -070048 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 Chan62173ed2013-06-13 14:16:23 -070054
55 Context* const context_;
Ben Chan62173ed2013-06-13 14:16:23 -070056};
57
58} // namespace mist
59
60#endif // MIST_USB_MODEM_SWITCHER_H_