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 IMEDIA_SCANNER_CLIENT_H 17 #define IMEDIA_SCANNER_CLIENT_H 18 19 #include <string> 20 21 namespace OHOS { 22 namespace Media { 23 /** 24 * @brief Enumerates Scan operation states 25 */ 26 enum ScanState : int32_t { 27 SCAN_ERROR = -1, 28 SCAN_SUCCESS, 29 SCAN_EMPTY_ARGS, 30 SCAN_NOT_ACCESSIBLE, 31 SCAN_INCORRECT_PATH, 32 SCAN_MEM_ALLOC_FAIL, 33 SCAN_MIMETYPE_NOTSUPPORT, 34 SCAN_SCAN_NOT_INIT, 35 SCAN_SERVICE_NOT_READY, 36 SCAN_INV_CB_ERR 37 }; 38 39 class IMediaScannerAppCallback { 40 public: 41 virtual ~IMediaScannerAppCallback() = default; 42 43 /** 44 * @brief OnScanFinished will be executed when client receives callback from service after scan is finished/error 45 * 46 * @param status scan result 47 * @param uri file uri generated after database updation. For scanDir(), uri will be empty 48 * @param path The path which was requested for scanning 49 */ 50 virtual void OnScanFinished(const int32_t status, const std::string &uri, const std::string &path) = 0; 51 }; 52 53 class IMediaScannerClient { 54 public: 55 virtual ~IMediaScannerClient() = default; 56 57 /** 58 * @brief Helps to release the current client instance from scanner service ability. 59 * 60 */ 61 virtual void Release() = 0; 62 63 /** 64 * @brief This API will help to scan the specified directory and updates the metadata to database 65 * 66 * @param scanDirPath Valid path to a directory {/storage/media/local/files} 67 * @param appCb Callback object to be passed along with request 68 * @return int32_t Returns the request ID of scanDir 69 */ 70 virtual ScanState ScanDir(std::string &scanDirPath, const std::shared_ptr<IMediaScannerAppCallback> &appCb) = 0; 71 72 /** 73 * @brief This API will help to scan the specified file and updates the metadata to database 74 * 75 * @param scanFilePath Valid path to a file along with filename{/storage/media/local/files/sample.mp3} 76 * @param appCb Callback object to be passed along with request 77 * @return int32_t Returns the request ID of scanFile 78 */ 79 virtual ScanState ScanFile(std::string &scanFilePath, const std::shared_ptr<IMediaScannerAppCallback> &appCb) = 0; 80 }; 81 82 class __attribute__((visibility("default"))) MediaScannerHelperFactory { 83 public: 84 static std::shared_ptr<IMediaScannerClient> CreateScannerHelper(); 85 86 private: 87 MediaScannerHelperFactory() = default; 88 ~MediaScannerHelperFactory() = default; 89 }; 90 } // namespace Media 91 } // namespace OHOS 92 #endif // IMEDIA_SCANNER_CLIENT_H 93