• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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_SYSTEM_DATA_H
17 #define SCAN_SYSTEM_DATA_H
18 
19 #include <string>
20 #include <map>
21 #include <json/json.h>
22 #include "scanner_info.h"
23 #include "print_json_util.h"
24 
25 namespace OHOS {
26 namespace Scan {
27 
28 class ScanSystemData {
29 public:
GetInstance()30     static ScanSystemData& GetInstance()
31     {
32         static ScanSystemData instance;
33         return instance;
34     }
35     bool Init();
36     void InsertScannerInfo(const std::string &uniqueId, const ScanDeviceInfo &scannerInfo);
37     bool DeleteScannerInfo(const std::string &uniqueId);
38     bool UpdateScannerNameByUniqueId(const std::string &uniqueId, const std::string &deviceName);
39     bool UpdateScannerInfoByUniqueId(const std::string &uniqueId, const ScanDeviceInfo &scannerInfo);
40     bool UpdateScannerIdByUsbDevicePort(const std::string &uniqueId, const std::string &usbDevicePort);
41     bool QueryScannerNameByUniqueId(const std::string &uniqueId, std::string &deviceName);
42     bool QueryScannerInfoByUniqueId(const std::string &uniqueId, ScanDeviceInfo &scannerInfo);
43     void RefreshUsbDeviceId();
44     void GetAddedScannerInfoList(std::vector<ScanDeviceInfo> &infoList);
45     bool SaveScannerMap();
46     bool IsContainScanner(const std::string &uniqueId);
47     std::pair<std::string, std::string> UpdateNetScannerByUuid(const std::string &uuid, const std::string& ip);
48 private:
49     bool ParseScannerListJsonV1(Json::Value& jsonObject);
50     bool CheckJsonObjectValue(const Json::Value& object);
51     void ParseScannerJsonV1(ScanDeviceInfo &scanDeviceInfo, Json::Value &object);
52     std::map<std::string, std::shared_ptr<ScanDeviceInfo>> addedScannerMap_;
53     std::mutex addedScannerMapLock_;
54     const uint32_t MAX_SCANNER_SIZE = 1000;
55 };
56 
57 }  // namespace Scan
58 }  // namespace OHOS
59 #endif  // SCAN_SYSTEM_DATA_H
60