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 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 SetUsbd(const sptr<HDI::Usb::V1_0::IUsbInterface> &usbd); 38 int32_t GetPorts(std::vector<UsbPort> &ports); 39 int32_t GetSupportedModes(int32_t portId, int32_t &supportedModes); 40 void SetPortRoles(int32_t portId, int32_t powerRole, int32_t dataRole); 41 int32_t QueryPort(); 42 void UpdatePort(int32_t portId, int32_t powerRole, int32_t dataRole, int32_t mode); 43 void AddPort(UsbPort &port); 44 void RemovePort(int32_t portId); 45 void GetDumpHelp(int32_t fd); 46 void Dump(int32_t fd, const std::vector<std::string> &args); 47 48 private: 49 void GetIUsbInterface(); 50 void GetPortsInfo(int32_t fd); 51 void DumpGetSupportPort(int32_t fd); 52 void DumpSetPortRoles(int32_t fd, const std::string &args); 53 void ReportPortRoleChangeSysEvent( 54 int32_t currentPowerRole, int32_t updatePowerRole, int32_t currentDataRole, int32_t updateDataRole); 55 std::mutex mutex_; 56 std::map<int32_t, UsbPort> portMap_; 57 sptr<HDI::Usb::V1_0::IUsbInterface> usbd_ = nullptr; 58 }; 59 } // namespace USB 60 } // namespace OHOS 61 62 #endif 63