1 /*
2  * Copyright (c) 2022-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 #include <iostream>
17 #include <vector>
18 #include "hdf_log.h"
19 #include "osal_time.h"
20 #include "UsbSubscriberTest.h"
21 #include "v1_0/iusb_interface.h"
22 #include "v1_0/usb_types.h"
23 
24 using namespace OHOS;
25 using namespace OHOS::USB;
26 using namespace std;
27 using namespace OHOS::HDI::Usb::V1_0;
28 
29 namespace {sptr<IUsbInterface> g_usbInterface = nullptr;}
30 constexpr int32_t BIND_TIME = 60;
main(int32_t argc,const char * argv[])31 int32_t main(int32_t argc, const char *argv[])
32 {
33     g_usbInterface = IUsbInterface::Get();
34     if (g_usbInterface == nullptr) {
35         HDF_LOGE("%{public}s:IUsbInterface::Get() failed", __func__);
36         return HDF_FAILURE;
37     }
38     sptr<UsbSubscriberTest> subscriber = new UsbSubscriberTest();
39     HDF_LOGI("%{public}s: bind usbd subscriber", __func__);
40     if (g_usbInterface->BindUsbdSubscriber(subscriber) != HDF_SUCCESS) {
41         HDF_LOGE("%{public}s: bind usbd subscriber failed", __func__);
42         return HDF_FAILURE;
43     }
44     OsalSleep(BIND_TIME);
45     HDF_LOGI("%{public}s: unbind usbd subscriber", __func__);
46     if (g_usbInterface->UnbindUsbdSubscriber(subscriber) != HDF_SUCCESS) {
47         HDF_LOGE("%{public}s: unbind usbd subscriber failed", __func__);
48         return HDF_FAILURE;
49     }
50     return HDF_SUCCESS;
51 }
52