1 /* 2 * Copyright (c) 2022 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_MANAGER_CLIENT_H 17 #define SCAN_MANAGER_CLIENT_H 18 #define TDD_ENABLE 1 19 20 #include <condition_variable> 21 #include <map> 22 #include <mutex> 23 #include <shared_mutex> 24 25 #include "iscan_callback.h" 26 #include "iscan_service.h" 27 #include "iremote_object.h" 28 29 #include "scan_sync_load_callback.h" 30 #include "scan_sa_death_recipient.h" 31 #include "scanner_info.h" 32 #include "refbase.h" 33 34 namespace OHOS::Scan { 35 class ScanManagerClient : public RefBase { 36 public: 37 ScanManagerClient(); 38 ~ScanManagerClient(); 39 static sptr<ScanManagerClient> GetInstance(); 40 41 void OnRemoteSaDied(const wptr<IRemoteObject> &object); 42 43 int32_t InitScan(int32_t &scanVersion); 44 int32_t ExitScan(); 45 int32_t GetScannerList(); 46 int32_t StopDiscover(); 47 int32_t OpenScanner(const std::string scannerId); 48 int32_t CloseScanner(const std::string scannerId); 49 int32_t GetScanOptionDesc(const std::string scannerId, const int32_t optionIndex, ScanOptionDescriptor &desc); 50 int32_t OpScanOptionValue(const std::string scannerId, const int32_t optionIndex, 51 const ScanOptionOpType op, ScanOptionValue &value, int32_t &info); 52 int32_t GetScanParameters(const std::string scannerId, ScanParameters ¶); 53 int32_t StartScan(const std::string scannerId, const bool &batchMode); 54 int32_t GetSingleFrameFD(const std::string scannerId, uint32_t &size, uint32_t fd); 55 int32_t CancelScan(const std::string scannerId); 56 int32_t SetScanIOMode(const std::string scannerId, const bool isNonBlocking); 57 int32_t GetScanSelectFd(const std::string scannerId, int32_t &fd); 58 int32_t GetScannerState(int32_t &scannerState); 59 int32_t GetScanProgress(const std::string scannerId, ScanProgress &prog); 60 int32_t AddScanner(const std::string& serialNumber, const std::string& discoverMode); 61 int32_t DeleteScanner(const std::string& serialNumber, const std::string& discoverMode); 62 int32_t GetAddedScanner(std::vector<ScanDeviceInfo>& allAddedScanner); 63 int32_t UpdateScannerName(const std::string& serialNumber, 64 const std::string& discoverMode, const std::string& deviceName); 65 66 int32_t On(const std::string &taskId, const std::string &type, const sptr<IScanCallback> &listener); 67 int32_t Off(const std::string &taskId, const std::string &type); 68 69 void LoadServerSuccess(const sptr<IRemoteObject> &remoteObject); 70 void LoadServerFail(); 71 72 #ifndef TDD_ENABLE 73 private: 74 #endif 75 bool LoadScanService(); 76 sptr<IScanService> GetScanServiceProxy(); 77 78 #ifndef TDD_ENABLE 79 private: 80 #endif 81 static std::mutex instanceLock_; 82 static sptr<ScanManagerClient> instance_; 83 sptr<IScanService> scanServiceProxy_; 84 sptr<ScanSaDeathRecipient> deathRecipient_; 85 std::mutex loadMutex_; 86 std::mutex conditionMutex_; 87 std::condition_variable_any syncCon_; 88 bool ready_ = false; 89 std::shared_mutex proxyLock_; 90 static constexpr int LOAD_SA_TIMEOUT_MS = 15000; 91 }; 92 } // namespace OHOS::Scan 93 #endif // SCAN_MANAGER_CLIENT_H 94