1 /* 2 * Copyright (C) 2021 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 MEDIA_SCAN_EXECUTOR_H 17 #define MEDIA_SCAN_EXECUTOR_H 18 19 #include <string> 20 #include <iostream> 21 #include <queue> 22 #include <future> 23 #include <memory> 24 25 #include "media_scanner.h" 26 27 namespace OHOS { 28 namespace Media { 29 class MediaScanExecutor { 30 public: 31 MediaScanExecutor() = default; 32 virtual ~MediaScanExecutor() = default; 33 34 int32_t Commit(std::unique_ptr<MediaScannerObj> scanner); 35 36 void Start(); 37 void Stop(); 38 39 private: 40 void HandleScanExecution(); 41 42 const size_t MAX_THREAD = 1; 43 size_t activeThread_ = 0; 44 45 std::queue<std::unique_ptr<MediaScannerObj>> queue_; 46 std::mutex queueMutex_; 47 48 std::shared_ptr<bool> stopFlag_ = make_shared<bool>(false); 49 int32_t sleepTime_ = 200; 50 }; 51 } // namespace Media 52 } // namespace OHOS 53 54 #endif /* MEDIA_SCAN_EXECUTOR_H */ 55