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 36 private: 37 CloudSyncHelper(); 38 void OnTimerCallback(); 39 40 /* singleton */ 41 static std::shared_ptr<CloudSyncHelper> instance_; 42 static std::mutex instanceMutex_; 43 44 /* delayed trigger */ 45 OHOS::Utils::Timer timer_; 46 int32_t timerId_; 47 bool isPending_ = false; 48 std::mutex syncMutex_; 49 }; 50 51 class MediaCloudSyncCallback : public FileManagement::CloudSync::CloudSyncCallback { 52 public: 53 void OnSyncStateChanged(FileManagement::CloudSync::SyncType type, 54 FileManagement::CloudSync::SyncPromptState state); 55 }; 56 } // namespace Media 57 } // namespace OHOS 58 59 #endif // FRAMEWORKS_SERVICES_CLOUD_SERVICE_INCLUDE_CLOUD_SYNC_HELPER_H_