• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 DISTRIBUTEDDATAFWK_RDB_TYPES_H
17 #define DISTRIBUTEDDATAFWK_RDB_TYPES_H
18 
19 #include <functional>
20 #include <map>
21 #include <string>
22 #include <vector>
23 
24 namespace OHOS::DistributedRdb {
25 enum RdbStatus {
26     RDB_OK,
27     RDB_ERROR,
28 };
29 
30 enum RdbDistributedType {
31     RDB_DEVICE_COLLABORATION = 10,
32     RDB_DISTRIBUTED_TYPE_MAX
33 };
34 
35 struct RdbSyncerParam {
36     std::string bundleName_;
37     std::string relativePath_;
38     std::string storeName_;
39     std::string encryptLevel_;
40     std::string realPath_;
41     int type_ = RDB_DEVICE_COLLABORATION;
42     bool isAutoSync_ = false;
43 };
44 
45 enum SyncMode {
46     PUSH,
47     PULL,
48 };
49 
50 struct SyncOption {
51     SyncMode mode;
52     bool isBlock;
53 };
54 
55 using SyncResult = std::map<std::string, int>; // networkId
56 using SyncCallback = std::function<void(const SyncResult&)>;
57 
58 enum RdbPredicateOperator {
59     EQUAL_TO,
60     NOT_EQUAL_TO,
61     AND,
62     OR,
63     ORDER_BY,
64     LIMIT,
65     OPERATOR_MAX
66 };
67 
68 struct RdbPredicateOperation {
69     RdbPredicateOperator operator_;
70     std::string field_;
71     std::vector<std::string> values_;
72 };
73 
74 struct RdbPredicates {
AddOperationRdbPredicates75     inline void AddOperation(const RdbPredicateOperator op, const std::string& field,
76                              const std::string& value)
77     {
78         operations_.push_back({ op, field, { value } });
79     }
AddOperationRdbPredicates80     inline void AddOperation(const RdbPredicateOperator op, const std::string& field,
81                              const std::vector<std::string>& values)
82     {
83         operations_.push_back({ op, field, values });
84     }
85 
86     std::string table_;
87     std::vector<std::string> devices_;
88     std::vector<RdbPredicateOperation> operations_;
89 };
90 
91 enum SubscribeMode {
92     REMOTE,
93     SUBSCRIBE_MODE_MAX
94 };
95 
96 struct SubscribeOption {
97     SubscribeMode mode;
98 };
99 
100 class RdbStoreObserver {
101 public:
102     virtual void OnChange(const std::vector<std::string>& devices) = 0; // networkid
103 };
104 
105 struct DropOption {
106 };
107 }
108 #endif
109