• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef USB_PORT_MANAGER_H
17 #define USB_PORT_MANAGER_H
18 
19 #include <algorithm>
20 #include <map>
21 #include <mutex>
22 #include <string>
23 #include <vector>
24 #include "usb_common.h"
25 #include "usb_port.h"
26 #include "v1_0/iusb_interface.h"
27 #ifdef USB_MANAGER_V2_0
28 #include "v2_0/iusb_port_interface.h"
29 #include "usb_manager_subscriber.h"
30 #include "mem_mgr_proxy.h"
31 #include "mem_mgr_client.h"
32 #include "system_ability_definition.h"
33 #endif // USB_MANAGER_V2_0
34 
35 namespace OHOS {
36 namespace USB {
37 class UsbPortManager {
38 public:
39     UsbPortManager();
40     ~UsbPortManager();
41 
42     void Init();
43     void Init(int32_t test);
44 #ifdef USB_MANAGER_V2_0
45     bool InitUsbPortInterface();
46     void Stop();
47     int32_t BindUsbdSubscriber(const sptr<HDI::Usb::V2_0::IUsbdSubscriber> &subscriber);
48     int32_t UnbindUsbdSubscriber(const sptr<HDI::Usb::V2_0::IUsbdSubscriber> &subscriber);
49 #endif // USB_MANAGER_V2_0
50     int32_t SetUsbd(const sptr<HDI::Usb::V1_0::IUsbInterface> &usbd);
51     int32_t GetPorts(std::vector<UsbPort> &ports);
52     int32_t GetSupportedModes(int32_t portId, int32_t &supportedModes);
53     void SetPortRoles(int32_t portId, int32_t powerRole, int32_t dataRole);
54     int32_t QueryPort();
55     void UpdatePort(int32_t portId, int32_t powerRole, int32_t dataRole, int32_t mode);
56     void AddPort(UsbPort &port);
57     void RemovePort(int32_t portId);
58     void GetDumpHelp(int32_t fd);
59     void Dump(int32_t fd, const std::vector<std::string> &args);
60 
61     int32_t SetPortRole(int32_t portId, int32_t powerRole, int32_t dataRole);
62 private:
63     void GetIUsbInterface();
64     void GetPortsInfo(int32_t fd);
65     void DumpGetSupportPort(int32_t fd);
66     void DumpSetPortRoles(int32_t fd, const std::string &args);
67     void ReportPortRoleChangeSysEvent(
68         int32_t currentPowerRole, int32_t updatePowerRole, int32_t currentDataRole, int32_t updateDataRole);
69     std::mutex mutex_;
70     std::map<int32_t, UsbPort> portMap_;
71     sptr<HDI::Usb::V1_0::IUsbInterface> usbd_ = nullptr;
72 #ifdef USB_MANAGER_V2_0
73     sptr<HDI::Usb::V2_0::IUsbPortInterface> usbPortInterface_ = nullptr;
74     sptr<UsbManagerSubscriber> usbManagerSubscriber_;
75 #endif // USB_MANAGER_V2_0
76 };
77 } // namespace USB
78 } // namespace OHOS
79 
80 #endif
81