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(); 44 int32_t ExitScan(); 45 int32_t GetScannerList(); 46 int32_t OpenScanner(const std::string scannerId); 47 int32_t CloseScanner(const std::string scannerId); 48 int32_t GetScanOptionDesc(const std::string scannerId, const int32_t optionIndex, ScanOptionDescriptor &desc); 49 int32_t OpScanOptionValue(const std::string scannerId, const int32_t optionIndex, 50 const ScanOptionOpType op, ScanOptionValue &value); 51 int32_t GetScanParameters(const std::string scannerId, ScanParameters ¶); 52 int32_t StartScan(const std::string scannerId, const bool &batchMode); 53 int32_t CancelScan(const std::string scannerId); 54 int32_t GetScanProgress(const std::string scannerId, ScanProgress &prog); 55 int32_t AddScanner(const std::string& serialNumber, const std::string& discoverMode); 56 int32_t DeleteScanner(const std::string& serialNumber, const std::string& discoverMode); 57 int32_t GetAddedScanner(std::vector<ScanDeviceInfo>& allAddedScanner); 58 int32_t On(const std::string &taskId, const std::string &type, const sptr<IScanCallback> &listener); 59 int32_t Off(const std::string &taskId, const std::string &type); 60 61 void LoadServerSuccess(const sptr<IRemoteObject> &remoteObject); 62 void LoadServerFail(); 63 64 #ifndef TDD_ENABLE 65 private: 66 #endif 67 bool LoadScanService(); 68 sptr<IScanService> GetScanServiceProxy(); 69 70 #ifndef TDD_ENABLE 71 private: 72 #endif 73 static std::mutex instanceLock_; 74 static sptr<ScanManagerClient> instance_; 75 sptr<IScanService> scanServiceProxy_; 76 sptr<ScanSaDeathRecipient> deathRecipient_; 77 std::mutex loadMutex_; 78 std::mutex conditionMutex_; 79 std::condition_variable_any syncCon_; 80 bool ready_ = false; 81 std::shared_mutex proxyLock_; 82 static constexpr int LOAD_SA_TIMEOUT_MS = 15000; 83 }; 84 } // namespace OHOS::Scan 85 #endif // SCAN_MANAGER_CLIENT_H 86