1 /* 2 * Copyright (c) 2025 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 OHOS_HDI_USB_V2_0_USB_DEVICE_IMPL_H 17 #define OHOS_HDI_USB_V2_0_USB_DEVICE_IMPL_H 18 19 #include <iostream> 20 21 #include "hdf_slist.h" 22 #include "hdf_usb_pnp_manage.h" 23 #include "iproxy_broker.h" 24 #include "iremote_object.h" 25 #include "osal_mutex.h" 26 #include "usb_host_data.h" 27 #include "usbd_function.h" 28 #include "usbd_load_usb_service.h" 29 #include "usbd_port.h" 30 #include "v2_0/iusb_device_interface.h" 31 32 #define BASE_CLASS_HUB 0x09 33 constexpr uint8_t MAX_INTERFACEID = 0xFF; 34 namespace OHOS { 35 namespace HDI { 36 namespace Usb { 37 namespace V2_0 { 38 using namespace OHOS; 39 class UsbDeviceImpl : public IUsbDeviceInterface { 40 public: 41 42 UsbDeviceImpl(); 43 ~UsbDeviceImpl() override; 44 int32_t GetCurrentFunctions(int32_t &funcs) override; 45 int32_t SetCurrentFunctions(int32_t funcs) override; 46 int32_t BindUsbdDeviceSubscriber(const sptr<IUsbdSubscriber> &subscriber) override; 47 int32_t UnbindUsbdDeviceSubscriber(const sptr<IUsbdSubscriber> &subscriber) override; 48 int32_t GetAccessoryInfo(std::vector<std::string> &accessoryInfo) override; 49 int32_t OpenAccessory(int32_t &fd) override; 50 int32_t CloseAccessory(int32_t fd) override; 51 static int32_t UsbdEventHandle(void); 52 static int32_t UsbdEventHandleRelease(void); 53 class UsbDeathRecipient : public IRemoteObject::DeathRecipient { 54 public: UsbDeathRecipient(const sptr<IUsbdSubscriber> & deathSubscriber)55 explicit UsbDeathRecipient(const sptr<IUsbdSubscriber> &deathSubscriber) : deathSubscriber_(deathSubscriber) {}; ~UsbDeathRecipient()56 ~UsbDeathRecipient() override {}; 57 void OnRemoteDied(const wptr<IRemoteObject> &object) override; 58 private: 59 sptr<IUsbdSubscriber> deathSubscriber_; 60 }; 61 private: 62 static int32_t UsbdLoadServiceCallback(void *priv, uint32_t id, HdfSBuf *data); 63 static int32_t UsbdPnpLoaderEventReceived(void *priv, uint32_t id, HdfSBuf *data); 64 static void UpdateFunctionStatus(void); 65 static UsbdSubscriber subscribers_[MAX_SUBSCRIBER]; 66 static bool isGadgetConnected_; 67 static bool isEdmExist_; 68 static HdfDevEventlistener listenerForLoadService_; 69 static V1_2::UsbdLoadService loadUsbService_; 70 static V1_2::UsbdLoadService loadHdfEdm_; 71 }; 72 } // namespace v2_0 73 } // namespace Usb 74 } // namespace HDI 75 } // namespace OHOS 76 #endif // OHOS_HDI_USB_V2_0_USB_DEVICE_IMPL_H