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_ANI_SRC_INCLUDE_FETCH_RESULT_ANI_H 17 #define FRAMEWORKS_ANI_SRC_INCLUDE_FETCH_RESULT_ANI_H 18 19 #include <ani.h> 20 #include "ani_error.h" 21 #include "datashare_helper.h" 22 #include "datashare_predicates.h" 23 #include "photo_album.h" 24 #include "values_bucket.h" 25 #include "fetch_result.h" 26 #include "file_asset.h" 27 #include "medialibrary_type_const.h" 28 29 namespace OHOS { 30 namespace Media { 31 32 class FetchResultProperty { 33 public: 34 std::shared_ptr<FetchResult<FileAsset>> fetchFileResult_ = nullptr; 35 std::shared_ptr<FetchResult<AlbumAsset>> fetchAlbumResult_ = nullptr; 36 std::shared_ptr<FetchResult<PhotoAlbum>> fetchPhotoAlbumResult_ = nullptr; 37 std::shared_ptr<FetchResult<SmartAlbumAsset>> fetchSmartAlbumResult_ = nullptr; 38 FetchResType fetchResType_; 39 }; 40 41 class FetchFileResultAni { 42 public: 43 FetchFileResultAni() = default; 44 ~FetchFileResultAni() = default; 45 static ani_status FetchFileResultInit(ani_env *env); 46 static FetchFileResultAni* Unwrap(ani_env *env, ani_object fetchFileResultHandle); 47 static ani_object Constructor(ani_env *env, [[maybe_unused]] ani_class clazz); 48 49 static ani_object GetAllObjects(ani_env *env, [[maybe_unused]] ani_object fetchFileResultHandle); 50 static ani_status Close(ani_env *env, [[maybe_unused]] ani_object fetchFileResultHandle); 51 static ani_object GetFirstObject(ani_env *env, [[maybe_unused]] ani_object fetchFileResultHandle); 52 static ani_object GetNextObject(ani_env *env, [[maybe_unused]] ani_object fetchFileResultHandle); 53 static ani_double GetCount([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object fetchFileResultHandle); 54 55 static ani_object CreateFetchFileResult(ani_env *env, std::unique_ptr<FetchResult<FileAsset>> fileResult); 56 static ani_object CreateFetchFileResult(ani_env *env, std::unique_ptr<FetchResult<PhotoAlbum>> fileResult); 57 std::shared_ptr<FetchResult<FileAsset>> GetFetchFileResultObject(); 58 std::shared_ptr<FetchResult<AlbumAsset>> GetFetchAlbumResultObject(); 59 std::shared_ptr<FetchResult<PhotoAlbum>> GetFetchPhotoAlbumResultObject(); 60 std::shared_ptr<FetchResult<SmartAlbumAsset>> GetFetchSmartAlbumResultObject(); 61 62 FetchResType GetFetchResType(); 63 bool CheckIfPropertyPtrNull(); GetPropertyPtrInstance()64 inline std::shared_ptr<FetchResultProperty> GetPropertyPtrInstance() 65 { 66 return propertyPtr; 67 } 68 69 private: 70 EXPORT static void GetFetchResult(unique_ptr<FetchFileResultAni> &obj); 71 EXPORT static ani_object FetchFileResultAniConstructor(ani_env *env, [[maybe_unused]] ani_class clazz); 72 73 ani_env *env_; 74 std::shared_ptr<FetchResultProperty> propertyPtr; 75 static inline thread_local std::unique_ptr<FetchResult<FileAsset>> sFetchFileResult_ = nullptr; 76 static inline thread_local std::unique_ptr<FetchResult<AlbumAsset>> sFetchAlbumResult_ = nullptr; 77 static inline thread_local std::unique_ptr<FetchResult<PhotoAlbum>> sFetchPhotoAlbumResult_ = nullptr; 78 static inline thread_local std::unique_ptr<FetchResult<SmartAlbumAsset>> sFetchSmartAlbumResult_ = nullptr; 79 static inline thread_local FetchResType sFetchResType_ = FetchResType::TYPE_FILE; 80 }; 81 82 class FetchFileResultAniContext : public AniError { 83 public: 84 FetchFileResultAni* objectInfo; 85 std::shared_ptr<FetchResultProperty> objectPtr; 86 bool status; 87 int32_t position; 88 std::unique_ptr<FileAsset> fileAsset; 89 std::unique_ptr<AlbumAsset> albumAsset; 90 std::unique_ptr<PhotoAlbum> photoAlbum; 91 std::unique_ptr<SmartAlbumAsset> smartAlbumAsset; 92 std::vector<std::unique_ptr<FileAsset>> fileAssetArray; 93 std::vector<std::unique_ptr<AlbumAsset>> fileAlbumArray; 94 std::vector<std::unique_ptr<PhotoAlbum>> filePhotoAlbumArray; 95 std::vector<std::unique_ptr<SmartAlbumAsset>> fileSmartAlbumArray; 96 }; 97 } // namespace Media 98 } // namespace OHOS 99 100 #endif // FRAMEWORKS_ANI_SRC_INCLUDE_FETCH_RESULT_ANI_H