• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 
28 namespace OHOS {
29 namespace USB {
30 class UsbPortManager {
31 public:
32     UsbPortManager();
33     ~UsbPortManager();
34 
35     void Init();
36     void Init(int32_t test);
37     int32_t GetPorts(std::vector<UsbPort> &ports);
38     int32_t GetSupportedModes(int32_t portId, int32_t &supportedModes);
39     void SetPortRoles(int32_t portId, int32_t powerRole, int32_t dataRole);
40     int32_t QueryPort();
41     void UpdatePort(int32_t portId, int32_t powerRole, int32_t dataRole, int32_t mode);
42     void AddPort(UsbPort &port);
43     void RemovePort(int32_t portId);
44     bool Dump(int fd, const std::string &args);
45 
46 private:
47     void ReportPortRoleChangeSysEvent(
48         int32_t currentPowerRole, int32_t updatePowerRole, int32_t currentDataRole, int32_t updateDataRole);
49     std::mutex mutex_;
50     std::map<int32_t, UsbPort> portMap_;
51     sptr<HDI::Usb::V1_0::IUsbInterface> usbd_ = nullptr;
52 };
53 } // namespace USB
54 } // namespace OHOS
55 
56 #endif
57