1 /* 2 * Copyright (c) 2025 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 BACKENDS_MANAGER_CLIENT_H 17 #define BACKENDS_MANAGER_CLIENT_H 18 19 #include <condition_variable> 20 #include <map> 21 #include <mutex> 22 #include <shared_mutex> 23 #include "isane_backends.h" 24 #include "iremote_object.h" 25 #include "refbase.h" 26 #include "sane_backends_proxy.h" 27 #include "sane_sa_death_recipient.h" 28 #include "scan_log.h" 29 #include "scan_constant.h" 30 namespace OHOS::Scan { 31 class SaneManagerClient : public RefBase { 32 public: 33 SaneManagerClient(); 34 ~SaneManagerClient(); 35 static sptr<SaneManagerClient> GetInstance(); 36 SaneStatus SaneInit(); 37 SaneStatus SaneExit(); 38 SaneStatus SaneOpen(const std::string& scannerId); 39 SaneStatus SaneClose(const std::string& scannerId); 40 SaneStatus SaneStart(const std::string& scannerId); 41 SaneStatus SaneCancel(const std::string& scannerId); 42 SaneStatus SaneGetOptionDescriptor(const std::string& scannerId, const int32_t& option, SaneOptionDescriptor& desc); 43 SaneStatus SaneGetParameters(const std::string& scannerId, SaneParameters& params); 44 SaneStatus SaneGetDevices(std::vector<SaneDevice>& deviceInfos); 45 SaneStatus SaneControlOption(const std::string& scannerId, SaneControlParam& controlParam, SaneOutParam& outParam); 46 SaneStatus SaneRead(const std::string& scannerId, const int32_t buflen, SanePictureData& pictureData); 47 SaneStatus UnloadSystemAbility(); 48 void LoadSystemAbilitysuccess(const sptr<IRemoteObject> &remoteObject); 49 void LoadSystemAbilityFail(); 50 void OnRemoteSaDied(const wptr<IRemoteObject>& object); 51 52 private: 53 bool LoadSaneService(); 54 sptr<ISaneBackends> GetSaneServiceProxy(); 55 sptr<OHOS::Scan::ISaneBackends> proxy_; 56 sptr<SaneSaDeathRecipient> deathRecipient_; 57 static sptr<SaneManagerClient> instance_; 58 static std::mutex instanceLock_; 59 static std::shared_mutex serviceLock_; 60 std::condition_variable_any syncCon_; 61 }; 62 } // namespage OHOS::Scan 63 #endif // BACKENDS_MANAGER_CLIENT_H