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 FRAMEWORKS_SERVICES_CLOUD_SERVICE_INCLUDE_CLOUD_SYNC_HELPER_H_ 17 #define FRAMEWORKS_SERVICES_CLOUD_SERVICE_INCLUDE_CLOUD_SYNC_HELPER_H_ 18 19 #include <mutex> 20 21 #include <timer.h> 22 23 #include "cloud_sync_manager.h" 24 25 namespace OHOS { 26 namespace Media { 27 constexpr int32_t SYNC_INTERVAL = 5000; 28 29 class CloudSyncHelper final { 30 public: 31 static std::shared_ptr<CloudSyncHelper> GetInstance(); 32 virtual ~CloudSyncHelper(); 33 34 void StartSync(); 35 int32_t StartDownloadFile(const std::string &path); 36 37 private: 38 CloudSyncHelper(); 39 void OnTimerCallback(); 40 41 /* singleton */ 42 static std::shared_ptr<CloudSyncHelper> instance_; 43 static std::mutex instanceMutex_; 44 45 /* delayed trigger */ 46 OHOS::Utils::Timer timer_; 47 int32_t timerId_; 48 bool isPending_ = false; 49 std::mutex syncMutex_; 50 }; 51 52 class MediaCloudSyncCallback : public FileManagement::CloudSync::CloudSyncCallback { 53 public: 54 void OnSyncStateChanged(FileManagement::CloudSync::SyncType type, 55 FileManagement::CloudSync::SyncPromptState state); 56 }; 57 } // namespace Media 58 } // namespace OHOS 59 60 #endif // FRAMEWORKS_SERVICES_CLOUD_SERVICE_INCLUDE_CLOUD_SYNC_HELPER_H_