1 /* 2 * Copyright (c) 2021 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_BASE_RESOURCE_ASSET_MANAGER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_BASE_RESOURCE_ASSET_MANAGER_H 18 19 #include <vector> 20 21 #include "base/memory/ace_type.h" 22 #include "base/memory/referenced.h" 23 24 namespace OHOS::Ace { 25 struct MediaFileInfo { 26 std::string fileName; 27 uint32_t offset = 0; 28 uint32_t length = 0; 29 uint16_t lastModTime = 0; 30 uint16_t lastModDate = 0; 31 }; 32 33 class Asset : public Referenced { 34 public: 35 ~Asset() override = default; 36 37 virtual size_t GetSize() const = 0; 38 virtual const uint8_t* GetData() const = 0; 39 }; 40 41 class AssetProvider : public AceType { 42 DECLARE_ACE_TYPE(AssetProvider, AceType); 43 44 public: 45 virtual std::string GetAssetPath(const std::string& assetName, bool isAddHapPath) = 0; 46 47 virtual void GetAssetList(const std::string& path, std::vector<std::string>& assetList) = 0; 48 49 virtual bool IsValid() const = 0; 50 GetFileInfo(const std::string &,MediaFileInfo &)51 virtual bool GetFileInfo(const std::string& /* fileName */, MediaFileInfo& /* fileInfo */) const 52 { 53 return false; 54 } 55 Reload()56 virtual void Reload() {} 57 }; 58 59 class AssetManager : public AceType { 60 DECLARE_ACE_TYPE(AssetManager, AceType); 61 62 public: 63 ~AssetManager() override = default; 64 65 virtual void PushFront(RefPtr<AssetProvider> provider) = 0; 66 67 virtual void PushBack(RefPtr<AssetProvider> provider) = 0; 68 69 virtual RefPtr<Asset> GetAsset(const std::string& assetName) = 0; 70 71 virtual std::vector<RefPtr<Asset>> GetAssetFromI18n(const std::string& assetName) = 0; 72 73 virtual std::string GetAssetPath(const std::string& assetName, bool isAddHapPath) = 0; 74 75 virtual void SetLibPath(const std::string& appLibPathKey, const std::vector<std::string>& packagePath) = 0; 76 77 virtual std::vector<std::string> GetLibPath() const = 0; 78 79 virtual std::string GetAppLibPathKey() const = 0; 80 81 virtual void GetAssetList(const std::string& path, std::vector<std::string>& assetList) const = 0; 82 83 virtual bool GetFileInfo(const std::string& fileName, MediaFileInfo& fileInfo) const = 0; 84 }; 85 } // namespace OHOS::Ace 86 #endif // FOUNDATION_ACE_FRAMEWORKS_BASE_RESOURCE_ASSET_MANAGER_H 87