1 /* 2 * Copyright (C) 2022 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 #include "trash_async_worker.h" 16 #include "medialibrary_album_operations.h" 17 #include "medialibrary_smartalbum_map_operations.h" 18 #include "media_log.h" 19 20 using namespace std; 21 22 namespace OHOS { 23 namespace Media { 24 shared_ptr<TrashAsyncTaskWorker> TrashAsyncTaskWorker::asyncWorkerInstance_{nullptr}; 25 mutex TrashAsyncTaskWorker::instanceLock_; 26 GetInstance()27shared_ptr<TrashAsyncTaskWorker> TrashAsyncTaskWorker::GetInstance() 28 { 29 if (asyncWorkerInstance_ == nullptr) { 30 lock_guard<mutex> lockGuard(instanceLock_); 31 asyncWorkerInstance_ = shared_ptr<TrashAsyncTaskWorker>(new TrashAsyncTaskWorker()); 32 } 33 return asyncWorkerInstance_; 34 } 35 TrashAsyncTaskWorker()36TrashAsyncTaskWorker::TrashAsyncTaskWorker() {} 37 ~TrashAsyncTaskWorker()38TrashAsyncTaskWorker::~TrashAsyncTaskWorker() {} 39 Init()40void TrashAsyncTaskWorker::Init() 41 { 42 thread(&TrashAsyncTaskWorker::StartWorker, this).detach(); 43 } 44 Interrupt()45void TrashAsyncTaskWorker::Interrupt() 46 { 47 MediaLibrarySmartAlbumMapOperations::SetInterrupt(true); 48 } 49 StartWorker()50void TrashAsyncTaskWorker::StartWorker() 51 { 52 string name("TrashAsyncWorker"); 53 pthread_setname_np(pthread_self(), name.c_str()); 54 MediaLibrarySmartAlbumMapOperations::SetInterrupt(false); 55 MediaLibrarySmartAlbumMapOperations::HandleAgingOperation(); 56 MediaLibraryAlbumOperations::HandlePhotoAlbum(OperationType::AGING, {}, {}); 57 } 58 } // namespace Media 59 } // namespace OHOS 60