• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 RINGTONE_SCAN_EXECUTOR_H
17 #define RINGTONE_SCAN_EXECUTOR_H
18 
19 #include <queue>
20 
21 #include "ringtone_scanner.h"
22 #include <condition_variable>
23 
24 namespace OHOS {
25 namespace Media {
26 class RingtoneScanExecutor {
27 public:
28     RingtoneScanExecutor() = default;
29     virtual ~RingtoneScanExecutor() = default;
30 
31     int32_t Commit(std::shared_ptr<RingtoneScannerObj> scanner);
32 
33     void Start();
34     void Stop();
35 
36 private:
37     void HandleScanExecution();
38 
39     size_t activeThread_ = 0;
40 
41     std::queue<std::shared_ptr<RingtoneScannerObj>> queue_;
42     std::mutex queueMtx_;
43 
44     std::shared_ptr<bool> stopFlag_ = std::make_shared<bool>(false);
45     std::condition_variable stopCond;
46     bool isScanFinished = true;
47 };
48 } // namespace Media
49 } // namespace OHOS
50 
51 #endif /* RINGTONE_SCAN_EXECUTOR_H */
52