• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "bus_extension_core.h"
23 #include "dev_change_callback.h"
24 #include "driver_pkg_manager.h"
25 #include "etx_device_mgr.h"
26 
27 #undef private
28 
29 constexpr const char *START_TEXT = "Begin to loop and listen usb event:\n\
30 enter q to exit.\n\
31 enter p to print all usb device.";
32 using namespace OHOS::ExternalDeviceManager;
33 using namespace std;
PrintAllDevice()34 static void PrintAllDevice()
35 {
36     ExtDeviceManager &devmgr = ExtDeviceManager::GetInstance();
37     cout << "------------------" << endl;
38     std::unordered_map<uint64_t, std::shared_ptr<Device>> &map = devmgr.deviceMap_[BUS_TYPE_USB];
39     cout << "usb device size: " << map.size() << endl;
40     for (auto &iter : map) {
41         std::shared_ptr<Device> device = iter.second;
42         cout << "description: " << device->GetDeviceInfo()->GetDeviceDescription().c_str() << endl;
43         cout << "deviceId: " << std::hex << device->GetDeviceInfo()->GetDeviceId() << endl;
44     }
45     std::unordered_map<string, unordered_set<uint64_t>> &bundleMatchMap = devmgr.bundleMatchMap_;
46     cout << "bundleMatchMap size:" << bundleMatchMap.size() << endl;
47     for (auto &iter : bundleMatchMap) {
48         cout << "bundleInfo [" << iter.first << "]: ";
49         for (auto &devId : iter.second) {
50             cout << std::hex << devId << " ";
51         }
52         cout << endl;
53     }
54     cout << "------------------" << endl;
55 }
56 
main(int argc,char ** argv)57 int main(int argc, char **argv)
58 {
59     cout << START_TEXT << endl;
60     BusExtensionCore::GetInstance().LoadBusExtensionLibs();
61     int32_t ret = DriverPkgManager::GetInstance().Init();
62     if (ret != EDM_OK) {
63         cout << "DriverPkgManager Init failed, ret = " << ret << endl;
64         return -1;
65     }
66     ret = ExtDeviceManager::GetInstance().Init();
67     if (ret != EDM_OK) {
68         cout << "ExtDeviceManager Init failed, ret = " << ret << endl;
69         return -1;
70     }
71     std::shared_ptr<DevChangeCallback> callback = std::make_shared<DevChangeCallback>();
72     ret = BusExtensionCore::GetInstance().Init(callback);
73     if (ret != EDM_OK) {
74         cout << "BusExtensionCore Init failed, ret = " << ret << endl;
75         return -1;
76     }
77 
78     while (true) {
79         std::string in;
80         cin >> in;
81         if (in == "q") {
82             break;
83         } else if (in == "p") {
84             PrintAllDevice();
85         } else {
86             cout << in;
87         }
88     }
89     cout << "exit!" << endl;
90     return ret;
91 }