1 /* 2 * Copyright (c) 2024 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 RELATIONAL_STORE_UTILS_H 17 #define RELATIONAL_STORE_UTILS_H 18 19 #include "rdb_store.h" 20 #include "rdb_types.h" 21 #include "securec.h" 22 #include "value_object.h" 23 24 namespace OHOS { 25 namespace Relational { 26 char *MallocCString(const std::string &origin); 27 28 struct StoreConfig { 29 char *name; 30 int32_t securityLevel; 31 bool encrypt; 32 char *dataGroupId; 33 char *customDir; 34 bool isSearchable; 35 bool autoCleanDirtyData; 36 }; 37 38 struct Asset { 39 const char *name; 40 const char *uri; 41 const char *path; 42 const char *createTime; 43 const char *modifyTime; 44 const char *size; 45 int32_t status; 46 }; 47 48 struct Assets { 49 Asset *head; 50 int64_t size; 51 }; 52 53 struct CArrUI8 { 54 uint8_t *head; 55 int64_t size; 56 }; 57 58 struct CArrStr { 59 char **head; 60 int64_t size; 61 }; 62 63 CArrStr VectorToCArrStr(const std::vector<std::string> &devices); 64 65 std::vector<std::string> CArrStrToVector(CArrStr carr); 66 67 struct ValueType { 68 int64_t integer; 69 double dou; 70 char *string; 71 bool boolean; 72 CArrUI8 Uint8Array; 73 Asset asset; 74 Assets assets; 75 uint8_t tag; 76 }; 77 78 enum TagType { TYPE_NULL, TYPE_INT, TYPE_DOU, TYPE_STR, TYPE_BOOL, TYPE_BLOB, TYPE_ASSET, TYPE_ASSETS }; 79 80 struct ValuesBucket { 81 char **key; 82 ValueType *value; 83 int64_t size; 84 }; 85 86 NativeRdb::ValueObject ValueTypeToValueObject(const ValueType &value); 87 88 struct CArrInt32 { 89 int32_t *head; 90 int64_t size; 91 }; 92 93 struct CArrSyncResult { 94 char **str; 95 int32_t *num; 96 int64_t size; 97 }; 98 99 ValueType ValueObjectToValueType(const NativeRdb::ValueObject &object); 100 101 struct RetPRIKeyType { 102 int64_t integer; 103 double dou; 104 char *string; 105 uint8_t tag; 106 }; 107 108 std::variant<std::monostate, std::string, int64_t, double> RetPRIKeyTypeToVariant(RetPRIKeyType &value); 109 110 RetPRIKeyType VariantToRetPRIKeyType(const std::variant<std::monostate, std::string, int64_t, double> &value); 111 112 struct CArrPRIKeyType { 113 RetPRIKeyType *head; 114 int64_t size; 115 }; 116 117 std::vector<NativeRdb::RdbStore::PRIKey> CArrPRIKeyTypeToPRIKeyArray(CArrPRIKeyType &cPrimaryKeys); 118 119 struct ModifyTime { 120 RetPRIKeyType *key; 121 uint64_t *value; 122 int64_t size; 123 }; 124 125 ModifyTime MapToModifyTime(std::map<NativeRdb::RdbStore::PRIKey, NativeRdb::RdbStore::Date> &map, int32_t &errCode); 126 127 struct RetChangeInfo { 128 char *table; 129 int32_t type; 130 CArrPRIKeyType inserted; 131 CArrPRIKeyType updated; 132 CArrPRIKeyType deleted; 133 }; 134 135 struct CArrRetChangeInfo { 136 RetChangeInfo *head; 137 int64_t size; 138 }; 139 140 CArrPRIKeyType VectorToCArrPRIKeyType(std::vector<DistributedRdb::RdbStoreObserver::PrimaryKey> arr); 141 142 RetChangeInfo ToRetChangeInfo( 143 const DistributedRdb::Origin &origin, DistributedRdb::RdbStoreObserver::ChangeInfo::iterator info); 144 145 CArrRetChangeInfo ToCArrRetChangeInfo(const DistributedRdb::Origin &origin, 146 const DistributedRdb::RdbStoreObserver::PrimaryFields &fields, 147 DistributedRdb::RdbStoreObserver::ChangeInfo &&changeInfo); 148 149 struct CStatistic { 150 uint32_t total; 151 uint32_t successful; 152 uint32_t failed; 153 uint32_t remained; 154 }; 155 156 CStatistic ToStatistic(DistributedRdb::Statistic statistic); 157 158 struct CTableDetails { 159 CStatistic upload; 160 CStatistic download; 161 }; 162 163 CTableDetails ToCTableDetails(DistributedRdb::TableDetail detail); 164 165 struct CDetails { 166 char **key; 167 CTableDetails *value; 168 int64_t size; 169 }; 170 171 CDetails ToCDetails(DistributedRdb::TableDetails details); 172 173 struct CProgressDetails { 174 int32_t schedule; 175 int32_t code; 176 CDetails details; 177 }; 178 179 CProgressDetails ToCProgressDetails(const DistributedRdb::Details &details); 180 181 struct RetDistributedConfig { 182 bool autoSync; 183 }; 184 } // namespace Relational 185 } // namespace OHOS 186 #endif