1 /* 2 * Copyright (c) 2023-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 USB_BUS_EXTENSION_H 17 #define USB_BUS_EXTENSION_H 18 #include <iproxy_broker.h> 19 #include <iremote_object.h> 20 21 #include "ibus_extension.h" 22 #include "usb_dev_subscriber.h" 23 #include "usb_device_info.h" 24 #include "usb_driver_change_callback.h" 25 #include "v1_1/iusb_ddk.h" 26 #ifdef EXTDEVMGR_USB_PASS_THROUGH 27 #include "v2_0/iusb_host_interface.h" 28 #else 29 #include "v1_0/iusb_interface.h" 30 #endif // EXTDEVMGR_USB_PASS_THROUGH 31 namespace OHOS { 32 namespace ExternalDeviceManager { 33 using namespace std; 34 #ifdef EXTDEVMGR_USB_PASS_THROUGH 35 using namespace OHOS::HDI::Usb::V2_0; 36 #else 37 using namespace OHOS::HDI::Usb::V1_0; 38 #endif // EXTDEVMGR_USB_PASS_THROUGH 39 using namespace OHOS::HDI::Usb::Ddk; 40 class UsbBusExtension : public IBusExtension { 41 public: 42 UsbBusExtension(); 43 ~UsbBusExtension(); 44 int32_t SetDevChangeCallback(shared_ptr<IDevChangeCallback> callback) override; 45 bool MatchDriver(const DriverInfo &driver, const DeviceInfo &device, const std::string &type = "") override; 46 shared_ptr<DriverInfoExt> ParseDriverInfo(const map<string, string> &metadata) override; 47 shared_ptr<DriverInfoExt> GetNewDriverInfoExtObject() override; 48 #ifdef EXTDEVMGR_USB_PASS_THROUGH 49 void SetUsbInferface(sptr<IUsbHostInterface> iusb); 50 #else 51 void SetUsbInferface(sptr<IUsbInterface> iusb); 52 #endif // EXTDEVMGR_USB_PASS_THROUGH 53 void SetUsbDdk(sptr<V1_1::IUsbDdk> iUsbDdk); 54 BusType GetBusType() override; 55 shared_ptr<IDriverChangeCallback> AcquireDriverChangeCallback() override; 56 57 private: 58 sptr<UsbDevSubscriber> subScriber_ = nullptr; 59 sptr<V1_1::IUsbDdk> iUsbDdk_ = nullptr; 60 vector<uint16_t> ParseCommaStrToVectorUint16(const string &str); 61 #ifdef EXTDEVMGR_USB_PASS_THROUGH 62 sptr<IUsbHostInterface> usbInterface_ = nullptr; 63 #else 64 class UsbdDeathRecipient : public IRemoteObject::DeathRecipient { 65 public: 66 void OnRemoteDied(const wptr<IRemoteObject> &object) override; 67 }; 68 sptr<IUsbInterface> usbInterface_ = nullptr; // in usb HDI; 69 sptr<IRemoteObject::DeathRecipient> recipient_; 70 #endif // EXTDEVMGR_USB_PASS_THROUGH 71 }; 72 } 73 } 74 #endif