1 /* 2 * Copyright (c) 2023 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 OHOS_CLOUD_DISK_SERVICE_RDBSTORE_H 17 #define OHOS_CLOUD_DISK_SERVICE_RDBSTORE_H 18 19 #include "rdb_errno.h" 20 #include "rdb_helper.h" 21 #include "rdb_open_callback.h" 22 #include "rdb_store.h" 23 #include "rdb_store_config.h" 24 25 #include "clouddisk_db_const.h" 26 #include "file_column.h" 27 #include "cloud_file_utils.h" 28 29 namespace OHOS { 30 namespace FileManagement { 31 namespace CloudDisk { 32 33 class CloudDiskRdbStore final { 34 public: 35 CloudDiskRdbStore(const std::string &bundleName, const int32_t &userId); 36 ~CloudDiskRdbStore(); 37 38 int32_t RdbInit(); 39 std::shared_ptr<NativeRdb::RdbStore> GetRaw(); 40 41 int32_t LookUp(const std::string &parentCloudId, const std::string &fileName, CloudDiskFileInfo &info); 42 int32_t GetAttr(const std::string &cloudId, CloudDiskFileInfo &info); 43 int32_t ReadDir(const std::string &cloudId, std::vector<CloudDiskFileInfo> &infos); 44 int32_t MkDir(const std::string &cloudId, const std::string &parentCloudId, 45 const std::string &directoryName); 46 int32_t Create(const std::string &cloudId, const std::string &parentCloudId, 47 const std::string &fileName); 48 int32_t Write(const std::string &cloudId); 49 int32_t GetXAttr(const std::string &cloudId, const std::string &key, std::string &value); 50 int32_t SetXAttr(const std::string &cloudId, const std::string &key, const std::string &value); 51 int32_t Rename(const std::string &oldParentCloudId, const std::string &oldFileName, 52 const std::string &newParentCloudId, const std::string &newFileName); 53 int32_t Unlink(const std::string &parentCloudId, const std::string &fileName, std::string &unlinkCloudId); 54 55 private: 56 void Stop(); 57 int32_t UnlinkSynced(const std::string &cloudId); 58 int32_t UnlinkLocal(const std::string &cloudId); 59 60 std::shared_ptr<NativeRdb::RdbStore> rdbStore_; 61 NativeRdb::RdbStoreConfig config_{""}; 62 std::string bundleName_; 63 int32_t userId_{0}; 64 }; 65 66 class CloudDiskDataCallBack : public NativeRdb::RdbOpenCallback { 67 public: 68 int32_t OnCreate(NativeRdb::RdbStore &rdbStore) override; 69 int32_t OnUpgrade(NativeRdb::RdbStore &rdbStore, int32_t oldVersion, int32_t newVersion) override; 70 }; 71 72 #define RDBPTR_IS_NULLPTR(rdbStore_) \ 73 do { \ 74 if ((rdbStore_) == nullptr) { \ 75 LOGE("rdbStore_ is nullptr"); \ 76 return E_RDB; \ 77 } \ 78 } while (0) 79 80 #define CLOUDID_IS_NULL(cloudId) \ 81 do { \ 82 if ((cloudId).empty()) { \ 83 LOGE("cloudId is null"); \ 84 return E_INVAL_ARG; \ 85 } \ 86 } while (0) 87 } // namespace CloudDisk 88 } // namespace FileManagement 89 } // namespace OHOS 90 91 #endif // OHOS_CLOUD_DISK_SERVICE_RDBSTORE_H