• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
28 namespace OHOS::DistributedKv {
29 class KvStoreDataServiceProxy;
30 }
31 
32 namespace OHOS::DistributedRdb {
33 class RdbService;
34 class IRdbService;
35 class RdbManagerImpl {
36 public:
37     static constexpr int GET_SA_RETRY_TIMES = 3;
38     static constexpr int RETRY_INTERVAL = 1;
39     static constexpr int WAIT_TIME = 2;
40 
41     static RdbManagerImpl &GetInstance();
42 
43     std::shared_ptr<RdbService> GetRdbService(const RdbSyncerParam& param);
44 
45     void OnRemoteDied();
46 
47     class ServiceDeathRecipient : public IRemoteObject::DeathRecipient {
48     public:
ServiceDeathRecipient(RdbManagerImpl * owner)49         explicit ServiceDeathRecipient(RdbManagerImpl* owner) : owner_(owner) {}
OnRemoteDied(const wptr<IRemoteObject> & object)50         void OnRemoteDied(const wptr<IRemoteObject> &object) override
51         {
52             if (owner_ != nullptr) {
53                 owner_->OnRemoteDied();
54             }
55         }
56     private:
57         RdbManagerImpl* owner_;
58     };
59 
60 private:
61     RdbManagerImpl();
62 
63     ~RdbManagerImpl();
64 
65     sptr<IRdbService> GetRdbService();
66 
67     void ResetServiceHandle();
68 
69     std::mutex mutex_;
70     sptr<OHOS::DistributedKv::KvStoreDataServiceProxy> distributedDataMgr_;
71     std::shared_ptr<RdbService> rdbService_;
72     std::string bundleName_;
73 };
74 }
75 #endif
76