• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_PORT_IMPL_H
17 #define OHOS_HDI_USB_V2_0_USB_PORT_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 "usb_host_data.h"
26 #include "usbd_function.h"
27 #include "usbd_load_usb_service.h"
28 #include "usbd_port.h"
29 #include "usbd_ports.h"
30 #include "v2_0/iusb_port_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 UsbPortImpl : public IUsbPortInterface {
40 public:
41     UsbPortImpl();
42     ~UsbPortImpl() override;
43     int32_t SetPortRole(int32_t portId, int32_t powerRole, int32_t dataRole) override;
44     int32_t QueryPort(int32_t &portId, int32_t &powerRole, int32_t &dataRole, int32_t &mode) override;
45     int32_t QueryPorts(std::vector<UsbPort>& portList) override;
46     int32_t BindUsbdPortSubscriber(const sptr<IUsbdSubscriber> &subscriber) override;
47     int32_t UnbindUsbdPortSubscriber(const sptr<IUsbdSubscriber> &subscriber) override;
48     static int32_t UsbdEventHandle(const sptr<UsbPortImpl> &inst);
49     class UsbDeathRecipient : public IRemoteObject::DeathRecipient {
50     public:
UsbDeathRecipient(const sptr<IUsbdSubscriber> & deathSubscriber)51         explicit UsbDeathRecipient(const sptr<IUsbdSubscriber> &deathSubscriber) : deathSubscriber_(deathSubscriber) {};
~UsbDeathRecipient()52         ~UsbDeathRecipient() override {};
53         void OnRemoteDied(const wptr<IRemoteObject> &object) override;
54     private:
55         sptr<IUsbdSubscriber> deathSubscriber_;
56     };
57     HdfDeviceObject *device_;
58 private:
59     static int32_t UsbdPnpLoaderEventReceived(void *priv, uint32_t id, HdfSBuf *data);
60     static int32_t UsbdLoadServiceCallback(void *priv, uint32_t id, HdfSBuf *data);
61     void ParsePortPath();
62     bool UsbPortImplInit();
63     static UsbdSubscriber subscribers_[MAX_SUBSCRIBER];
64     static bool isGadgetConnected_;
65 };
66 } // namespace V2_0
67 } // namespace Usb
68 } // namespace HDI
69 } // namespace OHOS
70 #endif // OHOS_HDI_USB_V2_0_USB_PORT_IMPL_H