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