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 OBJECT_CLIENT_ADAPTOR_H
17 #define OBJECT_CLIENT_ADAPTOR_H
18 
19 #include "object_service_proxy.h"
20 #include "iobject_service.h"
21 
22 namespace OHOS::ObjectStore {
23 class ObjectStoreDataServiceProxy;
24 class ClientAdaptor {
25 public:
26     static sptr<OHOS::DistributedObject::IObjectService> GetObjectService();
27     static uint32_t RegisterClientDeathListener(const std::string &appId, sptr<IRemoteObject> remoteObject);
28 private:
29     class ServiceDeathRecipient : public IRemoteObject::DeathRecipient {
30     public:
31         ServiceDeathRecipient();
32         virtual ~ServiceDeathRecipient();
33 
34         void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
35     };
36 
37     static constexpr int32_t DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID = 1301;
38     static constexpr int32_t GET_SA_RETRY_TIMES = 3;
39     static constexpr int32_t RETRY_INTERVAL = 1;
40     static std::shared_ptr<ObjectStoreDataServiceProxy> distributedDataMgr_;
41     static std::shared_ptr<ObjectStoreDataServiceProxy> GetDistributedDataManager();
42     static std::mutex mutex_;
43 };
44 
45 class ObjectStoreDataServiceProxy  : public IRemoteProxy<OHOS::DistributedObject::IKvStoreDataService> {
46 public:
47     explicit ObjectStoreDataServiceProxy(const sptr<IRemoteObject> &impl);
48     ~ObjectStoreDataServiceProxy() = default;
49     sptr<IRemoteObject> GetFeatureInterface(const std::string &name) override;
50     uint32_t RegisterClientDeathObserver(const std::string &appId, sptr<IRemoteObject> observer) override;
51 };
52 } // namespace OHOS::ObjectStore
53 
54 #endif // OBJECT_CLIENT_ADAPTOR_H
55