/* * Copyright (c) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef OHOS_CLOUD_SYNC_SERVICE_SDK_HELPER_H #define OHOS_CLOUD_SYNC_SERVICE_SDK_HELPER_H #include #include #include "dk_database.h" #include "drive_kit.h" namespace OHOS { namespace FileManagement { namespace CloudSync { struct FetchCondition { int32_t limitRes; DriveKit::DKRecordType recordType; DriveKit::DKFieldKeyArray desiredKeys; DriveKit::DKFieldKeyArray fullKeys; }; class SdkHelper { public: SdkHelper() = default; ~SdkHelper() = default; /* init */ int32_t Init(const int32_t userId, const std::string &bundleName); /* lock */ int32_t GetLock(DriveKit::DKLock &lock); void DeleteLock(DriveKit::DKLock &lock); /* record download */ using FetchRecordsCallback = std::function, std::shared_ptr, std::shared_ptr>, DriveKit::DKQueryCursor, const DriveKit::DKError &)>; using FetchDatabaseChangesCallback = std::function, std::shared_ptr, std::shared_ptr>, DriveKit::DKQueryCursor, bool, const DriveKit::DKError &)>; using FetchRecordCallback = std::function, std::shared_ptr, DriveKit::DKRecordId, DriveKit::DKRecord &, const DriveKit::DKError &)>; int32_t FetchRecords(std::shared_ptr context, FetchCondition &cond, DriveKit::DKQueryCursor, FetchRecordsCallback callback); int32_t FetchRecordWithId(std::shared_ptr context, FetchCondition &cond, DriveKit::DKRecordId recordId, FetchRecordCallback callback); int32_t FetchDatabaseChanges(std::shared_ptr context, FetchCondition &cond, DriveKit::DKQueryCursor cursor, FetchDatabaseChangesCallback callback); /* record upload */ int32_t CreateRecords(std::shared_ptr context, std::vector &records, std::function, std::shared_ptr, std::shared_ptr>, const DriveKit::DKError &)> callback ); int32_t DeleteRecords(std::shared_ptr context, std::vector &records, std::function, std::shared_ptr, std::shared_ptr>, const DriveKit::DKError &)> callback ); int32_t ModifyRecords(std::shared_ptr context, std::vector &records, DriveKit::DKDatabase::ModifyRecordsCallback callback ); /* asset download */ int32_t DownloadAssets(std::shared_ptr context, std::vector &assetsToDownload, DriveKit::DKAssetPath downLoadPath, DriveKit::DKDownloadId &id, std::function, std::shared_ptr, const std::map &, const DriveKit::DKError &)> resultCallback, std::function, DriveKit::DKDownloadAsset, DriveKit::TotalSize, DriveKit::DownloadSize)> progressCallback); int32_t DownloadAssets(DriveKit::DKDownloadAsset &assetsToDownload); int32_t CancelDownloadAssets(int32_t id); int32_t GetStartCursor(DriveKit::DKRecordType recordType, DriveKit::DKQueryCursor &cursor); std::shared_ptr GetAssetReadSession(DriveKit::DKRecordType recordType, DriveKit::DKRecordId recordId, DriveKit::DKFieldKey assetKey, DriveKit::DKAssetPath assetPath); using SaveSubscriptionCallback = std::function, std::shared_ptr, DriveKit::DKSubscriptionResult &)>; using DelSubscriptionCallback = std::function, const DriveKit::DKError &)>; int32_t SaveSubscription(SaveSubscriptionCallback callback); int32_t DeleteSubscription(DelSubscriptionCallback callback); private: std::shared_ptr container_; std::shared_ptr database_; std::shared_ptr downloader_; }; struct SdkLock { DriveKit::DKLock lock = { 0 }; std::mutex mtx; int count = 0; }; } // namespace CloudSync } // namespace FileManagement } // namespace OHOS #endif // OHOS_CLOUD_SYNC_SERVICE_SDK_HELPER_H