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 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_ASSET_MANAGER_IMPL_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_ASSET_MANAGER_IMPL_H 18 19 #include <deque> 20 #include <vector> 21 #include <memory> 22 #include <mutex> 23 24 #include "base/memory/ace_type.h" 25 #include "base/resource/asset_manager.h" 26 #include "base/utils/macros.h" 27 #include "core/common/asset_mapping.h" 28 29 namespace OHOS::Ace { 30 class AssetImpl final : public Asset { 31 public: AssetImpl(std::unique_ptr<AssetMapping> mapping)32 AssetImpl(std::unique_ptr<AssetMapping> mapping) : assetMapping_(std::move(mapping)) {}; 33 ~AssetImpl() override = default; 34 size_t GetSize() const override; 35 const uint8_t* GetData() const override; 36 37 private: 38 std::unique_ptr<AssetMapping> assetMapping_; 39 }; 40 41 class AssetProviderImpl : public AssetProvider { 42 DECLARE_ACE_TYPE(AssetProviderImpl, AssetProvider); 43 44 public: 45 virtual std::unique_ptr<AssetMapping> GetAsMapping(const std::string& assetName) const = 0; 46 virtual std::vector<std::unique_ptr<AssetMapping>> GetAsMappingFromI18n(const std::string& assetName) const = 0; 47 }; 48 49 class ACE_EXPORT AssetManagerImpl final : public AssetManager { 50 DECLARE_ACE_TYPE(AssetManagerImpl, AssetManager); 51 52 public: 53 AssetManagerImpl() = default; 54 ~AssetManagerImpl() override = default; 55 void PushFront(RefPtr<AssetProvider> provider) override; 56 void PushBack(RefPtr<AssetProvider> provider) override; 57 RefPtr<Asset> GetAsset(const std::string& assetName) override; 58 std::vector<RefPtr<Asset>> GetAssetFromI18n(const std::string& assetName) override; 59 std::string GetAssetPath(const std::string& assetName, bool isAddHapPath) override; 60 void SetLibPath(const std::string& appLibPathKey, const std::vector<std::string>& packagePath) override; 61 std::vector<std::string> GetLibPath() const override; 62 std::string GetAppLibPathKey() const override; 63 void GetAssetList(const std::string& path, std::vector<std::string>& assetList) const override; 64 bool GetFileInfo(const std::string& fileName, MediaFileInfo& fileInfo) const override; 65 void ReloadProvider(); 66 67 private: 68 std::vector<std::string> libPath_; 69 std::string libKey_; 70 std::deque<RefPtr<AssetProvider>> assetProviders_; 71 }; 72 } // namespace OHOS::Ace 73 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_ASSET_MANAGER_IMPL_H 74