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 
16 #ifndef MEDIA_SCANNER_MANAGER_H
17 #define MEDIA_SCANNER_MANAGER_H
18 
19 #include <memory>
20 
21 #include "media_scanner.h"
22 #include "media_scan_executor.h"
23 #include "medialibrary_errno.h"
24 #include "userfile_manager_types.h"
25 
26 namespace OHOS {
27 namespace Media {
28 #define EXPORT __attribute__ ((visibility ("default")))
29 class MediaScannerManager final {
30 public:
31     EXPORT static std::shared_ptr<MediaScannerManager> GetInstance();
32 
33     EXPORT virtual ~MediaScannerManager() = default;
34 
35     void Start();
36     void Stop();
37     void ScanError();
38     void ErrorRecord(const std::string &path = ROOT_MEDIA_DIR);
39 
40     EXPORT int32_t ScanFile(const std::string &path, const std::shared_ptr<IMediaScannerCallback> &callback,
41         MediaLibraryApi api = MediaLibraryApi::API_OLD);
42     int32_t ScanFileSync(const std::string &path, const std::shared_ptr<IMediaScannerCallback> &callback,
43         MediaLibraryApi api = MediaLibraryApi::API_OLD, bool isForceScan = false, int32_t fileId = 0);
44     int32_t ScanFileSyncWithoutAlbumUpdate(const std::string &path,
45         const std::shared_ptr<IMediaScannerCallback> &callback, MediaLibraryApi api = MediaLibraryApi::API_OLD,
46         bool isForceScan = false, int32_t fileId = 0);
47     EXPORT int32_t ScanDir(const std::string &path, const std::shared_ptr<IMediaScannerCallback> &callback);
48     EXPORT int32_t ScanDirSync(const std::string &path, const std::shared_ptr<IMediaScannerCallback> &callback);
49 private:
50     MediaScannerManager() = default;
51 
52     static std::shared_ptr<MediaScannerManager> instance_;
53     static std::mutex instanceMutex_;
54 
55     MediaScanExecutor executor_;
56 };
57 } // namespace Media
58 } // namespace OHOS
59 
60 #endif // MEDIA_SCANNER_MANAGER_H