• 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     RDB_NOT_SUPPORTED = 801,
29 };
30 
31 enum RdbDistributedType {
32     RDB_DEVICE_COLLABORATION = 10,
33     RDB_DISTRIBUTED_TYPE_MAX
34 };
35 
36 struct RdbSyncerParam {
37     std::string bundleName_;
38     std::string hapName_;
39     std::string storeName_;
40     int32_t area_ = 0;
41     int32_t level_ = 0;
42     int32_t type_ = RDB_DEVICE_COLLABORATION;
43     bool isAutoSync_ = false;
44     bool isEncrypt_ = false;
45     std::vector<uint8_t> password_;
46 };
47 
48 enum SyncMode {
49     PUSH,
50     PULL,
51 };
52 
53 struct SyncOption {
54     SyncMode mode;
55     bool isBlock;
56 };
57 
58 using SyncResult = std::map<std::string, int>; // networkId
59 using SyncCallback = std::function<void(const SyncResult&)>;
60 
61 enum RdbPredicateOperator {
62     EQUAL_TO,
63     NOT_EQUAL_TO,
64     AND,
65     OR,
66     ORDER_BY,
67     LIMIT,
68     OPERATOR_MAX
69 };
70 
71 struct RdbPredicateOperation {
72     RdbPredicateOperator operator_;
73     std::string field_;
74     std::vector<std::string> values_;
75 };
76 
77 struct RdbPredicates {
AddOperationRdbPredicates78     inline void AddOperation(const RdbPredicateOperator op, const std::string& field,
79                              const std::string& value)
80     {
81         operations_.push_back({ op, field, { value } });
82     }
AddOperationRdbPredicates83     inline void AddOperation(const RdbPredicateOperator op, const std::string& field,
84                              const std::vector<std::string>& values)
85     {
86         operations_.push_back({ op, field, values });
87     }
88 
89     std::string table_;
90     std::vector<std::string> devices_;
91     std::vector<RdbPredicateOperation> operations_;
92 };
93 
94 enum SubscribeMode {
95     REMOTE,
96     SUBSCRIBE_MODE_MAX
97 };
98 
99 struct SubscribeOption {
100     SubscribeMode mode;
101 };
102 
103 class RdbStoreObserver {
104 public:
105     virtual void OnChange(const std::vector<std::string>& devices) = 0; // networkid
106 };
107 
108 struct DropOption {
109 };
110 } // namespace OHOS::DistributedRdb
111 #endif
112