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 DISTRIBUTED_RDB_MANAGER_IMPL_H 17 #define DISTRIBUTED_RDB_MANAGER_IMPL_H 18 19 #include <map> 20 #include <memory> 21 #include <mutex> 22 23 #include "refbase.h" 24 #include "iremote_object.h" 25 #include "concurrent_map.h" 26 #include "rdb_types.h" 27 #include "visibility.h" 28 29 namespace OHOS::DistributedKv { 30 class KvStoreDataServiceProxy; 31 } 32 33 namespace OHOS::DistributedRdb { 34 class RdbService; 35 class RdbServiceProxy; 36 class API_EXPORT RdbManagerImpl { 37 public: 38 static constexpr int GET_SA_RETRY_TIMES = 3; 39 static constexpr int RETRY_INTERVAL = 1; 40 static constexpr int WAIT_TIME = 2; 41 42 static RdbManagerImpl &GetInstance(); 43 44 int GetRdbService(const RdbSyncerParam& param, std::shared_ptr<RdbService> &service); 45 46 void OnRemoteDied(); 47 48 class ServiceDeathRecipient : public IRemoteObject::DeathRecipient { 49 public: ServiceDeathRecipient(RdbManagerImpl * owner)50 explicit ServiceDeathRecipient(RdbManagerImpl* owner) : owner_(owner) {} OnRemoteDied(const wptr<IRemoteObject> & object)51 void OnRemoteDied(const wptr<IRemoteObject> &object) override 52 { 53 if (owner_ != nullptr) { 54 owner_->OnRemoteDied(); 55 } 56 } 57 private: 58 RdbManagerImpl* owner_; 59 }; 60 61 private: 62 RdbManagerImpl(); 63 64 ~RdbManagerImpl(); 65 66 void ResetServiceHandle(); 67 68 std::mutex mutex_; 69 sptr<OHOS::DistributedKv::KvStoreDataServiceProxy> distributedDataMgr_; 70 std::shared_ptr<RdbService> rdbService_; 71 std::string bundleName_; 72 }; 73 } // namespace OHOS::DistributedRdb 74 #endif 75