1 /* 2 * Copyright (C) 2025 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 FRAMEWORKS_INNERKITSIMPL_MEDIALIBRARY_NOTIFY_UTILS_H_ 17 #define FRAMEWORKS_INNERKITSIMPL_MEDIALIBRARY_NOTIFY_UTILS_H_ 18 19 #include <map> 20 #include <string> 21 #include <vector> 22 #include "album_change_info.h" 23 #include "photo_asset_change_info.h" 24 #include "napi/native_api.h" 25 #include "media_change_info.h" 26 27 namespace OHOS { 28 namespace Media { 29 #define EXPORT __attribute__ ((visibility ("default"))) 30 31 enum NotifyChangeType { 32 NOTIFY_CHANGE_ADD, 33 NOTIFY_CHANGE_UPDATE, 34 NOTIFY_CHANGE_REMOVE, 35 }; 36 37 class RegisterNotifyType { 38 public: 39 static const std::string PHOTO_CHANGE EXPORT; 40 static const std::string HIDDEN_PHOTO_CHANGE EXPORT; 41 static const std::string TRASH_PHOTO_CHANGE EXPORT; 42 static const std::string PHOTO_ALBUM_CHANGE EXPORT; 43 static const std::string HIDDEN_ALBUM_CHANGE EXPORT; 44 static const std::string TRASHED_ALBUM_CHANGE EXPORT; 45 }; 46 47 class MediaLibraryNotifyUtils { 48 public: 49 static const std::map<std::string, Notification::NotifyUriType> REGISTER_NOTIFY_TYPE_MAP; 50 static const std::map<Notification::NotifyUriType, Notification::NotifyUriType> REGISTER_TYPE_MAP; 51 static const std::map<Notification::NotifyUriType, std::string> REGISTER_URI_MAP; 52 static const std::map<Notification::NotifyType, NotifyChangeType> NOTIFY_CHANGE_TYPE_MAP; 53 54 static int32_t GetRegisterNotifyType(const std::string &type, Notification::NotifyUriType &uriType); 55 static int32_t GetNotifyTypeAndUri(const Notification::NotifyUriType type, 56 Notification::NotifyUriType &uriType, std::string &uri); 57 static int32_t GetNotifyChangeType(const Notification::NotifyType ¬ifyType); 58 59 static napi_status SetValueInt32(const napi_env& env, const char* name, const int32_t intValue, napi_value& result); 60 static napi_status SetValueInt64(const napi_env& env, const char* name, const int64_t intValue, napi_value& result); 61 static napi_status SetValueString(const napi_env& env, const char* name, const std::string& stringValue, 62 napi_value& result); 63 static napi_status SetValueBool(const napi_env& env, const char* name, const bool boolValue, napi_value& result); 64 static napi_status SetValueNull(const napi_env& env, const char* name, napi_value& result); 65 66 static napi_value BuildPhotoAssetChangeInfo(napi_env env, 67 const AccurateRefresh::PhotoAssetChangeInfo &photoAssetChangeInfo); 68 static napi_value BuildPhotoAssetChangeData(napi_env env, 69 const AccurateRefresh::PhotoAssetChangeData &photoAssetChangeData); 70 static napi_value BuildPhotoNapiArray(napi_env env, 71 const std::vector<std::variant<AccurateRefresh::PhotoAssetChangeData, AccurateRefresh::AlbumChangeData>> 72 &changeInfos); 73 static napi_value BuildPhotoAssetChangeInfos(napi_env env, 74 const std::shared_ptr<Notification::MediaChangeInfo> &changeInfo); 75 76 static napi_value BuildAlbumChangeInfo(napi_env env, const AccurateRefresh::AlbumChangeInfo &albumChangeInfo); 77 static napi_value BuildAlbumChangeData(napi_env env, const AccurateRefresh::AlbumChangeData &albumChangeData); 78 static napi_value BuildAlbumNapiArray(napi_env env, 79 const std::vector<std::variant<AccurateRefresh::PhotoAssetChangeData, AccurateRefresh::AlbumChangeData>> 80 &changeInfos); 81 static napi_value BuildAlbumChangeInfos(napi_env env, 82 const std::shared_ptr<Notification::MediaChangeInfo> &changeInfo); 83 static napi_value BuildPhotoAssetRecheckChangeInfos(napi_env env); 84 static napi_value BuildAlbumRecheckChangeInfos(napi_env env); 85 static int32_t ConvertToJsError(int32_t innerErr); 86 }; 87 } 88 } 89 #endif // FRAMEWORKS_INNERKITSIMPL_MEDIALIBRARY_NOTIFY_UTILS_H_