1 /*
2  * Copyright (c) 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 <dlfcn.h>
17 
18 #include "edm_errors.h"
19 #include "hilog_wrapper.h"
20 #include "iostream"
21 #define private public
22 #include "driver_pkg_manager.h"
23 #include "ibus_extension.h"
24 #include "usb_device_info.h"
25 #include "dev_change_callback.h"
26 #include "bus_extension_core.h"
27 #undef private
28 
29 constexpr const char *START_TEXT = "Begin to loop and listen pkg event:\n\
30 enter q to exit.\n\
31 enter p to print QueryMatchDriver.";
32 using namespace OHOS::ExternalDeviceManager;
33 using namespace std;
PrintQueryMatchDriver()34 static void PrintQueryMatchDriver()
35 {
36     cout << "------------------" << endl;
37     DriverPkgManager &drvPkgMgrInstance = DriverPkgManager::GetInstance();
38 
39     auto deviceInfo = make_shared<UsbDeviceInfo>(0);
40     deviceInfo->devInfo_.devBusInfo.busType = BusType::BUS_TYPE_USB;
41     deviceInfo->idProduct_ = 0x8835;
42     deviceInfo->idVendor_ = 0x0B57;
43     deviceInfo->deviceClass_ = 0;
44     deviceInfo->bcdUSB_ = 0x1122;
45     std::shared_ptr<BundleInfoNames> bundle = drvPkgMgrInstance.QueryMatchDriver(deviceInfo);
46 
47     if (bundle != nullptr) {
48         cout << "Query Success" << endl;
49     }
50     cout << "------------------" << endl;
51 }
52 
main(int argc,char ** argv)53 int main(int argc, char **argv)
54 {
55     cout << START_TEXT << endl;
56     std::shared_ptr<DevChangeCallback> callback = std::make_shared<DevChangeCallback>();
57     BusExtensionCore::GetInstance().LoadBusExtensionLibs();
58     bool ret = BusExtensionCore::GetInstance().Init(callback);
59     if (ret != EDM_OK) {
60         cout << "BusExtensionCore init failed" << endl;
61         return ret;
62     }
63     DriverPkgManager &drvPkgMgrInstance = DriverPkgManager::GetInstance();
64     ret = drvPkgMgrInstance.Init();
65     if (ret != EDM_OK) {
66         cout << "drvPkgMgrInstance init failed" << endl;
67         return ret;
68     }
69     while (true) {
70         std::string in;
71         cin >> in;
72         if (in == "q") {
73             break;
74         } else if (in == "p") {
75             PrintQueryMatchDriver();
76         } else {
77             cout << "invalid param" << endl;
78         }
79     }
80     cout << "exit!" << endl;
81     return ret;
82 }