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 STORE_OBSERVER_H
17 #define STORE_OBSERVER_H
18 
19 #include "cloud/cloud_store_types.h"
20 #include "store_changed_data.h"
21 
22 namespace DistributedDB {
23 
24 enum ChangeType : uint32_t {
25     OP_INSERT = 0,
26     OP_UPDATE,
27     OP_DELETE,
28     OP_BUTT,
29 };
30 
31 enum ChangedDataType : uint32_t {
32     DATA = 0,
33     ASSET = 1,
34 };
35 
36 struct ChangedData {
37     std::string tableName;
38     ChangedDataType type = DATA;
39     // CLOUD_COOPERATION mode, primaryData store primary keys
40     // primaryData store row id if have no data
41     std::vector<std::vector<Type>> primaryData[OP_BUTT];
42     std::vector<std::string> field;
43     ChangeProperties properties;
44 };
45 
46 enum Origin : int32_t {
47     ORIGIN_CLOUD,
48     ORIGIN_LOCAL,
49     ORIGIN_REMOTE,
50     ORIGIN_ALL,
51     ORIGIN_BUTT
52 };
53 
54 enum class CallbackDetailsType : uint32_t {
55     DEFAULT = 0x01,
56     BRIEF = 0x02,
57     DETAILED = DEFAULT | BRIEF
58 };
59 
60 class StoreObserver {
61 public:
~StoreObserver()62     virtual ~StoreObserver() {}
63 
64     using StoreChangedInfo = std::vector<ChangedData>;
65 
66     // Data change callback
OnChange(const StoreChangedData & data)67     virtual void OnChange(const StoreChangedData &data) {};
68 
OnChange(Origin origin,const std::string & originalId,ChangedData && data)69     virtual void OnChange(Origin origin, const std::string &originalId, ChangedData &&data) {};
70 
OnChange(StoreChangedInfo && data)71     virtual void OnChange(StoreChangedInfo &&data) {};
72 
GetCallbackDetailsType()73     virtual uint32_t GetCallbackDetailsType() const
74     {
75         return static_cast<uint32_t>(CallbackDetailsType::DEFAULT);
76     }
77 };
78 } // namespace DistributedDB
79 
80 #endif // STORE_OBSERVER_H