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