• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 I_KV_STORE_DATA_SERVICE_H
17 #define I_KV_STORE_DATA_SERVICE_H
18 
19 #include "distributeddata_ipc_interface_code.h"
20 #include "iremote_broker.h"
21 #include "ikvstore_client_death_observer.h"
22 #include "ikvstore_observer.h"
23 #include "iremote_proxy.h"
24 #include "iremote_stub.h"
25 #include "message_parcel.h"
26 #include "types.h"
27 
28 namespace OHOS::DistributedKv {
29 class IKvStoreDataService : public IRemoteBroker {
30 public:
31     DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.DistributedKv.IKvStoreDataService");
32 
33     virtual sptr<IRemoteObject> GetFeatureInterface(const std::string &name) = 0;
34 
35     virtual Status RegisterClientDeathObserver(const AppId &appId, sptr<IRemoteObject> observer) = 0;
36 
37 protected:
38     static constexpr size_t MAX_IPC_CAPACITY = 800 * 1024;
39 };
40 
41 class KvStoreDataServiceStub : public IRemoteStub<IKvStoreDataService> {
42 public:
43     int API_EXPORT OnRemoteRequest(uint32_t code, MessageParcel &data,
44                                    MessageParcel &reply, MessageOption &option) override;
45 
46 private:
47     int32_t GetFeatureInterfaceOnRemote(MessageParcel &data, MessageParcel &reply);
48     int32_t RegisterClientDeathObserverOnRemote(MessageParcel &data, MessageParcel &reply);
49 
50     using RequestHandler = int32_t(KvStoreDataServiceStub::*)(MessageParcel&, MessageParcel&);
51     static constexpr RequestHandler
52         HANDLERS[static_cast<uint32_t>(KvStoreDataServiceInterfaceCode::SERVICE_CMD_LAST)] = {
53         &KvStoreDataServiceStub::GetFeatureInterfaceOnRemote,
54         &KvStoreDataServiceStub::RegisterClientDeathObserverOnRemote,
55     };
56 };
57 
58 class API_EXPORT KvStoreDataServiceProxy : public IRemoteProxy<IKvStoreDataService> {
59 public:
60     explicit KvStoreDataServiceProxy(const sptr<IRemoteObject> &impl);
61     ~KvStoreDataServiceProxy() = default;
62     sptr<IRemoteObject> GetFeatureInterface(const std::string &name) override;
63 
64     Status RegisterClientDeathObserver(const AppId &appId, sptr<IRemoteObject> observer) override;
65 
66 private:
67     static inline BrokerDelegator<KvStoreDataServiceProxy> delegator_;
68 };
69 } // namespace OHOS::DistributedKv
70 
71 #endif  // I_KV_STORE_DATA_SERVICE_H