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 INTERCEPTED_DATA_H
17 #define INTERCEPTED_DATA_H
18 
19 #include <vector>
20 #include "store_types.h"
21 #include "types_export.h"
22 
23 namespace DistributedDB {
24 struct KVEntry {
25     const Key &key;
26     const Value &value;
27 };
28 
29 class InterceptedData {
30 public:
InterceptedData()31     InterceptedData() {}
~InterceptedData()32     DB_API virtual ~InterceptedData() {}
33 
34     // Interface for getting the intercepted entries.
35     DB_API virtual std::vector<KVEntry> GetEntries() = 0;
36 
37     // Interface for modifying key. Index is the index of GetEntries().
38     DB_API virtual DBStatus ModifyKey(size_t index, const Key &newKey) = 0;
39 
40     // Interface for modifying value. Index is the index of GetEntries().
41     DB_API virtual DBStatus ModifyValue(size_t index, const Value &newValue) = 0;
42 };
43 
44 // The callback function works on the send data from device "sourceID" to device "targetID".
45 using PushDataInterceptor = std::function<int(InterceptedData &data, const std::string &sourceID,
46     const std::string &targetID)>;
47 using DataInterceptor = PushDataInterceptor;
48 } // namespace DistributedDB
49 #endif // INTERCEPTED_DATA_H