blob: 949d93578634acd0755fe11f0bf7f6af680c55f2 [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);
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 Chan9c1068b2014-08-11 21:27:46 -070046 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 Chan62173ed2013-06-13 14:16:23 -070052
53 Context* const context_;
54
55 DISALLOW_COPY_AND_ASSIGN(UsbModemSwitcher);
56};
57
58} // namespace mist
59
60#endif // MIST_USB_MODEM_SWITCHER_H_