• 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 #ifndef SCAN_USB_MANAGER_H_
17 #define SCAN_USB_MANAGER_H_
18 
19 #include <map>
20 #include <string>
21 #include <utility>
22 #include "usb_srv_client.h"
23 #include "singleton.h"
24 #include "scan_event_subscriber.h"
25 
26 namespace OHOS::Scan {
27 
28 class ScanUsbManager final : public DelayedSingleton<ScanUsbManager> {
29 public:
30     ScanUsbManager();
31     ~ScanUsbManager();
32     void RefreshUsbDevice();
33     std::string GetSerialNumber(USB::UsbDevice &usbDevice);
34     void DealUsbDevStatusChange(const std::string &devStr, bool isAttach);
35     void Init();
36 private:
37     std::string GetDeviceSerialNumber(USB::USBDevicePipe &usbDevicePipe);
38     void formatUsbPort(std::string &port);
39     std::string getNewDeviceId(std::string oldDeviceId, std::string usbDeviceName);
40     void UpdateUsbScannerId(std::string serialNumber, std::string usbDeviceName);
41     void DisConnectUsbScanner(std::string usbDeviceName);
42     std::shared_ptr<ScanEventSubscriber> usbDevStatusListener;
43     bool isInit = false;
44 };
45 
46 }
47 
48 #endif // SCAN_USB_MANAGER_H_