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_KVSTORE_OBSERVER_H
17 #define I_KVSTORE_OBSERVER_H
18 
19 #include "change_notification.h"
20 #include "iremote_broker.h"
21 #include "ikvstore_observer.h"
22 #include "iremote_proxy.h"
23 #include "iremote_stub.h"
24 #include "types.h"
25 
26 namespace OHOS {
27 namespace DistributedKv {
28 class IKvStoreObserver : public IRemoteBroker {
29 public:
30     DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.DistributedKv.IKvStoreObserver");
31     enum ChangeOp : int32_t {
32         OP_INSERT,
33         OP_UPDATE,
34         OP_DELETE,
35         OP_BUTT,
36     };
37     using Keys = std::vector<std::string>[OP_BUTT];
38     virtual void OnChange(const ChangeNotification &changeNotification) = 0;
39     virtual void OnChange(const DataOrigin &origin, Keys &&keys) = 0;
40 protected:
41     static constexpr int64_t SWITCH_RAW_DATA_SIZE = 200 * 1024;
42     static constexpr size_t MAX_IPC_CAPACITY = 800 * 1024;
43 };
44 
45 class KvStoreObserverStub : public IRemoteStub<IKvStoreObserver> {
46 public:
47     int OnRemoteRequest(uint32_t code, MessageParcel &data,
48                         MessageParcel &reply, MessageOption &option) override;
49 };
50 
51 class API_EXPORT KvStoreObserverProxy : public IRemoteProxy<IKvStoreObserver> {
52 public:
53     explicit KvStoreObserverProxy(const sptr<IRemoteObject> &impl);
54     ~KvStoreObserverProxy() = default;
55     void OnChange(const ChangeNotification &changeNotification) override;
56     void OnChange(const DataOrigin &origin, Keys &&keys) override;
57 private:
58     static inline BrokerDelegator<KvStoreObserverProxy> delegator_;
59 };
60 }  // namespace DistributedKv
61 }  // namespace OHOS
62 
63 #endif  // I_KVSTORE_OBSERVER_H
64