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 KVSTORE_OBSERVER_H
17 #define KVSTORE_OBSERVER_H
18 
19 #include <memory>
20 #include "change_notification.h"
21 #include "types.h"
22 
23 namespace OHOS {
24 namespace DistributedKv {
25 // client implement this class to watch kvstore change.
26 class API_EXPORT KvStoreObserver {
27 public:
28     enum ChangeOp : int32_t {
29         OP_INSERT,
30         OP_UPDATE,
31         OP_DELETE,
32         OP_BUTT,
33     };
34     using Keys = std::vector<std::string>[OP_BUTT];
35     /**
36      * @brief Constructor.
37      */
38     API_EXPORT KvStoreObserver() = default;
39 
40     /**
41      * @brief Destructor.
42      */
~KvStoreObserver()43     API_EXPORT virtual ~KvStoreObserver() {}
44 
45     /**
46      * @brief Would called when kvstore data change.
47      *
48      * client should override this function to receive change notification.
49     */
OnChange(const ChangeNotification & changeNotification)50     API_EXPORT virtual void OnChange(const ChangeNotification &changeNotification) {}
51 
52     /**
53      * @brief Would called when kvstore data change.
54      *
55      * client should override this function to receive change notification.
56     */
OnChange(const DataOrigin & origin,Keys && keys)57     API_EXPORT virtual void OnChange(const DataOrigin &origin, Keys &&keys) {}
58 
59     /**
60      * @brief Would called when switch data change.
61      *
62      * client should override this function to receive change notification.
63      */
OnSwitchChange(const SwitchNotification & notification)64     API_EXPORT virtual void OnSwitchChange(const SwitchNotification &notification) {}
65 };
66 }  // namespace DistributedKv
67 }  // namespace OHOS
68 #endif  // KVSTORE_OBSERVER_H
69