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