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_FUNCTION_MANAGER_H 17 #define USB_FUNCTION_MANAGER_H 18 19 #include <map> 20 #include <string> 21 #include <vector> 22 23 #include "usb_common.h" 24 #include "usb_srv_support.h" 25 #include "v1_0/iusb_interface.h" 26 #include "v1_0/iusbd_subscriber.h" 27 28 namespace OHOS { 29 namespace USB { 30 class UsbDeviceManager { 31 public: 32 UsbDeviceManager(); 33 static bool AreSettableFunctions(int32_t funcs); 34 35 static uint32_t ConvertFromString(std::string_view funcs); 36 static std::string ConvertToString(uint32_t func); 37 void UpdateFunctions(int32_t func); 38 int32_t GetCurrentFunctions(); 39 void HandleEvent(int32_t status); 40 bool Dump(int fd, const std::string &args); 41 42 private: 43 void ReportFuncChangeSysEvent(int32_t currentFunctions, int32_t updateFunctions); 44 void ReportDevicePlugSysEvent(int32_t currentFunctions, bool connected); 45 static constexpr uint32_t functionSettable_ = 46 UsbSrvSupport::FUNCTION_HDC | UsbSrvSupport::FUNCTION_ACM | UsbSrvSupport::FUNCTION_ECM | 47 UsbSrvSupport::FUNCTION_RNDIS | UsbSrvSupport::FUNCTION_STORAGE; 48 static const std::map<std::string_view, uint32_t> FUNCTION_MAPPING_N2C; 49 int32_t currentFunctions_ {UsbSrvSupport::FUNCTION_HDC}; 50 bool connected_ {false}; 51 sptr<HDI::Usb::V1_0::IUsbInterface> usbd_ = nullptr; 52 }; 53 } // namespace USB 54 } // namespace OHOS 55 56 #endif // USB_FUNCTION_MANAGER_H 57