• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef OHOS_RESOURCE_MANAGER_RESOURCEMANAGER_H
16 #define OHOS_RESOURCE_MANAGER_RESOURCEMANAGER_H
17 
18 #include <map>
19 #include <string>
20 #include <vector>
21 #include <memory>
22 #include "res_config.h"
23 
24 namespace OHOS {
25 namespace Global {
26 namespace Resource {
27 class ResourceManager {
28 public:
29 
30     typedef struct {
31         /** the raw file fd */
32         int fd;
33 
34         /** the offset from where the raw file starts in the HAP */
35         long offset;
36 
37         /** the length of the raw file in the HAP. */
38         long length;
39     } RawFileDescriptor;
40 
41     struct RawFile {
42         /** the offset from where the raw file starts in the HAP */
43         long offset;
44 
45         /** the length of the raw file in the HAP. */
46         long length;
47 
48         FILE *pf;
49 
50         std::unique_ptr<uint8_t[]> buffer;
51     };
52 
53     struct Resource {
54         /** the hap bundle name */
55         std::string bundleName;
56 
57         /** the hap module name */
58         std::string moduleName;
59 
60         /** the resource id in hap */
61         int32_t id;
62     };
63 
64     virtual ~ResourceManager() = 0;
65 
66     virtual bool AddResource(const char *path) = 0;
67 
68     virtual RState UpdateResConfig(ResConfig &resConfig) = 0;
69 
70     virtual void GetResConfig(ResConfig &resConfig) = 0;
71 
72     virtual RState GetStringById(uint32_t id, std::string &outValue) = 0;
73 
74     virtual RState GetStringByName(const char *name, std::string &outValue) = 0;
75 
76     virtual RState GetStringFormatById(std::string &outValue, uint32_t id, ...) = 0;
77 
78     virtual RState GetStringFormatByName(std::string &outValue, const char *name, ...) = 0;
79 
80     virtual RState GetStringArrayById(uint32_t id, std::vector<std::string> &outValue) = 0;
81 
82     virtual RState GetStringArrayByName(const char *name, std::vector<std::string> &outValue) = 0;
83 
84     virtual RState GetPatternById(uint32_t id, std::map<std::string, std::string> &outValue) = 0;
85 
86     virtual RState GetPatternByName(const char *name, std::map<std::string, std::string> &outValue) = 0;
87 
88     virtual RState GetPluralStringById(uint32_t id, int quantity, std::string &outValue) = 0;
89 
90     virtual RState GetPluralStringByName(const char *name, int quantity, std::string &outValue) = 0;
91 
92     virtual RState GetPluralStringByIdFormat(std::string &outValue, uint32_t id, int quantity, ...) = 0;
93 
94     virtual RState GetPluralStringByNameFormat(std::string &outValue, const char *name, int quantity, ...) = 0;
95 
96     virtual RState GetThemeById(uint32_t id, std::map<std::string, std::string> &outValue) = 0;
97 
98     virtual RState GetThemeByName(const char *name, std::map<std::string, std::string> &outValue) = 0;
99 
100     virtual RState GetBooleanById(uint32_t id, bool &outValue) = 0;
101 
102     virtual RState GetBooleanByName(const char *name, bool &outValue) = 0;
103 
104     virtual RState GetIntegerById(uint32_t id, int &outValue) = 0;
105 
106     virtual RState GetIntegerByName(const char *name, int &outValue) = 0;
107 
108     virtual RState GetFloatById(uint32_t id, float &outValue) = 0;
109 
110     virtual RState GetFloatById(uint32_t id, float &outValue, std::string &unit) = 0;
111 
112     virtual RState GetFloatByName(const char *name, float &outValue) = 0;
113 
114     virtual RState GetFloatByName(const char *name, float &outValue, std::string &unit) = 0;
115 
116     virtual RState GetIntArrayById(uint32_t id, std::vector<int> &outValue) = 0;
117 
118     virtual RState GetIntArrayByName(const char *name, std::vector<int> &outValue) = 0;
119 
120     virtual RState GetColorById(uint32_t id, uint32_t &outValue) = 0;
121 
122     virtual RState GetColorByName(const char *name, uint32_t &outValue) = 0;
123 
124     virtual RState GetProfileById(uint32_t id, std::string &outValue) = 0;
125 
126     virtual RState GetProfileByName(const char *name, std::string &outValue) = 0;
127 
128     virtual RState GetMediaById(uint32_t id, std::string &outValue) = 0;
129 
130     virtual RState GetMediaById(uint32_t id, uint32_t density, std::string &outValue) = 0;
131 
132     virtual RState GetMediaByName(const char *name, std::string &outValue) = 0;
133 
134     virtual RState GetMediaByName(const char *name, uint32_t density, std::string &outValue) = 0;
135 
136     virtual RState GetRawFilePathByName(const std::string &name, std::string &outValue) = 0;
137 
138     virtual RState GetRawFileDescriptor(const std::string &name, RawFileDescriptor &descriptor) = 0;
139 
140     virtual RState CloseRawFileDescriptor(const std::string &name) = 0;
141 
142     virtual RState GetMediaBase64ByNameData(const char *name, uint32_t density, std::string &base64Data) = 0;
143 
144     virtual RState GetMediaBase64ByIdData(uint32_t id, uint32_t density, std::string &base64Data) = 0;
145 
146     virtual RState GetMediaDataById(uint32_t id, size_t& len, std::unique_ptr<uint8_t[]> &outValue) = 0;
147 
148     virtual RState GetMediaDataByName(const char *name, size_t& len, std::unique_ptr<uint8_t[]> &outValue) = 0;
149 
150     virtual RState GetMediaDataById(uint32_t id, uint32_t density, size_t& len,
151         std::unique_ptr<uint8_t[]> &outValue) = 0;
152 
153     virtual RState GetMediaDataByName(const char *name, uint32_t density, size_t& len,
154         std::unique_ptr<uint8_t[]> &outValue) = 0;
155 
156     virtual RState GetMediaBase64DataById(uint32_t id,  std::string &outValue) = 0;
157 
158     virtual RState GetMediaBase64DataByName(const char *name,  std::string &outValue) = 0;
159 
160     virtual RState GetMediaBase64DataById(uint32_t id, uint32_t density, std::string &outValue) = 0;
161 
162     virtual RState GetMediaBase64DataByName(const char *name, uint32_t density, std::string &outValue) = 0;
163 
164     virtual RState GetProfileDataById(uint32_t id, size_t &len, std::unique_ptr<uint8_t[]> &outValue) = 0;
165 
166     virtual RState GetProfileDataByName(const char *name, size_t &len, std::unique_ptr<uint8_t[]> &outValue) = 0;
167 
168     virtual RState GetRawFileFromHap(const std::string &rawFileName, std::unique_ptr<RawFile> &rawFile) = 0;
169 
170     virtual RState GetRawFileDescriptorFromHap(const std::string &rawFileName, RawFileDescriptor &descriptor) = 0;
171 
172     virtual RState IsLoadHap() = 0;
173 };
174 
175 EXPORT_FUNC ResourceManager *CreateResourceManager();
176 } // namespace Resource
177 } // namespace Global
178 } // namespace OHOS
179 #endif