1 /* 2 * Copyright (C) 2023 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 #ifndef OHOS_MEDIALIBRARY_NOTIFY_H 16 #define OHOS_MEDIALIBRARY_NOTIFY_H 17 18 #include <cstddef> 19 #include <string> 20 #include <unordered_map> 21 22 #include "dataobs_mgr_client.h" 23 #include "file_asset.h" 24 #include "medialibrary_async_worker.h" 25 #include "parcel.h" 26 #include "rdb_predicates.h" 27 #include "timer.h" 28 #include "uri.h" 29 #include "userfile_manager_types.h" 30 31 namespace OHOS { 32 namespace Media { 33 class NotifyTaskData : public AsyncTaskData { 34 public: NotifyTaskData(const std::string & uri,const NotifyType & notifyType,const int albumId)35 NotifyTaskData(const std::string &uri, const NotifyType ¬ifyType, const int albumId) 36 : uri_(std::move(uri)), notifyType_(notifyType), albumId_(albumId) {} 37 virtual ~NotifyTaskData() override = default; 38 std::string uri_; 39 NotifyType notifyType_; 40 int albumId_; 41 }; 42 constexpr size_t MAX_NOTIFY_LIST_SIZE = 32; 43 constexpr size_t MNOTIFY_TIME_INTERVAL = 500; 44 class MediaLibraryNotify { 45 public: 46 static std::shared_ptr<MediaLibraryNotify> GetInstance(); 47 virtual ~MediaLibraryNotify(); 48 int32_t Notify(const std::string &uri, const NotifyType notifyType, const int albumId = 0); 49 int32_t Notify(const std::shared_ptr<FileAsset> &closeAsset); 50 int32_t GetAlbumIdBySubType(const PhotoAlbumSubType subType); 51 static void GetNotifyUris(const NativeRdb::RdbPredicates &predicates, std::vector<std::string> ¬ifyUris); 52 53 static Utils::Timer timer_; 54 static uint32_t timerId_; 55 static std::mutex mutex_; 56 static std::unordered_map<std::string, std::unordered_map<NotifyType, std::list<Uri>>> nfListMap_; 57 private: 58 MediaLibraryNotify(); 59 int32_t Init(); 60 int32_t GetDefaultAlbums(std::unordered_map<PhotoAlbumSubType, int> &outAlbums); 61 static std::shared_ptr<MediaLibraryNotify> instance_; 62 std::unordered_map<PhotoAlbumSubType, int> defaultAlbums_; 63 }; 64 } // namespace Media 65 } // namespace OHOS 66 #endif // OHOS_MEDIALIBRARY_NOTIFY_H